FEM: Constraint view sizing and scaling of indicators for force, pressure and fixed constraints and limit on steps.

This commit is contained in:
vginkeo 2016-02-01 10:52:37 +02:00
parent 4cb5de6848
commit 80a791021b
14 changed files with 182 additions and 33 deletions

View File

@ -57,6 +57,7 @@
#include <Mod/Part/App/PartFeature.h> #include <Mod/Part/App/PartFeature.h>
#include <Base/Console.h> #include <Base/Console.h>
#include <Base/Exception.h> #include <Base/Exception.h>
#include <math.h> //OvG: Required for log10
using namespace Fem; using namespace Fem;
@ -71,6 +72,7 @@ Constraint::Constraint()
{ {
ADD_PROPERTY_TYPE(References,(0,0),"Constraint",(App::PropertyType)(App::Prop_None),"Elements where the constraint is applied"); ADD_PROPERTY_TYPE(References,(0,0),"Constraint",(App::PropertyType)(App::Prop_None),"Elements where the constraint is applied");
ADD_PROPERTY_TYPE(NormalDirection,(Base::Vector3d(0,0,1)),"Constraint",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),"Normal direction pointing outside of solid"); ADD_PROPERTY_TYPE(NormalDirection,(Base::Vector3d(0,0,1)),"Constraint",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),"Normal direction pointing outside of solid");
ADD_PROPERTY_TYPE(Scale,(1),"Base",App::PropertyType(App::Prop_Output),"Scale used for drawing constraints"); //OvG: Add scale parameter inherited by all derived constraints
} }
Constraint::~Constraint() Constraint::~Constraint()
@ -80,12 +82,29 @@ Constraint::~Constraint()
App::DocumentObjectExecReturn *Constraint::execute(void) App::DocumentObjectExecReturn *Constraint::execute(void)
{ {
References.touch(); References.touch();
Scale.touch();
return StdReturn; return StdReturn;
} }
//OvG: Provide the ability to determine how big to draw constraint arrows etc.
int Constraint::calcDrawScaleFactor(double lparam) const
{
return ((int)round(log(lparam)*log(lparam)*log(lparam)/10)>1)?((int)round(log(lparam)*log(lparam)*log(lparam)/10)):1;
}
int Constraint::calcDrawScaleFactor(double lvparam, double luparam) const
{
return calcDrawScaleFactor((lvparam+luparam)/2.0);
}
int Constraint::calcDrawScaleFactor() const
{
return 1;
}
#define CONSTRAINTSTEPLIMIT 50
void Constraint::onChanged(const App::Property* prop) void Constraint::onChanged(const App::Property* prop)
{ {
//Base::Console().Error("Constraint::onChanged() %s\n", prop->getName());
if (prop == &References) { if (prop == &References) {
// If References are changed, recalculate the normal direction. If no useful reference is found, // If References are changed, recalculate the normal direction. If no useful reference is found,
// use z axis or previous value. If several faces are selected, only the first one is used // use z axis or previous value. If several faces are selected, only the first one is used
@ -131,7 +150,7 @@ void Constraint::onDocumentRestored()
App::DocumentObject::onDocumentRestored(); App::DocumentObject::onDocumentRestored();
} }
const bool Constraint::getPoints(std::vector<Base::Vector3d> &points, std::vector<Base::Vector3d> &normals) const const bool Constraint::getPoints(std::vector<Base::Vector3d> &points, std::vector<Base::Vector3d> &normals, int * scale) const
{ {
std::vector<App::DocumentObject*> Objects = References.getValues(); std::vector<App::DocumentObject*> Objects = References.getValues();
std::vector<std::string> SubElements = References.getSubValues(); std::vector<std::string> SubElements = References.getSubValues();
@ -152,6 +171,11 @@ const bool Constraint::getPoints(std::vector<Base::Vector3d> &points, std::vecto
gp_Pnt p = BRep_Tool::Pnt(vertex); gp_Pnt p = BRep_Tool::Pnt(vertex);
points.push_back(Base::Vector3d(p.X(), p.Y(), p.Z())); points.push_back(Base::Vector3d(p.X(), p.Y(), p.Z()));
normals.push_back(NormalDirection.getValue()); normals.push_back(NormalDirection.getValue());
//OvG: Scale by whole object mass in case of a vertex
GProp_GProps props;
BRepGProp::VolumeProperties(toposhape._Shape, props);
double lx = props.Mass();
*scale = this->calcDrawScaleFactor(sqrt(lx)); //OvG: setup draw scale for constraint
} else if (sh.ShapeType() == TopAbs_EDGE) { } else if (sh.ShapeType() == TopAbs_EDGE) {
BRepAdaptor_Curve curve(TopoDS::Edge(sh)); BRepAdaptor_Curve curve(TopoDS::Edge(sh));
double fp = curve.FirstParameter(); double fp = curve.FirstParameter();
@ -161,10 +185,23 @@ const bool Constraint::getPoints(std::vector<Base::Vector3d> &points, std::vecto
double l = props.Mass(); double l = props.Mass();
// Create points with 10 units distance, but at least one at the beginning and end of the edge // Create points with 10 units distance, but at least one at the beginning and end of the edge
int steps; int steps;
if (l >= 20) if (l >= 100) //OvG: Increase 10 units distance proportionately to l for larger objects.
{
*scale = this->calcDrawScaleFactor(l); //OvG: setup draw scale for constraint
steps = (int)round(l / (10*( *scale)));
steps = steps<3?3:steps;
}
else if (l >= 20)
{
steps = (int)round(l / 10); steps = (int)round(l / 10);
*scale = this->calcDrawScaleFactor(); //OvG: setup draw scale for constraint
}
else else
{
steps = 1; steps = 1;
*scale = this->calcDrawScaleFactor(); //OvG: setup draw scale for constraint
}
steps = steps>CONSTRAINTSTEPLIMIT?CONSTRAINTSTEPLIMIT:steps; //OvG: Place upper limit on number of steps
double step = (lp - fp) / steps; double step = (lp - fp) / steps;
for (int i = 0; i < steps + 1; i++) { for (int i = 0; i < steps + 1; i++) {
gp_Pnt p = curve.Value(i * step); gp_Pnt p = curve.Value(i * step);
@ -195,15 +232,41 @@ const bool Constraint::getPoints(std::vector<Base::Vector3d> &points, std::vecto
isoc.Load(GeomAbs_IsoV, ulp); isoc.Load(GeomAbs_IsoV, ulp);
double lu = (l + GCPnts_AbscissaPoint::Length(isoc, Precision::Confusion()))/2.0; double lu = (l + GCPnts_AbscissaPoint::Length(isoc, Precision::Confusion()))/2.0;
int stepsv; int stepsv;
if (lv >= 20.0) if (lv >= 100) //OvG: Increase 10 units distance proportionately to lv for larger objects.
{
*scale = this->calcDrawScaleFactor(lv,lu); //OvG: setup draw scale for constraint
stepsv = (int)round(lv / (10*( *scale)));
stepsv = stepsv<3?3:stepsv;
}
else if (lv >= 20.0)
{
stepsv = (int)round(lv / 10); stepsv = (int)round(lv / 10);
*scale = this->calcDrawScaleFactor(); //OvG: setup draw scale for constraint
}
else else
{
stepsv = 2; // Minimum of three arrows to ensure (as much as possible) that at least one is displayed stepsv = 2; // Minimum of three arrows to ensure (as much as possible) that at least one is displayed
*scale = this->calcDrawScaleFactor(); //OvG: setup draw scale for constraint
}
stepsv = stepsv>CONSTRAINTSTEPLIMIT?CONSTRAINTSTEPLIMIT:stepsv; //OvG: Place upper limit on number of steps
int stepsu; int stepsu;
if (lu >= 20.0) if (lu >= 100) //OvG: Increase 10 units distance proportionately to lu for larger objects.
{
*scale = this->calcDrawScaleFactor(lv,lu); //OvG: setup draw scale for constraint
stepsu = (int)round(lu / (10*( *scale)));
stepsu = stepsu<3?3:stepsu;
}
else if (lu >= 20.0)
{
stepsu = (int)round(lu / 10); stepsu = (int)round(lu / 10);
*scale = this->calcDrawScaleFactor(); //OvG: setup draw scale for constraint
}
else else
{
stepsu = 2; stepsu = 2;
*scale = this->calcDrawScaleFactor(); //OvG: setup draw scale for constraint
}
stepsu = stepsu>CONSTRAINTSTEPLIMIT?CONSTRAINTSTEPLIMIT:stepsu; //OvG: Place upper limit on number of steps
double stepv = (vlp - vfp) / stepsv; double stepv = (vlp - vfp) / stepsv;
double stepu = (ulp - ufp) / stepsu; double stepu = (ulp - ufp) / stepsu;
// Create points and normals // Create points and normals

View File

@ -44,6 +44,9 @@ public:
App::PropertyLinkSubList References; App::PropertyLinkSubList References;
// Read-only (calculated values). These trigger changes in the ViewProvider // Read-only (calculated values). These trigger changes in the ViewProvider
App::PropertyVector NormalDirection; App::PropertyVector NormalDirection;
//OvG: Scale
App::PropertyInteger Scale;
/// recalculate the object /// recalculate the object
virtual App::DocumentObjectExecReturn *execute(void); virtual App::DocumentObjectExecReturn *execute(void);
@ -52,6 +55,11 @@ public:
virtual const char* getViewProviderName(void) const { virtual const char* getViewProviderName(void) const {
return "FemGui::ViewProviderFemConstraint"; return "FemGui::ViewProviderFemConstraint";
} }
//OvG: Allow automatic determination of scaling of constraint drawings, e.g. arrow length and size
int calcDrawScaleFactor(double lparam) const;
int calcDrawScaleFactor(double lvparam, double luparam) const;
int calcDrawScaleFactor() const;
protected: protected:
virtual void onChanged(const App::Property* prop); virtual void onChanged(const App::Property* prop);
@ -59,7 +67,7 @@ protected:
protected: protected:
/// Calculate the points where symbols should be drawn /// Calculate the points where symbols should be drawn
const bool getPoints(std::vector<Base::Vector3d>& points, std::vector<Base::Vector3d>& normals) const; const bool getPoints(std::vector<Base::Vector3d>& points, std::vector<Base::Vector3d>& normals, int * scale) const; //OvG: added scale parameter
const bool getCylinder(double& radius, double& height, Base::Vector3d& base, Base::Vector3d& axis) const; const bool getCylinder(double& radius, double& height, Base::Vector3d& base, Base::Vector3d& axis) const;
Base::Vector3d getBasePoint(const Base::Vector3d& base, const Base::Vector3d& axis, Base::Vector3d getBasePoint(const Base::Vector3d& base, const Base::Vector3d& axis,
const App::PropertyLinkSub &location, const double& dist); const App::PropertyLinkSub &location, const double& dist);

View File

@ -75,9 +75,11 @@ void ConstraintFixed::onChanged(const App::Property* 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)) { int scale = 1; //OvG: Enforce use of scale
if (getPoints(points, normals, &scale)) {
Points.setValues(points); Points.setValues(points);
Normals.setValues(normals); Normals.setValues(normals);
Scale.setValue(scale); //OvG: Scale
Points.touch(); // This triggers ViewProvider::updateData() Points.touch(); // This triggers ViewProvider::updateData()
} }
} }

View File

@ -70,8 +70,11 @@ void ConstraintForce::onChanged(const App::Property* 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)) { int scale = 1; //OvG: Enforce use of scale
if (getPoints(points, normals, &scale)) {
Points.setValues(points); // We don't use the normals because all arrows should have the same direction Points.setValues(points); // We don't use the normals because all arrows should have the same direction
Scale.setValue(scale); //OvG Scale
Points.touch();
} }
} else if (prop == &Direction) { } else if (prop == &Direction) {
Base::Vector3d direction = getDirection(Direction); Base::Vector3d direction = getDirection(Direction);

View File

@ -70,9 +70,11 @@ void ConstraintPressure::onChanged(const App::Property* 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)) { int scale = Scale.getValue();
if (getPoints(points, normals, &scale)) {
Points.setValues(points); Points.setValues(points);
Normals.setValues(normals); Normals.setValues(normals);
Scale.setValue(scale);
Points.touch(); Points.touch();
} }
} else if (prop == &Reversed) { } else if (prop == &Reversed) {

View File

@ -315,6 +315,7 @@ void CmdFemConstraintFixed::activated(int iMsg)
openCommand("Make FEM constraint fixed geometry"); openCommand("Make FEM constraint fixed geometry");
doCommand(Doc,"App.activeDocument().addObject(\"Fem::ConstraintFixed\",\"%s\")",FeatName.c_str()); doCommand(Doc,"App.activeDocument().addObject(\"Fem::ConstraintFixed\",\"%s\")",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Scale = 1",FeatName.c_str()); //OvG: set initial scale to 1
doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().%s]",Analysis->getNameInDocument(),Analysis->getNameInDocument(),FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().%s]",Analysis->getNameInDocument(),Analysis->getNameInDocument(),FeatName.c_str());
updateActive(); updateActive();
@ -353,7 +354,9 @@ void CmdFemConstraintForce::activated(int iMsg)
openCommand("Make FEM constraint force on geometry"); openCommand("Make FEM constraint force on geometry");
doCommand(Doc,"App.activeDocument().addObject(\"Fem::ConstraintForce\",\"%s\")",FeatName.c_str()); doCommand(Doc,"App.activeDocument().addObject(\"Fem::ConstraintForce\",\"%s\")",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Force = 0.0",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Force = 1.0",FeatName.c_str()); //OvG: set default not equal to 0
doCommand(Doc,"App.activeDocument().%s.Reversed = False",FeatName.c_str()); //OvG: set default to False
doCommand(Doc,"App.activeDocument().%s.Scale = 1",FeatName.c_str()); //OvG: set initial scale to 1
doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().%s]",Analysis->getNameInDocument(),Analysis->getNameInDocument(),FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().%s]",Analysis->getNameInDocument(),Analysis->getNameInDocument(),FeatName.c_str());
updateActive(); updateActive();
@ -392,7 +395,9 @@ void CmdFemConstraintPressure::activated(int iMsg)
openCommand("Make FEM constraint pressure on face"); openCommand("Make FEM constraint pressure on face");
doCommand(Doc,"App.activeDocument().addObject(\"Fem::ConstraintPressure\",\"%s\")",FeatName.c_str()); 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.Pressure = 1000.0",FeatName.c_str()); //OvG: set default not equal to 0
doCommand(Doc,"App.activeDocument().%s.Reversed = False",FeatName.c_str()); //OvG: set default to False
doCommand(Doc,"App.activeDocument().%s.Scale = 1",FeatName.c_str()); //OvG: set initial scale to 1
doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().%s]", doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().%s]",
Analysis->getNameInDocument(),Analysis->getNameInDocument(),FeatName.c_str()); Analysis->getNameInDocument(),Analysis->getNameInDocument(),FeatName.c_str());
updateActive(); updateActive();

