+ fix whitespaces

This commit is contained in:
wmayer 2015-05-26 17:55:38 +02:00
parent cd4952dee4
commit 24b71377e1
6 changed files with 314 additions and 318 deletions

View File

@ -1,24 +1,24 @@
/*************************************************************************** /***************************************************************************
* Copyright (c) 2015 FreeCAD Developers * * Copyright (c) 2015 FreeCAD Developers *
* Author: Przemo Firszt <przemo@firszt.eu> * * Author: Przemo Firszt <przemo@firszt.eu> *
* Based on Force constraint by Jan Rheinländer * * Based on Force constraint by Jan Rheinländer *
* This file is part of the FreeCAD CAx development system. * * This file is part of the FreeCAD CAx development system. *
* * * *
* This library is free software; you can redistribute it and/or * * This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public * * modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either * * License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. * * version 2 of the License, or (at your option) any later version. *
* * * *
* This library is distributed in the hope that it will be useful, * * This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of * * but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. * * GNU Library General Public License for more details. *
* * * *
* You should have received a copy of the GNU Library General Public * * You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, * * License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, * * write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA * * Suite 330, Boston, MA 02111-1307, USA *
* * * *
***************************************************************************/ ***************************************************************************/
#include "PreCompiled.h" #include "PreCompiled.h"
@ -41,41 +41,41 @@ PROPERTY_SOURCE(Fem::ConstraintPressure, Fem::Constraint);
ConstraintPressure::ConstraintPressure() ConstraintPressure::ConstraintPressure()
{ {
ADD_PROPERTY(Pressure,(0.0)); ADD_PROPERTY(Pressure,(0.0));
ADD_PROPERTY(Reversed,(0)); ADD_PROPERTY(Reversed,(0));
ADD_PROPERTY_TYPE(Points,(Base::Vector3d()),"ConstraintPressure", ADD_PROPERTY_TYPE(Points,(Base::Vector3d()),"ConstraintPressure",
App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
"Points where arrows are drawn"); "Points where arrows are drawn");
ADD_PROPERTY_TYPE(Normals,(Base::Vector3d()),"ConstraintPressure", ADD_PROPERTY_TYPE(Normals,(Base::Vector3d()),"ConstraintPressure",
App::PropertyType(App::Prop_ReadOnly|App::Prop_Output), App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
"Normals where symbols are drawn"); "Normals where symbols are drawn");
Points.setValues(std::vector<Base::Vector3d>()); Points.setValues(std::vector<Base::Vector3d>());
Normals.setValues(std::vector<Base::Vector3d>()); Normals.setValues(std::vector<Base::Vector3d>());
} }
App::DocumentObjectExecReturn *ConstraintPressure::execute(void) App::DocumentObjectExecReturn *ConstraintPressure::execute(void)
{ {
return Constraint::execute(); return Constraint::execute();
} }
const char* ConstraintPressure::getViewProviderName(void) const const char* ConstraintPressure::getViewProviderName(void) const
{ {
return "FemGui::ViewProviderFemConstraintPressure"; return "FemGui::ViewProviderFemConstraintPressure";
} }
void ConstraintPressure::onChanged(const App::Property* prop) void ConstraintPressure::onChanged(const App::Property* prop)
{ {
Constraint::onChanged(prop); Constraint::onChanged(prop);
if (prop == &References) { if (prop == &References) {
std::vector<Base::Vector3d> points; std::vector<Base::Vector3d> points;
std::vector<Base::Vector3d> normals; std::vector<Base::Vector3d> normals;
if (getPoints(points, normals)) { if (getPoints(points, normals)) {
Points.setValues(points); Points.setValues(points);
Normals.setValues(normals); Normals.setValues(normals);
Points.touch(); Points.touch();
} }
} else if (prop == &Reversed) { } else if (prop == &Reversed) {
Points.touch(); Points.touch();
} }
} }

View File

