FEM: C++98 compatible fix to constraint displacement reference deletion, update vertice, edge, face selection

This commit is contained in:
vginkeo 2016-02-29 07:48:58 +01:00 committed by wmayer
parent e47560003e
commit f14758d5e5
13 changed files with 105 additions and 26 deletions

View File

@ -109,7 +109,10 @@ typedef unsigned int flex_uint32_t;
#endif #endif
/* Returned upon end-of-file. */ /* Returned upon end-of-file. */
#define YY_NULL 0 # ifdef YY_NULL
# undef YY_NULL
# define YY_NULL 0
# endif
/* Promotes a possibly negative, possibly signed char to an unsigned /* Promotes a possibly negative, possibly signed char to an unsigned
* integer for use as an array index. If the signed char is negative, * integer for use as an array index. If the signed char is negative,
@ -686,7 +689,7 @@ static int input (void );
if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
{ \ { \
int c = '*'; \ int c = '*'; \
int n; \ unsigned int n; \
for ( n = 0; n < max_size && \ for ( n = 0; n < max_size && \
(c = getc( yyin )) != EOF && c != '\n'; ++n ) \ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
buf[n] = (char) c; \ buf[n] = (char) c; \

View File

@ -81,11 +81,12 @@ bool getConstraintPrerequisits(Fem::FemAnalysis **Analysis)
} }
//OvG: Visibility automation show parts and hide meshes on activation of a constraint //OvG: Visibility automation show parts and hide meshes on activation of a constraint
std::string gethideMeshShowPartStr() std::string gethideMeshShowPartStr(std::string showConstr="")
{ {
return return "for amesh in App.activeDocument().Objects:\n\
"for amesh in App.activeDocument().Objects:\n\ if \""+showConstr+"\" == amesh.Name:\n\
if \"Mesh\" in amesh.TypeId:\n\ amesh.ViewObject.Visibility = True\n\
elif \"Mesh\" in amesh.TypeId:\n\
aparttoshow = amesh.Name.replace(\"_Mesh\",\"\")\n\ aparttoshow = amesh.Name.replace(\"_Mesh\",\"\")\n\
for apart in App.activeDocument().Objects:\n\ for apart in App.activeDocument().Objects:\n\
if aparttoshow == apart.Name:\n\ if aparttoshow == apart.Name:\n\
@ -291,7 +292,7 @@ void CmdFemConstraintBearing::activated(int iMsg)
doCommand(Doc,"App.activeDocument().addObject(\"Fem::ConstraintBearing\",\"%s\")",FeatName.c_str()); doCommand(Doc,"App.activeDocument().addObject(\"Fem::ConstraintBearing\",\"%s\")",FeatName.c_str());
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());
doCommand(Doc,"%s",gethideMeshShowPartStr().c_str()); //OvG: Hide meshes and show parts doCommand(Doc,"%s",gethideMeshShowPartStr(FeatName).c_str()); //OvG: Hide meshes and show parts
updateActive(); updateActive();
@ -333,7 +334,7 @@ void CmdFemConstraintFixed::activated(int iMsg)
doCommand(Doc,"App.activeDocument().%s.Scale = 1",FeatName.c_str()); //OvG: set initial scale to 1 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());
doCommand(Doc,"%s",gethideMeshShowPartStr().c_str()); //OvG: Hide meshes and show parts doCommand(Doc,"%s",gethideMeshShowPartStr(FeatName).c_str()); //OvG: Hide meshes and show parts
updateActive(); updateActive();
@ -377,7 +378,7 @@ void CmdFemConstraintForce::activated(int iMsg)
doCommand(Doc,"App.activeDocument().%s.Scale = 1",FeatName.c_str()); //OvG: set initial scale to 1 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());
doCommand(Doc,"%s",gethideMeshShowPartStr().c_str()); //OvG: Hide meshes and show parts doCommand(Doc,"%s",gethideMeshShowPartStr(FeatName).c_str()); //OvG: Hide meshes and show parts
updateActive(); updateActive();
@ -422,7 +423,7 @@ void CmdFemConstraintPressure::activated(int iMsg)
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());
doCommand(Doc,"%s",gethideMeshShowPartStr().c_str()); //OvG: Hide meshes and show parts doCommand(Doc,"%s",gethideMeshShowPartStr(FeatName).c_str()); //OvG: Hide meshes and show parts
updateActive(); updateActive();
@ -463,7 +464,7 @@ void CmdFemConstraintGear::activated(int iMsg)
doCommand(Doc,"App.activeDocument().%s.Diameter = 100.0",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.Diameter = 100.0",FeatName.c_str());
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());
doCommand(Doc,"%s",gethideMeshShowPartStr().c_str()); //OvG: Hide meshes and show parts doCommand(Doc,"%s",gethideMeshShowPartStr(FeatName).c_str()); //OvG: Hide meshes and show parts
updateActive(); updateActive();
@ -509,7 +510,7 @@ void CmdFemConstraintPulley::activated(int iMsg)
doCommand(Doc,"App.activeDocument().%s.TensionForce = 100.0",FeatName.c_str()); doCommand(Doc,"App.activeDocument().%s.TensionForce = 100.0",FeatName.c_str());
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());
doCommand(Doc,"%s",gethideMeshShowPartStr().c_str()); //OvG: Hide meshes and show parts doCommand(Doc,"%s",gethideMeshShowPartStr(FeatName).c_str()); //OvG: Hide meshes and show parts
updateActive(); updateActive();
@ -551,7 +552,7 @@ void CmdFemConstraintDisplacement::activated(int iMsg)
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());
doCommand(Doc,"%s",gethideMeshShowPartStr().c_str()); //OvG: Hide meshes and show parts doCommand(Doc,"%s",gethideMeshShowPartStr(FeatName).c_str()); //OvG: Hide meshes and show parts
updateActive(); updateActive();

View File

@ -181,6 +181,11 @@ const QString TaskFemConstraint::makeRefText(const App::DocumentObject* obj, con
//==== calls from the TaskView =============================================================== //==== calls from the TaskView ===============================================================
void TaskDlgFemConstraint::open()
{
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
}
bool TaskDlgFemConstraint::accept() bool TaskDlgFemConstraint::accept()
{ {

View File

@ -77,9 +77,10 @@ class TaskDlgFemConstraint : public Gui::TaskView::TaskDialog
Q_OBJECT Q_OBJECT
public: public:
/*
/// is called the TaskView when the dialog is opened /// is called the TaskView when the dialog is opened
virtual void open() {} void open();
/*
/// is called by the framework if an button is clicked which has no accept or reject role /// is called by the framework if an button is clicked which has no accept or reject role
virtual void clicked(int) {} virtual void clicked(int) {}
/// is called by the framework if the dialog is accepted (Ok) /// is called by the framework if the dialog is accepted (Ok)

View File

@ -435,10 +435,30 @@ void TaskFemConstraintDisplacement::addToSelection()
addMe=false; addMe=false;
} }
} }
// 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)
searchStr="Vertex";
else if (subNames[subIt].find("Edge")!=std::string::npos)
searchStr="Edge";
else
searchStr="Face";
for (unsigned int iStr=0;iStr<(SubElements.size());++iStr){
if ((SubElements[iStr].find(searchStr)==std::string::npos)&&(SubElements.size()>0)){
std::string Msg="Only one type of selection (vertex,face or edge) per constraint allowed!";
QMessageBox::warning(this, tr("Selection error"),QString::fromStdString(Msg));
addMe=false;
break;
}
}
if (addMe){ if (addMe){
disconnect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),
this, SLOT(setSelection(QListWidgetItem*)));
Objects.push_back(obj); Objects.push_back(obj);
SubElements.push_back(subNames[subIt]); SubElements.push_back(subNames[subIt]);
ui->lw_references->addItem(makeRefText(obj, subNames[subIt])); ui->lw_references->addItem(makeRefText(obj, subNames[subIt]));
connect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),
this, SLOT(setSelection(QListWidgetItem*)));
} }
} }
} }
@ -458,7 +478,7 @@ void TaskFemConstraintDisplacement::removeFromSelection()
Fem::ConstraintDisplacement* pcConstraint = static_cast<Fem::ConstraintDisplacement*>(ConstraintView->getObject()); Fem::ConstraintDisplacement* pcConstraint = static_cast<Fem::ConstraintDisplacement*>(ConstraintView->getObject());
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();
std::vector<int> itemsToDel; std::vector<unsigned int> 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 (static_cast<std::string>(it->getTypeName()).substr(0,4).compare(std::string("Part"))!=0){ if (static_cast<std::string>(it->getTypeName()).substr(0,4).compare(std::string("Part"))!=0){
QMessageBox::warning(this, tr("Selection error"),tr("Selected object is not a part!")); QMessageBox::warning(this, tr("Selection error"),tr("Selected object is not a part!"));
@ -480,6 +500,7 @@ void TaskFemConstraintDisplacement::removeFromSelection()
} }
} }
std::sort(itemsToDel.begin(),itemsToDel.end());
while (itemsToDel.size()>0){ while (itemsToDel.size()>0){
Objects.erase(Objects.begin()+itemsToDel.back()); Objects.erase(Objects.begin()+itemsToDel.back());
SubElements.erase(SubElements.begin()+itemsToDel.back()); SubElements.erase(SubElements.begin()+itemsToDel.back());
@ -502,9 +523,9 @@ void TaskFemConstraintDisplacement::removeFromSelection()
} }
void TaskFemConstraintDisplacement::setSelection(QListWidgetItem* item){ void TaskFemConstraintDisplacement::setSelection(QListWidgetItem* item){
std::string docName=ConstraintView->getObject()->getDocument()->getName();
std::string s = item->text().toStdString(); std::string s = item->text().toStdString();
std::string docName=ConstraintView->getObject()->getDocument()->getName();
std::string delimiter = ":"; std::string delimiter = ":";
size_t pos = 0; size_t pos = 0;
@ -520,10 +541,7 @@ void TaskFemConstraintDisplacement::setSelection(QListWidgetItem* item){
} }
void TaskFemConstraintDisplacement::onReferenceDeleted() { void TaskFemConstraintDisplacement::onReferenceDeleted() {
int row = ui->lw_references->currentIndex().row(); TaskFemConstraintDisplacement::removeFromSelection(); //OvG: On right-click face is automatically selected, so just remove
TaskFemConstraint::onReferenceDeleted(row);
ui->lw_references->model()->removeRow(row);
ui->lw_references->setCurrentRow(0, QItemSelectionModel::ClearAndSelect);
} }
const std::string TaskFemConstraintDisplacement::getReferences() const const std::string TaskFemConstraintDisplacement::getReferences() const
@ -585,8 +603,10 @@ void TaskDlgFemConstraintDisplacement::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 displacement");
Gui::Command::openCommand((const char*)msg.toUtf8()); 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
} }
} }

View File

@ -213,6 +213,17 @@ TaskDlgFemConstraintFixed::TaskDlgFemConstraintFixed(ViewProviderFemConstraintFi
//==== calls from the TaskView =============================================================== //==== calls from the TaskView ===============================================================
void TaskDlgFemConstraintFixed::open()
{
// a transaction is already open at creation time of the panel
if (!Gui::Command::hasPendingCommand()) {
QString msg = QObject::tr("Constraint fixed");
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
}
}
bool TaskDlgFemConstraintFixed::accept() bool TaskDlgFemConstraintFixed::accept()
{ {
std::string name = ConstraintView->getObject()->getNameInDocument(); std::string name = ConstraintView->getObject()->getNameInDocument();

View File

@ -76,7 +76,7 @@ public:
/// is called by the framework if the dialog is accepted (Ok) /// is called by the framework if the dialog is accepted (Ok)
virtual bool accept(); virtual bool accept();
void open();
}; };
} //namespace FemGui } //namespace FemGui

View File

@ -342,6 +342,8 @@ void TaskDlgFemConstraintForce::open()
if (!Gui::Command::hasPendingCommand()) { if (!Gui::Command::hasPendingCommand()) {
QString msg = QObject::tr("Constraint force"); QString msg = QObject::tr("Constraint force");
Gui::Command::openCommand((const char*)msg.toUtf8()); 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
} }
} }

View File

@ -240,8 +240,10 @@ 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 pressure");
Gui::Command::openCommand((const char*)msg.toUtf8()); 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
} }
} }

View File

@ -188,6 +188,17 @@ TaskDlgFemConstraintPulley::TaskDlgFemConstraintPulley(ViewProviderFemConstraint
//==== calls from the TaskView =============================================================== //==== calls from the TaskView ===============================================================
void TaskDlgFemConstraintPulley::open()
{
// a transaction is already open at creation time of the panel
if (!Gui::Command::hasPendingCommand()) {
QString msg = QObject::tr("Constraint pulley");
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
}
}
bool TaskDlgFemConstraintPulley::accept() bool TaskDlgFemConstraintPulley::accept()
{ {
std::string name = ConstraintView->getObject()->getNameInDocument(); std::string name = ConstraintView->getObject()->getNameInDocument();

View File

@ -66,7 +66,7 @@ public:
/// is called by the framework if the dialog is accepted (Ok) /// is called by the framework if the dialog is accepted (Ok)
virtual bool accept(); virtual bool accept();
void open();
}; };
} //namespace FemGui } //namespace FemGui

View File

@ -168,8 +168,28 @@ void ViewProviderFemConstraint::onChanged(const App::Property* prop)
} }
} }
//OvG: Visibility automation show parts and hide meshes on activation of a constraint
std::string ViewProviderFemConstraint::gethideMeshShowPartStr(const std::string showConstr)
{
return "for amesh in App.activeDocument().Objects:\n\
if \""+showConstr+"\" == amesh.Name:\n\
amesh.ViewObject.Visibility = True\n\
elif \"Mesh\" in amesh.TypeId:\n\
aparttoshow = amesh.Name.replace(\"_Mesh\",\"\")\n\
for apart in App.activeDocument().Objects:\n\
if aparttoshow == apart.Name:\n\
apart.ViewObject.Visibility = True\n\
amesh.ViewObject.Visibility = False\n";
}
std::string ViewProviderFemConstraint::gethideMeshShowPartStr()
{
return ViewProviderFemConstraint::gethideMeshShowPartStr("");
}
bool ViewProviderFemConstraint::setEdit(int ModNum) bool ViewProviderFemConstraint::setEdit(int ModNum)
{ {
Gui::Command::doCommand(Gui::Command::Doc,"%s",ViewProviderFemConstraint::gethideMeshShowPartStr().c_str());
return Gui::ViewProviderGeometryObject::setEdit(ModNum); return Gui::ViewProviderGeometryObject::setEdit(ModNum);
} }

View File

@ -64,6 +64,9 @@ public:
std::vector<App::DocumentObject*> claimChildren(void)const; std::vector<App::DocumentObject*> claimChildren(void)const;
void setupContextMenu(QMenu*, QObject*, const char*); void setupContextMenu(QMenu*, QObject*, const char*);
static std::string gethideMeshShowPartStr();
static std::string gethideMeshShowPartStr(const std::string showConstr);
protected: protected:
void onChanged(const App::Property* prop); void onChanged(const App::Property* prop);