View File

@ -56,6 +56,8 @@
#include <Base/Console.h> #include <Base/Console.h>
# include <boost/lexical_cast.hpp> //OvG conversion between string and int etc.
using namespace FemGui; using namespace FemGui;
using namespace Gui; using namespace Gui;
@ -113,6 +115,14 @@ const std::string TaskFemConstraint::getReferences(const std::vector<std::string
return result; return result;
} }
const std::string TaskFemConstraint::getScale() const //OvG: Return pre-calculated scale for constraint display
{
std::string result;
Fem::Constraint* pcConstraint = static_cast<Fem::Constraint*>(ConstraintView->getObject());
result = boost::lexical_cast<std::string>(pcConstraint->Scale.getValue());
return result;
}
void TaskFemConstraint::onReferenceDeleted(const int row) { void TaskFemConstraint::onReferenceDeleted(const int row) {
Fem::Constraint* pcConstraint = static_cast<Fem::Constraint*>(ConstraintView->getObject()); Fem::Constraint* pcConstraint = static_cast<Fem::Constraint*>(ConstraintView->getObject());
std::vector<App::DocumentObject*> Objects = pcConstraint->References.getValues(); std::vector<App::DocumentObject*> Objects = pcConstraint->References.getValues();

View File

@ -42,6 +42,7 @@ public:
virtual const std::string getReferences(void) const {return std::string();} virtual const std::string getReferences(void) const {return std::string();}
const std::string getReferences(const std::vector<std::string>& items) const; const std::string getReferences(const std::vector<std::string>& items) const;
const std::string getScale() const;
protected Q_SLOTS: protected Q_SLOTS:
void onReferenceDeleted(const int row); void onReferenceDeleted(const int row);

View File

@ -215,6 +215,10 @@ TaskDlgFemConstraintFixed::TaskDlgFemConstraintFixed(ViewProviderFemConstraintFi
bool TaskDlgFemConstraintFixed::accept() bool TaskDlgFemConstraintFixed::accept()
{ {
std::string name = ConstraintView->getObject()->getNameInDocument();
const TaskFemConstraintFixed* parameterFixed = static_cast<const TaskFemConstraintFixed*>(parameter);
std::string scale = parameterFixed->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
return TaskDlgFemConstraint::accept(); return TaskDlgFemConstraint::accept();
} }

View File

@ -352,10 +352,19 @@ bool TaskDlgFemConstraintForce::accept()
try { try {
//Gui::Command::openCommand("FEM force constraint changed"); //Gui::Command::openCommand("FEM force constraint changed");
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Force = %f",name.c_str(), parameterForce->getForce());
if (parameterForce->getForce()<=0)
{
QMessageBox::warning(parameter, tr("Input error"), tr("Please specify a force greater than 0"));
return false;
}
else
{
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Force = %f",name.c_str(), parameterForce->getForce());
}
std::string dirname = parameterForce->getDirectionName().data(); std::string dirname = parameterForce->getDirectionName().data();
std::string dirobj = parameterForce->getDirectionObject().data(); std::string dirobj = parameterForce->getDirectionObject().data();
std::string scale = "1";
if (!dirname.empty()) { if (!dirname.empty()) {
QString buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])"); QString buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])");
@ -367,6 +376,9 @@ bool TaskDlgFemConstraintForce::accept()
} }
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %s", name.c_str(), parameterForce->getReverse() ? "True" : "False"); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %s", name.c_str(), parameterForce->getReverse() ? "True" : "False");
scale = parameterForce->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) { catch (const Base::Exception& e) {
QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what())); QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what()));