@ -29,26 +29,27 @@
namespace Fem { namespace Fem {
class AppFemExport ConstraintPressure : public Fem::Constraint { class AppFemExport ConstraintPressure : public Fem::Constraint
PROPERTY_HEADER(Fem::ConstraintPressure); {
PROPERTY_HEADER(Fem::ConstraintPressure);
public: public:
ConstraintPressure(void); ConstraintPressure(void);
App::PropertyFloat Pressure; App::PropertyFloat Pressure;
App::PropertyBool Reversed; App::PropertyBool Reversed;
App::PropertyVectorList Points; App::PropertyVectorList Points;
App::PropertyVectorList Normals; App::PropertyVectorList Normals;
/// recalculate the object /// recalculate the object
virtual App::DocumentObjectExecReturn *execute(void); virtual App::DocumentObjectExecReturn *execute(void);
/// returns the type name of the ViewProvider /// returns the type name of the ViewProvider
const char* getViewProviderName(void) const; const char* getViewProviderName(void) const;
protected: protected:
virtual void onChanged(const App::Property* prop); virtual void onChanged(const App::Property* prop);
}; };
} }

View File

@ -51,173 +51,175 @@ using namespace Gui;
/* TRANSLATOR FemGui::TaskFemConstraintPressure */ /* TRANSLATOR FemGui::TaskFemConstraintPressure */
TaskFemConstraintPressure::TaskFemConstraintPressure(ViewProviderFemConstraintPressure *ConstraintView,QWidget *parent) TaskFemConstraintPressure::TaskFemConstraintPressure(ViewProviderFemConstraintPressure *ConstraintView,QWidget *parent)
: TaskFemConstraint(ConstraintView, parent, "Fem_ConstraintPressure") : TaskFemConstraint(ConstraintView, parent, "Fem_ConstraintPressure")
{ {
proxy = new QWidget(this); proxy = new QWidget(this);
ui = new Ui_TaskFemConstraintPressure(); ui = new Ui_TaskFemConstraintPressure();
ui->setupUi(proxy); ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this); QMetaObject::connectSlotsByName(this);
QAction* action = new QAction(tr("Delete"), ui->lw_references); QAction* action = new QAction(tr("Delete"), ui->lw_references);
action->connect(action, SIGNAL(triggered()), this, SLOT(onReferenceDeleted())); action->connect(action, SIGNAL(triggered()), this, SLOT(onReferenceDeleted()));
ui->lw_references->addAction(action); ui->lw_references->addAction(action);
ui->lw_references->setContextMenuPolicy(Qt::ActionsContextMenu); ui->lw_references->setContextMenuPolicy(Qt::ActionsContextMenu);
connect(ui->if_pressure, SIGNAL(valueChanged(Base::Quantity)), connect(ui->if_pressure, SIGNAL(valueChanged(Base::Quantity)),
this, SLOT(onPressureChanged(Base::Quantity))); this, SLOT(onPressureChanged(Base::Quantity)));
connect(ui->b_add_reference, SIGNAL(pressed()), connect(ui->b_add_reference, SIGNAL(pressed()),
this, SLOT(onButtonReference())); this, SLOT(onButtonReference()));
connect(ui->cb_reverse_direction, SIGNAL(toggled(bool)), connect(ui->cb_reverse_direction, SIGNAL(toggled(bool)),
this, SLOT(onCheckReverse(bool))); this, SLOT(onCheckReverse(bool)));
this->groupLayout()->addWidget(proxy); this->groupLayout()->addWidget(proxy);
// Temporarily prevent unnecessary feature recomputes // Temporarily prevent unnecessary feature recomputes
ui->if_pressure->blockSignals(true); ui->if_pressure->blockSignals(true);
ui->lw_references->blockSignals(true); ui->lw_references->blockSignals(true);
ui->b_add_reference->blockSignals(true); ui->b_add_reference->blockSignals(true);
ui->cb_reverse_direction->blockSignals(true); ui->cb_reverse_direction->blockSignals(true);
// Get the feature data // Get the feature data
Fem::ConstraintPressure* pcConstraint = static_cast<Fem::ConstraintPressure*>(ConstraintView->getObject()); Fem::ConstraintPressure* pcConstraint = static_cast<Fem::ConstraintPressure*>(ConstraintView->getObject());
double f = pcConstraint->Pressure.getValue(); double f = pcConstraint->Pressure.getValue();
std::vector<App::DocumentObject*> Objects = pcConstraint->References.getValues(); std::vector<App::DocumentObject*> Objects = pcConstraint->References.getValues();
std::vector<std::string> SubElements = pcConstraint->References.getSubValues(); std::vector<std::string> SubElements = pcConstraint->References.getSubValues();
bool reversed = pcConstraint->Reversed.getValue(); bool reversed = pcConstraint->Reversed.getValue();
// Fill data into dialog elements // Fill data into dialog elements
ui->if_pressure->setMinimum(0); ui->if_pressure->setMinimum(0);
ui->if_pressure->setMaximum(FLOAT_MAX); ui->if_pressure->setMaximum(FLOAT_MAX);
//1000 because FreeCAD used kPa internally //1000 because FreeCAD used kPa internally
Base::Quantity p = Base::Quantity(1000 * f, Base::Unit::Stress); Base::Quantity p = Base::Quantity(1000 * f, Base::Unit::Stress);
double val = p.getValueAs(Base::Quantity::MegaPascal); double val = p.getValueAs(Base::Quantity::MegaPascal);
ui->if_pressure->setValue(p); ui->if_pressure->setValue(p);
ui->lw_references->clear(); ui->lw_references->clear();
for (std::size_t i = 0; i < Objects.size(); i++) { for (std::size_t i = 0; i < Objects.size(); i++) {
ui->lw_references->addItem(makeRefText(Objects[i], SubElements[i])); ui->lw_references->addItem(makeRefText(Objects[i], SubElements[i]));
} }
if (Objects.size() > 0) { if (Objects.size() > 0) {
ui->lw_references->setCurrentRow(0, QItemSelectionModel::ClearAndSelect); ui->lw_references->setCurrentRow(0, QItemSelectionModel::ClearAndSelect);
} }
ui->cb_reverse_direction->setChecked(reversed); ui->cb_reverse_direction->setChecked(reversed);
ui->if_pressure->blockSignals(false); ui->if_pressure->blockSignals(false);
ui->lw_references->blockSignals(false); ui->lw_references->blockSignals(false);
ui->b_add_reference->blockSignals(false); ui->b_add_reference->blockSignals(false);
ui->cb_reverse_direction->blockSignals(false); ui->cb_reverse_direction->blockSignals(false);
updateUI(); updateUI();
} }
TaskFemConstraintPressure::~TaskFemConstraintPressure() TaskFemConstraintPressure::~TaskFemConstraintPressure()
{ {
delete ui; delete ui;
} }
void TaskFemConstraintPressure::updateUI() void TaskFemConstraintPressure::updateUI()
{ {
if (ui->lw_references->model()->rowCount() == 0) { if (ui->lw_references->model()->rowCount() == 0) {
// Go into reference selection mode if no reference has been selected yet // Go into reference selection mode if no reference has been selected yet
onButtonReference(true); onButtonReference(true);
return; return;
} }
} }
void TaskFemConstraintPressure::onSelectionChanged(const Gui::SelectionChanges& msg) void TaskFemConstraintPressure::onSelectionChanged(const Gui::SelectionChanges& msg)
{ {
if ((msg.Type != Gui::SelectionChanges::AddSelection) || if ((msg.Type != Gui::SelectionChanges::AddSelection) ||
// Don't allow selection in other document // Don't allow selection in other document
(strcmp(msg.pDocName, ConstraintView->getObject()->getDocument()->getName()) != 0) || (strcmp(msg.pDocName, ConstraintView->getObject()->getDocument()->getName()) != 0) ||
// Don't allow selection mode none // Don't allow selection mode none
(selectionMode != selref) || (selectionMode != selref) ||
// Don't allow empty smenu/submenu // Don't allow empty smenu/submenu
(!msg.pSubName || msg.pSubName[0] == '\0')) { (!msg.pSubName || msg.pSubName[0] == '\0')) {
return; return;
} }
std::string subName(msg.pSubName); std::string subName(msg.pSubName);
Fem::ConstraintPressure* pcConstraint = static_cast<Fem::ConstraintPressure*>(ConstraintView->getObject()); Fem::ConstraintPressure* pcConstraint = static_cast<Fem::ConstraintPressure*>(ConstraintView->getObject());
App::DocumentObject* obj = ConstraintView->getObject()->getDocument()->getObject(msg.pObjectName); App::DocumentObject* obj = ConstraintView->getObject()->getDocument()->getObject(msg.pObjectName);
std::vector<App::DocumentObject*> Objects = pcConstraint->References.getValues(); std::vector<App::DocumentObject*> Objects = pcConstraint->References.getValues();
std::vector<std::string> SubElements = pcConstraint->References.getSubValues(); std::vector<std::string> SubElements = pcConstraint->References.getSubValues();
if (subName.substr(0,4) != "Face") { if (subName.substr(0,4) != "Face") {
QMessageBox::warning(this, tr("Selection error"), tr("Only faces can be picked")); QMessageBox::warning(this, tr("Selection error"), tr("Only faces can be picked"));
return; return;
} }
// Avoid duplicates // Avoid duplicates
std::size_t pos = 0; std::size_t pos = 0;
for (; pos < Objects.size(); pos++) for (; pos < Objects.size(); pos++) {
if (obj == Objects[pos]) if (obj == Objects[pos])
break; break;
}
if (pos != Objects.size()) if (pos != Objects.size()) {
if (subName == SubElements[pos]) if (subName == SubElements[pos])
return; return;
}
// add the new reference // add the new reference
Objects.push_back(obj); Objects.push_back(obj);
SubElements.push_back(subName); SubElements.push_back(subName);
pcConstraint->References.setValues(Objects,SubElements); pcConstraint->References.setValues(Objects,SubElements);
ui->lw_references->addItem(makeRefText(obj, subName)); ui->lw_references->addItem(makeRefText(obj, subName));
// Turn off reference selection mode // Turn off reference selection mode
onButtonReference(false); onButtonReference(false);
Gui::Selection().clearSelection(); Gui::Selection().clearSelection();
updateUI(); updateUI();
} }
void TaskFemConstraintPressure::onPressureChanged(const Base::Quantity& f) void TaskFemConstraintPressure::onPressureChanged(const Base::Quantity& f)
{ {
Fem::ConstraintPressure* pcConstraint = static_cast<Fem::ConstraintPressure*>(ConstraintView->getObject()); Fem::ConstraintPressure* pcConstraint = static_cast<Fem::ConstraintPressure*>(ConstraintView->getObject());
double val = f.getValueAs(Base::Quantity::MegaPascal); double val = f.getValueAs(Base::Quantity::MegaPascal);
pcConstraint->Pressure.setValue(val); pcConstraint->Pressure.setValue(val);
} }
void TaskFemConstraintPressure::onReferenceDeleted() { void TaskFemConstraintPressure::onReferenceDeleted() {
int row = ui->lw_references->currentIndex().row(); int row = ui->lw_references->currentIndex().row();
TaskFemConstraint::onReferenceDeleted(row); TaskFemConstraint::onReferenceDeleted(row);
ui->lw_references->model()->removeRow(row); ui->lw_references->model()->removeRow(row);
ui->lw_references->setCurrentRow(0, QItemSelectionModel::ClearAndSelect); ui->lw_references->setCurrentRow(0, QItemSelectionModel::ClearAndSelect);
} }
void TaskFemConstraintPressure::onCheckReverse(const bool pressed) void TaskFemConstraintPressure::onCheckReverse(const bool pressed)
{ {
Fem::ConstraintPressure* pcConstraint = static_cast<Fem::ConstraintPressure*>(ConstraintView->getObject()); Fem::ConstraintPressure* pcConstraint = static_cast<Fem::ConstraintPressure*>(ConstraintView->getObject());
pcConstraint->Reversed.setValue(pressed); pcConstraint->Reversed.setValue(pressed);
} }
const std::string TaskFemConstraintPressure::getReferences() const const std::string TaskFemConstraintPressure::getReferences() const
{ {
int rows = ui->lw_references->model()->rowCount(); int rows = ui->lw_references->model()->rowCount();
std::vector<std::string> items; std::vector<std::string> items;
for (int r = 0; r < rows; r++) { for (int r = 0; r < rows; r++) {
items.push_back(ui->lw_references->item(r)->text().toStdString()); items.push_back(ui->lw_references->item(r)->text().toStdString());
} }
return TaskFemConstraint::getReferences(items); return TaskFemConstraint::getReferences(items);
} }
double TaskFemConstraintPressure::getPressure(void) const double TaskFemConstraintPressure::getPressure(void) const
{ {
Base::Quantity pressure = ui->if_pressure->getQuantity(); Base::Quantity pressure = ui->if_pressure->getQuantity();
double pressure_in_MPa = pressure.getValueAs(Base::Quantity::MegaPascal); double pressure_in_MPa = pressure.getValueAs(Base::Quantity::MegaPascal);
return pressure_in_MPa; return pressure_in_MPa;
} }
bool TaskFemConstraintPressure::getReverse() const bool TaskFemConstraintPressure::getReverse() const
{ {
return ui->cb_reverse_direction->isChecked(); return ui->cb_reverse_direction->isChecked();
} }
void TaskFemConstraintPressure::changeEvent(QEvent *e) void TaskFemConstraintPressure::changeEvent(QEvent *e)
{ {
TaskBox::changeEvent(e); TaskBox::changeEvent(e);
if (e->type() == QEvent::LanguageChange) { if (e->type() == QEvent::LanguageChange) {
ui->if_pressure->blockSignals(true); ui->if_pressure->blockSignals(true);
ui->retranslateUi(proxy); ui->retranslateUi(proxy);
ui->if_pressure->blockSignals(false); ui->if_pressure->blockSignals(false);
} }
} }
//************************************************************************** //**************************************************************************
@ -226,50 +228,50 @@ void TaskFemConstraintPressure::changeEvent(QEvent *e)
TaskDlgFemConstraintPressure::TaskDlgFemConstraintPressure(ViewProviderFemConstraintPressure *ConstraintView) TaskDlgFemConstraintPressure::TaskDlgFemConstraintPressure(ViewProviderFemConstraintPressure *ConstraintView)
{ {
this->ConstraintView = ConstraintView; this->ConstraintView = ConstraintView;
assert(ConstraintView); assert(ConstraintView);
this->parameter = new TaskFemConstraintPressure(ConstraintView);; this->parameter = new TaskFemConstraintPressure(ConstraintView);;
Content.push_back(parameter); Content.push_back(parameter);
} }
//==== calls from the TaskView =============================================================== //==== calls from the TaskView ===============================================================
void TaskDlgFemConstraintPressure::open() void TaskDlgFemConstraintPressure::open()
{ {
// a transaction is already open at creation time of the panel // a transaction is already open at creation time of the panel
if (!Gui::Command::hasPendingCommand()) { if (!Gui::Command::hasPendingCommand()) {
QString msg = QObject::tr("Constraint normal stress"); QString msg = QObject::tr("Constraint normal stress");
Gui::Command::openCommand((const char*)msg.toUtf8()); Gui::Command::openCommand((const char*)msg.toUtf8());
} }
} }
bool TaskDlgFemConstraintPressure::accept() bool TaskDlgFemConstraintPressure::accept()
{ {
std::string name = ConstraintView->getObject()->getNameInDocument(); std::string name = ConstraintView->getObject()->getNameInDocument();
const TaskFemConstraintPressure* parameterPressure = static_cast<const TaskFemConstraintPressure*>(parameter); const TaskFemConstraintPressure* parameterPressure = static_cast<const TaskFemConstraintPressure*>(parameter);
try { try {
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Pressure = %f", Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Pressure = %f",
name.c_str(), parameterPressure->getPressure()); name.c_str(), parameterPressure->getPressure());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %s", Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %s",
name.c_str(), parameterPressure->getReverse() ? "True" : "False"); name.c_str(), parameterPressure->getReverse() ? "True" : "False");
} }
catch (const Base::Exception& e) { catch (const Base::Exception& e) {
QMessageBox::warning(parameter, tr("Input error"), QString::fromAscii(e.what())); QMessageBox::warning(parameter, tr("Input error"), QString::fromAscii(e.what()));
return false; return false;
} }
return TaskDlgFemConstraint::accept(); return TaskDlgFemConstraint::accept();
} }
bool TaskDlgFemConstraintPressure::reject() bool TaskDlgFemConstraintPressure::reject()
{ {
Gui::Command::abortCommand(); Gui::Command::abortCommand();
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
Gui::Command::updateActive(); Gui::Command::updateActive();
return true; return true;
} }
#include "moc_TaskFemConstraintPressure.cpp" #include "moc_TaskFemConstraintPressure.cpp"

