Improvements to FEM constraint objects

This commit is contained in:
jrheinlaender
2013-03-08 19:59:08 +04:30
parent 517443fb59
commit f5c6e4eae3
29 changed files with 939 additions and 318 deletions

View File

@@ -53,6 +53,7 @@ ViewProviderFemConstraintPulley::~ViewProviderFemConstraintPulley()
bool ViewProviderFemConstraintPulley::setEdit(int ModNum)
{
Base::Console().Error("ViewProviderFemConstraintPulley::setEdit()\n");
if (ModNum == ViewProvider::Default ) {
// When double-clicking on the item for this constraint the
// object unsets and sets its edit mode without closing
@@ -62,21 +63,28 @@ bool ViewProviderFemConstraintPulley::setEdit(int ModNum)
if (constrDlg && constrDlg->getConstraintView() != this)
constrDlg = 0; // another constraint left open its task panel
if (dlg && !constrDlg) {
// Allow stacking of dialogs, for ShaftWizard application
// Note: If other features start to allow stacking, we need to check for oldDlg != NULL
oldDlg = dlg;
/*
QMessageBox msgBox;
msgBox.setText(QObject::tr("A dialog is already open in the task panel"));
msgBox.setInformativeText(QObject::tr("Do you want to close this dialog?"));
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::Yes);
int ret = msgBox.exec();
if (ret == QMessageBox::Yes)
Gui::Control().closeDialog();
else
// This case will occur in the ShaftWizard application
checkForWizard();
if ((wizardWidget == NULL) || (wizardSubLayout == NULL)) {
// No shaft wizard is running
QMessageBox msgBox;
msgBox.setText(QObject::tr("A dialog is already open in the task panel"));
msgBox.setInformativeText(QObject::tr("Do you want to close this dialog?"));
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::Yes);
int ret = msgBox.exec();
if (ret == QMessageBox::Yes)
Gui::Control().closeDialog();
else
return false;
} else if (constraintDialog != NULL) {
// Another FemConstraint* dialog is already open inside the Shaft Wizard
// Ignore the request to open another dialog
return false;
*/
} else {
constraintDialog = new TaskFemConstraintPulley(this);
return true;
}
}
// clear the selection (convenience)
@@ -99,10 +107,6 @@ void ViewProviderFemConstraintPulley::updateData(const App::Property* prop)
{
// Gets called whenever a property of the attached object changes
Fem::ConstraintPulley* pcConstraint = static_cast<Fem::ConstraintPulley*>(this->getObject());
if (this->getObject() != NULL)
Base::Console().Error("%s: VP updateData: %s\n", this->getObject()->getNameInDocument(), prop->getName());
else
Base::Console().Error("Anonymous: VP updateData: %s\n", prop->getName());
if (strcmp(prop->getName(),"BasePoint") == 0) {
if (pcConstraint->Height.getValue() > Precision::Confusion()) {
@@ -116,49 +120,104 @@ void ViewProviderFemConstraintPulley::updateData(const App::Property* prop)
float dia = pcConstraint->Diameter.getValue();
if (dia < 2 * radius)
dia = 2 * radius;
float angle = pcConstraint->Angle.getValue();
float forceAngle = pcConstraint->ForceAngle.getValue() / 180 * M_PI;
float beltAngle = pcConstraint->BeltAngle.getValue();
double rat1 = 0.8, rat2 = 0.2;
float f1 = pcConstraint->BeltForce1.getValue();
float f2 = pcConstraint->BeltForce2.getValue();
if (f1+f2 > Precision::Confusion()) {
rat1 = f1 / (f1+f2);
rat2 = f2 / (f1+f2);
}
SbVec3f b(base.x, base.y, base.z);
SbVec3f dir(axis.x, axis.y, axis.z);
SbRotation rot(SbVec3f(0,-1,0), dir);
SbVec3f ax(axis.x, axis.y, axis.z);
createPlacement(pShapeSep, b, rot); // child 0 and 1
createPlacement(pShapeSep, b, SbRotation(SbVec3f(0,1,0), ax)); // child 0 and 1
pShapeSep->addChild(createCylinder(pcConstraint->Height.getValue() * 0.8, dia/2)); // child 2
SoSeparator* sep = new SoSeparator();
createPlacement(sep, SbVec3f(dia/2,0,0), SbRotation(SbVec3f(0,1,0), SbVec3f(sin(angle),0,cos(angle))));
sep->addChild(createArrow(dia/2, dia/8));
createPlacement(sep, SbVec3f(dia/2 * sin(forceAngle+beltAngle), 0, dia/2 * cos(forceAngle+beltAngle)),
SbRotation(SbVec3f(0,1,0), SbVec3f(sin(forceAngle+beltAngle+M_PI_2),0,cos(forceAngle+beltAngle+M_PI_2))));
createPlacement(sep, SbVec3f(0, dia/8 + dia/2 * rat1, 0), SbRotation());
sep->addChild(createArrow(dia/8 + dia/2 * rat1, dia/8));
pShapeSep->addChild(sep); // child 3
sep = new SoSeparator();
createPlacement(sep, SbVec3f(-dia/2,0,0), SbRotation(SbVec3f(0,1,0), SbVec3f(-sin(angle),0,cos(angle))));
sep->addChild(createArrow(dia/2, dia/8));
createPlacement(sep, SbVec3f(-dia/2 * sin(forceAngle-beltAngle), 0, -dia/2 * cos(forceAngle-beltAngle)),
SbRotation(SbVec3f(0,1,0), SbVec3f(-sin(forceAngle-beltAngle-M_PI_2),0,-cos(forceAngle-beltAngle-M_PI_2))));
createPlacement(sep, SbVec3f(0, dia/8 + dia/2 * rat2, 0), SbRotation());
sep->addChild(createArrow(dia/8 + dia/2 * rat2, dia/8));
pShapeSep->addChild(sep); // child 4
}
} else if (strcmp(prop->getName(),"Angle") == 0) {
} else if (strcmp(prop->getName(),"Diameter") == 0) {
if (pShapeSep->getNumChildren() > 0) {
// Change the symbol
Base::Vector3f base = pcConstraint->BasePoint.getValue();
Base::Vector3f axis = pcConstraint->Axis.getValue();
float radius = pcConstraint->Radius.getValue();
float dia = pcConstraint->Diameter.getValue();
if (dia < 2 * radius)
dia = 2 * radius;
float angle = pcConstraint->Angle.getValue();
float forceAngle = pcConstraint->ForceAngle.getValue() / 180 * M_PI;
float beltAngle = pcConstraint->BeltAngle.getValue();
double rat1 = 0.8, rat2 = 0.2;
float f1 = pcConstraint->BeltForce1.getValue();
float f2 = pcConstraint->BeltForce2.getValue();
if (f1+f2 > Precision::Confusion()) {
rat1 = f1 / (f1+f2);
rat2 = f2 / (f1+f2);
}
SbVec3f b(base.x, base.y, base.z);
SbVec3f dir(axis.x, axis.y, axis.z);
SbRotation rot(SbVec3f(0,-1,0), dir);
updatePlacement(pShapeSep, 0, b, rot);
const SoSeparator* sep = static_cast<SoSeparator*>(pShapeSep->getChild(2));
updateCylinder(sep, 0, pcConstraint->Height.getValue() * 0.8, dia/2);
sep = static_cast<SoSeparator*>(pShapeSep->getChild(3));
updatePlacement(sep, 0, SbVec3f(dia/2,0,0), SbRotation(SbVec3f(0,1,0), SbVec3f(sin(angle),0,cos(angle))));
const SoSeparator* subsep = static_cast<SoSeparator*>(sep->getChild(2));
updateArrow(subsep, 0, dia/2, dia/8);
updatePlacement(sep, 0, SbVec3f(dia/2 * sin(forceAngle+beltAngle), 0, dia/2 * cos(forceAngle+beltAngle)),
SbRotation(SbVec3f(0,1,0), SbVec3f(sin(forceAngle+beltAngle+M_PI_2),0,cos(forceAngle+beltAngle+M_PI_2))));
updatePlacement(sep, 2, SbVec3f(0, dia/8 + dia/2 * rat1, 0), SbRotation());
const SoSeparator* subsep = static_cast<SoSeparator*>(sep->getChild(4));
updateArrow(subsep, 0, dia/8 + dia/2 * rat1, dia/8);
sep = static_cast<SoSeparator*>(pShapeSep->getChild(4));
updatePlacement(sep, 0, SbVec3f(-dia/2,0,0), SbRotation(SbVec3f(0,1,0), SbVec3f(-sin(angle),0,cos(angle))));
subsep = static_cast<SoSeparator*>(sep->getChild(2));
updateArrow(subsep, 0, dia/2, dia/8);
updatePlacement(sep, 0, SbVec3f(-dia/2 * sin(forceAngle-beltAngle), 0, -dia/2 * cos(forceAngle-beltAngle)),
SbRotation(SbVec3f(0,1,0), SbVec3f(-sin(forceAngle-beltAngle-M_PI_2),0,-cos(forceAngle-beltAngle-M_PI_2))));
updatePlacement(sep, 2, SbVec3f(0, dia/8 + dia/2 * rat2, 0), SbRotation());
subsep = static_cast<SoSeparator*>(sep->getChild(4));
updateArrow(subsep, 0, dia/8 + dia/2 * rat2, dia/8);
}
} else if ((strcmp(prop->getName(), "ForceAngle") == 0) || (strcmp(prop->getName(), "BeltAngle") == 0)) {
if (pShapeSep->getNumChildren() > 0) {
float radius = pcConstraint->Radius.getValue();
float dia = pcConstraint->Diameter.getValue();
if (dia < 2 * radius)
dia = 2 * radius;
float forceAngle = pcConstraint->ForceAngle.getValue() / 180 * M_PI;
float beltAngle = pcConstraint->BeltAngle.getValue();
const SoSeparator* sep = static_cast<SoSeparator*>(pShapeSep->getChild(3));
updatePlacement(sep, 0, SbVec3f(dia/2 * sin(forceAngle+beltAngle), 0, dia/2 * cos(forceAngle+beltAngle)),
SbRotation(SbVec3f(0,1,0), SbVec3f(sin(forceAngle+beltAngle+M_PI_2),0,cos(forceAngle+beltAngle+M_PI_2))));
sep = static_cast<SoSeparator*>(pShapeSep->getChild(4));
updatePlacement(sep, 0, SbVec3f(-dia/2 * sin(forceAngle-beltAngle), 0, -dia/2 * cos(forceAngle-beltAngle)),
SbRotation(SbVec3f(0,1,0), SbVec3f(-sin(forceAngle-beltAngle-M_PI_2),0,-cos(forceAngle-beltAngle-M_PI_2))));
}
} else if ((strcmp(prop->getName(), "BeltForce1") == 0) || (strcmp(prop->getName(), "BeltForce2") == 0)) {
if (pShapeSep->getNumChildren() > 0) {
float radius = pcConstraint->Radius.getValue();
float dia = pcConstraint->Diameter.getValue();
if (dia < 2 * radius)
dia = 2 * radius;
double rat1 = 0.8, rat2 = 0.2;
float f1 = pcConstraint->BeltForce1.getValue();
float f2 = pcConstraint->BeltForce2.getValue();
if (f1+f2 > Precision::Confusion()) {
rat1 = f1 / (f1+f2);
rat2 = f2 / (f1+f2);
}
const SoSeparator* sep = static_cast<SoSeparator*>(pShapeSep->getChild(3));
updatePlacement(sep, 2, SbVec3f(0, dia/8 + dia/2 * rat1, 0), SbRotation());
const SoSeparator* subsep = static_cast<SoSeparator*>(sep->getChild(4));
updateArrow(subsep, 0, dia/8 + dia/2 * rat1, dia/8);
sep = static_cast<SoSeparator*>(pShapeSep->getChild(4));
updatePlacement(sep, 2, SbVec3f(0, dia/8 + dia/2 * rat2, 0), SbRotation());
subsep = static_cast<SoSeparator*>(sep->getChild(4));
updateArrow(subsep, 0, dia/8 + dia/2 * rat2, dia/8);
}
}