diff --git a/src/Mod/Fem/App/AppFem.cpp b/src/Mod/Fem/App/AppFem.cpp index d420ff74c..5f6d0aa17 100755 --- a/src/Mod/Fem/App/AppFem.cpp +++ b/src/Mod/Fem/App/AppFem.cpp @@ -47,6 +47,7 @@ #include "FemConstraintBearing.h" #include "FemConstraintFixed.h" #include "FemConstraintForce.h" +#include "FemConstraintPressure.h" #include "FemConstraintGear.h" #include "FemConstraintPulley.h" @@ -135,6 +136,7 @@ void AppFemExport initFem() Fem::ConstraintBearing ::init(); Fem::ConstraintFixed ::init(); Fem::ConstraintForce ::init(); + Fem::ConstraintPressure ::init(); Fem::ConstraintGear ::init(); Fem::ConstraintPulley ::init(); diff --git a/src/Mod/Fem/App/CMakeLists.txt b/src/Mod/Fem/App/CMakeLists.txt index d18d74d62..e0efcf21e 100755 --- a/src/Mod/Fem/App/CMakeLists.txt +++ b/src/Mod/Fem/App/CMakeLists.txt @@ -121,6 +121,8 @@ SET(FemConstraints_SRCS FemConstraintFixed.h FemConstraintForce.cpp FemConstraintForce.h + FemConstraintPressure.cpp + FemConstraintPressure.h FemConstraintGear.cpp FemConstraintGear.h FemConstraintPulley.cpp diff --git a/src/Mod/Fem/App/FemConstraintPressure.cpp b/src/Mod/Fem/App/FemConstraintPressure.cpp new file mode 100644 index 000000000..eca753fd2 --- /dev/null +++ b/src/Mod/Fem/App/FemConstraintPressure.cpp @@ -0,0 +1,81 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Author: Przemo Firszt * + * 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 "FemConstraintPressure.h" + +using namespace Fem; + +PROPERTY_SOURCE(Fem::ConstraintPressure, Fem::Constraint); + +ConstraintPressure::ConstraintPressure() +{ + ADD_PROPERTY(Pressure,(0.0)); + ADD_PROPERTY(Reversed,(0)); + ADD_PROPERTY_TYPE(Points,(Base::Vector3d()),"ConstraintPressure", + App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), + "Points where arrows are drawn"); + ADD_PROPERTY_TYPE(Normals,(Base::Vector3d()),"ConstraintPressure", + App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), + "Normals where symbols are drawn"); + Points.setValues(std::vector()); + Normals.setValues(std::vector()); +} + +App::DocumentObjectExecReturn *ConstraintPressure::execute(void) +{ + return Constraint::execute(); +} + +const char* ConstraintPressure::getViewProviderName(void) const +{ + return "FemGui::ViewProviderFemConstraintPressure"; +} + +void ConstraintPressure::onChanged(const App::Property* prop) +{ + Constraint::onChanged(prop); + + if (prop == &References) { + std::vector points; + std::vector normals; + if (getPoints(points, normals)) { + Points.setValues(points); + Normals.setValues(normals); + Points.touch(); + } + } else if (prop == &Reversed) { + Points.touch(); + } +} diff --git a/src/Mod/Fem/App/FemConstraintPressure.h b/src/Mod/Fem/App/FemConstraintPressure.h new file mode 100644 index 000000000..c103352db --- /dev/null +++ b/src/Mod/Fem/App/FemConstraintPressure.h @@ -0,0 +1,55 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Author: Przemo Firszt * + * 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_CONSTRAINTPRESSURE_H +#define FEM_CONSTRAINTPRESSURE_H + +#include "FemConstraint.h" + +namespace Fem { + + class AppFemExport ConstraintPressure : public Fem::Constraint { + PROPERTY_HEADER(Fem::ConstraintPressure); + + public: + ConstraintPressure(void); + + App::PropertyFloat Pressure; + App::PropertyBool Reversed; + 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_CONSTRAINTPRESSURE_H diff --git a/src/Mod/Fem/Gui/AppFemGui.cpp b/src/Mod/Fem/Gui/AppFemGui.cpp index 621b45940..7030d9c42 100755 --- a/src/Mod/Fem/Gui/AppFemGui.cpp +++ b/src/Mod/Fem/Gui/AppFemGui.cpp @@ -45,6 +45,7 @@ #include "ViewProviderFemConstraintBearing.h" #include "ViewProviderFemConstraintFixed.h" #include "ViewProviderFemConstraintForce.h" +#include "ViewProviderFemConstraintPressure.h" #include "ViewProviderFemConstraintGear.h" #include "ViewProviderFemConstraintPulley.h" #include "ViewProviderResult.h" @@ -95,6 +96,7 @@ void FemGuiExport initFemGui() FemGui::ViewProviderFemConstraintBearing ::init(); FemGui::ViewProviderFemConstraintFixed ::init(); FemGui::ViewProviderFemConstraintForce ::init(); + FemGui::ViewProviderFemConstraintPressure ::init(); FemGui::ViewProviderFemConstraintGear ::init(); FemGui::ViewProviderFemConstraintPulley ::init(); FemGui::ViewProviderResult ::init(); diff --git a/src/Mod/Fem/Gui/CMakeLists.txt b/src/Mod/Fem/Gui/CMakeLists.txt index 27288f250..38f888e6a 100755 --- a/src/Mod/Fem/Gui/CMakeLists.txt +++ b/src/Mod/Fem/Gui/CMakeLists.txt @@ -49,6 +49,7 @@ set(FemGui_MOC_HDRS TaskFemConstraintBearing.h TaskFemConstraintFixed.h TaskFemConstraintForce.h + TaskFemConstraintPressure.h TaskFemConstraintGear.h TaskFemConstraintPulley.h TaskTetParameter.h @@ -68,6 +69,7 @@ set(FemGui_UIC_SRCS TaskFemConstraintBearing.ui TaskFemConstraintFixed.ui TaskFemConstraintForce.ui + TaskFemConstraintPressure.ui TaskTetParameter.ui TaskAnalysisInfo.ui TaskDriver.ui @@ -91,6 +93,9 @@ SET(FemGui_DLG_SRCS TaskFemConstraintForce.ui TaskFemConstraintForce.cpp TaskFemConstraintForce.h + TaskFemConstraintPressure.ui + TaskFemConstraintPressure.cpp + TaskFemConstraintPressure.h TaskFemConstraintGear.cpp TaskFemConstraintGear.h TaskFemConstraintPulley.cpp @@ -129,6 +134,8 @@ SET(FemGui_SRCS_ViewProvider ViewProviderFemConstraintFixed.h ViewProviderFemConstraintForce.cpp ViewProviderFemConstraintForce.h + ViewProviderFemConstraintPressure.cpp + ViewProviderFemConstraintPressure.h ViewProviderFemConstraintGear.cpp ViewProviderFemConstraintGear.h ViewProviderFemConstraintPulley.cpp diff --git a/src/Mod/Fem/Gui/Command.cpp b/src/Mod/Fem/Gui/Command.cpp index a02c492ce..f8ddeb7d8 100755 --- a/src/Mod/Fem/Gui/Command.cpp +++ b/src/Mod/Fem/Gui/Command.cpp @@ -321,6 +321,46 @@ bool CmdFemConstraintForce::isActive(void) //===================================================================================== +DEF_STD_CMD_A(CmdFemConstraintPressure); + +CmdFemConstraintPressure::CmdFemConstraintPressure() + : Command("Fem_ConstraintPressure") +{ + sAppModule = "Fem"; + sGroup = QT_TR_NOOP("Fem"); + sMenuText = QT_TR_NOOP("Create FEM pressure constraint"); + sToolTipText = QT_TR_NOOP("Create FEM constraint for a pressure acting on a face"); + sWhatsThis = "Fem_ConstraintPressure"; + sStatusTip = sToolTipText; + sPixmap = "Fem_ConstraintPressure"; +} + +void CmdFemConstraintPressure::activated(int iMsg) +{ + Fem::FemAnalysis *Analysis; + + if(getConstraintPrerequisits(&Analysis)) + return; + + std::string FeatName = getUniqueObjectName("FemConstraintPressure"); + + openCommand("Make FEM constraint pressure on face"); + doCommand(Doc,"App.activeDocument().addObject(\"Fem::ConstraintPressure\",\"%s\")",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Pressure = 0.0",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().%s]", + Analysis->getNameInDocument(),Analysis->getNameInDocument(),FeatName.c_str()); + updateActive(); + + doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str()); +} + +bool CmdFemConstraintPressure::isActive(void) +{ + return hasActiveDocument(); +} + +//===================================================================================== + DEF_STD_CMD_A(CmdFemConstraintGear); CmdFemConstraintGear::CmdFemConstraintGear() @@ -607,6 +647,7 @@ void CreateFemCommands(void) rcCmdMgr.addCommand(new CmdFemConstraintBearing()); rcCmdMgr.addCommand(new CmdFemConstraintFixed()); rcCmdMgr.addCommand(new CmdFemConstraintForce()); + rcCmdMgr.addCommand(new CmdFemConstraintPressure()); rcCmdMgr.addCommand(new CmdFemConstraintGear()); rcCmdMgr.addCommand(new CmdFemConstraintPulley()); } diff --git a/src/Mod/Fem/Gui/Resources/Fem.qrc b/src/Mod/Fem/Gui/Resources/Fem.qrc index 3b3d193d6..f30970544 100755 --- a/src/Mod/Fem/Gui/Resources/Fem.qrc +++ b/src/Mod/Fem/Gui/Resources/Fem.qrc @@ -5,6 +5,7 @@ icons/Fem_Analysis.svg icons/Fem_ConstraintForce.svg icons/Fem_ConstraintFixed.svg + icons/Fem_ConstraintPressure.svg icons/Fem_ConstraintBearing.svg icons/Fem_ConstraintGear.svg icons/Fem_ConstraintPulley.svg diff --git a/src/Mod/Fem/Gui/Resources/icons/Fem_ConstraintPressure.svg b/src/Mod/Fem/Gui/Resources/icons/Fem_ConstraintPressure.svg new file mode 100644 index 000000000..06c326b95 --- /dev/null +++ b/src/Mod/Fem/Gui/Resources/icons/Fem_ConstraintPressure.svg @@ -0,0 +1,216 @@ + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp b/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp new file mode 100644 index 000000000..e32382427 --- /dev/null +++ b/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp @@ -0,0 +1,275 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Author: Przemo Firszt * + * 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/FemConstraintPressure.h" +#include "TaskFemConstraintPressure.h" +#include "ui_TaskFemConstraintPressure.h" +#include +#include + +using namespace FemGui; +using namespace Gui; + +/* TRANSLATOR FemGui::TaskFemConstraintPressure */ + +TaskFemConstraintPressure::TaskFemConstraintPressure(ViewProviderFemConstraintPressure *ConstraintView,QWidget *parent) + : TaskFemConstraint(ConstraintView, parent, "Fem_ConstraintPressure") +{ + proxy = new QWidget(this); + ui = new Ui_TaskFemConstraintPressure(); + 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_pressure, SIGNAL(valueChanged(Base::Quantity)), + this, SLOT(onPressureChanged(Base::Quantity))); + connect(ui->b_add_reference, SIGNAL(pressed()), + this, SLOT(onButtonReference())); + connect(ui->cb_reverse_direction, SIGNAL(toggled(bool)), + this, SLOT(onCheckReverse(bool))); + + this->groupLayout()->addWidget(proxy); + + // Temporarily prevent unnecessary feature recomputes + ui->if_pressure->blockSignals(true); + ui->lw_references->blockSignals(true); + ui->b_add_reference->blockSignals(true); + ui->cb_reverse_direction->blockSignals(true); + + // Get the feature data + Fem::ConstraintPressure* pcConstraint = static_cast(ConstraintView->getObject()); + double f = pcConstraint->Pressure.getValue(); + std::vector Objects = pcConstraint->References.getValues(); + std::vector SubElements = pcConstraint->References.getSubValues(); + bool reversed = pcConstraint->Reversed.getValue(); + + // Fill data into dialog elements + ui->if_pressure->setMinimum(0); + ui->if_pressure->setMaximum(FLOAT_MAX); + //1000 because FreeCAD used kPa internally + Base::Quantity p = Base::Quantity(1000 * f, Base::Unit::Stress); + double val = p.getValueAs(Base::Quantity::MegaPascal); + ui->if_pressure->setValue(p); + 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); + } + ui->cb_reverse_direction->setChecked(reversed); + + ui->if_pressure->blockSignals(false); + ui->lw_references->blockSignals(false); + ui->b_add_reference->blockSignals(false); + ui->cb_reverse_direction->blockSignals(false); + + updateUI(); +} + +TaskFemConstraintPressure::~TaskFemConstraintPressure() +{ + delete ui; +} + +void TaskFemConstraintPressure::updateUI() +{ + if (ui->lw_references->model()->rowCount() == 0) { + // Go into reference selection mode if no reference has been selected yet + onButtonReference(true); + return; + } +} + +void TaskFemConstraintPressure::onSelectionChanged(const Gui::SelectionChanges& msg) +{ + if ((msg.Type != Gui::SelectionChanges::AddSelection) || + // Don't allow selection in other document + (strcmp(msg.pDocName, ConstraintView->getObject()->getDocument()->getName()) != 0) || + // Don't allow selection mode none + (selectionMode != selref) || + // Don't allow empty smenu/submenu + (!msg.pSubName || msg.pSubName[0] == '\0')) { + return; + } + + std::string subName(msg.pSubName); + Fem::ConstraintPressure* pcConstraint = static_cast(ConstraintView->getObject()); + App::DocumentObject* obj = ConstraintView->getObject()->getDocument()->getObject(msg.pObjectName); + + std::vector Objects = pcConstraint->References.getValues(); + std::vector SubElements = pcConstraint->References.getSubValues(); + + if (subName.substr(0,4) != "Face") { + QMessageBox::warning(this, tr("Selection error"), tr("Only faces can be picked")); + return; + } + // Avoid duplicates + std::size_t pos = 0; + for (; pos < Objects.size(); pos++) + if (obj == Objects[pos]) + break; + + if (pos != Objects.size()) + if (subName == SubElements[pos]) + return; + + // add the new reference + Objects.push_back(obj); + SubElements.push_back(subName); + pcConstraint->References.setValues(Objects,SubElements); + ui->lw_references->addItem(makeRefText(obj, subName)); + + // Turn off reference selection mode + onButtonReference(false); + Gui::Selection().clearSelection(); + updateUI(); +} + +void TaskFemConstraintPressure::onPressureChanged(const Base::Quantity& f) +{ + Fem::ConstraintPressure* pcConstraint = static_cast(ConstraintView->getObject()); + double val = f.getValueAs(Base::Quantity::MegaPascal); + pcConstraint->Pressure.setValue(val); +} + +void TaskFemConstraintPressure::onReferenceDeleted() { + int row = ui->lw_references->currentIndex().row(); + TaskFemConstraint::onReferenceDeleted(row); + ui->lw_references->model()->removeRow(row); + ui->lw_references->setCurrentRow(0, QItemSelectionModel::ClearAndSelect); +} + +void TaskFemConstraintPressure::onCheckReverse(const bool pressed) +{ + Fem::ConstraintPressure* pcConstraint = static_cast(ConstraintView->getObject()); + pcConstraint->Reversed.setValue(pressed); +} + +const std::string TaskFemConstraintPressure::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 TaskFemConstraintPressure::getPressure(void) const +{ + Base::Quantity pressure = ui->if_pressure->getQuantity(); + double pressure_in_MPa = pressure.getValueAs(Base::Quantity::MegaPascal); + return pressure_in_MPa; +} + +bool TaskFemConstraintPressure::getReverse() const +{ + return ui->cb_reverse_direction->isChecked(); +} + +void TaskFemConstraintPressure::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 +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +TaskDlgFemConstraintPressure::TaskDlgFemConstraintPressure(ViewProviderFemConstraintPressure *ConstraintView) +{ + this->ConstraintView = ConstraintView; + assert(ConstraintView); + this->parameter = new TaskFemConstraintPressure(ConstraintView);; + + Content.push_back(parameter); +} + +//==== calls from the TaskView =============================================================== + +void TaskDlgFemConstraintPressure::open() +{ + // a transaction is already open at creation time of the panel + if (!Gui::Command::hasPendingCommand()) { + QString msg = QObject::tr("Constraint normal stress"); + Gui::Command::openCommand((const char*)msg.toUtf8()); + } +} + +bool TaskDlgFemConstraintPressure::accept() +{ + std::string name = ConstraintView->getObject()->getNameInDocument(); + const TaskFemConstraintPressure* parameterPressure = static_cast(parameter); + + try { + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Pressure = %f", + name.c_str(), parameterPressure->getPressure()); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %s", + name.c_str(), parameterPressure->getReverse() ? "True" : "False"); + } + catch (const Base::Exception& e) { + QMessageBox::warning(parameter, tr("Input error"), QString::fromAscii(e.what())); + return false; + } + + return TaskDlgFemConstraint::accept(); +} + +bool TaskDlgFemConstraintPressure::reject() +{ + Gui::Command::abortCommand(); + Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); + Gui::Command::updateActive(); + + return true; +} + +#include "moc_TaskFemConstraintPressure.cpp" diff --git a/src/Mod/Fem/Gui/TaskFemConstraintPressure.h b/src/Mod/Fem/Gui/TaskFemConstraintPressure.h new file mode 100644 index 000000000..a24ed61c7 --- /dev/null +++ b/src/Mod/Fem/Gui/TaskFemConstraintPressure.h @@ -0,0 +1,78 @@ +/*************************************************************************** + * Copyright (c) 2015 Przemo Firszt * + * Based on Force constraint * + * 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_TaskFemConstraintPressure_H +#define GUI_TASKVIEW_TaskFemConstraintPressure_H + +#include +#include +#include +#include + +#include "TaskFemConstraint.h" +#include "ViewProviderFemConstraintPressure.h" + +class Ui_TaskFemConstraintPressure; + +namespace App { + class Property; +} + +namespace Gui { + class ViewProvider; +} + +namespace FemGui { + class TaskFemConstraintPressure : public TaskFemConstraint { + Q_OBJECT public: + TaskFemConstraintPressure(ViewProviderFemConstraintPressure *ConstraintView,QWidget *parent = 0); + virtual ~TaskFemConstraintPressure(); + double getPressure(void) const; + virtual const std::string getReferences() const; + bool getReverse(void) const; + + private Q_SLOTS: + void onReferenceDeleted(void); + void onPressureChanged(const Base::Quantity & f); + void onCheckReverse(bool); + + protected: + virtual void changeEvent(QEvent *e); + + private: + virtual void onSelectionChanged(const Gui::SelectionChanges& msg); + void updateUI(); + Ui_TaskFemConstraintPressure* ui; + }; + + class TaskDlgFemConstraintPressure : public TaskDlgFemConstraint { + Q_OBJECT public: + TaskDlgFemConstraintPressure(ViewProviderFemConstraintPressure *ConstraintView); + virtual void open(); + virtual bool accept(); + virtual bool reject(); + + }; +} //namespace FemGui + +#endif // GUI_TASKVIEW_TaskFemConstraintPressure_H diff --git a/src/Mod/Fem/Gui/TaskFemConstraintPressure.ui b/src/Mod/Fem/Gui/TaskFemConstraintPressure.ui new file mode 100644 index 000000000..82a0fdf29 --- /dev/null +++ b/src/Mod/Fem/Gui/TaskFemConstraintPressure.ui @@ -0,0 +1,79 @@ + + + TaskFemConstraintPressure + + + + 0 + 0 + 257 + 250 + + + + Form + + + + + + Add reference + + + + + + + + + + + + Pressure + + + + + + + 1 MPa + + + + + + + + + + + + Reverse direction + + + + + + + Qt::Vertical + + + + 17 + 56 + + + + + + + + + Gui::InputField + QLineEdit +
Gui/InputField.h
+
+
+ + +
diff --git a/src/Mod/Fem/Gui/ViewProviderFemConstraintPressure.cpp b/src/Mod/Fem/Gui/ViewProviderFemConstraintPressure.cpp new file mode 100644 index 000000000..cc698224b --- /dev/null +++ b/src/Mod/Fem/Gui/ViewProviderFemConstraintPressure.cpp @@ -0,0 +1,143 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Author: Przemo Firszt * + * 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 +#endif + +#include "Mod/Fem/App/FemConstraintPressure.h" +#include "TaskFemConstraintPressure.h" +#include "ViewProviderFemConstraintPressure.h" +#include +#include + +using namespace FemGui; + +PROPERTY_SOURCE(FemGui::ViewProviderFemConstraintPressure, FemGui::ViewProviderFemConstraint) + +ViewProviderFemConstraintPressure::ViewProviderFemConstraintPressure() +{ + sPixmap = "Fem_ConstraintPressure"; + ADD_PROPERTY(FaceColor,(0.0f,0.2f,0.8f)); +} + +ViewProviderFemConstraintPressure::~ViewProviderFemConstraintPressure() +{ +} + +//FIXME setEdit needs a careful review +bool ViewProviderFemConstraintPressure::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(); + TaskDlgFemConstraintPressure *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 TaskFemConstraintPressure(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 TaskDlgFemConstraintPressure(this)); + return true; + } + else { + return ViewProviderDocumentObject::setEdit(ModNum); + } +} + +#define ARROWLENGTH 5 +#define ARROWHEADRADIUS 3 + +void ViewProviderFemConstraintPressure::updateData(const App::Property* prop) +{ + // Gets called whenever a property of the attached object changes + Fem::ConstraintPressure* pcConstraint = static_cast(this->getObject()); + + if (pShapeSep->getNumChildren() == 0) { + // Set up the nodes + SoMultipleCopy* cp = new SoMultipleCopy(); + cp->ref(); + cp->matrix.setNum(0); + cp->addChild((SoNode*)createArrow(ARROWLENGTH, ARROWHEADRADIUS)); + pShapeSep->addChild(cp); + } + + 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(); + + SoMultipleCopy* cp = static_cast(pShapeSep->getChild(0)); + cp->matrix.setNum(points.size()); + SbMatrix* matrices = cp->matrix.startEditing(); + int idx = 0; + + for (std::vector::const_iterator p = points.begin(); p != points.end(); p++) { + SbVec3f base(p->x, p->y, p->z); + SbVec3f dir(n->x, n->y, n->z); + double rev; + if (pcConstraint->Reversed.getValue()) { + base = base + dir * ARROWLENGTH; + rev = 1; + } else { + rev = -1; + } + SbRotation rot(SbVec3f(0, rev, 0), dir); + SbMatrix m; + m.setTransform(base, rot, SbVec3f(1,1,1)); + matrices[idx] = m; + idx++; + n++; + } + cp->matrix.finishEditing(); + } + + ViewProviderFemConstraint::updateData(prop); +} diff --git a/src/Mod/Fem/Gui/ViewProviderFemConstraintPressure.h b/src/Mod/Fem/Gui/ViewProviderFemConstraintPressure.h new file mode 100644 index 000000000..318070699 --- /dev/null +++ b/src/Mod/Fem/Gui/ViewProviderFemConstraintPressure.h @@ -0,0 +1,52 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Author: Przemo Firszt * + * 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_VIEWPROVIDERFEMCONSTRAINTPRESSURE_H +#define GUI_VIEWPROVIDERFEMCONSTRAINTPRESSURE_H + +#include +#include +#include "ViewProviderFemConstraint.h" + +namespace Gui { + class View3DInventorViewer; + namespace TaskView { + class TaskDialog; + } +} + +namespace FemGui { + class FemGuiExport ViewProviderFemConstraintPressure : public FemGui::ViewProviderFemConstraint { + PROPERTY_HEADER(FemGui::ViewProviderFemConstraintPressure); + + public: + ViewProviderFemConstraintPressure(); + virtual ~ViewProviderFemConstraintPressure(); + virtual void updateData(const App::Property*); + + protected: + virtual bool setEdit(int ModNum); + }; +} + +#endif // GUI_VIEWPROVIDERFEMCONSTRAINTPRESSURE_H diff --git a/src/Mod/Fem/Gui/Workbench.cpp b/src/Mod/Fem/Gui/Workbench.cpp index cbb361517..54a56b9de 100755 --- a/src/Mod/Fem/Gui/Workbench.cpp +++ b/src/Mod/Fem/Gui/Workbench.cpp @@ -63,6 +63,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const << "Separator" << "Fem_ConstraintFixed" << "Fem_ConstraintForce" + << "Fem_ConstraintPressure" << "Fem_ConstraintBearing" << "Fem_ConstraintGear" << "Fem_ConstraintPulley" @@ -87,6 +88,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const << "Separator" << "Fem_ConstraintFixed" << "Fem_ConstraintForce" + << "Fem_ConstraintPressure" << "Fem_ConstraintBearing" << "Fem_ConstraintGear" << "Fem_ConstraintPulley" diff --git a/src/Mod/Fem/MechanicalAnalysis.py b/src/Mod/Fem/MechanicalAnalysis.py index b80f1d80b..1b6985b9d 100644 --- a/src/Mod/Fem/MechanicalAnalysis.py +++ b/src/Mod/Fem/MechanicalAnalysis.py @@ -377,7 +377,7 @@ class _JobControlTaskPanel: try: import ccxInpWriter as iw inp_writer = iw.inp_writer(self.TempDir, self.MeshObject, self.MaterialObjects, - self.FixedObjects, self.ForceObjects) + self.FixedObjects, self.ForceObjects, self.PressureObjects) self.base_name = inp_writer.write_calculix_input_file() if self.base_name != "": self.femConsoleMessage("Write completed.") @@ -435,8 +435,16 @@ class _JobControlTaskPanel: if i.isDerivedFrom("Fem::ConstraintForce"): ForceObjectDict['Object'] = i self.ForceObjects.append(ForceObjectDict) - if not self.ForceObjects: - QtGui.QMessageBox.critical(None, "Missing prerequisite", "No force-constraint nodes defined in the Analysis") + + self.PressureObjects = [] # [{'Object':PressureObject, 'xxxxxxxx':value}, {}, ...] + for i in FemGui.getActiveAnalysis().Member: + PressureObjectDict = {} + if i.isDerivedFrom("Fem::ConstraintPressure"): + PressureObjectDict['Object'] = i + self.PressureObjects.append(PressureObjectDict) + + if not (self.ForceObjects or self.PressureObjects): + QtGui.QMessageBox.critical(None, "Missing prerequisite", "No force-constraint or pressure-constraint defined in the Analysis") return False return True diff --git a/src/Mod/Fem/ccxInpWriter.py b/src/Mod/Fem/ccxInpWriter.py index 664e42feb..a902cd852 100644 --- a/src/Mod/Fem/ccxInpWriter.py +++ b/src/Mod/Fem/ccxInpWriter.py @@ -6,11 +6,12 @@ import sys class inp_writer: - def __init__(self, dir_name, mesh_obj, mat_obj, fixed_obj, force_obj): + def __init__(self, dir_name, mesh_obj, mat_obj, fixed_obj, force_obj, pressure_obj): self.mesh_object = mesh_obj self.material_objects = mat_obj self.fixed_objects = fixed_obj self.force_objects = force_obj + self.pressure_objects = pressure_obj self.base_name = dir_name + '/' + self.mesh_object.Name self.file_name = self.base_name + '.inp' print 'CalculiX .inp file will be written to: ', self.file_name @@ -29,7 +30,7 @@ class inp_writer: self.write_step_begin(inpfile) self.write_constraints_fixed(inpfile) self.write_constraints_force(inpfile) - #self.write_face_load(inpfile) + self.write_face_load(inpfile) self.write_outputs_types(inpfile) self.write_step_end(inpfile) self.write_footer(inpfile) @@ -306,16 +307,17 @@ class inp_writer: f.write('\n***********************************************************\n') f.write('** Element + CalculiX face + load in [MPa]\n') f.write('** written by {} function\n'.format(sys._getframe().f_code.co_name)) - for fobj in self.force_objects: - frc_obj = fobj['Object'] + for fobj in self.pressure_objects: + prs_obj = fobj['Object'] f.write('*DLOAD\n') - for o, e in frc_obj.References: + for o, e in prs_obj.References: + rev = -1 if prs_obj.Reversed else 1 elem = o.Shape.getElement(e) if elem.ShapeType == 'Face': v = self.mesh_object.FemMesh.getccxVolumesByFace(elem) f.write("** Load on face {}\n".format(e)) for i in v: - f.write("{},P{},{}\n".format(i[0], i[1], frc_obj.Force)) + f.write("{},P{},{}\n".format(i[0], i[1], rev * prs_obj.Pressure)) def write_outputs_types(self, f): f.write('\n***********************************************************\n')