View File

@ -249,12 +249,25 @@ 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);
std::string scale = "1";
try { try {
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Pressure = %f", if (parameterPressure->getPressure()<=0)
name.c_str(), parameterPressure->getPressure()); {
QMessageBox::warning(parameter, tr("Input error"), tr("Please specify a pressure greater than 0"));
return false;
}
else
{
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", 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");
scale = parameterPressure->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) { catch (const Base::Exception& e) {
QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what())); QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what()));

View File

@ -107,19 +107,22 @@ bool ViewProviderFemConstraintFixed::setEdit(int ModNum)
#define HEIGHT 4 #define HEIGHT 4
#define WIDTH (1.5*HEIGHT) #define WIDTH (1.5*HEIGHT)
#define USE_MULTIPLE_COPY //#define USE_MULTIPLE_COPY //OvG: MULTICOPY fails to update scaled display on initial drawing - so disable
void ViewProviderFemConstraintFixed::updateData(const App::Property* prop) void ViewProviderFemConstraintFixed::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::ConstraintFixed* pcConstraint = static_cast<Fem::ConstraintFixed*>(this->getObject()); Fem::ConstraintFixed* pcConstraint = static_cast<Fem::ConstraintFixed*>(this->getObject());
float scaledwidth = WIDTH * pcConstraint->Scale.getValue(); //OvG: Calculate scaled values once only
float scaledheight = HEIGHT * pcConstraint->Scale.getValue();
#ifdef USE_MULTIPLE_COPY #ifdef USE_MULTIPLE_COPY
//OvG: always need access to cp for scaling
SoMultipleCopy* cp = new SoMultipleCopy();
if (pShapeSep->getNumChildren() == 0) { if (pShapeSep->getNumChildren() == 0) {
// Set up the nodes // Set up the nodes
SoMultipleCopy* cp = new SoMultipleCopy();
cp->matrix.setNum(0); cp->matrix.setNum(0);
cp->addChild((SoNode*)createFixed(HEIGHT, WIDTH)); cp->addChild((SoNode*)createFixed(scaledheight, scaledwidth)); //OvG: Scaling
pShapeSep->addChild(cp); pShapeSep->addChild(cp);
} }
#endif #endif
@ -132,7 +135,7 @@ void ViewProviderFemConstraintFixed::updateData(const App::Property* prop)
std::vector<Base::Vector3d>::const_iterator n = normals.begin(); std::vector<Base::Vector3d>::const_iterator n = normals.begin();
#ifdef USE_MULTIPLE_COPY #ifdef USE_MULTIPLE_COPY
SoMultipleCopy* cp = static_cast<SoMultipleCopy*>(pShapeSep->getChild(0)); 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;
@ -153,7 +156,7 @@ void ViewProviderFemConstraintFixed::updateData(const App::Property* prop)
#else #else
SoSeparator* sep = new SoSeparator(); SoSeparator* sep = new SoSeparator();
createPlacement(sep, base, rot); createPlacement(sep, base, rot);
createFixed(sep, HEIGHT, WIDTH); createFixed(sep, scaledheight, scaledwidth); //OvG: Scaling
pShapeSep->addChild(sep); pShapeSep->addChild(sep);
#endif #endif
n++; n++;

