From 5adea8f032ad9809f0b06d447f5e0d4b55d7e6d6 Mon Sep 17 00:00:00 2001 From: vdwalts Date: Mon, 1 Aug 2016 21:57:32 +0100 Subject: [PATCH] FEM: constraints thermomechanical: object implementation --- src/Mod/Fem/App/AppFem.cpp | 6 + src/Mod/Fem/App/CMakeLists.txt | 6 + src/Mod/Fem/App/FemConstraintHeatflux.cpp | 85 ++++ src/Mod/Fem/App/FemConstraintHeatflux.h | 59 +++ .../App/FemConstraintInitialTemperature.cpp | 84 ++++ .../Fem/App/FemConstraintInitialTemperature.h | 65 +++ src/Mod/Fem/App/FemConstraintTemperature.cpp | 84 ++++ src/Mod/Fem/App/FemConstraintTemperature.h | 65 +++ src/Mod/Fem/Gui/AppFemGui.cpp | 6 + src/Mod/Fem/Gui/CMakeLists.txt | 21 + src/Mod/Fem/Gui/Command.cpp | 132 ++++++ src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp | 403 ++++++++++++++++++ src/Mod/Fem/Gui/TaskFemConstraintHeatflux.h | 90 ++++ src/Mod/Fem/Gui/TaskFemConstraintHeatflux.ui | 98 +++++ .../TaskFemConstraintInitialTemperature.cpp | 163 +++++++ .../Gui/TaskFemConstraintInitialTemperature.h | 78 ++++ .../TaskFemConstraintInitialTemperature.ui | 48 +++ .../Fem/Gui/TaskFemConstraintTemperature.cpp | 323 ++++++++++++++ .../Fem/Gui/TaskFemConstraintTemperature.h | 86 ++++ .../Fem/Gui/TaskFemConstraintTemperature.ui | 77 ++++ .../Fem/Gui/TaskPanelConstraintTemperature.ui | 110 +++++ .../Fem/Gui/TaskPanelInitialTemperature.ui | 78 ++++ .../Gui/ViewProviderFemConstraintHeatflux.cpp | 194 +++++++++ .../Gui/ViewProviderFemConstraintHeatflux.h | 48 +++ ...roviderFemConstraintInitialTemperature.cpp | 104 +++++ ...wProviderFemConstraintInitialTemperature.h | 48 +++ .../ViewProviderFemConstraintTemperature.cpp | 184 ++++++++ .../ViewProviderFemConstraintTemperature.h | 48 +++ src/Mod/Fem/Gui/Workbench.cpp | 8 + 29 files changed, 2801 insertions(+) create mode 100644 src/Mod/Fem/App/FemConstraintHeatflux.cpp create mode 100644 src/Mod/Fem/App/FemConstraintHeatflux.h create mode 100644 src/Mod/Fem/App/FemConstraintInitialTemperature.cpp create mode 100644 src/Mod/Fem/App/FemConstraintInitialTemperature.h create mode 100644 src/Mod/Fem/App/FemConstraintTemperature.cpp create mode 100644 src/Mod/Fem/App/FemConstraintTemperature.h create mode 100644 src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp create mode 100644 src/Mod/Fem/Gui/TaskFemConstraintHeatflux.h create mode 100644 src/Mod/Fem/Gui/TaskFemConstraintHeatflux.ui create mode 100644 src/Mod/Fem/Gui/TaskFemConstraintInitialTemperature.cpp create mode 100644 src/Mod/Fem/Gui/TaskFemConstraintInitialTemperature.h create mode 100644 src/Mod/Fem/Gui/TaskFemConstraintInitialTemperature.ui create mode 100644 src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp create mode 100644 src/Mod/Fem/Gui/TaskFemConstraintTemperature.h create mode 100644 src/Mod/Fem/Gui/TaskFemConstraintTemperature.ui create mode 100644 src/Mod/Fem/Gui/TaskPanelConstraintTemperature.ui create mode 100644 src/Mod/Fem/Gui/TaskPanelInitialTemperature.ui create mode 100644 src/Mod/Fem/Gui/ViewProviderFemConstraintHeatflux.cpp create mode 100644 src/Mod/Fem/Gui/ViewProviderFemConstraintHeatflux.h create mode 100644 src/Mod/Fem/Gui/ViewProviderFemConstraintInitialTemperature.cpp create mode 100644 src/Mod/Fem/Gui/ViewProviderFemConstraintInitialTemperature.h create mode 100644 src/Mod/Fem/Gui/ViewProviderFemConstraintTemperature.cpp create mode 100644 src/Mod/Fem/Gui/ViewProviderFemConstraintTemperature.h diff --git a/src/Mod/Fem/App/AppFem.cpp b/src/Mod/Fem/App/AppFem.cpp index 2929d8eaf..1ce09fc7c 100644 --- a/src/Mod/Fem/App/AppFem.cpp +++ b/src/Mod/Fem/App/AppFem.cpp @@ -51,6 +51,9 @@ #include "FemConstraintGear.h" #include "FemConstraintPulley.h" #include "FemConstraintDisplacement.h" +#include "FemConstraintTemperature.h" +#include "FemConstraintHeatflux.h" +#include "FemConstraintInitialTemperature.h" #include "FemConstraintPlaneRotation.h" #include "FemConstraintContact.h" @@ -149,6 +152,9 @@ PyMODINIT_FUNC initFem() Fem::ConstraintGear ::init(); Fem::ConstraintPulley ::init(); Fem::ConstraintDisplacement ::init(); + Fem::ConstraintTemperature ::init(); + Fem::ConstraintHeatflux ::init(); + Fem::ConstraintInitialTemperature ::init(); Fem::ConstraintPlaneRotation ::init(); Fem::ConstraintContact ::init(); diff --git a/src/Mod/Fem/App/CMakeLists.txt b/src/Mod/Fem/App/CMakeLists.txt index 770af3c8c..6d67bf563 100755 --- a/src/Mod/Fem/App/CMakeLists.txt +++ b/src/Mod/Fem/App/CMakeLists.txt @@ -200,6 +200,12 @@ SET(FemConstraints_SRCS FemConstraintPulley.h FemConstraintDisplacement.h FemConstraintDisplacement.cpp + FemConstraintTemperature.h + FemConstraintTemperature.cpp + FemConstraintHeatflux.h + FemConstraintHeatflux.cpp + FemConstraintInitialTemperature.h + FemConstraintInitialTemperature.cpp FemConstraintPlaneRotation.cpp FemConstraintPlaneRotation.h FemConstraintContact.cpp diff --git a/src/Mod/Fem/App/FemConstraintHeatflux.cpp b/src/Mod/Fem/App/FemConstraintHeatflux.cpp new file mode 100644 index 000000000..6eaa7c792 --- /dev/null +++ b/src/Mod/Fem/App/FemConstraintHeatflux.cpp @@ -0,0 +1,85 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Authors: Michael Hindley * + * Ruan Olwagen * + * Oswald van Ginkel * + * 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 +#include +#include +#include +#include +#include +#include +#endif + +#include "FemConstraintHeatflux.h" + +using namespace Fem; + +PROPERTY_SOURCE(Fem::ConstraintHeatflux, Fem::Constraint); + +ConstraintHeatflux::ConstraintHeatflux() +{ + ADD_PROPERTY(AmbientTemp,(0.0)); + /*ADD_PROPERTY(FaceTemp,(0.0));*/ + ADD_PROPERTY(FilmCoef,(0.0)); + + ADD_PROPERTY_TYPE(Points,(Base::Vector3d()),"ConstraintHeatflux",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), + "Points where symbols are drawn"); + ADD_PROPERTY_TYPE(Normals,(Base::Vector3d()),"ConstraintHeatflux",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), + "Normals where symbols are drawn"); + Points.setValues(std::vector()); + Normals.setValues(std::vector()); +} + +App::DocumentObjectExecReturn *ConstraintHeatflux::execute(void) +{ + return Constraint::execute(); +} + +const char* ConstraintHeatflux::getViewProviderName(void) const +{ + return "FemGui::ViewProviderFemConstraintHeatflux"; +} + +void ConstraintHeatflux::onChanged(const App::Property* prop) +{ + // Note: If we call this at the end, then the arrows are not oriented correctly initially + // because the NormalDirection has not been calculated yet + Constraint::onChanged(prop); + + if (prop == &References) { + std::vector points; + std::vector normals; + int scale = 1; //OvG: Enforce use of scale + if (getPoints(points, normals, &scale)) { + Points.setValues(points); + Normals.setValues(normals); + Scale.setValue(scale); //OvG: Scale + Points.touch(); // This triggers ViewProvider::updateData() + } + } +} diff --git a/src/Mod/Fem/App/FemConstraintHeatflux.h b/src/Mod/Fem/App/FemConstraintHeatflux.h new file mode 100644 index 000000000..4d74f4bcd --- /dev/null +++ b/src/Mod/Fem/App/FemConstraintHeatflux.h @@ -0,0 +1,59 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Authors: Michael Hindley * + * Ruan Olwagen * + * Oswald van Ginkel * + * Based on Force constraint by Jan Rheinländer * + * 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 FEM_CONSTRAINTHEATFLUX_H +#define FEM_CONSTRAINTHEATFLUX_H + +#include "FemConstraint.h" + +namespace Fem { + +class AppFemExport ConstraintHeatflux : public Fem::Constraint +{ + PROPERTY_HEADER(Fem::ConstraintHeatflux); + +public: + ConstraintHeatflux(void); + + App::PropertyFloat AmbientTemp; + /*App::PropertyFloat FaceTemp;*/ + App::PropertyFloat FilmCoef; + App::PropertyVectorList Points; + App::PropertyVectorList Normals; + + /// recalculate the object + virtual App::DocumentObjectExecReturn *execute(void); + + /// returns the type name of the ViewProvider + const char* getViewProviderName(void) const; + +protected: + virtual void onChanged(const App::Property* prop); +}; + +} + +#endif // FEM_CONSTRAINTHEATFLUX_H diff --git a/src/Mod/Fem/App/FemConstraintInitialTemperature.cpp b/src/Mod/Fem/App/FemConstraintInitialTemperature.cpp new file mode 100644 index 000000000..e45d51710 --- /dev/null +++ b/src/Mod/Fem/App/FemConstraintInitialTemperature.cpp @@ -0,0 +1,84 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Authors: Michael Hindley * + * Ruan Olwagen * + * Oswald van Ginkel * + * Based on Force constraint by Jan Rheinländer * + * 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 +#include +#include +#include +#include +#include +#include +#endif + +#include "FemConstraintInitialTemperature.h" + +using namespace Fem; + +PROPERTY_SOURCE(Fem::ConstraintInitialTemperature, Fem::Constraint); + +ConstraintInitialTemperature::ConstraintInitialTemperature() +{ + ADD_PROPERTY(initialTemperature,(300.0)); + + ADD_PROPERTY_TYPE(Points,(Base::Vector3d()),"ConstraintInitialTemperature",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), + "Points where symbols are drawn"); + ADD_PROPERTY_TYPE(Normals,(Base::Vector3d()),"ConstraintInitialTemperature",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), + "Normals where symbols are drawn"); + Points.setValues(std::vector()); + Normals.setValues(std::vector()); +} + +App::DocumentObjectExecReturn *ConstraintInitialTemperature::execute(void) +{ + return Constraint::execute(); +} + +const char* ConstraintInitialTemperature::getViewProviderName(void) const +{ + return "FemGui::ViewProviderFemConstraintInitialTemperature"; +} + +void ConstraintInitialTemperature::onChanged(const App::Property* prop) +{ + // Note: If we call this at the end, then the arrows are not oriented correctly initially + // because the NormalDirection has not been calculated yet + Constraint::onChanged(prop); + + if (prop == &References) { + std::vector points; + std::vector normals; + int scale = 1; //OvG: Enforce use of scale + if (getPoints(points, normals, &scale)) { + Points.setValues(points); + Normals.setValues(normals); + Scale.setValue(scale); //OvG: Scale + Points.touch(); // This triggers ViewProvider::updateData() + } + } +} diff --git a/src/Mod/Fem/App/FemConstraintInitialTemperature.h b/src/Mod/Fem/App/FemConstraintInitialTemperature.h new file mode 100644 index 000000000..f27144496 --- /dev/null +++ b/src/Mod/Fem/App/FemConstraintInitialTemperature.h @@ -0,0 +1,65 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Authors: Michael Hindley * + * Ruan Olwagen * + * Oswald van Ginkel * + * Based on Force constraint by Jan Rheinländer * + * 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 FEM_CONSTRAINTINITIALTEMPERATURE_H +#define FEM_CONSTRAINTINITIALTEMPERATURE_H + +#include "FemConstraint.h" + +namespace Fem +{ + +class AppFemExport ConstraintInitialTemperature : public Fem::Constraint +{ + PROPERTY_HEADER(Fem::ConstraintInitialTemperature); + +public: + /// Constructor + ConstraintInitialTemperature(void); + + // Read-only (calculated values). These trigger changes in the ViewProvider + App::PropertyVectorList Points; + App::PropertyVectorList Normals; + + //Temperature parameters + App::PropertyFloat initialTemperature; + + + /// recalculate the object + virtual App::DocumentObjectExecReturn *execute(void); + + /// returns the type name of the ViewProvider + const char* getViewProviderName(void) const; + +protected: + virtual void onChanged(const App::Property* prop); + +}; + +} //namespace Fem + + +#endif // FEM_CONSTRAINTINITIALTEMPERATURE_H diff --git a/src/Mod/Fem/App/FemConstraintTemperature.cpp b/src/Mod/Fem/App/FemConstraintTemperature.cpp new file mode 100644 index 000000000..477cc381b --- /dev/null +++ b/src/Mod/Fem/App/FemConstraintTemperature.cpp @@ -0,0 +1,84 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Authors: Michael Hindley * + * Ruan Olwagen * + * Oswald van Ginkel * + * Based on Force constraint by Jan Rheinländer * + * 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 +#include +#include +#include +#include +#include +#include +#endif + +#include "FemConstraintTemperature.h" + +using namespace Fem; + +PROPERTY_SOURCE(Fem::ConstraintTemperature, Fem::Constraint); + +ConstraintTemperature::ConstraintTemperature() +{ + ADD_PROPERTY(Temperature,(300.0)); + + ADD_PROPERTY_TYPE(Points,(Base::Vector3d()),"ConstraintTemperature",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), + "Points where symbols are drawn"); + ADD_PROPERTY_TYPE(Normals,(Base::Vector3d()),"ConstraintTemperature",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), + "Normals where symbols are drawn"); + Points.setValues(std::vector()); + Normals.setValues(std::vector()); +} + +App::DocumentObjectExecReturn *ConstraintTemperature::execute(void) +{ + return Constraint::execute(); +} + +const char* ConstraintTemperature::getViewProviderName(void) const +{ + return "FemGui::ViewProviderFemConstraintTemperature"; +} + +void ConstraintTemperature::onChanged(const App::Property* prop) +{ + // Note: If we call this at the end, then the arrows are not oriented correctly initially + // because the NormalDirection has not been calculated yet + Constraint::onChanged(prop); + + if (prop == &References) { + std::vector points; + std::vector normals; + int scale = 1; //OvG: Enforce use of scale + if (getPoints(points, normals, &scale)) { + Points.setValues(points); + Normals.setValues(normals); + Scale.setValue(scale); //OvG: Scale + Points.touch(); // This triggers ViewProvider::updateData() + } + } +} diff --git a/src/Mod/Fem/App/FemConstraintTemperature.h b/src/Mod/Fem/App/FemConstraintTemperature.h new file mode 100644 index 000000000..47cfad0a2 --- /dev/null +++ b/src/Mod/Fem/App/FemConstraintTemperature.h @@ -0,0 +1,65 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Authors: Michael Hindley * + * Ruan Olwagen * + * Oswald van Ginkel * + * Based on Force constraint by Jan Rheinländer * + * 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 FEM_CONSTRAINTTEMPERATURE_H +#define FEM_CONSTRAINTTEMPERATURE_H + +#include "FemConstraint.h" + +namespace Fem +{ + +class AppFemExport ConstraintTemperature : public Fem::Constraint +{ + PROPERTY_HEADER(Fem::ConstraintTemperature); + +public: + /// Constructor + ConstraintTemperature(void); + + // Read-only (calculated values). These trigger changes in the ViewProvider + App::PropertyVectorList Points; + App::PropertyVectorList Normals; + + //Temperature parameters + App::PropertyFloat Temperature; + + + /// recalculate the object + virtual App::DocumentObjectExecReturn *execute(void); + + /// returns the type name of the ViewProvider + const char* getViewProviderName(void) const; + +protected: + virtual void onChanged(const App::Property* prop); + +}; + +} //namespace Fem + + +#endif // FEM_CONSTRAINTTEMPERATURE_H diff --git a/src/Mod/Fem/Gui/AppFemGui.cpp b/src/Mod/Fem/Gui/AppFemGui.cpp index 92aa44283..06488582b 100644 --- a/src/Mod/Fem/Gui/AppFemGui.cpp +++ b/src/Mod/Fem/Gui/AppFemGui.cpp @@ -52,6 +52,9 @@ #include "ViewProviderFemConstraintGear.h" #include "ViewProviderFemConstraintPulley.h" #include "ViewProviderFemConstraintDisplacement.h" +#include "ViewProviderFemConstraintTemperature.h" +#include "ViewProviderFemConstraintHeatflux.h" +#include "ViewProviderFemConstraintInitialTemperature.h" #include "ViewProviderFemConstraintPlaneRotation.h" #include "ViewProviderFemConstraintContact.h" #include "ViewProviderResult.h" @@ -119,6 +122,9 @@ PyMODINIT_FUNC initFemGui() FemGui::ViewProviderFemConstraintGear ::init(); FemGui::ViewProviderFemConstraintPulley ::init(); FemGui::ViewProviderFemConstraintDisplacement ::init(); + FemGui::ViewProviderFemConstraintHeatflux ::init(); + FemGui::ViewProviderFemConstraintTemperature ::init(); + FemGui::ViewProviderFemConstraintInitialTemperature ::init(); FemGui::ViewProviderFemConstraintPlaneRotation::init(); FemGui::ViewProviderFemConstraintContact ::init(); FemGui::ViewProviderResult ::init(); diff --git a/src/Mod/Fem/Gui/CMakeLists.txt b/src/Mod/Fem/Gui/CMakeLists.txt index f777aee65..eb71cd23d 100755 --- a/src/Mod/Fem/Gui/CMakeLists.txt +++ b/src/Mod/Fem/Gui/CMakeLists.txt @@ -65,6 +65,9 @@ set(FemGui_MOC_HDRS TaskFemConstraintGear.h TaskFemConstraintPulley.h TaskFemConstraintDisplacement.h + TaskFemConstraintTemperature.h + TaskFemConstraintHeatflux.h + TaskFemConstraintInitialTemperature.h TaskFemConstraintPlaneRotation.h TaskFemConstraintContact.h TaskTetParameter.h @@ -94,6 +97,9 @@ set(FemGui_UIC_SRCS TaskFemConstraintForce.ui TaskFemConstraintPressure.ui TaskFemConstraintDisplacement.ui + TaskFemConstraintTemperature.ui + TaskFemConstraintHeatflux.ui + TaskFemConstraintInitialTemperature.ui TaskFemConstraintPlaneRotation.ui TaskFemConstraintContact.ui TaskTetParameter.ui @@ -144,6 +150,15 @@ SET(FemGui_DLG_SRCS TaskFemConstraintDisplacement.ui TaskFemConstraintDisplacement.cpp TaskFemConstraintDisplacement.h + TaskFemConstraintTemperature.ui + TaskFemConstraintTemperature.cpp + TaskFemConstraintTemperature.h + TaskFemConstraintHeatflux.ui + TaskFemConstraintHeatflux.cpp + TaskFemConstraintHeatflux.h + TaskFemConstraintInitialTemperature.ui + TaskFemConstraintInitialTemperature.cpp + TaskFemConstraintInitialTemperature.h TaskFemConstraintPlaneRotation.ui TaskFemConstraintPlaneRotation.cpp TaskFemConstraintPlaneRotation.h @@ -194,6 +209,12 @@ SET(FemGui_SRCS_ViewProvider ViewProviderFemConstraintPulley.h ViewProviderFemConstraintDisplacement.cpp ViewProviderFemConstraintDisplacement.h + ViewProviderFemConstraintTemperature.cpp + ViewProviderFemConstraintTemperature.h + ViewProviderFemConstraintHeatflux.cpp + ViewProviderFemConstraintHeatflux.h + ViewProviderFemConstraintInitialTemperature.cpp + ViewProviderFemConstraintInitialTemperature.h ViewProviderFemConstraintPlaneRotation.cpp ViewProviderFemConstraintPlaneRotation.h ViewProviderFemConstraintContact.cpp diff --git a/src/Mod/Fem/Gui/Command.cpp b/src/Mod/Fem/Gui/Command.cpp index a52ee34da..945ef428e 100644 --- a/src/Mod/Fem/Gui/Command.cpp +++ b/src/Mod/Fem/Gui/Command.cpp @@ -439,7 +439,50 @@ bool CmdFemConstraintContact::isActive(void) } //===================================================================================== +DEF_STD_CMD_A(CmdFemConstraintHeatflux); +CmdFemConstraintHeatflux::CmdFemConstraintHeatflux() + : Command("Fem_ConstraintHeatflux") +{ + sAppModule = "Fem"; + sGroup = QT_TR_NOOP("Fem"); + sMenuText = QT_TR_NOOP("Constraint heatflux "); + sToolTipText = QT_TR_NOOP("Creates a FEM constraint for a heatflux acting on a face"); + sWhatsThis = "Fem_ConstraintHeatflux"; + sStatusTip = sToolTipText; + sPixmap = "fem-constraint-heatflux"; +} + +void CmdFemConstraintHeatflux::activated(int iMsg) +{ + Fem::FemAnalysis *Analysis; + + if(getConstraintPrerequisits(&Analysis)) + return; + + std::string FeatName = getUniqueObjectName("FemConstraintHeatflux"); + + openCommand("Make FEM constraint heatflux on face"); + doCommand(Doc,"App.activeDocument().addObject(\"Fem::ConstraintHeatflux\",\"%s\")",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.AmbientTemp = 300.0",FeatName.c_str()); //OvG: set default not equal to 0 + doCommand(Doc,"App.activeDocument().%s.FilmCoef = 10.0",FeatName.c_str()); //OvG: set default not equal to 0 + doCommand(Doc,"App.activeDocument().%s.Scale = 1",FeatName.c_str()); //OvG: set initial scale to 1 + doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().%s]", + Analysis->getNameInDocument(),Analysis->getNameInDocument(),FeatName.c_str()); + + doCommand(Doc,"%s",gethideMeshShowPartStr().c_str()); //OvG: Hide meshes and show parts + + updateActive(); + + doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str()); +} + +bool CmdFemConstraintHeatflux::isActive(void) +{ + return FemGui::ActiveAnalysisObserver::instance()->hasActiveObject(); +} + +//===================================================================================== DEF_STD_CMD_A(CmdFemConstraintForce); CmdFemConstraintForce::CmdFemConstraintForce() @@ -655,6 +698,92 @@ bool CmdFemConstraintDisplacement::isActive(void) { return FemGui::ActiveAnalysisObserver::instance()->hasActiveObject(); } + +//===================================================================================== + +DEF_STD_CMD_A(CmdFemConstraintTemperature); + +CmdFemConstraintTemperature::CmdFemConstraintTemperature() + : Command("Fem_ConstraintTemperature") +{ + sAppModule = "Fem"; + sGroup = QT_TR_NOOP("Fem"); + sMenuText = QT_TR_NOOP("Constraint temperature "); + sToolTipText = QT_TR_NOOP("Creates a FEM constraint for a temperature acting on a face"); + sWhatsThis = "Fem_ConstraintTemperature"; + sStatusTip = sToolTipText; + sPixmap = "fem-constraint-temperature"; +} + +void CmdFemConstraintTemperature::activated(int iMsg) +{ + Fem::FemAnalysis *Analysis; + + if(getConstraintPrerequisits(&Analysis)) + return; + + std::string FeatName = getUniqueObjectName("FemConstraintTemperature"); + + openCommand("Make FEM constraint temperature on face"); + doCommand(Doc,"App.activeDocument().addObject(\"Fem::ConstraintTemperature\",\"%s\")",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Scale = 1",FeatName.c_str()); //OvG: set initial scale to 1 + doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().%s]", + Analysis->getNameInDocument(),Analysis->getNameInDocument(),FeatName.c_str()); + + doCommand(Doc,"%s",gethideMeshShowPartStr().c_str()); //OvG: Hide meshes and show parts + + updateActive(); + + doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str()); +} + +bool CmdFemConstraintTemperature::isActive(void) +{ + return FemGui::ActiveAnalysisObserver::instance()->hasActiveObject(); +} + +//===================================================================================== + +DEF_STD_CMD_A(CmdFemConstraintInitialTemperature); + +CmdFemConstraintInitialTemperature::CmdFemConstraintInitialTemperature() + : Command("Fem_ConstraintInitialTemperature") +{ + sAppModule = "Fem"; + sGroup = QT_TR_NOOP("Fem"); + sMenuText = QT_TR_NOOP("Constraint initial temperature"); + sToolTipText = QT_TR_NOOP("Creates a FEM constraint for initial temperature acting on a body"); + sWhatsThis = "Fem_ConstraintInitialTemperature"; + sStatusTip = sToolTipText; + sPixmap = "fem-constraint-InitialTemperature"; +} + +void CmdFemConstraintInitialTemperature::activated(int iMsg) +{ + Fem::FemAnalysis *Analysis; + + if(getConstraintPrerequisits(&Analysis)) + return; + + std::string FeatName = getUniqueObjectName("FemConstraintInitialTemperature"); + + openCommand("Make FEM constraint intial temperature on body"); + doCommand(Doc,"App.activeDocument().addObject(\"Fem::ConstraintInitialTemperature\",\"%s\")",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Scale = 1",FeatName.c_str()); //OvG: set initial scale to 1 + doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().%s]", + Analysis->getNameInDocument(),Analysis->getNameInDocument(),FeatName.c_str()); + + doCommand(Doc,"%s",gethideMeshShowPartStr().c_str()); //OvG: Hide meshes and show parts + + updateActive(); + + doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str()); +} + +bool CmdFemConstraintInitialTemperature::isActive(void) +{ + return FemGui::ActiveAnalysisObserver::instance()->hasActiveObject(); +} // ##################################################################################################### @@ -1229,6 +1358,9 @@ void CreateFemCommands(void) rcCmdMgr.addCommand(new CmdFemConstraintGear()); rcCmdMgr.addCommand(new CmdFemConstraintPulley()); rcCmdMgr.addCommand(new CmdFemConstraintDisplacement()); + rcCmdMgr.addCommand(new CmdFemConstraintTemperature()); + rcCmdMgr.addCommand(new CmdFemConstraintHeatflux()); + rcCmdMgr.addCommand(new CmdFemConstraintInitialTemperature()); rcCmdMgr.addCommand(new CmdFemConstraintPlaneRotation()); rcCmdMgr.addCommand(new CmdFemConstraintContact()); diff --git a/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp b/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp new file mode 100644 index 000000000..e9aabde85 --- /dev/null +++ b/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp @@ -0,0 +1,403 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Authors: Michael Hindley * + * Ruan Olwagen * + * Oswald van Ginkel * + * Based on Force constraint by Jan Rheinländer * + * 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 +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +#endif + +#include "Mod/Fem/App/FemConstraintHeatflux.h" +#include "TaskFemConstraintHeatflux.h" +#include "ui_TaskFemConstraintHeatflux.h" +#include +#include + +using namespace FemGui; +using namespace Gui; + +/* TRANSLATOR FemGui::TaskFemConstraintHeatflux */ + +TaskFemConstraintHeatflux::TaskFemConstraintHeatflux(ViewProviderFemConstraintHeatflux *ConstraintView,QWidget *parent) + : TaskFemConstraint(ConstraintView, parent, "fem-constraint-heatflux") +{ + proxy = new QWidget(this); + ui = new Ui_TaskFemConstraintHeatflux(); + ui->setupUi(proxy); + QMetaObject::connectSlotsByName(this); + + QAction* action = new QAction(tr("Delete"), ui->lw_references); + action->connect(action, SIGNAL(triggered()), this, SLOT(onReferenceDeleted())); + ui->lw_references->addAction(action); + ui->lw_references->setContextMenuPolicy(Qt::ActionsContextMenu); + + connect(ui->if_ambienttemp, SIGNAL(valueChanged(double)), + this, SLOT(onAmbientTempChanged(double))); + //connect(ui->if_facetemp, SIGNAL(valueChanged(double)), + // this, SLOT(onFaceTempChanged(double))); + connect(ui->if_filmcoef, SIGNAL(valueChanged(double)), + this, SLOT(onFilmCoefChanged(double))); + + this->groupLayout()->addWidget(proxy); + + // Temporarily prevent unnecessary feature recomputes + ui->if_ambienttemp->blockSignals(true); + //ui->if_facetemp->blockSignals(true); + ui->if_filmcoef->blockSignals(true); + ui->lw_references->blockSignals(true); + ui->btnAdd->blockSignals(true); + ui->btnRemove->blockSignals(true); + + // Get the feature data + Fem::ConstraintHeatflux* pcConstraint = static_cast(ConstraintView->getObject()); + std::vector Objects = pcConstraint->References.getValues(); + std::vector SubElements = pcConstraint->References.getSubValues(); + + // Fill data into dialog elements + ui->if_ambienttemp->setMinimum(0); + ui->if_ambienttemp->setMaximum(FLOAT_MAX); + Base::Quantity t = Base::Quantity(pcConstraint->AmbientTemp.getValue(), Base::Unit::Temperature); + ui->if_ambienttemp->setValue(t); + + ui->if_filmcoef->setMinimum(0); + ui->if_filmcoef->setMaximum(FLOAT_MAX); + Base::Quantity f = Base::Quantity(pcConstraint->FilmCoef.getValue(), Base::Unit::ThermalTransferCoefficient); + ui->if_filmcoef->setValue(f); + + ui->lw_references->clear(); + for (std::size_t i = 0; i < Objects.size(); i++) { + ui->lw_references->addItem(makeRefText(Objects[i], SubElements[i])); + } + if (Objects.size() > 0) { + ui->lw_references->setCurrentRow(0, QItemSelectionModel::ClearAndSelect); + } + + //Selection buttons + connect(ui->btnAdd, SIGNAL(clicked()), this, SLOT(addToSelection())); + connect(ui->btnRemove, SIGNAL(clicked()), this, SLOT(removeFromSelection())); + + ui->if_ambienttemp->blockSignals(false); + //ui->if_facetemp->blockSignals(false); + ui->if_filmcoef->blockSignals(false); + ui->lw_references->blockSignals(false); + ui->btnAdd->blockSignals(false); + ui->btnRemove->blockSignals(false); + + + + updateUI(); +} + +TaskFemConstraintHeatflux::~TaskFemConstraintHeatflux() +{ + delete ui; +} + +void TaskFemConstraintHeatflux::updateUI() +{ + if (ui->lw_references->model()->rowCount() == 0) { + // Go into reference selection mode if no reference has been selected yet + onButtonReference(true); + return; + } +} + +void TaskFemConstraintHeatflux::onAmbientTempChanged(double val) +{ + Fem::ConstraintHeatflux* pcConstraint = static_cast(ConstraintView->getObject()); + pcConstraint->AmbientTemp.setValue(val);//[K] +} + +/*void TaskFemConstraintHeatflux::onFaceTempChanged(double val) +{ + Fem::ConstraintHeatflux* pcConstraint = static_cast(ConstraintView->getObject()); + pcConstraint->FaceTemp.setValue(val); //[K] +}*/ + +void TaskFemConstraintHeatflux::onFilmCoefChanged(double val) +{ + Fem::ConstraintHeatflux* pcConstraint = static_cast(ConstraintView->getObject()); + pcConstraint->FilmCoef.setValue(val); // [W]/[[m^2]/[K]] +} + +void TaskFemConstraintHeatflux::addToSelection() +{ + std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document + if (selection.size()==0){ + QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); + return; + } + + Fem::ConstraintHeatflux* pcConstraint = static_cast(ConstraintView->getObject()); + std::vector Objects = pcConstraint->References.getValues(); + std::vector SubElements = pcConstraint->References.getSubValues(); + + for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object + if (static_cast(it->getTypeName()).substr(0,4).compare(std::string("Part"))!=0){ + QMessageBox::warning(this, tr("Selection error"),tr("Selected object is not a part!")); + return; + } + + std::vector subNames=it->getSubNames(); + + if (subNames.size()>0){ + for (unsigned int subIt=0;subIt<(subNames.size());++subIt){ + if (subNames[subIt].substr(0,4).compare(std::string("Face"))!=0){ + QMessageBox::warning(this, tr("Selection error"),tr("Selection must only consist of faces!")); + return; + } + } + } + else{ + //fix me, if an object is selected completely, getSelectionEx does not return any SubElements + } + + App::DocumentObject* obj = ConstraintView->getObject()->getDocument()->getObject(it->getFeatName()); + for (unsigned int subIt=0;subIt<(subNames.size());++subIt){// for every selected sub element + bool addMe=true; + for (std::vector::iterator itr=std::find(SubElements.begin(),SubElements.end(),subNames[subIt]); + itr!= SubElements.end(); + itr = std::find(++itr,SubElements.end(),subNames[subIt])) + {// for every sub element in selection that matches one in old list + if (obj==Objects[std::distance(SubElements.begin(),itr)]){//if selected sub element's object equals the one in old list then it was added before so don't add + addMe=false; + } + } + if (addMe){ + disconnect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), + this, SLOT(setSelection(QListWidgetItem*))); + Objects.push_back(obj); + SubElements.push_back(subNames[subIt]); + ui->lw_references->addItem(makeRefText(obj, subNames[subIt])); + connect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), + this, SLOT(setSelection(QListWidgetItem*))); + } + } + } + //Update UI + pcConstraint->References.setValues(Objects,SubElements); + updateUI(); +} + +void TaskFemConstraintHeatflux::removeFromSelection() +{ + std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document + if (selection.size()==0){ + QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); + return; + } + + Fem::ConstraintHeatflux* pcConstraint = static_cast(ConstraintView->getObject()); + std::vector Objects = pcConstraint->References.getValues(); + std::vector SubElements = pcConstraint->References.getSubValues(); + std::vector itemsToDel; + for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object + if (static_cast(it->getTypeName()).substr(0,4).compare(std::string("Part"))!=0){ + QMessageBox::warning(this, tr("Selection error"),tr("Selected object is not a part!")); + return; + } + + std::vector subNames=it->getSubNames(); + + if (subNames.size()>0){ + for (unsigned int subIt=0;subIt<(subNames.size());++subIt){ + if (subNames[subIt].substr(0,4).compare(std::string("Face"))!=0){ + QMessageBox::warning(this, tr("Selection error"),tr("Selection must only consist of faces!")); + return; + } + } + } + else{ + //fix me, if an object is selected completely, getSelectionEx does not return any SubElements + } + + App::DocumentObject* obj = ConstraintView->getObject()->getDocument()->getObject(it->getFeatName()); + + for (unsigned int subIt=0;subIt<(subNames.size());++subIt){// for every selected sub element + for (std::vector::iterator itr=std::find(SubElements.begin(),SubElements.end(),subNames[subIt]); + itr!= SubElements.end(); + itr = std::find(++itr,SubElements.end(),subNames[subIt])) + {// for every sub element in selection that matches one in old list + if (obj==Objects[std::distance(SubElements.begin(),itr)]){//if selected sub element's object equals the one in old list then it was added before so mark for deletion + itemsToDel.push_back(std::distance(SubElements.begin(),itr)); + } + } + } + } + + std::sort(itemsToDel.begin(),itemsToDel.end()); + while (itemsToDel.size()>0){ + Objects.erase(Objects.begin()+itemsToDel.back()); + SubElements.erase(SubElements.begin()+itemsToDel.back()); + itemsToDel.pop_back(); + } + //Update UI + disconnect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), + this, SLOT(setSelection(QListWidgetItem*))); + + ui->lw_references->clear(); + for (unsigned int j=0;jlw_references->addItem(makeRefText(Objects[j], SubElements[j])); + } + connect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), + this, SLOT(setSelection(QListWidgetItem*))); + + pcConstraint->References.setValues(Objects,SubElements); + updateUI(); +} + + +void TaskFemConstraintHeatflux::setSelection(QListWidgetItem* item){ + std::string docName=ConstraintView->getObject()->getDocument()->getName(); + + std::string s = item->text().toStdString(); + std::string delimiter = ":"; + + size_t pos = 0; + std::string objName; + std::string subName; + pos = s.find(delimiter); + objName = s.substr(0, pos); + s.erase(0, pos + delimiter.length()); + subName=s; + + Gui::Selection().clearSelection(); + Gui::Selection().addSelection(docName.c_str(),objName.c_str(),subName.c_str(),0,0,0); +} + +void TaskFemConstraintHeatflux::onReferenceDeleted() { + TaskFemConstraintHeatflux::removeFromSelection(); +} + +const std::string TaskFemConstraintHeatflux::getReferences() const +{ + int rows = ui->lw_references->model()->rowCount(); + std::vector items; + for (int r = 0; r < rows; r++) { + items.push_back(ui->lw_references->item(r)->text().toStdString()); + } + return TaskFemConstraint::getReferences(items); +} + +double TaskFemConstraintHeatflux::getAmbientTemp(void) const +{ + Base::Quantity temperature = ui->if_ambienttemp->getQuantity(); + double temperature_in_kelvin = temperature.getValueAs(Base::Quantity::Kelvin); + return temperature_in_kelvin; +} + +double TaskFemConstraintHeatflux::getFilmCoef(void) const +{ + Base::Quantity filmcoef = ui->if_filmcoef->getQuantity(); + double filmcoef_in_units = filmcoef.getValueAs(Base::Quantity(1.0,Base::Unit::ThermalTransferCoefficient)); + return filmcoef_in_units; +} + +void TaskFemConstraintHeatflux::changeEvent(QEvent *e) +{ + TaskBox::changeEvent(e); + if (e->type() == QEvent::LanguageChange) { + ui->if_ambienttemp->blockSignals(true); + ui->if_filmcoef->blockSignals(true); + ui->retranslateUi(proxy); + ui->if_ambienttemp->blockSignals(false); + ui->if_filmcoef->blockSignals(false); + } +} + +//************************************************************************** +// TaskDialog +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +TaskDlgFemConstraintHeatflux::TaskDlgFemConstraintHeatflux(ViewProviderFemConstraintHeatflux *ConstraintView) +{ + this->ConstraintView = ConstraintView; + assert(ConstraintView); + this->parameter = new TaskFemConstraintHeatflux(ConstraintView);; + + Content.push_back(parameter); +} + +//==== calls from the TaskView =============================================================== + +void TaskDlgFemConstraintHeatflux::open() +{ + // a transaction is already open at creation time of the panel + if (!Gui::Command::hasPendingCommand()) { + QString msg = QObject::tr("Constraint heat flux"); + Gui::Command::openCommand((const char*)msg.toUtf8()); + ConstraintView->setVisible(true); + Gui::Command::doCommand(Gui::Command::Doc,ViewProviderFemConstraint::gethideMeshShowPartStr((static_cast(ConstraintView->getObject()))->getNameInDocument()).c_str()); //OvG: Hide meshes and show parts + } +} + +bool TaskDlgFemConstraintHeatflux::accept() +{ + std::string name = ConstraintView->getObject()->getNameInDocument(); + const TaskFemConstraintHeatflux* parameterHeatflux = static_cast(parameter); + std::string scale = "1"; + + try { + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.AmbientTemp = %f", + name.c_str(), parameterHeatflux->getAmbientTemp()); + /*Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.FaceTemp = %f", + name.c_str(), parameterHeatflux->getFaceTemp());*/ + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.FilmCoef = %f", + name.c_str(), parameterHeatflux->getFilmCoef()); + + scale = parameterHeatflux->getScale(); //OvG: determine modified scale + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Scale = %s", + name.c_str(), scale.c_str()); //OvG: implement modified scale + } + catch (const Base::Exception& e) { + QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what())); + return false; + } + + return TaskDlgFemConstraint::accept(); +} + +bool TaskDlgFemConstraintHeatflux::reject() +{ + Gui::Command::abortCommand(); + Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); + Gui::Command::updateActive(); + + return true; +} + +#include "moc_TaskFemConstraintHeatflux.cpp" diff --git a/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.h b/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.h new file mode 100644 index 000000000..cbc27c4b8 --- /dev/null +++ b/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.h @@ -0,0 +1,90 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Authors: Michael Hindley * + * Ruan Olwagen * + * Oswald van Ginkel * + * Based on Force constraint by Jan Rheinländer * + * 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 GUI_TASKVIEW_TaskFemConstraintHeatflux_H +#define GUI_TASKVIEW_TaskFemConstraintHeatflux_H + +#include +#include +#include +#include + +#include "TaskFemConstraint.h" +#include "ViewProviderFemConstraintHeatflux.h" + +#include +#include +#include +#include + +class Ui_TaskFemConstraintHeatflux; + +namespace FemGui { +class TaskFemConstraintHeatflux : public TaskFemConstraint +{ + Q_OBJECT + +public: + TaskFemConstraintHeatflux(ViewProviderFemConstraintHeatflux *ConstraintView,QWidget *parent = 0); + virtual ~TaskFemConstraintHeatflux(); + double getAmbientTemp(void) const; + /*double getFaceTemp(void) const;*/ + double getFilmCoef(void) const; + virtual const std::string getReferences() const; + +private Q_SLOTS: + void onReferenceDeleted(void); + void onAmbientTempChanged(double val); + /*void onFaceTempChanged(double val);*/ + void onFilmCoefChanged(double val); + + void addToSelection(); + void removeFromSelection(); + void setSelection(QListWidgetItem* item); + +protected: + virtual void changeEvent(QEvent *e); + +private: + //void onSelectionChanged(const Gui::SelectionChanges& msg); + void updateUI(); + Ui_TaskFemConstraintHeatflux* ui; +}; + +class TaskDlgFemConstraintHeatflux : public TaskDlgFemConstraint +{ + Q_OBJECT + +public: + TaskDlgFemConstraintHeatflux(ViewProviderFemConstraintHeatflux *ConstraintView); + virtual void open(); + virtual bool accept(); + virtual bool reject(); +}; + +} //namespace FemGui + +#endif // GUI_TASKVIEW_TaskFemConstraintHeatflux_H diff --git a/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.ui b/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.ui new file mode 100644 index 000000000..28feb3078 --- /dev/null +++ b/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.ui @@ -0,0 +1,98 @@ + + + TaskFemConstraintHeatflux + + + + 0 + 0 + 379 + 400 + + + + TaskFemConstraintHeatflux + + + + + + Select multiple face(s), click Add or Remove: + + + + + + + + + Add + + + + + + + Remove + + + + + + + + + + + + + + Ambient Temperature + + + + + + + 300 K + + + K + + + + + + + + + + + Film coefficient + + + + + + + 1 W/m^2/K + + + W/m^2/K + + + + + + + + + + Gui::InputField + QLineEdit +
Gui/InputField.h
+
+
+ + +
diff --git a/src/Mod/Fem/Gui/TaskFemConstraintInitialTemperature.cpp b/src/Mod/Fem/Gui/TaskFemConstraintInitialTemperature.cpp new file mode 100644 index 000000000..02635d12e --- /dev/null +++ b/src/Mod/Fem/Gui/TaskFemConstraintInitialTemperature.cpp @@ -0,0 +1,163 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Authors: Michael Hindley * + * Ruan Olwagen * + * Oswald van Ginkel * + * Based on Force constraint by Jan Rheinländer * + * 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 +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +#endif + +#include "Mod/Fem/App/FemConstraintInitialTemperature.h" +#include "TaskFemConstraintInitialTemperature.h" +#include "ui_TaskFemConstraintInitialTemperature.h" +#include +#include + + + +#include +#include + + +using namespace FemGui; +using namespace Gui; + +/* TRANSLATOR FemGui::TaskFemConstraintInitialTemperature */ + +TaskFemConstraintInitialTemperature::TaskFemConstraintInitialTemperature(ViewProviderFemConstraintInitialTemperature *ConstraintView,QWidget *parent) + : TaskFemConstraint(ConstraintView, parent, "fem-constraint-InitialTemperature") +{ + proxy = new QWidget(this); + ui = new Ui_TaskFemConstraintInitialTemperature(); + ui->setupUi(proxy); + QMetaObject::connectSlotsByName(this); + + this->groupLayout()->addWidget(proxy); + + // Get the feature data + Fem::ConstraintInitialTemperature* pcConstraint = static_cast(ConstraintView->getObject()); + std::vector Objects = pcConstraint->References.getValues(); + std::vector SubElements = pcConstraint->References.getSubValues(); + + // Fill data into dialog elements + ui->if_temperature->setMinimum(0); + ui->if_temperature->setMaximum(FLOAT_MAX); + Base::Quantity t = Base::Quantity(pcConstraint->initialTemperature.getValue(), Base::Unit::Temperature); + ui->if_temperature->setValue(t); +} + +TaskFemConstraintInitialTemperature::~TaskFemConstraintInitialTemperature() +{ + delete ui; +} + +double TaskFemConstraintInitialTemperature::get_temperature() const{ + Base::Quantity temperature = ui->if_temperature->getQuantity(); + double temperature_in_kelvin = temperature.getValueAs(Base::Quantity::Kelvin); + return temperature_in_kelvin; +} + +void TaskFemConstraintInitialTemperature::changeEvent(QEvent *e){ +} + +//************************************************************************** +// TaskDialog +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +TaskDlgFemConstraintInitialTemperature::TaskDlgFemConstraintInitialTemperature(ViewProviderFemConstraintInitialTemperature *ConstraintView) +{ + this->ConstraintView = ConstraintView; + assert(ConstraintView); + this->parameter = new TaskFemConstraintInitialTemperature(ConstraintView);; + + Content.push_back(parameter); +} + +//==== calls from the TaskView =============================================================== +void TaskDlgFemConstraintInitialTemperature::open() +{ + // a transaction is already open at creation time of the panel + if (!Gui::Command::hasPendingCommand()) { + QString msg = QObject::tr("Constraint initial temperature"); + Gui::Command::openCommand((const char*)msg.toUtf8()); + ConstraintView->setVisible(true); + Gui::Command::doCommand(Gui::Command::Doc,ViewProviderFemConstraint::gethideMeshShowPartStr((static_cast(ConstraintView->getObject()))->getNameInDocument()).c_str()); //OvG: Hide meshes and show parts + } +} + +bool TaskDlgFemConstraintInitialTemperature::accept() +{ + std::string name = ConstraintView->getObject()->getNameInDocument(); + const TaskFemConstraintInitialTemperature* parameterTemperature = static_cast(parameter); + + try { + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.initialTemperature = %f", + name.c_str(), parameterTemperature->get_temperature()); + + std::string scale = parameterTemperature->getScale(); //OvG: determine modified scale + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Scale = %s", name.c_str(), scale.c_str()); //OvG: implement modified scale + } + catch (const Base::Exception& e) { + QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what())); + return false; + } + + try { + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()"); + if (!ConstraintView->getObject()->isValid()) + throw Base::Exception(ConstraintView->getObject()->getStatusString()); + Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); + Gui::Command::commitCommand(); + } + catch (const Base::Exception& e) { + QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what())); + return false; + } + + return true; +} + +bool TaskDlgFemConstraintInitialTemperature::reject() +{ + Gui::Command::abortCommand(); + Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); + Gui::Command::updateActive(); + + return true; +} + +#include "moc_TaskFemConstraintInitialTemperature.cpp" diff --git a/src/Mod/Fem/Gui/TaskFemConstraintInitialTemperature.h b/src/Mod/Fem/Gui/TaskFemConstraintInitialTemperature.h new file mode 100644 index 000000000..7f7e7d277 --- /dev/null +++ b/src/Mod/Fem/Gui/TaskFemConstraintInitialTemperature.h @@ -0,0 +1,78 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Authors: Michael Hindley * + * Ruan Olwagen * + * Oswald van Ginkel * + * Based on Force constraint by Jan Rheinländer * + * 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 GUI_TASKVIEW_TaskFemConstraintInitialTemperature_H +#define GUI_TASKVIEW_TaskFemConstraintInitialTemperature_H + +#include +#include +#include +#include + +#include "TaskFemConstraint.h" +#include "ViewProviderFemConstraintInitialTemperature.h" + +#include +#include +#include +#include + +class Ui_TaskFemConstraintInitialTemperature; + +namespace FemGui { +class TaskFemConstraintInitialTemperature : public TaskFemConstraint +{ + Q_OBJECT + +public: + TaskFemConstraintInitialTemperature(ViewProviderFemConstraintInitialTemperature *ConstraintView,QWidget *parent = 0); + ~TaskFemConstraintInitialTemperature(); + double get_temperature()const; + +protected: + void changeEvent(QEvent *e); + +private: + //void onSelectionChanged(const Gui::SelectionChanges& msg); + void updateUI(); + Ui_TaskFemConstraintInitialTemperature* ui; + +}; + +class TaskDlgFemConstraintInitialTemperature : public TaskDlgFemConstraint +{ + Q_OBJECT + +public: + TaskDlgFemConstraintInitialTemperature(ViewProviderFemConstraintInitialTemperature *ConstraintView); + void open(); + bool accept(); + bool reject(); +}; + +} //namespace FemGui + +#endif // GUI_TASKVIEW_TaskFemConstraintInitialTemperature_H diff --git a/src/Mod/Fem/Gui/TaskFemConstraintInitialTemperature.ui b/src/Mod/Fem/Gui/TaskFemConstraintInitialTemperature.ui new file mode 100644 index 000000000..9f06e133d --- /dev/null +++ b/src/Mod/Fem/Gui/TaskFemConstraintInitialTemperature.ui @@ -0,0 +1,48 @@ + + + TaskFemConstraintInitialTemperature + + + + 0 + 0 + 307 + 118 + + + + Dialog + + + + + + Insert component's initial temperature: + + + Qt::AlignCenter + + + + + + + 300 K + + + + + + + + + + + Gui::InputField + QLineEdit +
Gui/InputField.h
+
+
+ + +
diff --git a/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp b/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp new file mode 100644 index 000000000..06177987a --- /dev/null +++ b/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp @@ -0,0 +1,323 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Authors: Michael Hindley * + * Ruan Olwagen * + * Oswald van Ginkel * + * Based on Force constraint by Jan Rheinländer * + * 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 +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +#endif + +#include "Mod/Fem/App/FemConstraintTemperature.h" +#include "TaskFemConstraintTemperature.h" +#include "ui_TaskFemConstraintTemperature.h" +#include +#include + + + +#include +#include + + +using namespace FemGui; +using namespace Gui; + +/* TRANSLATOR FemGui::TaskFemConstraintTemperature */ + +TaskFemConstraintTemperature::TaskFemConstraintTemperature(ViewProviderFemConstraintTemperature *ConstraintView,QWidget *parent) + : TaskFemConstraint(ConstraintView, parent, "fem-constraint-temperature") +{ + proxy = new QWidget(this); + ui = new Ui_TaskFemConstraintTemperature(); + ui->setupUi(proxy); + QMetaObject::connectSlotsByName(this); + + QAction* action = new QAction(tr("Delete"), ui->lw_references); + action->connect(action, SIGNAL(triggered()), this, SLOT(onReferenceDeleted())); + ui->lw_references->addAction(action); + ui->lw_references->setContextMenuPolicy(Qt::ActionsContextMenu); + + connect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), + this, SLOT(setSelection(QListWidgetItem*))); + + this->groupLayout()->addWidget(proxy); + + // Get the feature data + Fem::ConstraintTemperature* pcConstraint = static_cast(ConstraintView->getObject()); + + std::vector Objects = pcConstraint->References.getValues(); + std::vector SubElements = pcConstraint->References.getSubValues(); + + // Fill data into dialog elements + ui->if_temperature->setMinimum(0); + ui->if_temperature->setMaximum(FLOAT_MAX); + Base::Quantity t = Base::Quantity(pcConstraint->Temperature.getValue(), Base::Unit::Temperature); + ui->if_temperature->setValue(t); + + ui->lw_references->clear(); + for (std::size_t i = 0; i < Objects.size(); i++) { + ui->lw_references->addItem(makeRefText(Objects[i], SubElements[i])); + } + if (Objects.size() > 0) { + ui->lw_references->setCurrentRow(0, QItemSelectionModel::ClearAndSelect); + } + + //Selection buttons + connect(ui->btnAdd, SIGNAL(clicked()), this, SLOT(addToSelection())); + connect(ui->btnRemove, SIGNAL(clicked()), this, SLOT(removeFromSelection())); + + updateUI(); +} + +TaskFemConstraintTemperature::~TaskFemConstraintTemperature() +{ + delete ui; +} + +void TaskFemConstraintTemperature::updateUI() +{ + if (ui->lw_references->model()->rowCount() == 0) { + // Go into reference selection mode if no reference has been selected yet + onButtonReference(true); + return; + } +} + +void TaskFemConstraintTemperature::addToSelection() +{ + std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document + if (selection.size()==0){ + QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); + return; + } + + Fem::ConstraintTemperature* pcConstraint = static_cast(ConstraintView->getObject()); + std::vector Objects = pcConstraint->References.getValues(); + std::vector SubElements = pcConstraint->References.getSubValues(); + + for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object + if (static_cast(it->getTypeName()).substr(0,4).compare(std::string("Part"))!=0){ + QMessageBox::warning(this, tr("Selection error"),tr("Selected object is not a part!")); + return; + } + + std::vector subNames=it->getSubNames(); + App::DocumentObject* obj = ConstraintView->getObject()->getDocument()->getObject(it->getFeatName()); + for (unsigned int subIt=0;subIt<(subNames.size());++subIt){// for every selected sub element + bool addMe=true; + for (std::vector::iterator itr=std::find(SubElements.begin(),SubElements.end(),subNames[subIt]); + itr!= SubElements.end(); + itr = std::find(++itr,SubElements.end(),subNames[subIt])) + {// for every sub element in selection that matches one in old list + if (obj==Objects[std::distance(SubElements.begin(),itr)]){//if selected sub element's object equals the one in old list then it was added before so don't add + addMe=false; + } + } + if (addMe){ + disconnect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), + this, SLOT(setSelection(QListWidgetItem*))); + Objects.push_back(obj); + SubElements.push_back(subNames[subIt]); + ui->lw_references->addItem(makeRefText(obj, subNames[subIt])); + connect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), + this, SLOT(setSelection(QListWidgetItem*))); + } + } + } + //Update UI + pcConstraint->References.setValues(Objects,SubElements); + updateUI(); +} + +void TaskFemConstraintTemperature::removeFromSelection() +{ + std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document + if (selection.size()==0){ + QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); + return; + } + + Fem::ConstraintTemperature* pcConstraint = static_cast(ConstraintView->getObject()); + std::vector Objects = pcConstraint->References.getValues(); + std::vector SubElements = pcConstraint->References.getSubValues(); + std::vector itemsToDel; + for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object + if (static_cast(it->getTypeName()).substr(0,4).compare(std::string("Part"))!=0){ + QMessageBox::warning(this, tr("Selection error"),tr("Selected object is not a part!")); + return; + } + + std::vector subNames=it->getSubNames(); + App::DocumentObject* obj = ConstraintView->getObject()->getDocument()->getObject(it->getFeatName()); + + for (unsigned int subIt=0;subIt<(subNames.size());++subIt){// for every selected sub element + for (std::vector::iterator itr=std::find(SubElements.begin(),SubElements.end(),subNames[subIt]); + itr!= SubElements.end(); + itr = std::find(++itr,SubElements.end(),subNames[subIt])) + {// for every sub element in selection that matches one in old list + if (obj==Objects[std::distance(SubElements.begin(),itr)]){//if selected sub element's object equals the one in old list then it was added before so mark for deletion + itemsToDel.push_back(std::distance(SubElements.begin(),itr)); + } + } + } + } + + std::sort(itemsToDel.begin(),itemsToDel.end()); + while (itemsToDel.size()>0){ + Objects.erase(Objects.begin()+itemsToDel.back()); + SubElements.erase(SubElements.begin()+itemsToDel.back()); + itemsToDel.pop_back(); + } + //Update UI + disconnect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), + this, SLOT(setSelection(QListWidgetItem*))); + + ui->lw_references->clear(); + for (unsigned int j=0;jlw_references->addItem(makeRefText(Objects[j], SubElements[j])); + } + connect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), + this, SLOT(setSelection(QListWidgetItem*))); + + pcConstraint->References.setValues(Objects,SubElements); + updateUI(); +} + +void TaskFemConstraintTemperature::setSelection(QListWidgetItem* item){ + std::string docName=ConstraintView->getObject()->getDocument()->getName(); + + std::string s = item->text().toStdString(); + std::string delimiter = ":"; + + size_t pos = 0; + std::string objName; + std::string subName; + pos = s.find(delimiter); + objName = s.substr(0, pos); + s.erase(0, pos + delimiter.length()); + subName=s; + + Gui::Selection().clearSelection(); + Gui::Selection().addSelection(docName.c_str(),objName.c_str(),subName.c_str(),0,0,0); +} + +void TaskFemConstraintTemperature::onReferenceDeleted() { + TaskFemConstraintTemperature::removeFromSelection(); +} + +const std::string TaskFemConstraintTemperature::getReferences() const +{ + int rows = ui->lw_references->model()->rowCount(); + std::vector items; + for (int r = 0; r < rows; r++) { + items.push_back(ui->lw_references->item(r)->text().toStdString()); + } + return TaskFemConstraint::getReferences(items); +} + +double TaskFemConstraintTemperature::get_temperature() const{ + Base::Quantity temperature = ui->if_temperature->getQuantity(); + double temperature_in_kelvin = temperature.getValueAs(Base::Quantity::Kelvin); + return temperature_in_kelvin; +} + +void TaskFemConstraintTemperature::changeEvent(QEvent *e) +{ +// TaskBox::changeEvent(e); +// if (e->type() == QEvent::LanguageChange) { +// ui->if_pressure->blockSignals(true); +// ui->retranslateUi(proxy); +// ui->if_pressure->blockSignals(false); +// } +} + +//************************************************************************** +// TaskDialog +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +TaskDlgFemConstraintTemperature::TaskDlgFemConstraintTemperature(ViewProviderFemConstraintTemperature *ConstraintView) +{ + this->ConstraintView = ConstraintView; + assert(ConstraintView); + this->parameter = new TaskFemConstraintTemperature(ConstraintView);; + + Content.push_back(parameter); +} + +//==== calls from the TaskView =============================================================== + +void TaskDlgFemConstraintTemperature::open() +{ + // a transaction is already open at creation time of the panel + if (!Gui::Command::hasPendingCommand()) { + QString msg = QObject::tr("Constraint temperature"); + Gui::Command::openCommand((const char*)msg.toUtf8()); + ConstraintView->setVisible(true); + Gui::Command::doCommand(Gui::Command::Doc,ViewProviderFemConstraint::gethideMeshShowPartStr((static_cast(ConstraintView->getObject()))->getNameInDocument()).c_str()); //OvG: Hide meshes and show parts + } +} + +bool TaskDlgFemConstraintTemperature::accept() +{ + std::string name = ConstraintView->getObject()->getNameInDocument(); + const TaskFemConstraintTemperature* parameterTemperature = static_cast(parameter); + + try { + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Temperature = %f", + name.c_str(), parameterTemperature->get_temperature()); + + std::string scale = parameterTemperature->getScale(); //OvG: determine modified scale + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Scale = %s", name.c_str(), scale.c_str()); //OvG: implement modified scale + } + catch (const Base::Exception& e) { + QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what())); + return false; + } + + return TaskDlgFemConstraint::accept(); +} + +bool TaskDlgFemConstraintTemperature::reject() +{ + Gui::Command::abortCommand(); + Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); + Gui::Command::updateActive(); + + return true; +} + +#include "moc_TaskFemConstraintTemperature.cpp" diff --git a/src/Mod/Fem/Gui/TaskFemConstraintTemperature.h b/src/Mod/Fem/Gui/TaskFemConstraintTemperature.h new file mode 100644 index 000000000..bd425bf9d --- /dev/null +++ b/src/Mod/Fem/Gui/TaskFemConstraintTemperature.h @@ -0,0 +1,86 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Authors: Michael Hindley * + * Ruan Olwagen * + * Oswald van Ginkel * + * Based on Force constraint by Jan Rheinländer * + * 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 GUI_TASKVIEW_TaskFemConstraintTemperature_H +#define GUI_TASKVIEW_TaskFemConstraintTemperature_H + +#include +#include +#include +#include + +#include "TaskFemConstraint.h" +#include "ViewProviderFemConstraintTemperature.h" + +#include +#include +#include +#include + +class Ui_TaskFemConstraintTemperature; + +namespace FemGui { +class TaskFemConstraintTemperature : public TaskFemConstraint +{ + Q_OBJECT + +public: + TaskFemConstraintTemperature(ViewProviderFemConstraintTemperature *ConstraintView,QWidget *parent = 0); + ~TaskFemConstraintTemperature(); + const std::string getReferences() const; + double get_temperature()const; + +private Q_SLOTS: + void onReferenceDeleted(void); + + void addToSelection(); + void removeFromSelection(); + void setSelection(QListWidgetItem* item); + +protected: + void changeEvent(QEvent *e); + +private: + //void onSelectionChanged(const Gui::SelectionChanges& msg); + void updateUI(); + Ui_TaskFemConstraintTemperature* ui; + +}; + +class TaskDlgFemConstraintTemperature : public TaskDlgFemConstraint +{ + Q_OBJECT + +public: + TaskDlgFemConstraintTemperature(ViewProviderFemConstraintTemperature *ConstraintView); + void open(); + bool accept(); + bool reject(); +}; + +} //namespace FemGui + +#endif // GUI_TASKVIEW_TaskFemConstraintTemperature_H diff --git a/src/Mod/Fem/Gui/TaskFemConstraintTemperature.ui b/src/Mod/Fem/Gui/TaskFemConstraintTemperature.ui new file mode 100644 index 000000000..426b9eb8f --- /dev/null +++ b/src/Mod/Fem/Gui/TaskFemConstraintTemperature.ui @@ -0,0 +1,77 @@ + + + TaskFemConstraintTemperature + + + + 0 + 0 + 309 + 233 + + + + Form + + + + + + Select multiple face(s), click Add or Remove + + + + + + + + + Add + + + + + + + Remove + + + + + + + + + + + + + + Temperature + + + + + + + 300 K + + + + + + + + + + + + + Gui::InputField + QLineEdit +
Gui/InputField.h
+
+
+ + +
diff --git a/src/Mod/Fem/Gui/TaskPanelConstraintTemperature.ui b/src/Mod/Fem/Gui/TaskPanelConstraintTemperature.ui new file mode 100644 index 000000000..911587ddd --- /dev/null +++ b/src/Mod/Fem/Gui/TaskPanelConstraintTemperature.ui @@ -0,0 +1,110 @@ + + + Dialog + + + + 0 + 0 + 312 + 316 + + + + Dialog + + + + + 25 + 20 + 301 + 21 + + + + Select the vertices, lines and surfaces: + + + + + + 19 + 266 + 101 + 20 + + + + Temperature: + + + + + + 116 + 265 + 113 + 27 + + + + 25 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 231 + 270 + 66 + 17 + + + + ºC + + + + + + 20 + 50 + 131 + 31 + + + + Add + + + + + + 153 + 50 + 131 + 31 + + + + Remove + + + + + + 21 + 91 + 261 + 151 + + + + + + + diff --git a/src/Mod/Fem/Gui/TaskPanelInitialTemperature.ui b/src/Mod/Fem/Gui/TaskPanelInitialTemperature.ui new file mode 100644 index 000000000..cb27080b2 --- /dev/null +++ b/src/Mod/Fem/Gui/TaskPanelInitialTemperature.ui @@ -0,0 +1,78 @@ + + + Dialog + + + + 0 + 0 + 307 + 156 + + + + Dialog + + + + + 70 + 5 + 161 + 71 + + + + Insert component's + initial temperature: + + + Qt::AlignCenter + + + + + + 38 + 78 + 101 + 20 + + + + Temperature: + + + + + + 135 + 77 + 113 + 27 + + + + 25 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 250 + 82 + 66 + 17 + + + + ºC + + + + + + diff --git a/src/Mod/Fem/Gui/ViewProviderFemConstraintHeatflux.cpp b/src/Mod/Fem/Gui/ViewProviderFemConstraintHeatflux.cpp new file mode 100644 index 000000000..1998f735f --- /dev/null +++ b/src/Mod/Fem/Gui/ViewProviderFemConstraintHeatflux.cpp @@ -0,0 +1,194 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Authors: Michael Hindley * + * Ruan Olwagen * + * Oswald van Ginkel * + * Based on Force constraint by Jan Rheinländer * + * 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 +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +#endif + +#include "Mod/Fem/App/FemConstraintHeatflux.h" +#include "TaskFemConstraintHeatflux.h" +#include "ViewProviderFemConstraintHeatflux.h" +#include +#include + +using namespace FemGui; + +PROPERTY_SOURCE(FemGui::ViewProviderFemConstraintHeatflux, FemGui::ViewProviderFemConstraint) + +ViewProviderFemConstraintHeatflux::ViewProviderFemConstraintHeatflux() +{ + sPixmap = "fem-constraint-heatflux"; + ADD_PROPERTY(FaceColor,(0.2f,0.3f,0.2f)); +} + +ViewProviderFemConstraintHeatflux::~ViewProviderFemConstraintHeatflux() +{ +} + +//FIXME setEdit needs a careful review +bool ViewProviderFemConstraintHeatflux::setEdit(int ModNum) +{ + if (ModNum == ViewProvider::Default) { + // When double-clicking on the item for this constraint the + // object unsets and sets its edit mode without closing + // the task panel + Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); + TaskDlgFemConstraintHeatflux *constrDlg = qobject_cast(dlg); + if (constrDlg && constrDlg->getConstraintView() != this) + constrDlg = 0; // another constraint left open its task panel + if (dlg && !constrDlg) { + if (constraintDialog != NULL) { + // Ignore the request to open another dialog + return false; + } else { + constraintDialog = new TaskFemConstraintHeatflux(this); + return true; + } + } + + // clear the selection (convenience) + Gui::Selection().clearSelection(); + + // start the edit dialog + if (constrDlg) + Gui::Control().showDialog(constrDlg); + else + Gui::Control().showDialog(new TaskDlgFemConstraintHeatflux(this)); + return true; + } + else { + return ViewProviderDocumentObject::setEdit(ModNum); + } +} + +#define HEIGHT (1.5) +#define RADIUS (0.3) +//#define USE_MULTIPLE_COPY //OvG: MULTICOPY fails to update scaled display on initial drawing - so disable + +void ViewProviderFemConstraintHeatflux::updateData(const App::Property* prop) +{ + // Gets called whenever a property of the attached object changes + Fem::ConstraintHeatflux* pcConstraint = static_cast(this->getObject()); + float scaledradius = RADIUS * pcConstraint->Scale.getValue(); //OvG: Calculate scaled values once only + float scaledheight = HEIGHT * pcConstraint->Scale.getValue(); + //float ambienttemp = pcConstraint->AmbientTemp.getValue(); + ////float facetemp = pcConstraint->FaceTemp.getValue(); + //float filmcoef = pcConstraint->FilmCoef.getValue(); + + if (strcmp(prop->getName(),"Points") == 0) { + const std::vector& points = pcConstraint->Points.getValues(); + const std::vector& normals = pcConstraint->Normals.getValues(); + if (points.size() != normals.size()) + return; + std::vector::const_iterator n = normals.begin(); + + // Note: Points and Normals are always updated together + pShapeSep->removeAllChildren(); + + for (std::vector::const_iterator p = points.begin(); p != points.end(); p++) { + //Define base and normal directions + SbVec3f base(p->x, p->y, p->z); + SbVec3f dir(n->x, n->y, n->z);//normal + + ///Temperature indication + //define separator + SoSeparator* sep = new SoSeparator(); + + ///draw a temp gauge,with sphere and a cylinder + //first move to correct postion + SoTranslation* trans = new SoTranslation(); + SbVec3f newPos=base+scaledradius*dir*0.7; + trans->translation.setValue(newPos); + sep->addChild(trans); + + //adjust orientation + SoRotation* rot = new SoRotation(); + rot->rotation.setValue(SbRotation(SbVec3f(0,1,0),dir)); + sep->addChild(rot); + + //define color of shape + SoMaterial* myMaterial = new SoMaterial; + myMaterial->diffuseColor.set1Value(0,SbColor(0.65,0.1,0.25));//RGB + //myMaterial->diffuseColor.set1Value(1,SbColor(.1,.1,.1));//possible to adjust sides separately + sep->addChild(myMaterial); + + //draw a sphere + SoSphere* sph = new SoSphere(); + sph->radius.setValue(scaledradius*0.75); + sep->addChild(sph); + //translate postion + SoTranslation* trans2 = new SoTranslation(); + trans2->translation.setValue(SbVec3f(0,scaledheight*0.375,0)); + sep->addChild(trans2); + //draw a cylinder + SoCylinder* cyl = new SoCylinder(); + cyl->height.setValue(scaledheight*0.5); + cyl->radius.setValue(scaledradius*0.375); + sep->addChild(cyl); + //translate postion + SoTranslation* trans3 = new SoTranslation(); + trans3->translation.setValue(SbVec3f(0,scaledheight*0.375,0)); + sep->addChild(trans3); + //define color of shape + SoMaterial *myMaterial2 = new SoMaterial; + myMaterial2->diffuseColor.set1Value(0,SbColor(1,1,1));//RGB + sep->addChild(myMaterial2); + //draw a cylinder + SoCylinder* cyl2 = new SoCylinder(); + cyl2->height.setValue(scaledheight*0.25); + cyl2->radius.setValue(scaledradius*0.375); + sep->addChild(cyl2); + //translate postion + SoTranslation* trans4 = new SoTranslation(); + trans4->translation.setValue(SbVec3f(0,-scaledheight*0.375,0)); + sep->addChild(trans4); + //draw a cylinder + SoCylinder* cyl3 = new SoCylinder(); + cyl3->height.setValue(scaledheight*0.05); + cyl3->radius.setValue(scaledradius*1); + sep->addChild(cyl3); + + pShapeSep->addChild(sep); + + n++; + } + } + // Gets called whenever a property of the attached object changes + ViewProviderFemConstraint::updateData(prop); +} diff --git a/src/Mod/Fem/Gui/ViewProviderFemConstraintHeatflux.h b/src/Mod/Fem/Gui/ViewProviderFemConstraintHeatflux.h new file mode 100644 index 000000000..819fef2e8 --- /dev/null +++ b/src/Mod/Fem/Gui/ViewProviderFemConstraintHeatflux.h @@ -0,0 +1,48 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Authors: Michael Hindley * + * Ruan Olwagen * + * Oswald van Ginkel * + * Based on Force constraint by Jan Rheinländer * + * 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 GUI_VIEWPROVIDERFEMCONSTRAINTHEATFLUX_H +#define GUI_VIEWPROVIDERFEMCONSTRAINTHEATFLUX_H + +#include "ViewProviderFemConstraint.h" + +namespace FemGui { + +class FemGuiExport ViewProviderFemConstraintHeatflux : public FemGui::ViewProviderFemConstraint +{ + PROPERTY_HEADER(FemGui::ViewProviderFemConstraintHeatflux); + +public: + ViewProviderFemConstraintHeatflux(); + virtual ~ViewProviderFemConstraintHeatflux(); + virtual void updateData(const App::Property*); + +protected: + virtual bool setEdit(int ModNum); +}; + +} + +#endif // GUI_VIEWPROVIDERFEMCONSTRAINTHEATFLUX_H diff --git a/src/Mod/Fem/Gui/ViewProviderFemConstraintInitialTemperature.cpp b/src/Mod/Fem/Gui/ViewProviderFemConstraintInitialTemperature.cpp new file mode 100644 index 000000000..376afe5e0 --- /dev/null +++ b/src/Mod/Fem/Gui/ViewProviderFemConstraintInitialTemperature.cpp @@ -0,0 +1,104 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Authors: Michael Hindley * + * Ruan Olwagen * + * Oswald van Ginkel * + * Based on Force constraint by Jan Rheinländer * + * 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 +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +#endif + +#include "Mod/Fem/App/FemConstraintInitialTemperature.h" +#include "TaskFemConstraintInitialTemperature.h" +#include "ViewProviderFemConstraintInitialTemperature.h" +#include +#include + +using namespace FemGui; + +PROPERTY_SOURCE(FemGui::ViewProviderFemConstraintInitialTemperature, FemGui::ViewProviderFemConstraint) + +ViewProviderFemConstraintInitialTemperature::ViewProviderFemConstraintInitialTemperature() +{ + sPixmap = "fem-constraint-InitialTemperature"; + ADD_PROPERTY(FaceColor,(0.2f,0.3f,0.2f)); +} + +ViewProviderFemConstraintInitialTemperature::~ViewProviderFemConstraintInitialTemperature() +{ +} + +//FIXME setEdit needs a careful review +bool ViewProviderFemConstraintInitialTemperature::setEdit(int ModNum) +{ + if (ModNum == ViewProvider::Default) { + // When double-clicking on the item for this constraint the + // object unsets and sets its edit mode without closing + // the task panel + Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); + TaskDlgFemConstraintInitialTemperature *constrDlg = qobject_cast(dlg); + if (constrDlg && constrDlg->getConstraintView() != this) + constrDlg = 0; // another constraint left open its task panel + if (dlg && !constrDlg) { + if (constraintDialog != NULL) { + // Ignore the request to open another dialog + return false; + } else { + constraintDialog = new TaskFemConstraintInitialTemperature(this); + return true; + } + } + + // clear the selection (convenience) + Gui::Selection().clearSelection(); + + // start the edit dialog + if (constrDlg) + Gui::Control().showDialog(constrDlg); + else + Gui::Control().showDialog(new TaskDlgFemConstraintInitialTemperature(this)); + return true; + } + else { + return ViewProviderDocumentObject::setEdit(ModNum); + } +} + +void ViewProviderFemConstraintInitialTemperature::updateData(const App::Property* prop) +{ + // Gets called whenever a property of the attached object changes + ViewProviderFemConstraint::updateData(prop); +} diff --git a/src/Mod/Fem/Gui/ViewProviderFemConstraintInitialTemperature.h b/src/Mod/Fem/Gui/ViewProviderFemConstraintInitialTemperature.h new file mode 100644 index 000000000..c5904505c --- /dev/null +++ b/src/Mod/Fem/Gui/ViewProviderFemConstraintInitialTemperature.h @@ -0,0 +1,48 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Authors: Michael Hindley * + * Ruan Olwagen * + * Oswald van Ginkel * + * Based on Force constraint by Jan Rheinländer * + * 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 GUI_VIEWPROVIDERFEMCONSTRAINTInitialTemperature_H +#define GUI_VIEWPROVIDERFEMCONSTRAINTInitialTemperature_H + +#include "ViewProviderFemConstraint.h" + +namespace FemGui { + +class FemGuiExport ViewProviderFemConstraintInitialTemperature : public FemGui::ViewProviderFemConstraint +{ + PROPERTY_HEADER(FemGui::ViewProviderFemConstraintInitialTemperature); + +public: + ViewProviderFemConstraintInitialTemperature(); + virtual ~ViewProviderFemConstraintInitialTemperature(); + virtual void updateData(const App::Property*); + +protected: + virtual bool setEdit(int ModNum); +}; + +} + +#endif // GUI_VIEWPROVIDERFEMCONSTRAINTInitialTemperature_H diff --git a/src/Mod/Fem/Gui/ViewProviderFemConstraintTemperature.cpp b/src/Mod/Fem/Gui/ViewProviderFemConstraintTemperature.cpp new file mode 100644 index 000000000..692fd9eeb --- /dev/null +++ b/src/Mod/Fem/Gui/ViewProviderFemConstraintTemperature.cpp @@ -0,0 +1,184 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Authors: Michael Hindley * + * Ruan Olwagen * + * Oswald van Ginkel * + * Based on Force constraint by Jan Rheinländer * + * 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 +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +#endif + +#include "Mod/Fem/App/FemConstraintTemperature.h" +#include "TaskFemConstraintTemperature.h" +#include "ViewProviderFemConstraintTemperature.h" +#include +#include + +using namespace FemGui; + +PROPERTY_SOURCE(FemGui::ViewProviderFemConstraintTemperature, FemGui::ViewProviderFemConstraint) + +ViewProviderFemConstraintTemperature::ViewProviderFemConstraintTemperature() +{ + sPixmap = "fem-constraint-temperature"; + ADD_PROPERTY(FaceColor,(0.2f,0.3f,0.2f)); +} + +ViewProviderFemConstraintTemperature::~ViewProviderFemConstraintTemperature() +{ +} + +//FIXME setEdit needs a careful review +bool ViewProviderFemConstraintTemperature::setEdit(int ModNum) +{ + if (ModNum == ViewProvider::Default) { + // When double-clicking on the item for this constraint the + // object unsets and sets its edit mode without closing + // the task panel + Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); + TaskDlgFemConstraintTemperature *constrDlg = qobject_cast(dlg); + if (constrDlg && constrDlg->getConstraintView() != this) + constrDlg = 0; // another constraint left open its task panel + if (dlg && !constrDlg) { + if (constraintDialog != NULL) { + // Ignore the request to open another dialog + return false; + } else { + constraintDialog = new TaskFemConstraintTemperature(this); + return true; + } + } + + // clear the selection (convenience) + Gui::Selection().clearSelection(); + + // start the edit dialog + if (constrDlg) + Gui::Control().showDialog(constrDlg); + else + Gui::Control().showDialog(new TaskDlgFemConstraintTemperature(this)); + return true; + } + else { + return ViewProviderDocumentObject::setEdit(ModNum); + } +} + +#define HEIGHT (1.5) +#define RADIUS (0.3) +//#define USE_MULTIPLE_COPY //OvG: MULTICOPY fails to update scaled display on initial drawing - so disable + +void ViewProviderFemConstraintTemperature::updateData(const App::Property* prop) +{ + // Gets called whenever a property of the attached object changes + Fem::ConstraintTemperature* pcConstraint = static_cast(this->getObject()); + float scaledradius = RADIUS * pcConstraint->Scale.getValue(); //OvG: Calculate scaled values once only + float scaledheight = HEIGHT * pcConstraint->Scale.getValue(); + //float temperature = pcConstraint->temperature.getValue(); + + if (strcmp(prop->getName(),"Points") == 0) { + const std::vector& points = pcConstraint->Points.getValues(); + const std::vector& normals = pcConstraint->Normals.getValues(); + if (points.size() != normals.size()) + return; + std::vector::const_iterator n = normals.begin(); + + // Note: Points and Normals are always updated together + pShapeSep->removeAllChildren(); + + for (std::vector::const_iterator p = points.begin(); p != points.end(); p++) { + //Define base and normal directions + SbVec3f base(p->x, p->y, p->z); + SbVec3f dir(n->x, n->y, n->z);//normal + + ///Temperature indication + //define separator + SoSeparator* sep = new SoSeparator(); + + ///draw a temp gauge,with sphere and a cylinder + //first move to correct postion + SoTranslation* trans = new SoTranslation(); + SbVec3f newPos=base+scaledradius*dir*0.7; + trans->translation.setValue(newPos); + sep->addChild(trans); + + //adjust orientation + SoRotation* rot = new SoRotation(); + rot->rotation.setValue(SbRotation(SbVec3f(0,1,0),dir)); + sep->addChild(rot); + + //define color of shape + SoMaterial* myMaterial = new SoMaterial; + myMaterial->diffuseColor.set1Value(0,SbColor(1,0,0));//RGB + //myMaterial->diffuseColor.set1Value(1,SbColor(.1,.1,.1));//possible to adjust sides separately + sep->addChild(myMaterial); + + //draw a sphere + SoSphere* sph = new SoSphere(); + sph->radius.setValue(scaledradius*0.75); + sep->addChild(sph); + //translate postion + SoTranslation* trans2 = new SoTranslation(); + trans2->translation.setValue(SbVec3f(0,scaledheight*0.375,0)); + sep->addChild(trans2); + //draw a cylinder + SoCylinder* cyl = new SoCylinder(); + cyl->height.setValue(scaledheight*0.5); + cyl->radius.setValue(scaledradius*0.375); + sep->addChild(cyl); + //translate postion + SoTranslation* trans3 = new SoTranslation(); + trans3->translation.setValue(SbVec3f(0,scaledheight*0.375,0)); + sep->addChild(trans3); + //define color of shape + SoMaterial *myMaterial2 = new SoMaterial; + myMaterial2->diffuseColor.set1Value(0,SbColor(1,1,1));//RGB + sep->addChild(myMaterial2); + //draw a cylinder + SoCylinder* cyl2 = new SoCylinder(); + cyl2->height.setValue(scaledheight*0.25); + cyl2->radius.setValue(scaledradius*0.375); + sep->addChild(cyl2); + + pShapeSep->addChild(sep); + + n++; + } + } + // Gets called whenever a property of the attached object changes + ViewProviderFemConstraint::updateData(prop); +} diff --git a/src/Mod/Fem/Gui/ViewProviderFemConstraintTemperature.h b/src/Mod/Fem/Gui/ViewProviderFemConstraintTemperature.h new file mode 100644 index 000000000..4fefa97c4 --- /dev/null +++ b/src/Mod/Fem/Gui/ViewProviderFemConstraintTemperature.h @@ -0,0 +1,48 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Authors: Michael Hindley * + * Ruan Olwagen * + * Oswald van Ginkel * + * Based on Force constraint by Jan Rheinländer * + * 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 GUI_VIEWPROVIDERFEMCONSTRAINTTemperature_H +#define GUI_VIEWPROVIDERFEMCONSTRAINTTemperature_H + +#include "ViewProviderFemConstraint.h" + +namespace FemGui { + +class FemGuiExport ViewProviderFemConstraintTemperature : public FemGui::ViewProviderFemConstraint +{ + PROPERTY_HEADER(FemGui::ViewProviderFemConstraintTemperature); + +public: + ViewProviderFemConstraintTemperature(); + virtual ~ViewProviderFemConstraintTemperature(); + virtual void updateData(const App::Property*); + +protected: + virtual bool setEdit(int ModNum); +}; + +} + +#endif // GUI_VIEWPROVIDERFEMCONSTRAINTTemperature_H diff --git a/src/Mod/Fem/Gui/Workbench.cpp b/src/Mod/Fem/Gui/Workbench.cpp index 032c1fedb..78da15b73 100755 --- a/src/Mod/Fem/Gui/Workbench.cpp +++ b/src/Mod/Fem/Gui/Workbench.cpp @@ -78,6 +78,10 @@ Gui::ToolBarItem* Workbench::setupToolBars() const << "Fem_ConstraintGear" << "Fem_ConstraintPulley" << "Separator" + << "Fem_ConstraintTemperature" + << "Fem_ConstraintHeatflux" + << "Fem_ConstraintInitialTemperature" + << "Separator" << "Fem_ControlSolver" << "Fem_RunSolver" << "Separator" @@ -131,6 +135,10 @@ Gui::MenuItem* Workbench::setupMenuBar() const << "Fem_ConstraintGear" << "Fem_ConstraintPulley" << "Separator" + << "Fem_ConstraintTemperature" + << "Fem_ConstraintHeatflux" + << "Fem_ConstraintInitialTemperature" + << "Separator" << "Fem_ControlSolver" << "Fem_RunSolver" << "Separator"