View File

@ -34,45 +34,43 @@
class Ui_TaskFemConstraintPressure; class Ui_TaskFemConstraintPressure;
namespace App {
class Property;
}
namespace Gui {
class ViewProvider;
}
namespace FemGui { namespace FemGui {
class TaskFemConstraintPressure : public TaskFemConstraint { class TaskFemConstraintPressure : public TaskFemConstraint
Q_OBJECT public: {
TaskFemConstraintPressure(ViewProviderFemConstraintPressure *ConstraintView,QWidget *parent = 0); Q_OBJECT
virtual ~TaskFemConstraintPressure();
double getPressure(void) const;
virtual const std::string getReferences() const;
bool getReverse(void) const;
private Q_SLOTS: public:
void onReferenceDeleted(void); TaskFemConstraintPressure(ViewProviderFemConstraintPressure *ConstraintView,QWidget *parent = 0);
void onPressureChanged(const Base::Quantity & f); virtual ~TaskFemConstraintPressure();
void onCheckReverse(bool); double getPressure(void) const;
virtual const std::string getReferences() const;
bool getReverse(void) const;
protected: private Q_SLOTS:
virtual void changeEvent(QEvent *e); void onReferenceDeleted(void);
void onPressureChanged(const Base::Quantity & f);
void onCheckReverse(bool);
private: protected:
virtual void onSelectionChanged(const Gui::SelectionChanges& msg); virtual void changeEvent(QEvent *e);
void updateUI();
Ui_TaskFemConstraintPressure* ui;
};
class TaskDlgFemConstraintPressure : public TaskDlgFemConstraint { private:
Q_OBJECT public: virtual void onSelectionChanged(const Gui::SelectionChanges& msg);
TaskDlgFemConstraintPressure(ViewProviderFemConstraintPressure *ConstraintView); void updateUI();
virtual void open(); Ui_TaskFemConstraintPressure* ui;
virtual bool accept(); };
virtual bool reject();
class TaskDlgFemConstraintPressure : public TaskDlgFemConstraint
{
Q_OBJECT
public:
TaskDlgFemConstraintPressure(ViewProviderFemConstraintPressure *ConstraintView);
virtual void open();
virtual bool accept();
virtual bool reject();
};
};
} //namespace FemGui } //namespace FemGui
#endif // GUI_TASKVIEW_TaskFemConstraintPressure_H #endif // GUI_TASKVIEW_TaskFemConstraintPressure_H

View File

@ -45,8 +45,8 @@ PROPERTY_SOURCE(FemGui::ViewProviderFemConstraintPressure, FemGui::ViewProviderF
ViewProviderFemConstraintPressure::ViewProviderFemConstraintPressure() ViewProviderFemConstraintPressure::ViewProviderFemConstraintPressure()
{ {
sPixmap = "Fem_ConstraintPressure"; sPixmap = "Fem_ConstraintPressure";
ADD_PROPERTY(FaceColor,(0.0f,0.2f,0.8f)); ADD_PROPERTY(FaceColor,(0.0f,0.2f,0.8f));
} }
ViewProviderFemConstraintPressure::~ViewProviderFemConstraintPressure() ViewProviderFemConstraintPressure::~ViewProviderFemConstraintPressure()
@ -56,37 +56,37 @@ ViewProviderFemConstraintPressure::~ViewProviderFemConstraintPressure()
//FIXME setEdit needs a careful review //FIXME setEdit needs a careful review
bool ViewProviderFemConstraintPressure::setEdit(int ModNum) bool ViewProviderFemConstraintPressure::setEdit(int ModNum)
{ {
if (ModNum == ViewProvider::Default) { if (ModNum == ViewProvider::Default) {
// When double-clicking on the item for this constraint the // When double-clicking on the item for this constraint the
// object unsets and sets its edit mode without closing // object unsets and sets its edit mode without closing
// the task panel // the task panel
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
TaskDlgFemConstraintPressure *constrDlg = qobject_cast<TaskDlgFemConstraintPressure *>(dlg); TaskDlgFemConstraintPressure *constrDlg = qobject_cast<TaskDlgFemConstraintPressure *>(dlg);
if (constrDlg && constrDlg->getConstraintView() != this) if (constrDlg && constrDlg->getConstraintView() != this)
constrDlg = 0; // another constraint left open its task panel constrDlg = 0; // another constraint left open its task panel
if (dlg && !constrDlg) { if (dlg && !constrDlg) {
if (constraintDialog != NULL) { if (constraintDialog != NULL) {
// Ignore the request to open another dialog // Ignore the request to open another dialog
return false; return false;
} else { } else {
constraintDialog = new TaskFemConstraintPressure(this); constraintDialog = new TaskFemConstraintPressure(this);
return true; return true;
} }
} }
// clear the selection (convenience) // clear the selection (convenience)
Gui::Selection().clearSelection(); Gui::Selection().clearSelection();
// start the edit dialog // start the edit dialog
if (constrDlg) if (constrDlg)
Gui::Control().showDialog(constrDlg); Gui::Control().showDialog(constrDlg);
else else
Gui::Control().showDialog(new TaskDlgFemConstraintPressure(this)); Gui::Control().showDialog(new TaskDlgFemConstraintPressure(this));
return true; return true;
} }
else { else {
return ViewProviderDocumentObject::setEdit(ModNum); return ViewProviderDocumentObject::setEdit(ModNum);
} }
} }
#define ARROWLENGTH 5 #define ARROWLENGTH 5
@ -94,50 +94,50 @@ bool ViewProviderFemConstraintPressure::setEdit(int ModNum)
void ViewProviderFemConstraintPressure::updateData(const App::Property* prop) void ViewProviderFemConstraintPressure::updateData(const App::Property* prop)
{ {
// Gets called whenever a property of the attached object changes // Gets called whenever a property of the attached object changes
Fem::ConstraintPressure* pcConstraint = static_cast<Fem::ConstraintPressure*>(this->getObject()); Fem::ConstraintPressure* pcConstraint = static_cast<Fem::ConstraintPressure*>(this->getObject());
if (pShapeSep->getNumChildren() == 0) { if (pShapeSep->getNumChildren() == 0) {
// Set up the nodes // Set up the nodes
SoMultipleCopy* cp = new SoMultipleCopy(); SoMultipleCopy* cp = new SoMultipleCopy();
cp->ref(); cp->ref();
cp->matrix.setNum(0); cp->matrix.setNum(0);
cp->addChild((SoNode*)createArrow(ARROWLENGTH, ARROWHEADRADIUS)); cp->addChild((SoNode*)createArrow(ARROWLENGTH, ARROWHEADRADIUS));
pShapeSep->addChild(cp); pShapeSep->addChild(cp);
} }
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>& points = pcConstraint->Points.getValues();
const std::vector<Base::Vector3d>& normals = pcConstraint->Normals.getValues(); const std::vector<Base::Vector3d>& normals = pcConstraint->Normals.getValues();
if (points.size() != normals.size()) { if (points.size() != normals.size()) {
return; return;
} }
std::vector<Base::Vector3d>::const_iterator n = normals.begin(); std::vector<Base::Vector3d>::const_iterator n = normals.begin();
SoMultipleCopy* cp = static_cast<SoMultipleCopy*>(pShapeSep->getChild(0)); SoMultipleCopy* cp = static_cast<SoMultipleCopy*>(pShapeSep->getChild(0));
cp->matrix.setNum(points.size()); cp->matrix.setNum(points.size());
SbMatrix* matrices = cp->matrix.startEditing(); SbMatrix* matrices = cp->matrix.startEditing();
int idx = 0; int idx = 0;
for (std::vector<Base::Vector3d>::const_iterator p = points.begin(); p != points.end(); p++) { for (std::vector<Base::Vector3d>::const_iterator p = points.begin(); p != points.end(); p++) {
SbVec3f base(p->x, p->y, p->z); SbVec3f base(p->x, p->y, p->z);
SbVec3f dir(n->x, n->y, n->z); SbVec3f dir(n->x, n->y, n->z);
double rev; double rev;
if (pcConstraint->Reversed.getValue()) { if (pcConstraint->Reversed.getValue()) {
base = base + dir * ARROWLENGTH; base = base + dir * ARROWLENGTH;
rev = 1; rev = 1;
} else { } else {
rev = -1; rev = -1;
} }
SbRotation rot(SbVec3f(0, rev, 0), dir); SbRotation rot(SbVec3f(0, rev, 0), dir);
SbMatrix m; SbMatrix m;
m.setTransform(base, rot, SbVec3f(1,1,1)); m.setTransform(base, rot, SbVec3f(1,1,1));
matrices[idx] = m; matrices[idx] = m;
idx++; idx++;
n++; n++;
} }
cp->matrix.finishEditing(); cp->matrix.finishEditing();
} }
ViewProviderFemConstraint::updateData(prop); ViewProviderFemConstraint::updateData(prop);
} }