View File

@ -107,19 +107,22 @@ bool ViewProviderFemConstraintForce::setEdit(int ModNum)
#define ARROWLENGTH 9 #define ARROWLENGTH 9
#define ARROWHEADRADIUS (ARROWLENGTH/3) #define ARROWHEADRADIUS (ARROWLENGTH/3)
#define USE_MULTIPLE_COPY //#define USE_MULTIPLE_COPY //OvG: MULTICOPY fails to update scaled arrows on initial drawing - so disable
void ViewProviderFemConstraintForce::updateData(const App::Property* prop) void ViewProviderFemConstraintForce::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::ConstraintForce* pcConstraint = static_cast<Fem::ConstraintForce*>(this->getObject()); Fem::ConstraintForce* pcConstraint = static_cast<Fem::ConstraintForce*>(this->getObject());
float scaledheadradius = ARROWHEADRADIUS * pcConstraint->Scale.getValue(); //OvG: Calculate scaled values once only
float scaledlength = ARROWLENGTH * pcConstraint->Scale.getValue();
#ifdef USE_MULTIPLE_COPY #ifdef USE_MULTIPLE_COPY
//OvG: need access to cp for scaling
SoMultipleCopy* cp = new SoMultipleCopy();
if (pShapeSep->getNumChildren() == 0) { if (pShapeSep->getNumChildren() == 0) {
// Set up the nodes // Set up the nodes
SoMultipleCopy* cp = new SoMultipleCopy();
cp->matrix.setNum(0); cp->matrix.setNum(0);
cp->addChild((SoNode*)createArrow(ARROWLENGTH, ARROWHEADRADIUS)); cp->addChild((SoNode*)createArrow(scaledlength , scaledheadradius)); //OvG: Scaling
pShapeSep->addChild(cp); pShapeSep->addChild(cp);
} }
#endif #endif
@ -128,7 +131,7 @@ void ViewProviderFemConstraintForce::updateData(const App::Property* prop)
const std::vector<Base::Vector3d>& points = pcConstraint->Points.getValues(); const std::vector<Base::Vector3d>& points = pcConstraint->Points.getValues();
#ifdef USE_MULTIPLE_COPY #ifdef USE_MULTIPLE_COPY
SoMultipleCopy* cp = static_cast<SoMultipleCopy*>(pShapeSep->getChild(0)); 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;
@ -150,7 +153,7 @@ void ViewProviderFemConstraintForce::updateData(const App::Property* prop)
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);
if (forceDirection.GetAngle(normal) < M_PI_2) // Move arrow so it doesn't disappear inside the solid if (forceDirection.GetAngle(normal) < M_PI_2) // Move arrow so it doesn't disappear inside the solid
base = base + dir * ARROWLENGTH; base = base + dir * scaledlength; //OvG: Scaling
#ifdef USE_MULTIPLE_COPY #ifdef USE_MULTIPLE_COPY
SbMatrix m; SbMatrix m;
m.setTransform(base, rot, SbVec3f(1,1,1)); m.setTransform(base, rot, SbVec3f(1,1,1));
@ -159,7 +162,7 @@ void ViewProviderFemConstraintForce::updateData(const App::Property* prop)
#else #else
SoSeparator* sep = new SoSeparator(); SoSeparator* sep = new SoSeparator();
createPlacement(sep, base, rot); createPlacement(sep, base, rot);
createArrow(sep, ARROWLENGTH, ARROWHEADRADIUS); createArrow(sep, scaledlength, scaledheadradius); //OvG: Scaling
pShapeSep->addChild(sep); pShapeSep->addChild(sep);
#endif #endif
} }
@ -189,7 +192,7 @@ void ViewProviderFemConstraintForce::updateData(const App::Property* prop)
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);
if (forceDirection.GetAngle(normal) < M_PI_2) if (forceDirection.GetAngle(normal) < M_PI_2)
base = base + dir * ARROWLENGTH; base = base + dir * scaledlength; //OvG: Scaling
#ifdef USE_MULTIPLE_COPY #ifdef USE_MULTIPLE_COPY
SbMatrix m; SbMatrix m;
m.setTransform(base, rot, SbVec3f(1,1,1)); m.setTransform(base, rot, SbVec3f(1,1,1));
@ -197,7 +200,7 @@ void ViewProviderFemConstraintForce::updateData(const App::Property* prop)
#else #else
SoSeparator* sep = static_cast<SoSeparator*>(pShapeSep->getChild(idx)); SoSeparator* sep = static_cast<SoSeparator*>(pShapeSep->getChild(idx));
updatePlacement(sep, 0, base, rot); updatePlacement(sep, 0, base, rot);
updateArrow(sep, 2, ARROWLENGTH, ARROWHEADRADIUS); updateArrow(sep, 2, scaledlength, scaledheadradius); //OvG: Scaling
#endif #endif
idx++; idx++;
} }

