FEM: Add unit test for new ConstraintRigidBody object

This commit is contained in:
Ajinkya Dahale
2022-11-05 16:39:27 +05:30
committed by Chris Hennes
parent cc6e59eacc
commit 4feb519bc9
8 changed files with 318 additions and 150 deletions

View File

@@ -31,33 +31,39 @@ PROPERTY_SOURCE(Fem::ConstraintRigidBody, Fem::Constraint)
ConstraintRigidBody::ConstraintRigidBody()
{
ADD_PROPERTY(xRefNode,(0.0));
ADD_PROPERTY(yRefNode,(0.0));
ADD_PROPERTY(zRefNode,(0.0));
ADD_PROPERTY(xDisplacement,(0.0));
ADD_PROPERTY(yDisplacement,(0.0));
ADD_PROPERTY(zDisplacement,(0.0));
ADD_PROPERTY(xRotation,(0.0));
ADD_PROPERTY(yRotation,(0.0));
ADD_PROPERTY(zRotation,(0.0));
ADD_PROPERTY(xLoad,(0.0));
ADD_PROPERTY(yLoad,(0.0));
ADD_PROPERTY(zLoad,(0.0));
ADD_PROPERTY(xMoment,(0.0));
ADD_PROPERTY(yMoment,(0.0));
ADD_PROPERTY(zMoment,(0.0));
ADD_PROPERTY(DefineRefNode,(1));
ADD_PROPERTY(xRefNode, (0.0));
ADD_PROPERTY(yRefNode, (0.0));
ADD_PROPERTY(zRefNode, (0.0));
ADD_PROPERTY(xDisplacement, (0.0));
ADD_PROPERTY(yDisplacement, (0.0));
ADD_PROPERTY(zDisplacement, (0.0));
ADD_PROPERTY(xRotation, (0.0));
ADD_PROPERTY(yRotation, (0.0));
ADD_PROPERTY(zRotation, (0.0));
ADD_PROPERTY(xLoad, (0.0));
ADD_PROPERTY(yLoad, (0.0));
ADD_PROPERTY(zLoad, (0.0));
ADD_PROPERTY(xMoment, (0.0));
ADD_PROPERTY(yMoment, (0.0));
ADD_PROPERTY(zMoment, (0.0));
ADD_PROPERTY(DefineRefNode, (1));
// For drawing the icons
ADD_PROPERTY_TYPE(Points,(Base::Vector3d()),"ConstraintRigidBody",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
ADD_PROPERTY_TYPE(Points,
(Base::Vector3d()),
"ConstraintRigidBody",
App::PropertyType(App::Prop_ReadOnly | App::Prop_Output),
"Points where symbols are drawn");
ADD_PROPERTY_TYPE(Normals,(Base::Vector3d()),"ConstraintRigidBody",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
ADD_PROPERTY_TYPE(Normals,
(Base::Vector3d()),
"ConstraintRigidBody",
App::PropertyType(App::Prop_ReadOnly | App::Prop_Output),
"Normals where symbols are drawn");
Points.setValues(std::vector<Base::Vector3d>());
Normals.setValues(std::vector<Base::Vector3d>());
}
App::DocumentObjectExecReturn *ConstraintRigidBody::execute()
App::DocumentObjectExecReturn* ConstraintRigidBody::execute()
{
return Constraint::execute();
}
@@ -71,12 +77,12 @@ void ConstraintRigidBody::onChanged(const App::Property* prop)
if (prop == &References) {
std::vector<Base::Vector3d> points;
std::vector<Base::Vector3d> normals;
int scale = 1; //OvG: Enforce use of scale
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()
Scale.setValue(scale); // OvG: Scale
Points.touch(); // This triggers ViewProvider::updateData()
}
}
}

View File

@@ -29,7 +29,7 @@
namespace Fem
{
class FemExport ConstraintRigidBody : public Fem::Constraint
class FemExport ConstraintRigidBody: public Fem::Constraint
{
PROPERTY_HEADER_WITH_OVERRIDE(Fem::ConstraintRigidBody);
@@ -60,10 +60,11 @@ public:
App::PropertyBool DefineRefNode;
/// recalculate the object
App::DocumentObjectExecReturn *execute() override;
App::DocumentObjectExecReturn* execute() override;
/// returns the type name of the ViewProvider
const char* getViewProviderName() const override {
const char* getViewProviderName() const override
{
return "FemGui::ViewProviderFemConstraintRigidBody";
}
@@ -71,7 +72,7 @@ protected:
void onChanged(const App::Property* prop) override;
};
} // namespace Fem
} // namespace Fem
#endif // FEM_CONSTRAINTRIGIDBODY_H
#endif // FEM_CONSTRAINTRIGIDBODY_H

