mirror of
https://git.salome-platform.org/gitpub/modules/smesh.git
synced 2024-12-30 19:30:35 +05:00
Fix bug with SIGSEGV when entering wrong edge id in "Diagonal Inversion" and "Union Triangles" dialog boxes
This commit is contained in:
parent
a0a59a9d9c
commit
607c254121
@ -67,33 +67,21 @@
|
|||||||
#define SPACING 5
|
#define SPACING 5
|
||||||
#define MARGIN 10
|
#define MARGIN 10
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Class : SMESHGUI_DiagValidator
|
\class BusyLocker
|
||||||
* Description : validate munual input of edge like "id1-id2"
|
\brief Simple 'busy state' flag locker.
|
||||||
|
\internal
|
||||||
*/
|
*/
|
||||||
class SMESHGUI_DiagValidator: public QValidator
|
|
||||||
|
class BusyLocker
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SMESHGUI_DiagValidator (QWidget * parent, const char * name = 0):
|
//! Constructor. Sets passed boolean flag to \c true.
|
||||||
QValidator(parent,name) {}
|
BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
|
||||||
|
//! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
|
||||||
State validate (QString & text, int & pos) const
|
~BusyLocker() { myBusy = false; }
|
||||||
{
|
private:
|
||||||
text.stripWhiteSpace();
|
bool& myBusy; //! External 'busy state' boolean flag
|
||||||
text.replace(QRegExp("[^0-9]+"), "-");
|
|
||||||
if (text == "-")
|
|
||||||
text = "";
|
|
||||||
int ind = text.find(QRegExp("-[0-9]+-"));
|
|
||||||
if (ind > 0) { // leave only two ids
|
|
||||||
ind = text.find('-', ind + 1);
|
|
||||||
if (ind > 0)
|
|
||||||
text.truncate(ind);
|
|
||||||
}
|
|
||||||
if (pos > text.length())
|
|
||||||
pos = text.length();
|
|
||||||
return Acceptable;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -143,7 +131,7 @@ QFrame* SMESHGUI_SingleEditDlg::createMainFrame (QWidget* theParent)
|
|||||||
new QLabel(tr("SMESH_EDGE"), aMainGrp);
|
new QLabel(tr("SMESH_EDGE"), aMainGrp);
|
||||||
(new QPushButton(aMainGrp))->setPixmap(aPix);
|
(new QPushButton(aMainGrp))->setPixmap(aPix);
|
||||||
myEdge = new QLineEdit(aMainGrp);
|
myEdge = new QLineEdit(aMainGrp);
|
||||||
myEdge->setValidator(new SMESHGUI_DiagValidator(this, "validator"));
|
myEdge->setValidator(new QRegExpValidator(QRegExp("[\\d]*-[\\d]*"), this));
|
||||||
|
|
||||||
return aMainGrp;
|
return aMainGrp;
|
||||||
}
|
}
|
||||||
@ -340,6 +328,7 @@ static bool findTriangles (const SMDS_MeshNode * theNode1,
|
|||||||
void SMESHGUI_SingleEditDlg::onTextChange (const QString& theNewText)
|
void SMESHGUI_SingleEditDlg::onTextChange (const QString& theNewText)
|
||||||
{
|
{
|
||||||
if (myBusy) return;
|
if (myBusy) return;
|
||||||
|
BusyLocker lock(myBusy);
|
||||||
|
|
||||||
myOkBtn->setEnabled(false);
|
myOkBtn->setEnabled(false);
|
||||||
myApplyBtn->setEnabled(false);
|
myApplyBtn->setEnabled(false);
|
||||||
@ -347,7 +336,6 @@ void SMESHGUI_SingleEditDlg::onTextChange (const QString& theNewText)
|
|||||||
// hilight entered edge
|
// hilight entered edge
|
||||||
if(myActor){
|
if(myActor){
|
||||||
if(SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh()){
|
if(SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh()){
|
||||||
myBusy = true; // block onSelectionDone()
|
|
||||||
Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
|
Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
|
||||||
SALOME_ListIO aList;
|
SALOME_ListIO aList;
|
||||||
aList.Append(anIO);
|
aList.Append(anIO);
|
||||||
@ -356,44 +344,36 @@ void SMESHGUI_SingleEditDlg::onTextChange (const QString& theNewText)
|
|||||||
TColStd_IndexedMapOfInteger selectedIndices;
|
TColStd_IndexedMapOfInteger selectedIndices;
|
||||||
TColStd_MapOfInteger newIndices;
|
TColStd_MapOfInteger newIndices;
|
||||||
mySelector->GetIndex(anIO,selectedIndices);
|
mySelector->GetIndex(anIO,selectedIndices);
|
||||||
myBusy = false;
|
|
||||||
|
|
||||||
QStringList aListId = QStringList::split("-", theNewText, false);
|
int id1, id2;
|
||||||
if (aListId.count() != 2)
|
if ( !getNodeIds(myEdge->text(), id1, id2) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int i;
|
const SMDS_MeshNode* aNode1 = aMesh->FindNode( id1 );
|
||||||
bool allOk = true;
|
const SMDS_MeshNode* aNode2 = aMesh->FindNode( id2 );
|
||||||
const SMDS_MeshNode* a2Nodes[2];
|
|
||||||
for (i = 0; i < aListId.count(); i++) {
|
|
||||||
if(const SMDS_MeshNode *aNode = aMesh->FindNode(aListId[ i ].toInt()))
|
|
||||||
a2Nodes[ i ] = aNode;
|
|
||||||
else
|
|
||||||
allOk = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// find a triangle and an edge nb
|
if ( !aNode1 || !aNode2 || aNode1 == aNode2 )
|
||||||
const SMDS_MeshElement* tria[2];
|
return;
|
||||||
allOk &= a2Nodes[0] != a2Nodes[1] && findTriangles(a2Nodes[0],a2Nodes[1],tria[0],tria[1]);
|
|
||||||
myBusy = true; // block onSelectionDone()
|
// find a triangle and an edge index
|
||||||
if(allOk)
|
const SMDS_MeshElement* tria1;
|
||||||
|
const SMDS_MeshElement* tria2;
|
||||||
|
|
||||||
|
if ( findTriangles(aNode1,aNode2,tria1,tria2) )
|
||||||
{
|
{
|
||||||
newIndices.Add(tria[0]->GetID());
|
newIndices.Add(tria1->GetID());
|
||||||
|
|
||||||
const SMDS_MeshNode* a3Nodes[3];
|
const SMDS_MeshNode* a3Nodes[3];
|
||||||
SMDS_ElemIteratorPtr it;
|
SMDS_ElemIteratorPtr it;
|
||||||
int edgeInd = 2;
|
int edgeInd = 2, i;
|
||||||
for (i = 0, it = tria[0]->nodesIterator(); it->more(); i++) {
|
for (i = 0, it = tria1->nodesIterator(); it->more(); i++) {
|
||||||
a3Nodes[ i ] = static_cast<const SMDS_MeshNode*>(it->next());
|
a3Nodes[ i ] = static_cast<const SMDS_MeshNode*>(it->next());
|
||||||
if (i > 0) {
|
if (i > 0 && ( a3Nodes[ i ] == aNode1 && a3Nodes[ i - 1] == aNode2 ||
|
||||||
allOk = (a3Nodes[ i ] == a2Nodes[ 0 ] && a3Nodes[ i - 1] == a2Nodes[ 1 ]) ||
|
a3Nodes[ i ] == aNode2 && a3Nodes[ i - 1] == aNode1 ) ) {
|
||||||
(a3Nodes[ i ] == a2Nodes[ 1 ] && a3Nodes[ i - 1] == a2Nodes[ 0 ]);
|
|
||||||
if (allOk) {
|
|
||||||
edgeInd = i - 1;
|
edgeInd = i - 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
newIndices.Add(-edgeInd-1);
|
newIndices.Add(-edgeInd-1);
|
||||||
|
|
||||||
myOkBtn->setEnabled(true);
|
myOkBtn->setEnabled(true);
|
||||||
@ -401,8 +381,6 @@ void SMESHGUI_SingleEditDlg::onTextChange (const QString& theNewText)
|
|||||||
}
|
}
|
||||||
mySelector->AddOrRemoveIndex(anIO,newIndices, false);
|
mySelector->AddOrRemoveIndex(anIO,newIndices, false);
|
||||||
SMESH::GetViewWindow(mySMESHGUI)->highlight( anIO, true, true );
|
SMESH::GetViewWindow(mySMESHGUI)->highlight( anIO, true, true );
|
||||||
|
|
||||||
myBusy = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -414,6 +392,7 @@ void SMESHGUI_SingleEditDlg::onTextChange (const QString& theNewText)
|
|||||||
void SMESHGUI_SingleEditDlg::onSelectionDone()
|
void SMESHGUI_SingleEditDlg::onSelectionDone()
|
||||||
{
|
{
|
||||||
if (myBusy) return;
|
if (myBusy) return;
|
||||||
|
BusyLocker lock(myBusy);
|
||||||
|
|
||||||
int anId1 = 0, anId2 = 0;
|
int anId1 = 0, anId2 = 0;
|
||||||
|
|
||||||
@ -439,9 +418,7 @@ void SMESHGUI_SingleEditDlg::onSelectionDone()
|
|||||||
findTriangles( aMesh->FindNode( anId1 ), aMesh->FindNode( anId2 ), tria[0],tria[1] ) )
|
findTriangles( aMesh->FindNode( anId1 ), aMesh->FindNode( anId2 ), tria[0],tria[1] ) )
|
||||||
{
|
{
|
||||||
QString aText = QString("%1-%2").arg(anId1).arg(anId2);
|
QString aText = QString("%1-%2").arg(anId1).arg(anId2);
|
||||||
myBusy = true;
|
|
||||||
myEdge->setText(aText);
|
myEdge->setText(aText);
|
||||||
myBusy = false;
|
|
||||||
|
|
||||||
myOkBtn->setEnabled(true);
|
myOkBtn->setEnabled(true);
|
||||||
myApplyBtn->setEnabled(true);
|
myApplyBtn->setEnabled(true);
|
||||||
|
Loading…
Reference in New Issue
Block a user