Fix problems with quadratic elements preview in 'Add Quadriatic element' dialog box.

This commit is contained in:
vsr 2008-06-20 13:24:37 +00:00
parent e48a1779f1
commit 3506ddb84a
2 changed files with 287 additions and 272 deletions

View File

@ -316,6 +316,54 @@ static int FirstHexahedronIds[] = {0,1,2,3,4,5,6,7,0,1,2,3};
static int LastHexahedronIds[] = {1,2,3,0,5,6,7,4,4,5,6,7};
/*!
\class BusyLocker
\brief Simple 'busy state' flag locker.
\internal
*/
class BusyLocker
{
public:
//! Constructor. Sets passed boolean flag to \c true.
BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
//! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
~BusyLocker() { myBusy = false; }
private:
bool& myBusy; //! External 'busy state' boolean flag
};
/*!
\class IdEditItem
\brief Simple editable table item.
\internal
*/
class IdEditItem: public QTableItem
{
public:
IdEditItem(QTable*, EditType, const QString& );
~IdEditItem();
QWidget* createEditor() const;
};
IdEditItem::IdEditItem(QTable* table, EditType et, const QString& text )
: QTableItem( table, et, text )
{
}
IdEditItem::~IdEditItem()
{
}
QWidget* IdEditItem::createEditor() const
{
QLineEdit *aLineEdit = new QLineEdit(text(), table()->viewport());
aLineEdit->setValidator( new SMESHGUI_IdValidator(table()->viewport(), "validator", 1) );
return aLineEdit;
}
//=================================================================================
// function : SMESHGUI_AddQuadraticElementDlg()
@ -329,7 +377,8 @@ SMESHGUI_AddQuadraticElementDlg::SMESHGUI_AddQuadraticElementDlg( SMESHGUI* theM
WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
mySMESHGUI( theModule ),
mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
myType( theType )
myType( theType ),
myBusy( false )
{
SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
(SUIT_Session::session()->activeApplication());
@ -487,7 +536,6 @@ void SMESHGUI_AddQuadraticElementDlg::Init()
{
GroupArguments->show();
myRadioButton1->setChecked(TRUE);
myIsEditCorners = true;
mySMESHGUI->SetActiveDialogBox((QDialog*)this);
myActor = 0;
@ -554,8 +602,8 @@ void SMESHGUI_AddQuadraticElementDlg::Init()
for ( int row = 0; row < myTable->numRows(); row++ )
{
SMESHGUI_IdEditItem* anEditItem = new SMESHGUI_IdEditItem( myTable, QTableItem::OnTyping, "" );
anEditItem->setReplaceable(false);
IdEditItem* anEditItem = new IdEditItem( myTable, QTableItem::OnTyping, "" );
anEditItem->setReplaceable(true);
myTable->setItem(row, 1, anEditItem);
}
@ -583,8 +631,6 @@ void SMESHGUI_AddQuadraticElementDlg::Init()
if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
aViewWindow->SetSelectionMode( NodeSelection );
myBusy = false;
SetEditCorners();
}
@ -594,8 +640,10 @@ void SMESHGUI_AddQuadraticElementDlg::Init()
//=================================================================================
void SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
{
if (IsValid() && !mySMESHGUI->isActiveStudyLocked()) {
myBusy = true;
if ( mySMESHGUI->isActiveStudyLocked() || myBusy || !IsValid() )
return;
BusyLocker lock( myBusy );
vector<int> anIds;
@ -645,17 +693,13 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnApply()
mySelector->ClearIndex();
mySelectionMgr->setSelectedObjects( aList, false );
SMESH::UpdateView();
mySimulation->SetVisibility(false);
buttonOk->setEnabled(false);
buttonApply->setEnabled(false);
SMESH::UpdateView();
UpdateTable();
SetEditCorners();
myBusy = false;
}
updateButtons();
}
//=================================================================================
@ -666,7 +710,6 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnOk()
{
ClickOnApply();
ClickOnCancel();
return;
}
//=================================================================================
@ -683,7 +726,6 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnCancel()
disconnect(mySelectionMgr, 0, this, 0);
mySMESHGUI->ResetState();
reject();
return;
}
//=================================================================================
@ -702,7 +744,7 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnHelp()
#else
platform = "application";
#endif
SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
SUIT_MessageBox::warn1(this, QObject::tr("WRN_WARNING"),
QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
QObject::tr("BUT_OK"));
@ -716,10 +758,7 @@ void SMESHGUI_AddQuadraticElementDlg::ClickOnHelp()
void SMESHGUI_AddQuadraticElementDlg::onTextChange (const QString& theNewText)
{
if (myBusy) return;
myBusy = true;
buttonOk->setEnabled(false);
buttonApply->setEnabled(false);
BusyLocker lock( myBusy );
mySimulation->SetVisibility(false);
@ -734,8 +773,10 @@ void SMESHGUI_AddQuadraticElementDlg::onTextChange (const QString& theNewText)
QStringList aListId = QStringList::split(" ", theNewText, false);
bool allOk = true;
for (int i = 0; i < aListId.count(); i++) {
if( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) )
if ( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) )
{
newIndices.Add( n->GetID() );
}
else
{
allOk = false;
@ -751,15 +792,8 @@ void SMESHGUI_AddQuadraticElementDlg::onTextChange (const QString& theNewText)
UpdateTable( allOk );
}
if( IsValid() ) {
buttonOk->setEnabled(true);
buttonApply->setEnabled(true);
}
if ( sender() == myTable )
updateButtons();
displaySimulation();
myBusy = false;
}
//=================================================================================
@ -769,22 +803,18 @@ void SMESHGUI_AddQuadraticElementDlg::onTextChange (const QString& theNewText)
void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument()
{
if (myBusy) return;
BusyLocker lock( myBusy );
if ( myIsEditCorners )
{
// clear
myActor = 0;
myBusy = true;
myCornerNodes->setText("");
myBusy = false;
if (!GroupButtons->isEnabled()) // inactive
return;
buttonOk->setEnabled(false);
buttonApply->setEnabled(false);
mySimulation->SetVisibility(false);
// get selected mesh
@ -794,20 +824,25 @@ void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument()
if (aList.Extent() != 1)
{
UpdateTable();
updateButtons();
return;
}
Handle(SALOME_InteractiveObject) anIO = aList.First();
myMesh = SMESH::GetMeshByIO(anIO);
if (myMesh->_is_nil())
if (myMesh->_is_nil()) {
updateButtons();
return;
}
myActor = SMESH::FindActorByEntry(anIO->getEntry());
}
if (!myActor)
if (!myActor) {
updateButtons();
return;
}
// get selected nodes
QString aString = "";
@ -815,27 +850,18 @@ void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument()
if ( myIsEditCorners )
{
myBusy = true;
myCornerNodes->setText(aString);
myBusy = false;
UpdateTable();
}
else if ( myTable->isEnabled() && nbNodes == 1 )
{
myBusy = true;
int theRow = myTable->currentRow(), theCol = myTable->currentColumn();
if ( theCol == 1 )
myTable->setText(theRow, 1, aString);
myBusy = false;
}
if ( IsValid() )
{
buttonOk->setEnabled( true );
buttonApply->setEnabled( true );
}
updateButtons();
displaySimulation();
}
@ -845,7 +871,8 @@ void SMESHGUI_AddQuadraticElementDlg::SelectionIntoArgument()
//=================================================================================
void SMESHGUI_AddQuadraticElementDlg::displaySimulation()
{
if (!myIsEditCorners) {
if ( IsValid() )
{
SMESH::TElementSimulation::TVTKIds anIds;
// Collect ids from the dialog
@ -879,8 +906,12 @@ void SMESHGUI_AddQuadraticElementDlg::displaySimulation()
}
mySimulation->SetPosition(myActor,myType,anIds,aDisplayMode,myReverseCB->isChecked());
SMESH::UpdateView();
}
else
{
mySimulation->SetVisibility(false);
}
SMESH::UpdateView();
}
//=================================================================================
@ -891,8 +922,8 @@ void SMESHGUI_AddQuadraticElementDlg::SetEditCorners()
{
myCornerNodes->setFocus();
myIsEditCorners = true;
SelectionIntoArgument();
updateButtons();
}
//=================================================================================
@ -940,7 +971,6 @@ void SMESHGUI_AddQuadraticElementDlg::enterEvent (QEvent*)
if (GroupConstructors->isEnabled())
return;
ActivateThisDialog();
return;
}
//=================================================================================
@ -951,7 +981,6 @@ void SMESHGUI_AddQuadraticElementDlg::closeEvent (QCloseEvent*)
{
/* same than click on cancel button */
ClickOnCancel();
return;
}
//=================================================================================
@ -970,13 +999,9 @@ void SMESHGUI_AddQuadraticElementDlg::hideEvent (QHideEvent*)
//=================================================================================
void SMESHGUI_AddQuadraticElementDlg::onReverse (int state)
{
if (!IsValid())
return;
if (state >= 0) {
mySimulation->SetVisibility(false);
displaySimulation();
}
updateButtons();
}
@ -1083,11 +1108,9 @@ void SMESHGUI_AddQuadraticElementDlg::UpdateTable( bool theConersValidity )
//=================================================================================
void SMESHGUI_AddQuadraticElementDlg::onCellDoubleClicked( int theRow, int theCol, int theButton, const QPoint& theMousePos )
{
if ( theButton == 1 && theCol == 1 )
myIsEditCorners = false;
displaySimulation();
return;
updateButtons();
}
@ -1097,17 +1120,12 @@ void SMESHGUI_AddQuadraticElementDlg::onCellDoubleClicked( int theRow, int theCo
//=================================================================================
void SMESHGUI_AddQuadraticElementDlg::onCellTextChange(int theRow, int theCol)
{
onTextChange( myTable->text(theRow, theCol) );
myIsEditCorners = false;
displaySimulation();
updateButtons();
}
QWidget* SMESHGUI_IdEditItem::createEditor() const
{
QLineEdit *aLineEdit = new QLineEdit(text(), table()->viewport());
aLineEdit->setValidator( new SMESHGUI_IdValidator(table()->viewport(), "validator", 1) );
return aLineEdit;
}
//=================================================================================
// function : keyPressEvent()
// purpose :
@ -1124,3 +1142,10 @@ void SMESHGUI_AddQuadraticElementDlg::keyPressEvent( QKeyEvent* e )
ClickOnHelp();
}
}
void SMESHGUI_AddQuadraticElementDlg::updateButtons()
{
bool valid = IsValid();
buttonOk->setEnabled( valid );
buttonApply->setEnabled( valid );
}

View File

@ -71,6 +71,7 @@ private:
void displaySimulation();
void UpdateTable( bool theConersValidity = true );
bool IsValid();
void updateButtons();
SMESHGUI* mySMESHGUI; /* Current SMESHGUI object */
LightApp_SelectionMgr* mySelectionMgr; /* User shape selection */
@ -119,15 +120,4 @@ private slots:
void ActivateThisDialog() ;
};
class SMESHGUI_IdEditItem: public QTableItem
{
public:
SMESHGUI_IdEditItem(QTable* table, EditType et, const QString& text ):
QTableItem(table, et, text) {};
~SMESHGUI_IdEditItem() {};
QWidget* createEditor() const;
};
#endif // DIALOGBOX_ADD_QUADRATIC_ELEMENT_H