View File

@@ -393,30 +393,40 @@ DEF_STD_CMD_A(CmdFemConstraintRigidBody)
CmdFemConstraintRigidBody::CmdFemConstraintRigidBody()
: Command("FEM_ConstraintRigidBody")
{
sAppModule = "Fem";
sGroup = QT_TR_NOOP("Fem");
sMenuText = QT_TR_NOOP("Constraint rigid body");
sToolTipText = QT_TR_NOOP("Creates a FEM constraint for a rigid body");
sWhatsThis = "FEM_ConstraintRigidBody";
sStatusTip = sToolTipText;
sPixmap = "FEM_ConstraintRigidBody";
sAppModule = "Fem";
sGroup = QT_TR_NOOP("Fem");
sMenuText = QT_TR_NOOP("Constraint rigid body");
sToolTipText = QT_TR_NOOP("Creates a FEM constraint for a rigid body");
sWhatsThis = "FEM_ConstraintRigidBody";
sStatusTip = sToolTipText;
sPixmap = "FEM_ConstraintRigidBody";
}
void CmdFemConstraintRigidBody::activated(int)
{
Fem::FemAnalysis* Analysis;
if (getConstraintPrerequisits(&Analysis))
if (getConstraintPrerequisits(&Analysis)) {
return;
}
std::string FeatName = getUniqueObjectName("ConstraintRigidBody");
openCommand(QT_TRANSLATE_NOOP("Command", "Make FEM constraint fixed geometry"));
doCommand(Doc, "App.activeDocument().addObject(\"Fem::ConstraintRigidBody\",\"%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.addObject(App.activeDocument().%s)", Analysis->getNameInDocument(), FeatName.c_str());
doCommand(Doc,
"App.activeDocument().addObject(\"Fem::ConstraintRigidBody\",\"%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.addObject(App.activeDocument().%s)",
Analysis->getNameInDocument(),
FeatName.c_str());
doCommand(Doc, "%s", gethideMeshShowPartStr(FeatName).c_str()); //OvG: Hide meshes and show parts
doCommand(Doc,
"%s",
gethideMeshShowPartStr(FeatName).c_str()); // OvG: Hide meshes and show parts
updateActive();

View File

@@ -23,9 +23,9 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QAction>
# include <QMessageBox>
# include <sstream>
#include <QAction>
#include <QMessageBox>
#include <sstream>
#endif
#include <App/Document.h>
@@ -42,9 +42,11 @@ using namespace Gui;
/* TRANSLATOR FemGui::TaskFemConstraintRigidBody */
TaskFemConstraintRigidBody::TaskFemConstraintRigidBody(ViewProviderFemConstraintRigidBody* ConstraintView, QWidget* parent)
TaskFemConstraintRigidBody::TaskFemConstraintRigidBody(
ViewProviderFemConstraintRigidBody* ConstraintView,
QWidget* parent)
: TaskFemConstraintOnBoundary(ConstraintView, parent, "FEM_ConstraintRigidBody")
{ //Note change "RigidBody" in line above to new constraint name
{ // Note change "RigidBody" in line above to new constraint name
proxy = new QWidget(this);
ui = new Ui_TaskFemConstraintRigidBody();
ui->setupUi(proxy);
@@ -52,13 +54,19 @@ TaskFemConstraintRigidBody::TaskFemConstraintRigidBody(ViewProviderFemConstraint
// create a context menu for the listview of the references
createDeleteAction(ui->lw_references);
deleteAction->connect(deleteAction, &QAction::triggered,
this, &TaskFemConstraintRigidBody::onReferenceDeleted);
deleteAction->connect(deleteAction,
&QAction::triggered,
this,
&TaskFemConstraintRigidBody::onReferenceDeleted);
connect(ui->lw_references, &QListWidget::currentItemChanged,
this, &TaskFemConstraintRigidBody::setSelection);
connect(ui->lw_references, &QListWidget::itemClicked,
this, &TaskFemConstraintRigidBody::setSelection);
connect(ui->lw_references,
&QListWidget::currentItemChanged,
this,
&TaskFemConstraintRigidBody::setSelection);
connect(ui->lw_references,
&QListWidget::itemClicked,
this,
&TaskFemConstraintRigidBody::setSelection);
// TODO: Relate inputs to property
@@ -66,7 +74,8 @@ TaskFemConstraintRigidBody::TaskFemConstraintRigidBody(ViewProviderFemConstraint
/* Note: */
// Get the feature data
Fem::ConstraintRigidBody* pcConstraint = static_cast<Fem::ConstraintRigidBody*>(ConstraintView->getObject());
Fem::ConstraintRigidBody* pcConstraint =
static_cast<Fem::ConstraintRigidBody*>(ConstraintView->getObject());
double fStates[15];
fStates[0] = pcConstraint->xRefNode.getValue();
fStates[1] = pcConstraint->yRefNode.getValue();
@@ -106,7 +115,7 @@ TaskFemConstraintRigidBody::TaskFemConstraintRigidBody(ViewProviderFemConstraint
ui->lw_references->setCurrentRow(0, QItemSelectionModel::ClearAndSelect);
}
//Selection buttons
// Selection buttons
buttonGroup->addButton(ui->btnAdd, (int)SelectionChangeModes::refAdd);
buttonGroup->addButton(ui->btnRemove, (int)SelectionChangeModes::refRemove);
@@ -129,43 +138,60 @@ void TaskFemConstraintRigidBody::updateUI()
void TaskFemConstraintRigidBody::addToSelection()
{
std::vector<Gui::SelectionObject> selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document
std::vector<Gui::SelectionObject> selection =
Gui::Selection().getSelectionEx(); // gets vector of selected objects of active document
if (selection.empty()) {
QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!"));
return;
}
Fem::ConstraintRigidBody* pcConstraint = static_cast<Fem::ConstraintRigidBody*>(ConstraintView->getObject());
Fem::ConstraintRigidBody* pcConstraint =
static_cast<Fem::ConstraintRigidBody*>(ConstraintView->getObject());
std::vector<App::DocumentObject*> Objects = pcConstraint->References.getValues();
std::vector<std::string> SubElements = pcConstraint->References.getSubValues();
for (std::vector<Gui::SelectionObject>::iterator it = selection.begin(); it != selection.end(); ++it) {//for every selected object
for (std::vector<Gui::SelectionObject>::iterator it = selection.begin(); it != selection.end();
++it) { // for every selected object
if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) {
QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!"));
return;
}
std::vector<std::string> subNames = it->getSubNames();
App::DocumentObject* obj = ConstraintView->getObject()->getDocument()->getObject(it->getFeatName());
for (size_t subIt = 0; subIt < (subNames.size()); ++subIt) {// for every selected sub element
App::DocumentObject* obj =
ConstraintView->getObject()->getDocument()->getObject(it->getFeatName());
for (size_t subIt = 0; subIt < (subNames.size());
++subIt) { // for every selected sub element
bool addMe = true;
for (std::vector<std::string>::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
for (std::vector<std::string>::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;
}
}
// limit constraint such that only vertexes or faces or edges can be used depending on what was selected first
// limit constraint such that only vertexes or faces or edges can be used depending on
// what was selected first
std::string searchStr;
if (subNames[subIt].find("Vertex") != std::string::npos)
if (subNames[subIt].find("Vertex") != std::string::npos) {
searchStr = "Vertex";
else if (subNames[subIt].find("Edge") != std::string::npos)
}
else if (subNames[subIt].find("Edge") != std::string::npos) {
searchStr = "Edge";
else
}
else {
searchStr = "Face";
}
for (size_t iStr = 0; iStr < (SubElements.size()); ++iStr) {
if (SubElements[iStr].find(searchStr) == std::string::npos) {
QString msg = tr("Only one type of selection (vertex,face or edge) per constraint allowed!");
QString msg = tr(
"Only one type of selection (vertex,face or edge) per constraint allowed!");
QMessageBox::warning(this, tr("Selection error"), msg);
addMe = false;
break;
@@ -179,23 +205,26 @@ void TaskFemConstraintRigidBody::addToSelection()
}
}
}
//Update UI
// Update UI
pcConstraint->References.setValues(Objects, SubElements);
updateUI();
}
void TaskFemConstraintRigidBody::removeFromSelection()
{
std::vector<Gui::SelectionObject> selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document
std::vector<Gui::SelectionObject> selection =
Gui::Selection().getSelectionEx(); // gets vector of selected objects of active document
if (selection.empty()) {
QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!"));
return;
}
Fem::ConstraintRigidBody* pcConstraint = static_cast<Fem::ConstraintRigidBody*>(ConstraintView->getObject());
Fem::ConstraintRigidBody* pcConstraint =
static_cast<Fem::ConstraintRigidBody*>(ConstraintView->getObject());
std::vector<App::DocumentObject*> Objects = pcConstraint->References.getValues();
std::vector<std::string> SubElements = pcConstraint->References.getSubValues();
std::vector<size_t> itemsToDel;
for (std::vector<Gui::SelectionObject>::iterator it = selection.begin(); it != selection.end(); ++it) {//for every selected object
for (std::vector<Gui::SelectionObject>::iterator it = selection.begin(); it != selection.end();
++it) { // for every selected object
if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) {
QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!"));
return;
@@ -203,12 +232,20 @@ void TaskFemConstraintRigidBody::removeFromSelection()
const std::vector<std::string>& subNames = it->getSubNames();
App::DocumentObject* obj = it->getObject();
for (size_t subIt = 0; subIt < (subNames.size()); ++subIt) {// for every selected sub element
for (std::vector<std::string>::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
for (size_t subIt = 0; subIt < (subNames.size());
++subIt) { // for every selected sub element
for (std::vector<std::string>::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));
}
}
@@ -220,7 +257,7 @@ void TaskFemConstraintRigidBody::removeFromSelection()
SubElements.erase(SubElements.begin() + itemsToDel.back());
itemsToDel.pop_back();
}
//Update UI
// Update UI
{
QSignalBlocker block(ui->lw_references);
ui->lw_references->clear();
@@ -232,7 +269,8 @@ void TaskFemConstraintRigidBody::removeFromSelection()
updateUI();
}
void TaskFemConstraintRigidBody::onReferenceDeleted() {
void TaskFemConstraintRigidBody::onReferenceDeleted()
{
TaskFemConstraintRigidBody::removeFromSelection();
}
@@ -246,17 +284,47 @@ const std::string TaskFemConstraintRigidBody::getReferences() const
return TaskFemConstraint::getReferences(items);
}
double TaskFemConstraintRigidBody::get_xRefNode() const { return ui->if_ref_node_x->rawValue(); }
double TaskFemConstraintRigidBody::get_yRefNode() const { return ui->if_ref_node_y->rawValue(); }
double TaskFemConstraintRigidBody::get_zRefNode() const { return ui->if_ref_node_z->rawValue(); }
double TaskFemConstraintRigidBody::get_xLoad() const { return ui->if_ref_load_x->rawValue(); }
double TaskFemConstraintRigidBody::get_yLoad() const { return ui->if_ref_load_y->rawValue(); }
double TaskFemConstraintRigidBody::get_zLoad() const { return ui->if_ref_load_z->rawValue(); }
double TaskFemConstraintRigidBody::get_xMoment() const { return ui->if_rot_load_x->rawValue(); }
double TaskFemConstraintRigidBody::get_yMoment() const { return ui->if_rot_load_y->rawValue(); }
double TaskFemConstraintRigidBody::get_zMoment() const { return ui->if_rot_load_z->rawValue(); }
double TaskFemConstraintRigidBody::get_xRefNode() const
{
return ui->if_ref_node_x->rawValue();
}
double TaskFemConstraintRigidBody::get_yRefNode() const
{
return ui->if_ref_node_y->rawValue();
}
double TaskFemConstraintRigidBody::get_zRefNode() const
{
return ui->if_ref_node_z->rawValue();
}
double TaskFemConstraintRigidBody::get_xLoad() const
{
return ui->if_ref_load_x->rawValue();
}
double TaskFemConstraintRigidBody::get_yLoad() const
{
return ui->if_ref_load_y->rawValue();
}
double TaskFemConstraintRigidBody::get_zLoad() const
{
return ui->if_ref_load_z->rawValue();
}
double TaskFemConstraintRigidBody::get_xMoment() const
{
return ui->if_rot_load_x->rawValue();
}
double TaskFemConstraintRigidBody::get_yMoment() const
{
return ui->if_rot_load_y->rawValue();
}
double TaskFemConstraintRigidBody::get_zMoment() const
{
return ui->if_rot_load_z->rawValue();
}
// TODO: This needs to be implemented
bool TaskFemConstraintRigidBody::get_DefineRefNode() const { return true; }
bool TaskFemConstraintRigidBody::get_DefineRefNode() const
{
return true;
}
bool TaskFemConstraintRigidBody::event(QEvent* e)
{
@@ -264,22 +332,24 @@ bool TaskFemConstraintRigidBody::event(QEvent* e)
}
void TaskFemConstraintRigidBody::changeEvent(QEvent*)
{
}
{}
void TaskFemConstraintRigidBody::clearButtons(const SelectionChangeModes notThis)
{
if (notThis != SelectionChangeModes::refAdd)
if (notThis != SelectionChangeModes::refAdd) {
ui->btnAdd->setChecked(false);
if (notThis != SelectionChangeModes::refRemove)
}
if (notThis != SelectionChangeModes::refRemove) {
ui->btnRemove->setChecked(false);
}
}
//**************************************************************************
// TaskDialog
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TaskDlgFemConstraintRigidBody::TaskDlgFemConstraintRigidBody(ViewProviderFemConstraintRigidBody* ConstraintView)
TaskDlgFemConstraintRigidBody::TaskDlgFemConstraintRigidBody(
ViewProviderFemConstraintRigidBody* ConstraintView)
{
this->ConstraintView = ConstraintView;
assert(ConstraintView);
@@ -297,28 +367,66 @@ void TaskDlgFemConstraintRigidBody::open()
QString msg = QObject::tr("Constraint RigidBody");
Gui::Command::openCommand((const char*)msg.toUtf8());
ConstraintView->setVisible(true);
Gui::Command::doCommand(Gui::Command::Doc, ViewProviderFemConstraint::gethideMeshShowPartStr((static_cast<Fem::Constraint*>(ConstraintView->getObject()))->getNameInDocument()).c_str()); //OvG: Hide meshes and show parts
Gui::Command::doCommand(
Gui::Command::Doc,
ViewProviderFemConstraint::gethideMeshShowPartStr(
(static_cast<Fem::Constraint*>(ConstraintView->getObject()))->getNameInDocument())
.c_str()); // OvG: Hide meshes and show parts
}
}
bool TaskDlgFemConstraintRigidBody::accept()
{
std::string name = ConstraintView->getObject()->getNameInDocument();
const TaskFemConstraintRigidBody* parameters = static_cast<const TaskFemConstraintRigidBody*>(parameter);
const TaskFemConstraintRigidBody* parameters =
static_cast<const TaskFemConstraintRigidBody*>(parameter);
try {
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.xRefNode = %f", name.c_str(), parameters->get_xRefNode());
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.yRefNode = %f", name.c_str(), parameters->get_yRefNode());
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.zRefNode = %f", name.c_str(), parameters->get_zRefNode());
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.xLoad = %f", name.c_str(), parameters->get_xLoad());
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.yLoad = %f", name.c_str(), parameters->get_yLoad());
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.zLoad = %f", name.c_str(), parameters->get_zLoad());
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.xMoment = %f", name.c_str(), parameters->get_xMoment());
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.yMoment = %f", name.c_str(), parameters->get_yMoment());
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.zMoment = %f", name.c_str(), parameters->get_zMoment());
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.DefineRefNode = %s", name.c_str(), parameters->get_DefineRefNode() ? "True" : "False");
Gui::Command::doCommand(Gui::Command::Doc,
"App.ActiveDocument.%s.xRefNode = %f",
name.c_str(),
parameters->get_xRefNode());
Gui::Command::doCommand(Gui::Command::Doc,
"App.ActiveDocument.%s.yRefNode = %f",
name.c_str(),
parameters->get_yRefNode());
Gui::Command::doCommand(Gui::Command::Doc,
"App.ActiveDocument.%s.zRefNode = %f",
name.c_str(),
parameters->get_zRefNode());
Gui::Command::doCommand(Gui::Command::Doc,
"App.ActiveDocument.%s.xLoad = %f",
name.c_str(),
parameters->get_xLoad());
Gui::Command::doCommand(Gui::Command::Doc,
"App.ActiveDocument.%s.yLoad = %f",
name.c_str(),
parameters->get_yLoad());
Gui::Command::doCommand(Gui::Command::Doc,
"App.ActiveDocument.%s.zLoad = %f",
name.c_str(),
parameters->get_zLoad());
Gui::Command::doCommand(Gui::Command::Doc,
"App.ActiveDocument.%s.xMoment = %f",
name.c_str(),
parameters->get_xMoment());
Gui::Command::doCommand(Gui::Command::Doc,
"App.ActiveDocument.%s.yMoment = %f",
name.c_str(),
parameters->get_yMoment());
Gui::Command::doCommand(Gui::Command::Doc,
"App.ActiveDocument.%s.zMoment = %f",
name.c_str(),
parameters->get_zMoment());
Gui::Command::doCommand(Gui::Command::Doc,
"App.ActiveDocument.%s.DefineRefNode = %s",
name.c_str(),
parameters->get_DefineRefNode() ? "True" : "False");
std::string scale = parameters->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
std::string scale = parameters->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()));

View File

@@ -31,13 +31,15 @@
class Ui_TaskFemConstraintRigidBody;
namespace FemGui {
class TaskFemConstraintRigidBody : public TaskFemConstraintOnBoundary
namespace FemGui
{
class TaskFemConstraintRigidBody: public TaskFemConstraintOnBoundary
{
Q_OBJECT
public:
explicit TaskFemConstraintRigidBody(ViewProviderFemConstraintRigidBody *ConstraintView,QWidget *parent = nullptr);
explicit TaskFemConstraintRigidBody(ViewProviderFemConstraintRigidBody* ConstraintView,
QWidget* parent = nullptr);
~TaskFemConstraintRigidBody() override;
const std::string getReferences() const override;
double get_xRefNode() const;
@@ -57,27 +59,26 @@ private Q_SLOTS:
void removeFromSelection() override;
protected:
bool event(QEvent *e) override;
void changeEvent(QEvent *e) override;
bool event(QEvent* e) override;
void changeEvent(QEvent* e) override;
void clearButtons(const SelectionChangeModes notThis) override;
private:
void updateUI();
Ui_TaskFemConstraintRigidBody* ui;
};
class TaskDlgFemConstraintRigidBody : public TaskDlgFemConstraint
class TaskDlgFemConstraintRigidBody: public TaskDlgFemConstraint
{
Q_OBJECT
public:
explicit TaskDlgFemConstraintRigidBody(ViewProviderFemConstraintRigidBody *ConstraintView);
explicit TaskDlgFemConstraintRigidBody(ViewProviderFemConstraintRigidBody* ConstraintView);
void open() override;
bool accept() override;
bool reject() override;
};
} //namespace FemGui
} // namespace FemGui
#endif // GUI_TASKVIEW_TaskFemConstraintRigidBody_H
#endif // GUI_TASKVIEW_TaskFemConstraintRigidBody_H

View File

@@ -23,11 +23,11 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QMessageBox>
# include <Inventor/SbRotation.h>
# include <Inventor/SbVec3f.h>
# include <Inventor/nodes/SoMultipleCopy.h>
# include <Inventor/nodes/SoSeparator.h>
#include <QMessageBox>
#include <Inventor/SbRotation.h>
#include <Inventor/SbVec3f.h>
#include <Inventor/nodes/SoMultipleCopy.h>
#include <Inventor/nodes/SoSeparator.h>
#endif
#include <Mod/Fem/App/FemConstraintRigidBody.h>
@@ -39,7 +39,8 @@
using namespace FemGui;
PROPERTY_SOURCE(FemGui::ViewProviderFemConstraintRigidBody, FemGui::ViewProviderFemConstraintOnBoundary)
PROPERTY_SOURCE(FemGui::ViewProviderFemConstraintRigidBody,
FemGui::ViewProviderFemConstraintOnBoundary)
ViewProviderFemConstraintRigidBody::ViewProviderFemConstraintRigidBody()
@@ -48,19 +49,20 @@ ViewProviderFemConstraintRigidBody::ViewProviderFemConstraintRigidBody()
}
ViewProviderFemConstraintRigidBody::~ViewProviderFemConstraintRigidBody()
{
}
{}
bool ViewProviderFemConstraintRigidBody::setEdit(int ModNum)
{
if (ModNum == ViewProvider::Default ) {
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();
TaskDlgFemConstraintRigidBody *constrDlg = qobject_cast<TaskDlgFemConstraintRigidBody *>(dlg);
if (constrDlg && constrDlg->getConstraintView() != this)
constrDlg = nullptr; // another constraint left open its task panel
Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
TaskDlgFemConstraintRigidBody* constrDlg =
qobject_cast<TaskDlgFemConstraintRigidBody*>(dlg);
if (constrDlg && constrDlg->getConstraintView() != this) {
constrDlg = nullptr; // another constraint left open its task panel
}
if (dlg && !constrDlg) {
// This case will occur in the ShaftWizard application
checkForWizard();
@@ -72,15 +74,19 @@ bool ViewProviderFemConstraintRigidBody::setEdit(int ModNum)
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::Yes);
int ret = msgBox.exec();
if (ret == QMessageBox::Yes)
if (ret == QMessageBox::Yes) {
Gui::Control().reject();
else
}
else {
return false;
} else if (constraintDialog) {
}
}
else if (constraintDialog) {
// Another FemConstraint* dialog is already open inside the Shaft Wizard
// Ignore the request to open another dialog
return false;
} else {
}
else {
constraintDialog = new TaskFemConstraintRigidBody(this);
return true;
}
@@ -90,44 +96,51 @@ bool ViewProviderFemConstraintRigidBody::setEdit(int ModNum)
Gui::Selection().clearSelection();
// start the edit dialog
if (constrDlg)
if (constrDlg) {
Gui::Control().showDialog(constrDlg);
else
}
else {
Gui::Control().showDialog(new TaskDlgFemConstraintRigidBody(this));
}
return true;
} else {
return ViewProviderDocumentObject::setEdit(ModNum); // clazy:exclude=skipped-base-method
}
else {
return ViewProviderDocumentObject::setEdit(ModNum); // clazy:exclude=skipped-base-method
}
}
#define WIDTH (2)
#define HEIGHT (1)
//#define USE_MULTIPLE_COPY //OvG: MULTICOPY fails to update scaled display on initial drawing - so disable
// #define USE_MULTIPLE_COPY //OvG: MULTICOPY fails to update scaled display on initial drawing -
// so disable
void ViewProviderFemConstraintRigidBody::updateData(const App::Property* prop)
{
// Gets called whenever a property of the attached object changes
Fem::ConstraintRigidBody *pcConstraint = static_cast<Fem::ConstraintRigidBody *>(this->getObject());
float scaledwidth = WIDTH * pcConstraint->Scale.getValue(); //OvG: Calculate scaled values once only
Fem::ConstraintRigidBody* pcConstraint =
static_cast<Fem::ConstraintRigidBody*>(this->getObject());
float scaledwidth =
WIDTH * pcConstraint->Scale.getValue(); // OvG: Calculate scaled values once only
float scaledheight = HEIGHT * pcConstraint->Scale.getValue();
#ifdef USE_MULTIPLE_COPY
//OvG: always need access to cp for scaling
// OvG: always need access to cp for scaling
SoMultipleCopy* cp = new SoMultipleCopy();
if (pShapeSep->getNumChildren() == 0) {
// Set up the nodes
cp->matrix.setNum(0);
cp->addChild((SoNode*)createRigidBody(scaledheight, scaledwidth)); //OvG: Scaling
cp->addChild((SoNode*)createRigidBody(scaledheight, scaledwidth)); // OvG: Scaling
pShapeSep->addChild(cp);
}
#endif
if (strcmp(prop->getName(),"Points") == 0) {
if (strcmp(prop->getName(), "Points") == 0) {
const std::vector<Base::Vector3d>& points = pcConstraint->Points.getValues();
const std::vector<Base::Vector3d>& normals = pcConstraint->Normals.getValues();
if (points.size() != normals.size())
if (points.size() != normals.size()) {
return;
}
std::vector<Base::Vector3d>::const_iterator n = normals.begin();
#ifdef USE_MULTIPLE_COPY
@@ -153,7 +166,7 @@ void ViewProviderFemConstraintRigidBody::updateData(const App::Property* prop)
#else
SoSeparator* sep = new SoSeparator();
createPlacement(sep, base, rot);
createFixed(sep, scaledheight, scaledwidth); //OvG: Scaling
createFixed(sep, scaledheight, scaledwidth); // OvG: Scaling
pShapeSep->addChild(sep);
#endif
n++;

View File

@@ -29,7 +29,8 @@
namespace FemGui
{
class FemGuiExport ViewProviderFemConstraintRigidBody : public FemGui::ViewProviderFemConstraintOnBoundary
class FemGuiExport ViewProviderFemConstraintRigidBody
: public FemGui::ViewProviderFemConstraintOnBoundary
{
PROPERTY_HEADER_WITH_OVERRIDE(FemGui::ViewProviderFemConstraintRigidBody);
@@ -44,7 +45,7 @@ protected:
bool setEdit(int ModNum) override;
};
} //namespace FemGui
} // namespace FemGui
#endif // GUI_VIEWPROVIDERFEMCONSTRAINTRIGIDBODY_H
#endif // GUI_VIEWPROVIDERFEMCONSTRAINTRIGIDBODY_H

View File

@@ -189,6 +189,10 @@ class TestObjectType(unittest.TestCase):
"Fem::ConstraintFixed",
type_of_obj(ObjectsFem.makeConstraintFixed(doc))
)
self.assertEqual(
"Fem::ConstraintRigidBody",
type_of_obj(ObjectsFem.makeConstraintRigidBody(doc))
)
self.assertEqual(
"Fem::ConstraintFlowVelocity",
type_of_obj(ObjectsFem.makeConstraintFlowVelocity(doc))
@@ -434,6 +438,10 @@ class TestObjectType(unittest.TestCase):
ObjectsFem.makeConstraintFixed(doc),
"Fem::ConstraintFixed"
))
self.assertTrue(is_of_type(
ObjectsFem.makeConstraintRigidBody(doc),
"Fem::ConstraintRigidBody"
))
self.assertTrue(is_of_type(
ObjectsFem.makeConstraintFlowVelocity(doc),
"Fem::ConstraintFlowVelocity"
@@ -778,6 +786,21 @@ class TestObjectType(unittest.TestCase):
"Fem::ConstraintFixed"
))
# ConstraintRigidBody
constraint_rigidbody = ObjectsFem.makeConstraintRigidBody(doc)
self.assertTrue(is_derived_from(
constraint_rigidbody,
"App::DocumentObject"
))
self.assertTrue(is_derived_from(
constraint_rigidbody,
"Fem::Constraint"
))
self.assertTrue(is_derived_from(
constraint_rigidbody,
"Fem::ConstraintRigidBody"
))
# ConstraintFlowVelocity
constraint_flow_velocity = ObjectsFem.makeConstraintFlowVelocity(doc)
self.assertTrue(is_derived_from(
@@ -1573,6 +1596,10 @@ class TestObjectType(unittest.TestCase):
ObjectsFem.makeConstraintFixed(
doc).isDerivedFrom("Fem::ConstraintFixed")
)
self.assertTrue(
ObjectsFem.makeConstraintRigidBody(
doc).isDerivedFrom("Fem::ConstraintRigidBody")
)
self.assertTrue(
ObjectsFem.makeConstraintFlowVelocity(
doc).isDerivedFrom("Fem::ConstraintPython")
@@ -1844,6 +1871,7 @@ def create_all_fem_objects_doc(
analysis.addObject(ObjectsFem.makeConstraintDisplacement(doc))
analysis.addObject(ObjectsFem.makeConstraintElectrostaticPotential(doc))
analysis.addObject(ObjectsFem.makeConstraintFixed(doc))
analysis.addObject(ObjectsFem.makeConstraintRigidBody(doc))
analysis.addObject(ObjectsFem.makeConstraintFlowVelocity(doc))
analysis.addObject(ObjectsFem.makeConstraintFluidBoundary(doc))
analysis.addObject(ObjectsFem.makeConstraintSpring(doc))