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_CreatePolyhedralVolumeDlg.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 <SMDS_Mesh.hxx>
00040
00041
00042 #include <SUIT_Desktop.h>
00043 #include <SUIT_ResourceMgr.h>
00044 #include <SUIT_Session.h>
00045 #include <SUIT_MessageBox.h>
00046 #include <SUIT_ViewManager.h>
00047 #include <SUIT_OverrideCursor.h>
00048
00049 #include <SalomeApp_Application.h>
00050 #include <LightApp_SelectionMgr.h>
00051
00052 #include <SVTK_ViewWindow.h>
00053
00054
00055 #include <TColStd_ListOfInteger.hxx>
00056 #include <TColStd_ListIteratorOfListOfInteger.hxx>
00057
00058
00059 #include <vtkCell.h>
00060 #include <vtkIdList.h>
00061 #include <vtkUnstructuredGrid.h>
00062 #include <vtkDataSetMapper.h>
00063 #include <vtkProperty.h>
00064
00065
00066 #include <QApplication>
00067 #include <QButtonGroup>
00068 #include <QComboBox>
00069 #include <QGroupBox>
00070 #include <QLabel>
00071 #include <QLineEdit>
00072 #include <QPushButton>
00073 #include <QRadioButton>
00074 #include <QCheckBox>
00075 #include <QHBoxLayout>
00076 #include <QVBoxLayout>
00077 #include <QGridLayout>
00078 #include <QListWidget>
00079 #include <QKeyEvent>
00080
00081
00082 #include <SALOMEconfig.h>
00083 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
00084
00085 #define SPACING 6
00086 #define MARGIN 11
00087
00088 namespace SMESH
00089 {
00090 class TPolySimulation
00091 {
00092 SVTK_ViewWindow* myViewWindow;
00093
00094 SALOME_Actor *myPreviewActor;
00095 vtkDataSetMapper* myMapper;
00096 vtkUnstructuredGrid* myGrid;
00097
00098 public:
00099
00100 TPolySimulation(SalomeApp_Application* app)
00101 {
00102 SUIT_ViewManager* mgr = app->activeViewManager();
00103 myViewWindow = mgr ? dynamic_cast<SVTK_ViewWindow*>( mgr->getActiveView() ) : NULL;
00104
00105 myGrid = vtkUnstructuredGrid::New();
00106
00107
00108 myMapper = vtkDataSetMapper::New();
00109 myMapper->SetInput( myGrid );
00110
00111 myPreviewActor = SALOME_Actor::New();
00112 myPreviewActor->PickableOff();
00113 myPreviewActor->VisibilityOff();
00114 myPreviewActor->SetMapper( myMapper );
00115 myPreviewActor->SetRepresentation( 3 );
00116
00117 vtkFloatingPointType anRGB[3];
00118 vtkProperty* aProp = vtkProperty::New();
00119 GetColor( "SMESH", "selection_element_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
00120 aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
00121 myPreviewActor->SetProperty( aProp );
00122 vtkFloatingPointType aFactor,aUnits;
00123 myPreviewActor->SetResolveCoincidentTopology(true);
00124 myPreviewActor->GetPolygonOffsetParameters(aFactor,aUnits);
00125 myPreviewActor->SetPolygonOffsetParameters(aFactor,0.2*aUnits);
00126 aProp->Delete();
00127
00128 myViewWindow->AddActor( myPreviewActor );
00129
00130 }
00131
00132
00133 typedef std::vector<vtkIdType> TVTKIds;
00134 void SetPosition(SMESH_Actor* theActor,
00135 vtkIdType theType,
00136 const TVTKIds& theIds,
00137 bool theReset=true)
00138 {
00139 vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
00140 myGrid->SetPoints(aGrid->GetPoints());
00141
00142 ResetGrid(theReset);
00143
00144 vtkIdList *anIds = vtkIdList::New();
00145
00146 for (int i = 0, iEnd = theIds.size(); i < iEnd; i++)
00147 anIds->InsertId(i,theIds[i]);
00148
00149 myGrid->InsertNextCell(theType,anIds);
00150 if(theIds.size()!=0){
00151 myGrid->InsertNextCell(theType,anIds);
00152 myGrid->Modified();
00153 }
00154
00155 anIds->Delete();
00156
00157 SetVisibility(true);
00158
00159 }
00160
00161 void ResetGrid(bool theReset=true){
00162 if (theReset) myGrid->Reset();
00163 }
00164
00165 void SetVisibility(bool theVisibility){
00166 myPreviewActor->SetVisibility(theVisibility);
00167 RepaintCurrentView();
00168 }
00169
00170
00171 ~TPolySimulation(){
00172 if( myViewWindow )
00173 myViewWindow->RemoveActor(myPreviewActor);
00174
00175 myPreviewActor->Delete();
00176
00177 myMapper->RemoveAllInputs();
00178 myMapper->Delete();
00179
00180 myGrid->Delete();
00181 }
00182
00183 };
00184 }
00185
00186
00187
00188
00189
00190 SMESHGUI_CreatePolyhedralVolumeDlg::SMESHGUI_CreatePolyhedralVolumeDlg( SMESHGUI* theModule )
00191 : QDialog( SMESH::GetDesktop( theModule ) ),
00192 mySMESHGUI( theModule ),
00193 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
00194 {
00195 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH",tr("ICON_SELECT")));
00196
00197 setModal(false);
00198 setAttribute(Qt::WA_DeleteOnClose, true);
00199 setWindowTitle( tr( "SMESH_CREATE_POLYHEDRAL_VOLUME_TITLE" ) );
00200 setSizeGripEnabled( true );
00201
00202 QVBoxLayout* topLayout = new QVBoxLayout( this );
00203 topLayout->setSpacing( SPACING );
00204 topLayout->setMargin( MARGIN );
00205
00206
00207 ConstructorsBox = new QGroupBox(tr( "SMESH_ELEMENTS_TYPE" ), this);
00208 GroupConstructors = new QButtonGroup(this);
00209 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout( ConstructorsBox );
00210 ConstructorsBoxLayout->setSpacing( SPACING );
00211 ConstructorsBoxLayout->setMargin( MARGIN );
00212
00213 RadioButton1 = new QRadioButton( tr( "MESH_NODE" ), ConstructorsBox );
00214 RadioButton2 = new QRadioButton( tr( "SMESH_FACE" ), ConstructorsBox );
00215
00216 ConstructorsBoxLayout->addWidget( RadioButton1 );
00217 ConstructorsBoxLayout->addWidget( RadioButton2 );
00218 GroupConstructors->addButton(RadioButton1, 0);
00219 GroupConstructors->addButton(RadioButton2, 1);
00220
00221
00222 GroupContent = new QGroupBox( tr( "SMESH_CONTENT" ), this );
00223 QGridLayout* GroupContentLayout = new QGridLayout( GroupContent );
00224 GroupContentLayout->setSpacing( SPACING );
00225 GroupContentLayout->setMargin( MARGIN );
00226
00227 TextLabelIds = new QLabel( tr( "SMESH_ID_NODES" ), GroupContent );
00228 SelectElementsButton = new QPushButton( GroupContent );
00229 SelectElementsButton->setIcon( image0 );
00230 LineEditElements = new QLineEdit( GroupContent );
00231 LineEditElements->setValidator( new SMESHGUI_IdValidator( this ) );
00232
00233 myFacesByNodesLabel = new QLabel( tr( "FACES_BY_NODES" ), GroupContent );
00234 myFacesByNodes = new QListWidget( GroupContent);
00235 myFacesByNodes->setSelectionMode( QListWidget::ExtendedSelection );
00236 myFacesByNodes->setMinimumHeight( 150);
00237
00238 AddButton = new QPushButton( tr( "SMESH_BUT_ADD" ), GroupContent );
00239 RemoveButton = new QPushButton( tr( "SMESH_BUT_REMOVE" ), GroupContent );
00240
00241 Preview = new QCheckBox( tr( "SMESH_POLYEDRE_PREVIEW" ), GroupContent );
00242
00243 GroupContentLayout->addWidget( TextLabelIds, 0, 0 );
00244 GroupContentLayout->addWidget( SelectElementsButton, 0, 1 );
00245 GroupContentLayout->addWidget( LineEditElements, 0, 2, 1, 2 );
00246 GroupContentLayout->addWidget( myFacesByNodesLabel, 1, 0 );
00247 GroupContentLayout->addWidget( myFacesByNodes, 2, 0, 3, 3 );
00248 GroupContentLayout->addWidget( AddButton, 2, 3 );
00249 GroupContentLayout->addWidget( RemoveButton, 3, 3 );
00250 GroupContentLayout->addWidget( Preview, 5, 0, 1, 4 );
00251
00252
00253 GroupGroups = new QGroupBox( tr( "SMESH_ADD_TO_GROUP" ), this );
00254 GroupGroups->setCheckable( true );
00255 QHBoxLayout* GroupGroupsLayout = new QHBoxLayout(GroupGroups);
00256 GroupGroupsLayout->setSpacing(SPACING);
00257 GroupGroupsLayout->setMargin(MARGIN);
00258
00259 TextLabel_GroupName = new QLabel( tr( "SMESH_GROUP" ), GroupGroups );
00260 ComboBox_GroupName = new QComboBox( GroupGroups );
00261 ComboBox_GroupName->setEditable( true );
00262
00263 GroupGroupsLayout->addWidget( TextLabel_GroupName );
00264 GroupGroupsLayout->addWidget( ComboBox_GroupName, 1 );
00265
00266
00267 GroupButtons = new QGroupBox( this );
00268 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
00269 GroupButtonsLayout->setSpacing( SPACING );
00270 GroupButtonsLayout->setMargin( MARGIN );
00271
00272 buttonOk = new QPushButton( tr( "SMESH_BUT_APPLY_AND_CLOSE" ), GroupButtons );
00273 buttonOk->setAutoDefault( true );
00274 buttonOk->setDefault( true );
00275 buttonApply = new QPushButton( tr( "SMESH_BUT_APPLY" ), GroupButtons );
00276 buttonApply->setAutoDefault( true );
00277 buttonCancel = new QPushButton( tr( "SMESH_BUT_CLOSE" ), GroupButtons );
00278 buttonCancel->setAutoDefault( true );
00279 buttonHelp = new QPushButton( tr("SMESH_BUT_HELP" ), GroupButtons );
00280 buttonHelp->setAutoDefault(true);
00281
00282 GroupButtonsLayout->addWidget( buttonOk );
00283 GroupButtonsLayout->addSpacing( 10 );
00284 GroupButtonsLayout->addWidget( buttonApply );
00285 GroupButtonsLayout->addSpacing( 10 );
00286 GroupButtonsLayout->addStretch();
00287 GroupButtonsLayout->addWidget( buttonCancel );
00288 GroupButtonsLayout->addWidget( buttonHelp);
00289
00290
00291 topLayout->addWidget( ConstructorsBox );
00292 topLayout->addWidget( GroupContent );
00293 topLayout->addWidget( GroupGroups );
00294 topLayout->addWidget( GroupButtons );
00295
00296 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
00297
00298 RadioButton1->setChecked( true );
00299
00300 mySMESHGUI->SetActiveDialogBox( (QDialog*)this );
00301
00302 myHelpFileName = "adding_nodes_and_elements_page.html#adding_polyhedrons_anchor";
00303
00304 Init();
00305 }
00306
00307
00308
00309
00310
00311 SMESHGUI_CreatePolyhedralVolumeDlg::~SMESHGUI_CreatePolyhedralVolumeDlg()
00312 {
00313 delete mySimulation;
00314 }
00315
00316 static bool busy = false;
00317
00318
00319
00320
00321
00322 void SMESHGUI_CreatePolyhedralVolumeDlg::Init()
00323 {
00324 myEditCurrentArgument = LineEditElements;
00325 mySMESHGUI->SetActiveDialogBox( (QDialog*)this );
00326
00327
00328 GroupGroups->setChecked( false );
00329
00330 myNbOkElements = 0;
00331 myActor = 0;
00332
00333 mySimulation = new SMESH::TPolySimulation( dynamic_cast<SalomeApp_Application*>( mySMESHGUI->application() ) );
00334
00335
00336 connect(buttonOk, SIGNAL( clicked() ), SLOT( ClickOnOk() ) );
00337 connect(buttonCancel, SIGNAL( clicked() ), SLOT( ClickOnCancel() ) );
00338 connect(buttonApply, SIGNAL( clicked() ), SLOT( ClickOnApply() ) );
00339 connect(buttonHelp, SIGNAL( clicked() ), SLOT( ClickOnHelp() ) );
00340
00341 connect(GroupConstructors, SIGNAL(buttonClicked(int) ), SLOT( ConstructorsClicked(int) ) );
00342 connect(SelectElementsButton, SIGNAL( clicked() ), SLOT( SetEditCurrentArgument() ) );
00343 connect(LineEditElements, SIGNAL( textChanged(const QString&) ), SLOT(onTextChange(const QString&)));
00344
00345 connect(myFacesByNodes, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
00346 connect(AddButton, SIGNAL(clicked()), this, SLOT(onAdd()));
00347 connect(RemoveButton, SIGNAL(clicked()), this, SLOT(onRemove()));
00348
00349 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
00350 connect( mySelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
00351 connect( Preview, SIGNAL(toggled(bool)), this, SLOT(ClickOnPreview(bool)));
00352
00353 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
00354
00355 ConstructorsClicked(0);
00356 SelectionIntoArgument();
00357 }
00358
00359
00360
00361
00362
00363
00364 void SMESHGUI_CreatePolyhedralVolumeDlg::ConstructorsClicked(int constructorId)
00365 {
00366
00367
00368 SALOME_ListIO io;
00369 mySelectionMgr->selectedObjects( io );
00370 SALOME_ListIO aList;
00371 mySelectionMgr->setSelectedObjects( aList );
00372 myEditCurrentArgument->clear();
00373 myNbOkElements = 0;
00374 buttonApply->setEnabled(false);
00375 buttonOk->setEnabled(false);
00376 mySimulation->SetVisibility(false);
00377
00378 switch(constructorId)
00379 {
00380 case 0 :
00381 {
00382 if ( myActor ){
00383 myActor->SetPointRepresentation(true);
00384 }
00385 else
00386 SMESH::SetPointRepresentation(true);
00387 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00388 aViewWindow->SetSelectionMode(NodeSelection);
00389
00390 AddButton->setEnabled(false);
00391 RemoveButton->setEnabled(false);
00392 TextLabelIds->setText( tr( "SMESH_ID_NODES" ) );
00393 myFacesByNodesLabel->show();
00394 myFacesByNodes->clear();
00395 myFacesByNodes->show();
00396 AddButton->show();
00397 RemoveButton->show();
00398 Preview->show();
00399 break;
00400 }
00401 case 1 :
00402 {
00403 if( myActor ){
00404 myActor->SetPointRepresentation(false);
00405 } else {
00406 SMESH::SetPointRepresentation(false);
00407 }
00408 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00409 aViewWindow->SetSelectionMode(FaceSelection);
00410
00411 TextLabelIds->setText( tr( "SMESH_ID_FACES" ) );
00412 myFacesByNodesLabel->hide();
00413 myFacesByNodes->hide();
00414 AddButton->hide();
00415 RemoveButton->hide();
00416 Preview->show();
00417 break;
00418 }
00419 }
00420
00421
00422 mySelectionMgr->setSelectedObjects( io );
00423
00424 QApplication::instance()->processEvents();
00425 updateGeometry();
00426 resize(100,100);
00427 }
00428
00429
00430
00431
00432
00433 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnPreview(bool theToggled){
00434 Preview->setChecked(theToggled);
00435 displaySimulation();
00436 }
00437
00438
00439
00440
00441
00442 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnApply()
00443 {
00444 if( !isValid() )
00445 return;
00446
00447 if ( myNbOkElements>0 && !mySMESHGUI->isActiveStudyLocked())
00448 {
00449 if(checkEditLine(false) == -1) {return;}
00450 busy = true;
00451 long anElemId = -1;
00452
00453 bool addToGroup = GroupGroups->isChecked();
00454 QString aGroupName;
00455
00456 SMESH::SMESH_GroupBase_var aGroup;
00457 int idx = 0;
00458 if( addToGroup ) {
00459 aGroupName = ComboBox_GroupName->currentText();
00460 for ( int i = 1; i < ComboBox_GroupName->count(); i++ ) {
00461 QString aName = ComboBox_GroupName->itemText( i );
00462 if ( aGroupName == aName && ( i == ComboBox_GroupName->currentIndex() || idx == 0 ) )
00463 idx = i;
00464 }
00465 if ( idx > 0 ) {
00466 SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( myGroups[idx-1] );
00467 if ( !aGeomGroup->_is_nil() ) {
00468 int res = SUIT_MessageBox::question( this, tr( "SMESH_WRN_WARNING" ),
00469 tr( "MESH_STANDALONE_GRP_CHOSEN" ).arg( aGroupName ),
00470 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 );
00471 if ( res == 1 ) return;
00472 }
00473 aGroup = myGroups[idx-1];
00474 }
00475 }
00476
00477 if (GetConstructorId() == 0)
00478 {
00479 SMESH::long_array_var anIdsOfNodes = new SMESH::long_array;
00480 SMESH::long_array_var aQuantities = new SMESH::long_array;
00481
00482 aQuantities->length( myFacesByNodes->count() );
00483
00484 TColStd_ListOfInteger aNodesIds;
00485
00486 int aNbQuantities = 0;
00487 for (int i = 0; i < myFacesByNodes->count(); i++ ) {
00488 QStringList anIds = myFacesByNodes->item(i)->text().split( " ", QString::SkipEmptyParts );
00489 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it)
00490 aNodesIds.Append( (*it).toInt() );
00491
00492 aQuantities[aNbQuantities++] = anIds.count();
00493 }
00494
00495 anIdsOfNodes->length(aNodesIds.Extent());
00496
00497 int aNbIdsOfNodes = 0;
00498 TColStd_ListIteratorOfListOfInteger It;
00499 It.Initialize(aNodesIds);
00500 for( ;It.More();It.Next())
00501 anIdsOfNodes[aNbIdsOfNodes++] = It.Value();
00502
00503 try{
00504 SUIT_OverrideCursor aWaitCursor;
00505 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
00506 anElemId = aMeshEditor->AddPolyhedralVolume(anIdsOfNodes, aQuantities);
00507 }catch(SALOME::SALOME_Exception& exc){
00508 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
00509 }catch(std::exception& exc){
00510 INFOS("Follow exception was cought:\n\t"<<exc.what());
00511 }catch(...){
00512 INFOS("Unknown exception was cought !!!");
00513 }
00514 }
00515 else if (GetConstructorId() == 1)
00516 {
00517 SMESH::long_array_var anIdsOfFaces = new SMESH::long_array;
00518
00519 QStringList aListId = myEditCurrentArgument->text().split( " ", QString::SkipEmptyParts );
00520 anIdsOfFaces->length(aListId.count());
00521 for ( int i = 0; i < aListId.count(); i++ )
00522 anIdsOfFaces[i] = aListId[i].toInt();
00523
00524 try{
00525 SUIT_OverrideCursor aWaitCursor;
00526 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
00527 anElemId = aMeshEditor->AddPolyhedralVolumeByFaces(anIdsOfFaces);
00528 }catch(SALOME::SALOME_Exception& exc){
00529 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
00530 }catch(std::exception& exc){
00531 INFOS("Follow exception was cought:\n\t"<<exc.what());
00532 }catch(...){
00533 INFOS("Unknown exception was cought !!!");
00534 }
00535 }
00536
00537 if ( anElemId != -1 && addToGroup && !aGroupName.isEmpty() ) {
00538 SMESH::SMESH_Group_var aGroupUsed;
00539 if ( aGroup->_is_nil() ) {
00540
00541 aGroupUsed = SMESH::AddGroup( myMesh, SMESH::VOLUME, aGroupName );
00542 if ( !aGroupUsed->_is_nil() ) {
00543 myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroupUsed));
00544 ComboBox_GroupName->addItem( aGroupName );
00545 }
00546 }
00547 else {
00548 SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
00549 if ( !aGeomGroup->_is_nil() ) {
00550 aGroupUsed = myMesh->ConvertToStandalone( aGeomGroup );
00551 if ( !aGroupUsed->_is_nil() && idx > 0 ) {
00552 myGroups[idx-1] = SMESH::SMESH_GroupBase::_duplicate(aGroupUsed);
00553 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser();
00554 }
00555 }
00556 else
00557 aGroupUsed = SMESH::SMESH_Group::_narrow( aGroup );
00558 }
00559
00560 if ( !aGroupUsed->_is_nil() ) {
00561 SMESH::long_array_var anIdList = new SMESH::long_array;
00562 anIdList->length( 1 );
00563 anIdList[0] = anElemId;
00564 aGroupUsed->Add( anIdList.inout() );
00565 }
00566 }
00567
00568
00569
00570 SMESH::UpdateView();
00571 if( myActor ){
00572 unsigned int anEntityMode = myActor->GetEntityMode();
00573 myActor->SetEntityMode(SMESH_Actor::eVolumes | anEntityMode);
00574 }
00575
00576 busy = false;
00577
00578 SMESHGUI::Modified();
00579 }
00580 myFacesByNodes->clear();
00581 }
00582
00583
00584
00585
00586
00587 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnOk()
00588 {
00589 if(checkEditLine(false) == -1) {return;}
00590 ClickOnApply();
00591 ClickOnCancel();
00592 }
00593
00594
00595
00596
00597
00598
00599 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnCancel()
00600 {
00601 mySelectionMgr->clearFilters();
00602
00603
00604 SMESH::SetPointRepresentation(false);
00605 mySimulation->SetVisibility(false);
00606 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00607 aViewWindow->SetSelectionMode( ActorSelection );
00608 disconnect( mySelectionMgr, 0, this, 0 );
00609 mySMESHGUI->ResetState();
00610 reject();
00611 }
00612
00613
00614
00615
00616
00617 void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnHelp()
00618 {
00619 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00620 if (app)
00621 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
00622 else {
00623 QString platform;
00624 #ifdef WIN32
00625 platform = "winapplication";
00626 #else
00627 platform = "application";
00628 #endif
00629 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
00630 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00631 arg(app->resourceMgr()->stringValue("ExternalBrowser",
00632 platform)).
00633 arg(myHelpFileName));
00634 }
00635 }
00636
00637
00638
00639
00640
00641
00642 void SMESHGUI_CreatePolyhedralVolumeDlg::onTextChange(const QString& theNewText)
00643 {
00644 if ( busy ) return;
00645 if (checkEditLine() == -1) return;
00646 busy = true;
00647
00648 mySimulation->SetVisibility(false);
00649
00650 SMDS_Mesh* aMesh = 0;
00651 if ( myActor )
00652 aMesh = myActor->GetObject()->GetMesh();
00653
00654 if (GetConstructorId() == 0)
00655 {
00656 if ( aMesh ) {
00657 TColStd_MapOfInteger newIndices;
00658
00659 QStringList aListId = theNewText.split( " ", QString::SkipEmptyParts );
00660 for ( int i = 0; i < aListId.count(); i++ ) {
00661 const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() );
00662 if ( n ) {
00663 newIndices.Add(n->GetID());
00664 myNbOkElements++;
00665 }
00666 }
00667
00668 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
00669
00670 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00671 aViewWindow->highlight( myActor->getIO(), true, true );
00672
00673 if ( myNbOkElements>0 && aListId.count()>=3)
00674 AddButton->setEnabled(true);
00675 else
00676 AddButton->setEnabled(false);
00677
00678 displaySimulation();
00679 }
00680 } else if (GetConstructorId() == 1)
00681 {
00682 myNbOkElements = 0;
00683 buttonOk->setEnabled( false );
00684 buttonApply->setEnabled( false );
00685
00686
00687 QStringList aListId;
00688 if ( aMesh ) {
00689 TColStd_MapOfInteger newIndices;
00690
00691 aListId = theNewText.split( " ", QString::SkipEmptyParts );
00692
00693 for ( int i = 0; i < aListId.count(); i++ ) {
00694 const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
00695 if ( e ) {
00696 newIndices.Add(e->GetID());
00697 myNbOkElements++;
00698 }
00699 }
00700
00701 mySelector->AddOrRemoveIndex( myActor->getIO(), newIndices, false );
00702 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00703 aViewWindow->highlight( myActor->getIO(), true, true );
00704
00705 if ( myNbOkElements ) {
00706 if (aListId.count()>1){
00707 buttonOk->setEnabled( true );
00708 buttonApply->setEnabled( true );
00709 }
00710 else{
00711 buttonOk->setEnabled( false );
00712 buttonApply->setEnabled( false );
00713 }
00714 if(aListId.count()>1)
00715 displaySimulation();
00716 }
00717 }
00718 }
00719 busy = false;
00720 }
00721
00722
00723
00724
00725
00726 void SMESHGUI_CreatePolyhedralVolumeDlg::SelectionIntoArgument()
00727 {
00728 if ( busy ) return;
00729
00730
00731
00732 if (GetConstructorId() == 1 || myFacesByNodes->count() <= 1)
00733 {
00734 myNbOkElements = 0;
00735 AddButton->setEnabled(false);
00736 buttonOk->setEnabled( false );
00737 buttonApply->setEnabled( false );
00738 }
00739
00740 myActor = 0;
00741
00742 busy = true;
00743 myEditCurrentArgument->setText( "" );
00744 busy = false;
00745 if ( !GroupButtons->isEnabled() )
00746 return;
00747
00748 mySimulation->SetVisibility(false);
00749
00750 QString aCurrentEntry = myEntry;
00751
00752
00753
00754 SALOME_ListIO selected;
00755 mySelectionMgr->selectedObjects( selected );
00756 int nbSel = selected.Extent();
00757 if(nbSel != 1){
00758 return;
00759 }
00760
00761 myEntry = selected.First()->getEntry();
00762 myMesh = SMESH::GetMeshByIO( selected.First() );
00763 if ( myMesh->_is_nil() )
00764 return;
00765
00766
00767 if ( !myMesh->_is_nil() && myEntry != aCurrentEntry ) {
00768 myGroups.clear();
00769 ComboBox_GroupName->clear();
00770 ComboBox_GroupName->addItem( QString() );
00771 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
00772 for ( int i = 0, n = aListOfGroups.length(); i < n; i++ ) {
00773 SMESH::SMESH_GroupBase_var aGroup = aListOfGroups[i];
00774 if ( !aGroup->_is_nil() && aGroup->GetType() == SMESH::VOLUME ) {
00775 QString aGroupName( aGroup->GetName() );
00776 if ( !aGroupName.isEmpty() ) {
00777 myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroup));
00778 ComboBox_GroupName->addItem( aGroupName );
00779 }
00780 }
00781 }
00782 }
00783
00784 myActor = SMESH::FindActorByObject(myMesh);
00785 if ( !myActor )
00786 return;
00787
00788
00789 QString aString = "";
00790 int anbNodes=0,aNbFaces=0;
00791 switch(GetConstructorId()){
00792 case 0:{
00793 anbNodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
00794 if (anbNodes >= 3)
00795 AddButton->setEnabled(true);
00796 else if (anbNodes < 3){
00797 AddButton->setEnabled(false);
00798 }
00799 busy = true;
00800 myEditCurrentArgument->setText( aString );
00801 if (checkEditLine() == -1) {busy = false;return;}
00802 busy = false;
00803 break;
00804 }
00805 case 1:{
00806
00807 aNbFaces = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aString);
00808 if (aNbFaces<=1){
00809 buttonOk->setEnabled( false );
00810 buttonApply->setEnabled( false );
00811 } else {
00812 buttonOk->setEnabled( true );
00813 buttonApply->setEnabled( true );
00814 }
00815 busy = true;
00816 myEditCurrentArgument->setText( aString );
00817 if (checkEditLine() == -1) {busy = false;return;}
00818 busy = false;
00819
00820
00821 myNbOkElements = 1;
00822 break;
00823 }
00824 default: return;
00825 }
00826 if(anbNodes>2 || aNbFaces>1)
00827 displaySimulation();
00828 }
00829
00830
00831
00832
00833
00834
00835 int SMESHGUI_CreatePolyhedralVolumeDlg::checkEditLine(bool checkLast)
00836 {
00837 QString aString = "";
00838 SMDS_Mesh* aMesh = 0;
00839
00840 if(myMesh->_is_nil()) return 1;
00841 if(!myActor){
00842 myActor = SMESH::FindActorByObject(myMesh);
00843 if(!myActor)
00844 return 1;
00845 }
00846
00847 aMesh = myActor->GetObject()->GetMesh();
00848
00849
00850 if (checkLast && myEditCurrentArgument->text().right(1) != QString(" ") ) return 1;
00851 QStringList aListId = myEditCurrentArgument->text().split( " ", QString::SkipEmptyParts );
00852 for ( int i = 0; i < aListId.count(); i++ ){
00853 switch (GetConstructorId()){
00854 case 0:{
00855 const SMDS_MeshNode * aNode = aMesh->FindNode( aListId[ i ].toInt() );
00856 if( !aNode ){
00857 SUIT_MessageBox::warning(this,
00858 tr("SMESH_POLYEDRE_CREATE_ERROR"),
00859 tr("The incorrect indices of nodes!"));
00860
00861 myEditCurrentArgument->clear();
00862 myEditCurrentArgument->setText( aString );
00863 return -1;
00864 }
00865
00866 break;
00867 }
00868 case 1:{
00869 bool aElemIsOK = true;
00870 const SMDS_MeshElement * aElem = aMesh->FindElement( aListId[ i ].toInt() );
00871 if (!aElem)
00872 {
00873 aElemIsOK = false;
00874 }
00875 else
00876 {
00877 SMDSAbs_ElementType aType = aMesh->GetElementType( aElem->GetID(),true );
00878 if (aType != SMDSAbs_Face){
00879 aElemIsOK = false;
00880 }
00881 }
00882 if (!aElemIsOK){
00883 SUIT_MessageBox::warning(this,
00884 tr("SMESH_POLYEDRE_CREATE_ERROR"),
00885 tr("The incorrect indices of faces!"));
00886
00887 myEditCurrentArgument->clear();
00888 myEditCurrentArgument->setText( aString );
00889 return -1;
00890 }
00891 break;
00892 }
00893 }
00894 aString += aListId[ i ] + " ";
00895 }
00896
00897 return 1;
00898 }
00899
00900
00901
00902
00903
00904 void SMESHGUI_CreatePolyhedralVolumeDlg::displaySimulation()
00905 {
00906 if ( (myNbOkElements || AddButton->isEnabled()) && GroupButtons->isEnabled() && myActor)
00907 {
00908 SMESH::TPolySimulation::TVTKIds aVTKIds;
00909 vtkIdType aType = VTK_CONVEX_POINT_SET;
00910 SMDS_Mesh* aMesh = 0;
00911 if ( myActor ){
00912 aMesh = myActor->GetObject()->GetMesh();
00913 }
00914 if (GetConstructorId() == 0 && aMesh){
00915 if (!AddButton->isEnabled()){
00916 mySimulation->ResetGrid(true);
00917 for (int i = 0; i < myFacesByNodes->count(); i++) {
00918 QStringList anIds = myFacesByNodes->item(i)->text().split( " ", QString::SkipEmptyParts );
00919 SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
00920 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it){
00921 const SMDS_MeshNode* aNode = aMesh->FindNode( (*it).toInt() );
00922 if (!aNode) continue;
00923 vtkIdType aId = myActor->GetObject()->GetNodeVTKId( (*it).toInt() );
00924 aVTKIds.push_back(aId);
00925 aVTKIds_faces.push_back(aId);
00926 }
00927 if(!Preview->isChecked()){
00928 aType = VTK_POLYGON;
00929 mySimulation->SetPosition(myActor, aType, aVTKIds_faces,false);
00930 }
00931 }
00932 if(myFacesByNodes->count() == 0){
00933 mySimulation->SetVisibility(false);
00934 } else {
00935 mySimulation->SetVisibility(true);
00936 }
00937 if(Preview->isChecked()){
00938 mySimulation->SetPosition(myActor, aType, aVTKIds);
00939 }
00940 } else {
00941
00942 QStringList anEditIds = myEditCurrentArgument->text().split( " ", QString::SkipEmptyParts );
00943 for ( int i = 0; i < anEditIds.count(); i++ )
00944 aVTKIds.push_back( myActor->GetObject()->GetNodeVTKId( anEditIds[ i ].toInt() ));
00945 aType = VTK_POLYGON;
00946 mySimulation->SetPosition(myActor, aType, aVTKIds);
00947 }
00948 }else if(GetConstructorId() == 1 && aMesh){
00949 QStringList aListId = myEditCurrentArgument->text().split( " ", QString::SkipEmptyParts );
00950 for ( int i = 0; i < aListId.count(); i++ )
00951 {
00952 const SMDS_MeshElement * anElem = aMesh->FindElement( aListId[ i ].toInt() );
00953 if ( !anElem ) continue;
00954 SMDSAbs_ElementType aFaceType = aMesh->GetElementType( anElem->GetID(),true );
00955 if (aFaceType != SMDSAbs_Face) continue;
00956
00957 SMDS_ElemIteratorPtr anIter = anElem->nodesIterator();
00958 SMESH::TPolySimulation::TVTKIds aVTKIds_faces;
00959 while( anIter->more() )
00960 if ( const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next() ){
00961 vtkIdType aId = myActor->GetObject()->GetNodeVTKId( aNode->GetID() );
00962 aVTKIds.push_back(aId);
00963 aVTKIds_faces.push_back(aId);
00964 }
00965 if(!Preview->isChecked()){
00966 aType = VTK_POLYGON;
00967 mySimulation->SetPosition(myActor, aType, aVTKIds_faces);
00968 }
00969 }
00970 if(Preview->isChecked())
00971 mySimulation->SetPosition(myActor, aType, aVTKIds);
00972 }
00973 SMESH::UpdateView();
00974 }
00975 }
00976
00977
00978
00979
00980
00981 void SMESHGUI_CreatePolyhedralVolumeDlg::SetEditCurrentArgument()
00982 {
00983 QPushButton* send = (QPushButton*)sender();
00984 if(send == SelectElementsButton) {
00985 LineEditElements->setFocus();
00986 myEditCurrentArgument = LineEditElements;
00987 }
00988 SelectionIntoArgument();
00989 }
00990
00991
00992
00993
00994
00995 void SMESHGUI_CreatePolyhedralVolumeDlg::DeactivateActiveDialog()
00996 {
00997 if ( ConstructorsBox->isEnabled() ) {
00998 ConstructorsBox->setEnabled(false);
00999 GroupContent->setEnabled(false);
01000 GroupButtons->setEnabled(false);
01001 mySimulation->SetVisibility(false);
01002 mySMESHGUI->ResetState();
01003 mySMESHGUI->SetActiveDialogBox(0);
01004 }
01005 }
01006
01007
01008
01009
01010
01011
01012 void SMESHGUI_CreatePolyhedralVolumeDlg::ActivateThisDialog()
01013 {
01014
01015 mySMESHGUI->EmitSignalDeactivateDialog();
01016 ConstructorsBox->setEnabled(true);
01017 GroupContent->setEnabled(true);
01018 GroupButtons->setEnabled(true);
01019
01020 mySMESHGUI->SetActiveDialogBox( (QDialog*)this );
01021
01022 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
01023 aViewWindow->SetSelectionMode( FaceSelection );
01024 SelectionIntoArgument();
01025 }
01026
01027
01028
01029
01030
01031
01032 void SMESHGUI_CreatePolyhedralVolumeDlg::enterEvent(QEvent* e)
01033 {
01034 if ( ConstructorsBox->isEnabled() )
01035 return;
01036 ActivateThisDialog();
01037 }
01038
01039
01040
01041
01042
01043
01044 void SMESHGUI_CreatePolyhedralVolumeDlg::closeEvent( QCloseEvent* e )
01045 {
01046
01047 ClickOnCancel();
01048 }
01049
01050
01051
01052
01053
01054
01055
01056 void SMESHGUI_CreatePolyhedralVolumeDlg::hideEvent ( QHideEvent * e )
01057 {
01058 if ( !isMinimized() )
01059 ClickOnCancel();
01060 }
01061
01062
01063
01064
01065
01066
01067 int SMESHGUI_CreatePolyhedralVolumeDlg::GetConstructorId()
01068 {
01069 return GroupConstructors->checkedId();
01070 }
01071
01072
01073
01074
01075
01076 void SMESHGUI_CreatePolyhedralVolumeDlg::onAdd()
01077 {
01078 SALOME_ListIO selected;
01079 mySelectionMgr->selectedObjects( selected );
01080 int aNbSel = selected.Extent();
01081 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
01082
01083 if (checkEditLine(false) == -1) return;
01084
01085 busy = true;
01086 if ( !(myEditCurrentArgument->text().isEmpty()) )
01087 {
01088 myFacesByNodes->addItem(myEditCurrentArgument->text());
01089
01090 myNbOkElements = 1;
01091 myEditCurrentArgument->clear();
01092 AddButton->setEnabled(false);
01093 buttonApply->setEnabled( myFacesByNodes->count() > 1 );
01094 buttonOk->setEnabled( myFacesByNodes->count() > 1 );
01095 }
01096 busy = false;
01097 onListSelectionChanged();
01098 displaySimulation();
01099 }
01100
01101
01102
01103
01104
01105 void SMESHGUI_CreatePolyhedralVolumeDlg::onRemove()
01106 {
01107 busy = true;
01108 QList<QListWidgetItem*> selItems = myFacesByNodes->selectedItems();
01109 QListWidgetItem* anItem;
01110
01111 if ( selItems.count() > 0 ) myNbOkElements = 1;
01112
01113 foreach( anItem, selItems )
01114 delete anItem;
01115
01116 RemoveButton->setEnabled( myFacesByNodes->count() > 0 );
01117 buttonOk->setEnabled( myFacesByNodes->count() > 1 );
01118 buttonApply->setEnabled( myFacesByNodes->count() > 1 );
01119
01120 busy = false;
01121 displaySimulation();
01122 }
01123
01124
01125
01126
01127
01128 void SMESHGUI_CreatePolyhedralVolumeDlg::onListSelectionChanged()
01129 {
01130 if (busy || !myActor) return;
01131 busy = true;
01132
01133 SALOME_ListIO aList;
01134 mySelectionMgr->setSelectedObjects( aList );
01135 TColStd_MapOfInteger aIndexes;
01136
01137 QList<QListWidgetItem*> selItems = myFacesByNodes->selectedItems();
01138 QListWidgetItem* anItem;
01139 foreach( anItem, selItems ) {
01140 QStringList anIds = anItem->text().split( " ", QString::SkipEmptyParts );
01141 for (QStringList::iterator it = anIds.begin(); it != anIds.end(); ++it)
01142 aIndexes.Add((*it).toInt());
01143 }
01144 RemoveButton->setEnabled(selItems.count() > 0);
01145 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, true );
01146 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
01147 aViewWindow->highlight( myActor->getIO(), true, true );
01148 mySelectionMgr->clearFilters();
01149 aList.Append( myActor->getIO() );
01150 mySelectionMgr->setSelectedObjects( aList );
01151
01152 busy = false;
01153 }
01154
01155
01156
01157
01158
01159 void SMESHGUI_CreatePolyhedralVolumeDlg::keyPressEvent( QKeyEvent* e )
01160 {
01161 QDialog::keyPressEvent( e );
01162 if ( e->isAccepted() )
01163 return;
01164
01165 if ( e->key() == Qt::Key_F1 ) {
01166 e->accept();
01167 ClickOnHelp();
01168 }
01169 }
01170
01171
01172
01173
01174
01175 bool SMESHGUI_CreatePolyhedralVolumeDlg::isValid()
01176 {
01177 if( GroupGroups->isChecked() && ComboBox_GroupName->currentText().isEmpty() ) {
01178 SUIT_MessageBox::warning( this, tr( "SMESH_WRN_WARNING" ), tr( "GROUP_NAME_IS_EMPTY" ) );
01179 return false;
01180 }
01181 return true;
01182 }