View File

@ -89,21 +89,27 @@ bool ViewProviderFemConstraintPressure::setEdit(int ModNum)
} }
} }
#define ARROWLENGTH 5 #define ARROWLENGTH (6)
#define ARROWHEADRADIUS 3 #define ARROWHEADRADIUS (ARROWLENGTH/3)
//#define USE_MULTIPLE_COPY //OvG: MULTICOPY fails to update scaled arrows on initial drawing - so disable
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());
float scaledheadradius = ARROWHEADRADIUS * pcConstraint->Scale.getValue(); //OvG: Calculate scaled values once only
float scaledlength = ARROWLENGTH * pcConstraint->Scale.getValue();
#ifdef USE_MULTIPLE_COPY
//OvG: always need access to cp for scaling
SoMultipleCopy* cp = new SoMultipleCopy();
if (pShapeSep->getNumChildren() == 0) { if (pShapeSep->getNumChildren() == 0) {
// Set up the nodes // Set up the nodes
SoMultipleCopy* cp = new SoMultipleCopy();
cp->matrix.setNum(0); cp->matrix.setNum(0);
cp->addChild((SoNode*)createArrow(ARROWLENGTH, ARROWHEADRADIUS)); cp->addChild((SoNode*)createArrow(scaledlength , scaledheadradius)); //OvG: Scaling
pShapeSep->addChild(cp); 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>& points = pcConstraint->Points.getValues();
@ -113,29 +119,43 @@ void ViewProviderFemConstraintPressure::updateData(const App::Property* prop)
} }
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)); #ifdef USE_MULTIPLE_COPY
cp = static_cast<SoMultipleCopy*>(pShapeSep->getChild(0)); //OvG: Use top cp
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;
#else
// Redraw all arrows
pShapeSep->removeAllChildren();
#endif
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 * scaledlength; //OvG: Scaling
rev = 1; rev = 1;
} else { } else {
rev = -1; rev = -1;
} }
SbRotation rot(SbVec3f(0, rev, 0), dir); SbRotation rot(SbVec3f(0, rev, 0), dir);
#ifdef USE_MULTIPLE_COPY
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++;
#else
SoSeparator* sep = new SoSeparator();
createPlacement(sep, base, rot);
createArrow(sep, scaledlength , scaledheadradius); //OvG: Scaling
pShapeSep->addChild(sep);
#endif
n++; n++;
} }
#ifdef USE_MULTIPLE_COPY
cp->matrix.finishEditing(); cp->matrix.finishEditing();
#endif
} }
ViewProviderFemConstraint::updateData(prop); ViewProviderFemConstraint::updateData(prop);