00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "SMESHGUI_AddMeshElementDlg.h"
00029
00030 #include "SMESHGUI.h"
00031 #include "SMESHGUI_Utils.h"
00032 #include "SMESHGUI_VTKUtils.h"
00033 #include "SMESHGUI_MeshUtils.h"
00034 #include "SMESHGUI_GroupUtils.h"
00035 #include "SMESHGUI_IdValidator.h"
00036
00037 #include <SMESH_Actor.h>
00038 #include <SMESH_ActorUtils.h>
00039 #include <SMESH_FaceOrientationFilter.h>
00040 #include <SMDS_Mesh.hxx>
00041
00042
00043 #include <SUIT_Desktop.h>
00044 #include <SUIT_Session.h>
00045 #include <SUIT_ResourceMgr.h>
00046 #include <SUIT_MessageBox.h>
00047 #include <SUIT_ViewManager.h>
00048 #include <LightApp_SelectionMgr.h>
00049 #include <SALOME_ListIO.hxx>
00050 #include <SalomeApp_Application.h>
00051 #include <SVTK_ViewModel.h>
00052 #include <SVTK_ViewWindow.h>
00053
00054
00055 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
00056
00057
00058 #include <TColStd_MapOfInteger.hxx>
00059
00060
00061 #include <vtkCell.h>
00062 #include <vtkIdList.h>
00063 #include <vtkUnstructuredGrid.h>
00064 #include <vtkDataSetMapper.h>
00065 #include <vtkPolyDataMapper.h>
00066 #include <vtkProperty.h>
00067
00068
00069 #include <QComboBox>
00070 #include <QGroupBox>
00071 #include <QLabel>
00072 #include <QLineEdit>
00073 #include <QPushButton>
00074 #include <QRadioButton>
00075 #include <QHBoxLayout>
00076 #include <QVBoxLayout>
00077 #include <QGridLayout>
00078 #include <QVariant>
00079 #include <QCheckBox>
00080 #include <QKeyEvent>
00081 #include <QButtonGroup>
00082
00083 #define SPACING 6
00084 #define MARGIN 11
00085
00086 namespace SMESH
00087 {
00088 class TElementSimulation
00089 {
00090 SalomeApp_Application* myApplication;
00091 SUIT_ViewWindow* myViewWindow;
00092 SVTK_ViewWindow* myVTKViewWindow;
00093
00094 SALOME_Actor* myPreviewActor;
00095 vtkDataSetMapper* myMapper;
00096 vtkUnstructuredGrid* myGrid;
00097
00098 SALOME_Actor* myFaceOrientation;
00099 vtkPolyDataMapper* myFaceOrientationDataMapper;
00100 SMESH_FaceOrientationFilter* myFaceOrientationFilter;
00101
00102 public:
00103 TElementSimulation (SalomeApp_Application* theApplication)
00104 {
00105 myApplication = theApplication;
00106 SUIT_ViewManager* mgr = theApplication->activeViewManager();
00107 if (!mgr) return;
00108 myViewWindow = mgr->getActiveView();
00109 myVTKViewWindow = GetVtkViewWindow(myViewWindow);
00110
00111 myGrid = vtkUnstructuredGrid::New();
00112
00113
00114 myMapper = vtkDataSetMapper::New();
00115 myMapper->SetInput(myGrid);
00116
00117 myPreviewActor = SALOME_Actor::New();
00118 myPreviewActor->PickableOff();
00119 myPreviewActor->VisibilityOff();
00120 myPreviewActor->SetMapper(myMapper);
00121
00122 vtkFloatingPointType anRGB[3];
00123 vtkProperty* aProp = vtkProperty::New();
00124 GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
00125 aProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
00126 myPreviewActor->SetProperty( aProp );
00127 aProp->Delete();
00128
00129 vtkProperty* aBackProp = vtkProperty::New();
00130 GetColor( "SMESH", "backface_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 0, 255 ) );
00131 aBackProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
00132 myPreviewActor->SetBackfaceProperty( aBackProp );
00133 aBackProp->Delete();
00134
00135 myVTKViewWindow->AddActor(myPreviewActor);
00136
00137
00138 myFaceOrientationFilter = SMESH_FaceOrientationFilter::New();
00139 myFaceOrientationFilter->SetInput(myGrid);
00140
00141 myFaceOrientationDataMapper = vtkPolyDataMapper::New();
00142 myFaceOrientationDataMapper->SetInput(myFaceOrientationFilter->GetOutput());
00143
00144 myFaceOrientation = SALOME_Actor::New();
00145 myFaceOrientation->PickableOff();
00146 myFaceOrientation->VisibilityOff();
00147 myFaceOrientation->SetMapper(myFaceOrientationDataMapper);
00148
00149 vtkProperty* anOrientationProp = vtkProperty::New();
00150 GetColor( "SMESH", "orientation_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
00151 anOrientationProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
00152 myFaceOrientation->SetProperty( anOrientationProp );
00153 anOrientationProp->Delete();
00154
00155 myVTKViewWindow->AddActor(myFaceOrientation);
00156 }
00157
00158 typedef std::vector<vtkIdType> TVTKIds;
00159 void SetPosition (SMESH_Actor* theActor,
00160 vtkIdType theType,
00161 const TVTKIds& theIds)
00162 {
00163 vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
00164 myGrid->SetPoints(aGrid->GetPoints());
00165
00166 const int* aConn = NULL;
00167 switch (theType) {
00168 case VTK_TETRA:
00169 {
00170 static int anIds[] = {0,2,1,3};
00171 aConn = anIds;
00172 break;
00173 }
00174 case VTK_PYRAMID:
00175 {
00176 static int anIds[] = {0,3,2,1,4};
00177 aConn = anIds;
00178 break;
00179 }
00180 case VTK_HEXAHEDRON:
00181 {
00182 static int anIds[] = {0,3,2,1,4,7,6,5};
00183 aConn = anIds;
00184 break;
00185 }
00186 }
00187
00188 myGrid->Reset();
00189 vtkIdList *anIds = vtkIdList::New();
00190
00191 if(aConn)
00192 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
00193 anIds->InsertId(i,theIds[aConn[i]]);
00194 else
00195 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
00196 anIds->InsertId(i,theIds[i]);
00197
00198 myGrid->InsertNextCell(theType,anIds);
00199 anIds->Delete();
00200
00201 myGrid->Modified();
00202
00203 SetVisibility(true, theActor->GetFacesOriented());
00204 }
00205
00206
00207 void SetVisibility (bool theVisibility, bool theShowOrientation = false)
00208 {
00209 myPreviewActor->SetVisibility(theVisibility);
00210 myFaceOrientation->SetVisibility(theShowOrientation);
00211 RepaintCurrentView();
00212 }
00213
00214
00215 ~TElementSimulation()
00216 {
00217 if (FindVtkViewWindow(myApplication->activeViewManager(), myViewWindow)) {
00218 myVTKViewWindow->RemoveActor(myPreviewActor);
00219 myVTKViewWindow->RemoveActor(myFaceOrientation);
00220 }
00221 myPreviewActor->Delete();
00222 myFaceOrientation->Delete();
00223
00224 myMapper->RemoveAllInputs();
00225 myMapper->Delete();
00226
00227 myFaceOrientationFilter->Delete();
00228
00229 myFaceOrientationDataMapper->RemoveAllInputs();
00230 myFaceOrientationDataMapper->Delete();
00231
00232 myGrid->Delete();
00233 }
00234 };
00235 }
00236
00237
00238
00239
00240
00241 SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI* theModule,
00242 SMDSAbs_ElementType ElementType,
00243 int nbNodes )
00244 : QDialog( SMESH::GetDesktop( theModule ) ),
00245 mySMESHGUI( theModule ),
00246 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
00247 {
00248 setModal( false );
00249 setAttribute( Qt::WA_DeleteOnClose, true );
00250
00251 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
00252 (SUIT_Session::session()->activeApplication());
00253 myIsPoly = false;
00254 mySimulation = new SMESH::TElementSimulation (anApp);
00255 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
00256
00257
00258 myNbNodes = nbNodes;
00259 myElementType = ElementType;
00260 switch (ElementType) {
00261 case SMDSAbs_0DElement:
00262 if (myNbNodes != 1)
00263 myNbNodes = 1;
00264 break;
00265 case SMDSAbs_Face:
00266
00267
00268
00269 case SMDSAbs_Volume:
00270
00271
00272 break;
00273 default:
00274 myElementType = SMDSAbs_Edge;
00275 myNbNodes = 2;
00276 }
00277
00278 QString elemName;
00279 if (myNbNodes == 1) {
00280 elemName = "ELEM0D";
00281 myHelpFileName = "adding_nodes_and_elements_page.html#adding_0delems_anchor";
00282 }
00283 else if (myNbNodes == 2) {
00284 elemName = "EDGE";
00285 myHelpFileName = "adding_nodes_and_elements_page.html#adding_edges_anchor";
00286 }
00287 else if (myNbNodes == 3) {
00288 elemName = "TRIANGLE";
00289 myHelpFileName = "adding_nodes_and_elements_page.html#adding_triangles_anchor";
00290 }
00291 else if (myNbNodes == 4) {
00292 if (myElementType == SMDSAbs_Face) {
00293 elemName = "QUADRANGLE";
00294 myHelpFileName = "adding_nodes_and_elements_page.html#adding_quadrangles_anchor";
00295 }
00296 else {
00297 elemName = "TETRAS";
00298 myHelpFileName = "adding_nodes_and_elements_page.html#adding_tetrahedrons_anchor";
00299 }
00300 }
00301 else if (myNbNodes == 8) {
00302 elemName = "HEXAS";
00303 myHelpFileName = "adding_nodes_and_elements_page.html#adding_hexahedrons_anchor";
00304 }
00305 else if (myElementType == SMDSAbs_Face) {
00306 elemName = "POLYGON";
00307 myIsPoly = true;
00308 myHelpFileName = "adding_nodes_and_elements_page.html#adding_polygons_anchor";
00309 }
00310 else if (myElementType == SMDSAbs_Volume) {
00311 myHelpFileName = "adding_nodes_and_elements_page.html#adding_polyhedrons_anchor";
00312 }
00313
00314 QString iconName = tr(QString("ICON_DLG_%1").arg(elemName).toLatin1().data());
00315 QString buttonGrTitle = tr(QString("SMESH_%1").arg(elemName).toLatin1().data());
00316 QString caption = tr(QString("SMESH_ADD_%1_TITLE").arg(elemName).toLatin1().data());
00317 QString grBoxTitle = tr(QString("SMESH_ADD_%1").arg(elemName).toLatin1().data());
00318
00319 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", iconName));
00320 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
00321
00322 setWindowTitle(caption);
00323 setSizeGripEnabled(true);
00324
00325 QVBoxLayout* aTopLayout = new QVBoxLayout(this);
00326 aTopLayout->setSpacing(SPACING);
00327 aTopLayout->setMargin(MARGIN);
00328
00329
00330 GroupConstructors = new QGroupBox(buttonGrTitle, this);
00331 QButtonGroup* ButtonGroup = new QButtonGroup(this);
00332 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
00333 GroupConstructorsLayout->setSpacing(SPACING);
00334 GroupConstructorsLayout->setMargin(MARGIN);
00335
00336 Constructor1 = new QRadioButton(GroupConstructors);
00337 Constructor1->setIcon(image0);
00338 Constructor1->setChecked(true);
00339
00340 GroupConstructorsLayout->addWidget(Constructor1);
00341 ButtonGroup->addButton( Constructor1, 0 );
00342
00343
00344 GroupC1 = new QGroupBox(grBoxTitle, this);
00345 QGridLayout* GroupC1Layout = new QGridLayout(GroupC1);
00346 GroupC1Layout->setSpacing(SPACING);
00347 GroupC1Layout->setMargin(MARGIN);
00348
00349 TextLabelC1A1 = new QLabel(tr("SMESH_ID_NODES"), GroupC1);
00350 SelectButtonC1A1 = new QPushButton(GroupC1);
00351 SelectButtonC1A1->setIcon(image1);
00352 LineEditC1A1 = new QLineEdit(GroupC1);
00353
00354 if (!myIsPoly)
00355 LineEditC1A1->setValidator(new SMESHGUI_IdValidator(this, myNbNodes));
00356
00357 Reverse = myElementType == SMDSAbs_Face ? new QCheckBox(tr("SMESH_REVERSE"), GroupC1) : 0;
00358
00359 GroupC1Layout->addWidget(TextLabelC1A1, 0, 0);
00360 GroupC1Layout->addWidget(SelectButtonC1A1, 0, 1);
00361 GroupC1Layout->addWidget(LineEditC1A1, 0, 2);
00362 if ( Reverse ) GroupC1Layout->addWidget(Reverse, 1, 0, 1, 3);
00363
00364
00365 GroupGroups = new QGroupBox( tr( "SMESH_ADD_TO_GROUP" ), this );
00366 GroupGroups->setCheckable( true );
00367 QHBoxLayout* GroupGroupsLayout = new QHBoxLayout(GroupGroups);
00368 GroupGroupsLayout->setSpacing(SPACING);
00369 GroupGroupsLayout->setMargin(MARGIN);
00370
00371 TextLabel_GroupName = new QLabel( tr( "SMESH_GROUP" ), GroupGroups );
00372 ComboBox_GroupName = new QComboBox( GroupGroups );
00373 ComboBox_GroupName->setEditable( true );
00374
00375 GroupGroupsLayout->addWidget( TextLabel_GroupName );
00376 GroupGroupsLayout->addWidget( ComboBox_GroupName, 1 );
00377
00378
00379 GroupButtons = new QGroupBox(this);
00380 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
00381 GroupButtonsLayout->setSpacing(SPACING);
00382 GroupButtonsLayout->setMargin(MARGIN);
00383
00384 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
00385 buttonOk->setAutoDefault(true);
00386 buttonOk->setDefault(true);
00387 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
00388 buttonApply->setAutoDefault(true);
00389 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
00390 buttonCancel->setAutoDefault(true);
00391 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
00392 buttonHelp->setAutoDefault(true);
00393
00394 GroupButtonsLayout->addWidget(buttonOk);
00395 GroupButtonsLayout->addSpacing(10);
00396 GroupButtonsLayout->addWidget(buttonApply);
00397 GroupButtonsLayout->addSpacing(10);
00398 GroupButtonsLayout->addStretch();
00399 GroupButtonsLayout->addWidget(buttonCancel);
00400 GroupButtonsLayout->addWidget(buttonHelp);
00401
00402
00403 aTopLayout->addWidget(GroupConstructors);
00404 aTopLayout->addWidget(GroupC1);
00405 aTopLayout->addWidget(GroupGroups);
00406 aTopLayout->addWidget(GroupButtons);
00407
00408 Init();
00409 }
00410
00411
00412
00413
00414
00415 SMESHGUI_AddMeshElementDlg::~SMESHGUI_AddMeshElementDlg()
00416 {
00417 delete mySimulation;
00418 }
00419
00420
00421
00422
00423
00424 void SMESHGUI_AddMeshElementDlg::Init()
00425 {
00426 GroupC1->show();
00427 Constructor1->setChecked(true);
00428 myEditCurrentArgument = LineEditC1A1;
00429 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
00430
00431
00432 GroupGroups->setChecked( false );
00433 GroupGroups->setVisible( myElementType != SMDSAbs_0DElement );
00434
00435 myNbOkNodes = 0;
00436 myActor = 0;
00437
00438
00439 connect(buttonOk, SIGNAL(clicked()), SLOT(ClickOnOk()));
00440 connect(buttonCancel, SIGNAL(clicked()), SLOT(ClickOnCancel()));
00441 connect(buttonApply, SIGNAL(clicked()), SLOT(ClickOnApply()));
00442 connect(buttonHelp, SIGNAL(clicked()), SLOT(ClickOnHelp()));
00443
00444 connect(SelectButtonC1A1, SIGNAL(clicked()), SLOT(SetEditCurrentArgument()));
00445 connect(LineEditC1A1, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
00446 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog()));
00447 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(SelectionIntoArgument()));
00448
00449 connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), SLOT(ClickOnCancel()));
00450 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), SLOT(ClickOnCancel()));
00451
00452 if (Reverse)
00453 connect(Reverse, SIGNAL(stateChanged(int)), SLOT(CheckBox(int)));
00454
00455
00456 SMESH::SetPointRepresentation(true);
00457
00458 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00459 aViewWindow->SetSelectionMode( NodeSelection );
00460
00461 myBusy = false;
00462
00463 SelectionIntoArgument();
00464 }
00465
00466
00467
00468
00469
00470 void SMESHGUI_AddMeshElementDlg::ClickOnApply()
00471 {
00472 if( !isValid() )
00473 return;
00474
00475 if (myNbOkNodes && !mySMESHGUI->isActiveStudyLocked()) {
00476 myBusy = true;
00477 SMESH::long_array_var anArrayOfIndices = new SMESH::long_array;
00478 anArrayOfIndices->length(myNbNodes);
00479 bool reverse = (Reverse && Reverse->isChecked());
00480 QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
00481 for (int i = 0; i < aListId.count(); i++)
00482 if (reverse)
00483 anArrayOfIndices[i] = aListId[ myNbNodes - i - 1 ].toInt();
00484 else
00485 anArrayOfIndices[i] = aListId[ i ].toInt();
00486
00487 bool addToGroup = GroupGroups->isChecked();
00488 QString aGroupName;
00489
00490 SMESH::SMESH_GroupBase_var aGroup;
00491 int idx = 0;
00492 if( addToGroup ) {
00493 aGroupName = ComboBox_GroupName->currentText();
00494 for ( int i = 1; i < ComboBox_GroupName->count(); i++ ) {
00495 QString aName = ComboBox_GroupName->itemText( i );
00496 if ( aGroupName == aName && ( i == ComboBox_GroupName->currentIndex() || idx == 0 ) )
00497 idx = i;
00498 }
00499 if ( idx > 0 ) {
00500 SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( myGroups[idx-1] );
00501 if ( !aGeomGroup->_is_nil() ) {
00502 int res = SUIT_MessageBox::question( this, tr( "SMESH_WRN_WARNING" ),
00503 tr( "MESH_STANDALONE_GRP_CHOSEN" ).arg( aGroupName ),
00504 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 );
00505 if ( res == 1 ) return;
00506 }
00507 aGroup = myGroups[idx-1];
00508 }
00509 }
00510
00511 long anElemId = -1;
00512 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
00513 switch (myElementType) {
00514 case SMDSAbs_0DElement:
00515 anElemId = aMeshEditor->Add0DElement(anArrayOfIndices[0]); break;
00516 case SMDSAbs_Edge:
00517 anElemId = aMeshEditor->AddEdge(anArrayOfIndices.inout()); break;
00518 case SMDSAbs_Face: {
00519 if(myIsPoly)
00520 anElemId = aMeshEditor->AddPolygonalFace(anArrayOfIndices.inout());
00521 else
00522 anElemId = aMeshEditor->AddFace(anArrayOfIndices.inout());
00523 break;
00524 }
00525 case SMDSAbs_Volume:
00526 anElemId = aMeshEditor->AddVolume(anArrayOfIndices.inout()); break;
00527 default: break;
00528 }
00529
00530 if ( anElemId != -1 && addToGroup && !aGroupName.isEmpty() ) {
00531 SMESH::SMESH_Group_var aGroupUsed;
00532 if ( aGroup->_is_nil() ) {
00533
00534 aGroupUsed = SMESH::AddGroup( myMesh, (SMESH::ElementType)myElementType, aGroupName );
00535 if ( !aGroupUsed->_is_nil() ) {
00536 myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroupUsed));
00537 ComboBox_GroupName->addItem( aGroupName );
00538 }
00539 }
00540 else {
00541 SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
00542 if ( !aGeomGroup->_is_nil() ) {
00543 aGroupUsed = myMesh->ConvertToStandalone( aGeomGroup );
00544 if ( !aGroupUsed->_is_nil() && idx > 0 ) {
00545 myGroups[idx-1] = SMESH::SMESH_GroupBase::_duplicate(aGroupUsed);
00546 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser();
00547 }
00548 }
00549 else
00550 aGroupUsed = SMESH::SMESH_Group::_narrow( aGroup );
00551 }
00552
00553 if ( !aGroupUsed->_is_nil() ) {
00554 SMESH::long_array_var anIdList = new SMESH::long_array;
00555 anIdList->length( 1 );
00556 anIdList[0] = anElemId;
00557 aGroupUsed->Add( anIdList.inout() );
00558 }
00559 }
00560
00561 SALOME_ListIO aList; aList.Append( myActor->getIO() );
00562 mySelector->ClearIndex();
00563 mySelectionMgr->setSelectedObjects( aList, false );
00564
00565 SMESH::UpdateView();
00566 mySimulation->SetVisibility(false);
00567
00568 buttonOk->setEnabled(false);
00569 buttonApply->setEnabled(false);
00570
00571 myEditCurrentArgument->setText("");
00572
00573 myBusy = false;
00574
00575 SMESHGUI::Modified();
00576 }
00577 }
00578
00579
00580
00581
00582
00583 void SMESHGUI_AddMeshElementDlg::ClickOnOk()
00584 {
00585 ClickOnApply();
00586 ClickOnCancel();
00587 }
00588
00589
00590
00591
00592
00593 void SMESHGUI_AddMeshElementDlg::ClickOnCancel()
00594 {
00595
00596 mySimulation->SetVisibility(false);
00597 SMESH::SetPointRepresentation(false);
00598 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00599 aViewWindow->SetSelectionMode( ActorSelection );
00600 disconnect(mySelectionMgr, 0, this, 0);
00601 mySMESHGUI->ResetState();
00602 reject();
00603 }
00604
00605
00606
00607
00608
00609 void SMESHGUI_AddMeshElementDlg::ClickOnHelp()
00610 {
00611 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00612 if (app)
00613 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""),
00614 myHelpFileName);
00615 else {
00616 QString platform;
00617 #ifdef WIN32
00618 platform = "winapplication";
00619 #else
00620 platform = "application";
00621 #endif
00622 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
00623 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00624 arg(app->resourceMgr()->stringValue("ExternalBrowser",
00625 platform)).
00626 arg(myHelpFileName));
00627 }
00628 }
00629
00630
00631
00632
00633
00634 void SMESHGUI_AddMeshElementDlg::onTextChange (const QString& theNewText)
00635 {
00636 if (myBusy) return;
00637 myBusy = true;
00638
00639 myNbOkNodes = 0;
00640
00641 buttonOk->setEnabled(false);
00642 buttonApply->setEnabled(false);
00643
00644 mySimulation->SetVisibility(false);
00645
00646
00647 SMDS_Mesh* aMesh = 0;
00648 if (myActor)
00649 aMesh = myActor->GetObject()->GetMesh();
00650
00651 if (aMesh) {
00652 TColStd_MapOfInteger newIndices;
00653
00654 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
00655 bool allOk = true;
00656 for (int i = 0; i < aListId.count(); i++) {
00657 if( const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() ) )
00658 {
00659 newIndices.Add( n->GetID() );
00660 myNbOkNodes++;
00661 }
00662 else
00663 allOk = false;
00664 }
00665
00666 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
00667 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00668 aViewWindow->highlight( myActor->getIO(), true, true );
00669
00670 myNbOkNodes = ( allOk && myNbNodes == aListId.count() );
00671
00672 if (myIsPoly)
00673 {
00674 if ( !allOk || myElementType != SMDSAbs_Face || aListId.count() < 3 )
00675 myNbOkNodes = 0;
00676 else
00677 myNbOkNodes = aListId.count();
00678 }
00679 }
00680
00681 if(myNbOkNodes) {
00682 buttonOk->setEnabled(true);
00683 buttonApply->setEnabled(true);
00684 displaySimulation();
00685 }
00686
00687 myBusy = false;
00688 }
00689
00690
00691
00692
00693
00694 void SMESHGUI_AddMeshElementDlg::SelectionIntoArgument()
00695 {
00696 if (myBusy) return;
00697
00698
00699 myNbOkNodes = 0;
00700 myActor = 0;
00701
00702 myBusy = true;
00703 myEditCurrentArgument->setText("");
00704 myBusy = false;
00705
00706 if (!GroupButtons->isEnabled())
00707 return;
00708
00709 buttonOk->setEnabled(false);
00710 buttonApply->setEnabled(false);
00711
00712 mySimulation->SetVisibility(false);
00713
00714
00715 QString aCurrentEntry = myEntry;
00716
00717
00718 SALOME_ListIO aList;
00719 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
00720
00721 if (aList.Extent() != 1)
00722 return;
00723
00724 Handle(SALOME_InteractiveObject) anIO = aList.First();
00725 myEntry = anIO->getEntry();
00726 myMesh = SMESH::GetMeshByIO(anIO);
00727 if (myMesh->_is_nil())
00728 return;
00729
00730
00731 if ( !myMesh->_is_nil() && myEntry != aCurrentEntry ) {
00732 myGroups.clear();
00733 ComboBox_GroupName->clear();
00734 ComboBox_GroupName->addItem( QString() );
00735 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
00736 for ( int i = 0, n = aListOfGroups.length(); i < n; i++ ) {
00737 SMESH::SMESH_GroupBase_var aGroup = aListOfGroups[i];
00738 if ( !aGroup->_is_nil() && aGroup->GetType() == (SMESH::ElementType)myElementType ) {
00739 QString aGroupName( aGroup->GetName() );
00740 if ( !aGroupName.isEmpty() ) {
00741 myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroup));
00742 ComboBox_GroupName->addItem( aGroupName );
00743 }
00744 }
00745 }
00746 }
00747
00748 myActor = SMESH::FindActorByEntry(anIO->getEntry());
00749 if (!myActor)
00750 return;
00751
00752
00753 QString aString = "";
00754 int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,myActor->getIO(),aString);
00755 myBusy = true;
00756 myEditCurrentArgument->setText(aString);
00757 myBusy = false;
00758 if (myIsPoly && myElementType == SMDSAbs_Face && nbNodes >= 3 ) {
00759 myNbNodes = nbNodes;
00760 } else if (myNbNodes != nbNodes) {
00761 return;
00762 }
00763
00764
00765 myNbOkNodes = nbNodes;
00766
00767 buttonOk->setEnabled(true);
00768 buttonApply->setEnabled(true);
00769
00770 displaySimulation();
00771 }
00772
00773
00774
00775
00776
00777 void SMESHGUI_AddMeshElementDlg::displaySimulation()
00778 {
00779 if (myNbOkNodes && GroupButtons->isEnabled()) {
00780 SMESH::TElementSimulation::TVTKIds anIds;
00781 QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
00782 for (int i = 0; i < aListId.count(); i++)
00783 anIds.push_back(myActor->GetObject()->GetNodeVTKId(aListId[ i ].toInt()));
00784
00785 if (Reverse && Reverse->isChecked())
00786 reverse(anIds.begin(),anIds.end());
00787
00788 vtkIdType aType = 0;
00789 if (myIsPoly)
00790 switch ( myElementType ) {
00791 case SMDSAbs_Face : aType = VTK_POLYGON; break;
00792 default: return;
00793 }
00794 else {
00795 switch (myNbNodes) {
00796 case 2: aType = VTK_LINE; break;
00797 case 3: aType = VTK_TRIANGLE; break;
00798 case 4: aType = myElementType == SMDSAbs_Face ? VTK_QUAD : VTK_TETRA; break;
00799 case 8: aType = VTK_HEXAHEDRON; break;
00800 default: return;
00801 }
00802 }
00803
00804 mySimulation->SetPosition(myActor,aType,anIds);
00805 SMESH::UpdateView();
00806 }
00807 }
00808
00809
00810
00811
00812
00813 void SMESHGUI_AddMeshElementDlg::SetEditCurrentArgument()
00814 {
00815 QPushButton* send = (QPushButton*)sender();
00816 if (send == SelectButtonC1A1) {
00817 LineEditC1A1->setFocus();
00818 myEditCurrentArgument = LineEditC1A1;
00819 }
00820 SelectionIntoArgument();
00821 }
00822
00823
00824
00825
00826
00827 void SMESHGUI_AddMeshElementDlg::DeactivateActiveDialog()
00828 {
00829 if (GroupConstructors->isEnabled()) {
00830 GroupConstructors->setEnabled(false);
00831 GroupC1->setEnabled(false);
00832 GroupButtons->setEnabled(false);
00833 mySimulation->SetVisibility(false);
00834 mySMESHGUI->ResetState();
00835 mySMESHGUI->SetActiveDialogBox(0);
00836 }
00837 }
00838
00839
00840
00841
00842
00843 void SMESHGUI_AddMeshElementDlg::ActivateThisDialog()
00844 {
00845
00846 mySMESHGUI->EmitSignalDeactivateDialog();
00847
00848 GroupConstructors->setEnabled(true);
00849 GroupC1->setEnabled(true);
00850 GroupButtons->setEnabled(true);
00851
00852 SMESH::SetPointRepresentation(true);
00853
00854 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00855 aViewWindow->SetSelectionMode( NodeSelection );
00856 SelectionIntoArgument();
00857 }
00858
00859
00860
00861
00862
00863 void SMESHGUI_AddMeshElementDlg::enterEvent (QEvent*)
00864 {
00865 if (GroupConstructors->isEnabled())
00866 return;
00867 ActivateThisDialog();
00868 }
00869
00870
00871
00872
00873
00874 void SMESHGUI_AddMeshElementDlg::closeEvent (QCloseEvent*)
00875 {
00876
00877 ClickOnCancel();
00878 }
00879
00880
00881
00882
00883
00884 void SMESHGUI_AddMeshElementDlg::hideEvent (QHideEvent*)
00885 {
00886 if (!isMinimized())
00887 ClickOnCancel();
00888 }
00889
00890
00891
00892
00893
00894 void SMESHGUI_AddMeshElementDlg::CheckBox (int state)
00895 {
00896 if (!myNbOkNodes)
00897 return;
00898
00899 if (state >= 0) {
00900 mySimulation->SetVisibility(false);
00901 displaySimulation();
00902 }
00903 }
00904
00905
00906
00907
00908
00909 void SMESHGUI_AddMeshElementDlg::keyPressEvent( QKeyEvent* e )
00910 {
00911 QDialog::keyPressEvent( e );
00912 if ( e->isAccepted() )
00913 return;
00914
00915 if ( e->key() == Qt::Key_F1 ) {
00916 e->accept();
00917 ClickOnHelp();
00918 }
00919 }
00920
00921
00922
00923
00924
00925 bool SMESHGUI_AddMeshElementDlg::isValid()
00926 {
00927 if( GroupGroups->isChecked() && ComboBox_GroupName->currentText().isEmpty() ) {
00928 SUIT_MessageBox::warning( this, tr( "SMESH_WRN_WARNING" ), tr( "GROUP_NAME_IS_EMPTY" ) );
00929 return false;
00930 }
00931 return true;
00932 }