View File

@ -28,25 +28,20 @@
#include <TopoDS_Shape.hxx> #include <TopoDS_Shape.hxx>
#include "ViewProviderFemConstraint.h" #include "ViewProviderFemConstraint.h"
namespace Gui {
class View3DInventorViewer;
namespace TaskView {
class TaskDialog;
}
}
namespace FemGui { namespace FemGui {
class FemGuiExport ViewProviderFemConstraintPressure : public FemGui::ViewProviderFemConstraint { class FemGuiExport ViewProviderFemConstraintPressure : public FemGui::ViewProviderFemConstraint
PROPERTY_HEADER(FemGui::ViewProviderFemConstraintPressure); {
PROPERTY_HEADER(FemGui::ViewProviderFemConstraintPressure);
public: public:
ViewProviderFemConstraintPressure(); ViewProviderFemConstraintPressure();
virtual ~ViewProviderFemConstraintPressure(); virtual ~ViewProviderFemConstraintPressure();
virtual void updateData(const App::Property*); virtual void updateData(const App::Property*);
protected:
virtual bool setEdit(int ModNum);
};
protected:
virtual bool setEdit(int ModNum);
};
} }
#endif // GUI_VIEWPROVIDERFEMCONSTRAINTPRESSURE_H #endif // GUI_VIEWPROVIDERFEMCONSTRAINTPRESSURE_H