1 // Copyright (C) 2011-2020 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // SMESH SMESHGUI : GUI for the adaptation in the SMESH component
21 // File : SMESHGUI_AdaptDlg.cxx
22 // Author : Gerald NICOLAS, EDF
26 #include "SMESHGUI_AdaptDlg.h"
27 #include "SMESHGUI_Utils.h"
28 #include "SMESHGUI_VTKUtils.h"
29 #include "SMESHGUI_GroupUtils.h"
30 #include "SMESHGUI_FilterUtils.h"
31 #include "SMESHGUI_GEOMGenUtils.h"
32 #include "SMESHGUI_FilterDlg.h"
33 #include "SMESHGUI_ShapeByMeshDlg.h"
35 #include <SMESH_TypeFilter.hxx>
36 #include <SMESH_Actor.h>
37 //#include <SMESH_ActorUtils.h>
38 #include <SMESH_LogicalFilter.hxx>
40 // SALOME GEOM includes
42 #include <GEOM_SelectionFilter.h>
43 #include <GEOM_wrap.hxx>
45 // SALOME GUI includes
46 #include <LightApp_SelectionMgr.h>
47 #include <QtxColorButton.h>
48 #include <SALOME_ListIO.hxx>
49 #include <SUIT_Desktop.h>
50 #include <SUIT_MessageBox.h>
51 #include <SUIT_OverrideCursor.h>
52 #include <SUIT_ResourceMgr.h>
53 #include <SUIT_Session.h>
54 #include <SVTK_ViewWindow.h>
55 #include <SalomeApp_Application.h>
56 #include <SalomeApp_Study.h>
57 #include <SalomeApp_Tools.h>
58 #include <VTKViewer_Algorithm.h>
61 #include <QButtonGroup>
65 #include <QPushButton>
66 #include <QToolButton>
67 #include <QRadioButton>
69 #include <QGridLayout>
70 #include <QHBoxLayout>
71 #include <QVBoxLayout>
72 #include <QListWidget>
73 #include <QStackedWidget>
78 #include "MonCreateCase.h"
86 #include <vtkRenderer.h>
87 #include <vtkActorCollection.h>
89 // SALOME KERNEL includes
90 #include <SALOMEDSClient_ClientFactory.hxx>
91 #include <SALOMEDSClient_IParameters.hxx>
92 #include <SALOMEDSClient_SComponent.hxx>
93 #include <SALOMEDSClient_StudyBuilder.hxx>
94 #include <SALOMEDS_Study.hxx>
95 #include <SALOMEDS_SObject.hxx>
96 #include "utilities.h"
97 #include <SALOME_LifeCycleCORBA.hxx>
100 #include <TColStd_MapOfInteger.hxx>
105 enum grpSelectionMode {
107 grpNodeSelection = 0,
109 grpBallSelection = 2,
110 grpEdgeSelection = 3,
111 grpFaceSelection = 4,
112 grpVolumeSelection = 5,
113 grpSubMeshSelection = 6,
114 grpGroupSelection = 7,
115 grpMeshSelection = 8,
116 grpGeomSelection = 9,
117 grpAllSelection = 10,
120 //=================================================================================
121 // function : SMESHGUI_AdaptDlg()
123 //=================================================================================
124 SMESHGUI_AdaptDlg::SMESHGUI_AdaptDlg( SMESHGUI* theModule,
126 SMESH::SMESH_Mesh_ptr theMesh )
127 : QDialog( SMESH::GetDesktop( theModule ) ),
128 mySMESHGUI( theModule ),
129 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ), myStoredShownEntity(0),
130 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
132 myNameChanged( false ),
133 myNbChangesOfContents(0),
134 myIsApplyAndClose( false )
136 std::cout << "SMESHGUI_AdaptDlg avec theCommandID : " << theCommandID << std::endl;
137 if ( ! OnGUIEvent (theCommandID) )
141 // initDialog( true );
142 // if ( !theMesh->_is_nil() )
146 // mySelectSubMesh->setEnabled( false );
147 // mySelectGroup->setEnabled( false );
148 // myGeomGroupBtn->setEnabled( false );
149 // myGeomGroupLine->setEnabled( false );
153 * \brief Launches the GUI for the adaptation
154 * \param theCommandID - the integer taht references the operation
155 * \return Graphical object
157 bool SMESHGUI_AdaptDlg::OnGUIEvent (int theCommandID)
159 std::cout << "OnGUIEvent avec theCommandID : " << theCommandID << std::endl;
161 SalomeApp_Application* app =
162 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
163 if ( !app ) return false;
165 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
168 MESSAGE ( "FAILED to cast active study to SalomeApp_Study" );
172 SUIT_Desktop* parent = SUIT_Session::session()->activeApplication()->desktop();
174 SALOME_LifeCycleCORBA* ls = new SALOME_LifeCycleCORBA(app->namingService());
175 Engines::EngineComponent_var comp =
176 ls->FindOrLoad_Component("FactoryServer", "SMESH");
177 ADAPT::ADAPT_Gen_var homardGen = ADAPT::ADAPT_Gen::_narrow(comp);
178 if (!CORBA::is_nil(homardGen))
179 homardGen->UpdateStudy();
181 SMESHGUI::GetSMESHGUI()->getApp()->updateObjectBrowser();
183 // B. Choix selon les commandes
184 SCRUTE(theCommandID);
185 switch (theCommandID)
187 case 8011: // Creation d un Cas
189 INFOS("Creation d'un Cas");
190 MonCreateCase *aDlg = new MonCreateCase( true,
191 ADAPT::ADAPT_Gen::_duplicate(homardGen) ) ;
196 // case 8012: // Poursuite d une iteration
198 // MESSAGE("command " << theCommandID << " activated");
199 // MonPursueIteration *aDlg = new MonPursueIteration( true,
200 // ADAPT::ADAPT_Gen::_duplicate(homardGen) ) ;
205 // case 8013: // Creation d une Iteration
207 // MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
208 // MonCreateIteration *IterDlg = new MonCreateIteration( parent, true,
209 // ADAPT::ADAPT_Gen::_duplicate(homardGen), _ObjectName ) ;
214 // case 8014: // Compute une iteration
216 // MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
217 // try { homardGen->Compute(_ObjectName.toStdString().c_str(), 0, 1, -1, 1); }
218 // catch( SALOME::SALOME_Exception& S_ex )
220 // QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
221 // QObject::tr(CORBA::string_dup(S_ex.details.text)) );
222 // getApp()->updateObjectBrowser();
228 // case 8015: // Compute une iteration et publication
230 // MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
231 // try { homardGen->Compute(_ObjectName.toStdString().c_str(), 0, 1, -1, 2); }
232 // catch( SALOME::SALOME_Exception& S_ex )
234 // QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
235 // QObject::tr(CORBA::string_dup(S_ex.details.text)) );
236 // getApp()->updateObjectBrowser();
242 // case 1121: // Information sur le maillage de l'iteration
244 // MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
245 // MonIterInfo *IterDlg = new MonIterInfo( parent, true, ADAPT::ADAPT_Gen::_duplicate(homardGen), _ObjectName ) ;
250 // case 1131: // Publication du maillage de l'iteration
252 // MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
253 // homardGen->PublishMeshIterInSmesh(_ObjectName.toStdString().c_str());
257 // case 1132: // Publication du maillage de l'iteration a partir du fichier
259 // MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
260 // homardGen->PublishResultInSmesh(_ObjectName.toStdString().c_str(), 1);
264 // case 1201: // Edition d'un objet
266 // MESSAGE("command " << theCommandID << " activated");
267 // QString nomObjet = HOMARD_QT_COMMUN::SelectionArbreEtude(QString(""), 1);
268 // if (nomObjet == QString("")) break;
269 // _PTR(SObject) obj = chercheMonObjet();
272 // // Edition d'une frontiere CAO
273 // if (HOMARD_UTILS::isBoundaryCAO(obj))
275 // MonEditBoundaryCAO *aDlg = new MonEditBoundaryCAO(0, true, ADAPT::ADAPT_Gen::_duplicate(homardGen), QString(""), _ObjectName ) ;
278 // // Edition d'une frontiere discrete
279 // else if (HOMARD_UTILS::isBoundaryDi(obj))
281 // MonEditBoundaryDi *aDlg = new MonEditBoundaryDi(0, true, ADAPT::ADAPT_Gen::_duplicate(homardGen), QString(""), _ObjectName ) ;
284 // // Edition d'une frontiere analytique
285 // else if (HOMARD_UTILS::isBoundaryAn(obj))
287 // MonEditBoundaryAn *aDlg = new MonEditBoundaryAn(0, true, ADAPT::ADAPT_Gen::_duplicate(homardGen), QString(""), _ObjectName ) ;
290 // // Edition d'un cas
291 // else if (HOMARD_UTILS::isCase(obj))
293 // MonEditCase *aDlg = new MonEditCase(true, ADAPT::ADAPT_Gen::_duplicate(homardGen), _ObjectName ) ;
296 // // Edition d'une hypothese
297 // else if (HOMARD_UTILS::isHypo(obj))
299 // MonEditHypothesis *aDlg = new MonEditHypothesis(0, true, ADAPT::ADAPT_Gen::_duplicate(homardGen), _ObjectName, QString(""), QString("")) ;
302 // // Edition d'une iteration
303 // else if (HOMARD_UTILS::isIter(obj))
305 // MonEditIteration *aDlg = new MonEditIteration(parent, true, ADAPT::ADAPT_Gen::_duplicate(homardGen), QString(""), _ObjectName ) ;
308 // // Edition d'un schema YACS
309 // else if (HOMARD_UTILS::isYACS(obj))
311 // MESSAGE("appel de MonEditYACS");
312 // MonEditYACS *aDlg = new MonEditYACS(true, ADAPT::ADAPT_Gen::_duplicate(homardGen), _ObjectName) ;
315 // // Edition d'une zone
316 // else if (HOMARD_UTILS::isZone(obj))
318 // MonEditZone *aDlg = new MonEditZone(0, true, ADAPT::ADAPT_Gen::_duplicate(homardGen), QString(""), _ObjectName ) ;
325 // case 1211: // Suppression d'un objet
327 // MESSAGE("command " << theCommandID << " activated");
328 // QString nomObjet = HOMARD_QT_COMMUN::SelectionArbreEtude(QString(""), 1);
329 // if (nomObjet == QString("")) break;
330 // _PTR(SObject) obj = chercheMonObjet();
333 // // Suppression d'une frontiere
334 // if ( HOMARD_UTILS::isBoundaryCAO(obj) || HOMARD_UTILS::isBoundaryDi(obj) || HOMARD_UTILS::isBoundaryAn(obj) )
337 // { homardGen->DeleteBoundary(_ObjectName.toStdString().c_str()); }
338 // catch( SALOME::SALOME_Exception& S_ex )
340 // QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
341 // QObject::tr(CORBA::string_dup(S_ex.details.text)) );
342 // getApp()->updateObjectBrowser();
346 // // Suppression d'un cas
347 // else if (HOMARD_UTILS::isCase(obj))
350 // { homardGen->DeleteCase(_ObjectName.toStdString().c_str(), 1); }
351 // catch( SALOME::SALOME_Exception& S_ex )
353 // QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
354 // QObject::tr(CORBA::string_dup(S_ex.details.text)) );
355 // getApp()->updateObjectBrowser();
359 // // Suppression d'une hypothese
360 // else if (HOMARD_UTILS::isHypo(obj))
363 // { homardGen->DeleteHypo(_ObjectName.toStdString().c_str()); }
364 // catch( SALOME::SALOME_Exception& S_ex )
366 // QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
367 // QObject::tr(CORBA::string_dup(S_ex.details.text)) );
368 // getApp()->updateObjectBrowser();
372 // // Suppression d'une iteration
373 // else if (HOMARD_UTILS::isIter(obj))
376 // { homardGen->DeleteIteration(_ObjectName.toStdString().c_str(), 1); }
377 // catch( SALOME::SALOME_Exception& S_ex )
379 // QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
380 // QObject::tr(CORBA::string_dup(S_ex.details.text)) );
381 // getApp()->updateObjectBrowser();
385 // // Suppression d'un schema YACS
386 // else if (HOMARD_UTILS::isYACS(obj))
389 // { homardGen->DeleteYACS(_ObjectName.toStdString().c_str(), 1); }
390 // catch( SALOME::SALOME_Exception& S_ex )
392 // QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
393 // QObject::tr(CORBA::string_dup(S_ex.details.text)) );
394 // getApp()->updateObjectBrowser();
398 // // Suppression d'une zone
399 // else if (HOMARD_UTILS::isZone(obj))
402 // { homardGen->DeleteZone(_ObjectName.toStdString().c_str()); }
403 // catch( SALOME::SALOME_Exception& S_ex )
405 // QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
406 // QObject::tr(CORBA::string_dup(S_ex.details.text)) );
407 // getApp()->updateObjectBrowser();
415 // case 1301: // Information sur un maillage
417 // MESSAGE("etape 1301")
418 // MESSAGE("command " << theCommandID << " activated");
419 // MonMeshInfo *aDlg = new MonMeshInfo( parent, true, ADAPT::ADAPT_Gen::_duplicate(homardGen) ) ;
424 // case 1302: // Affichage de fichier texte
426 // MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
427 // _PTR(SObject) obj = chercheMonObjet();
428 // if ( (obj) && ( HOMARD_UTILS::isFileType(obj,QString("log")) || HOMARD_UTILS::isFileType(obj,QString("Summary")) || HOMARD_UTILS::isFileType(obj,QString("xml")) ) )
430 // MonEditFile *aDlg = new MonEditFile( 0, true, ADAPT::ADAPT_Gen::_duplicate(homardGen), _ObjectName, 0 ) ;
431 // if ( aDlg->_codret == 0 ) { aDlg->show(); }
436 // case 1401: // Création d'un schema YACS
438 // MESSAGE("etape 1401")
439 // MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
440 // MonCreateYACS *aDlg = new MonCreateYACS( true, ADAPT::ADAPT_Gen::_duplicate(homardGen), _ObjectName ) ;
445 // case 1402: // Ecriture d'un schéma YACS
447 // MESSAGE("etape 1402")
448 // MESSAGE("command " << theCommandID << " activated avec objet " << _ObjectName.toStdString().c_str() );
449 // try { homardGen->YACSWrite(_ObjectName.toStdString().c_str()); }
450 // catch( SALOME::SALOME_Exception& S_ex )
452 // QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
453 // QObject::tr(CORBA::string_dup(S_ex.details.text)) );
454 // getApp()->updateObjectBrowser();
461 // getApp()->updateObjectBrowser();
465 //=================================================================================
466 // function : SMESHGUI_AdaptDlg()
468 //=================================================================================
469 void SMESHGUI_AdaptDlg::initDialog( bool create)
471 std::cout << "passage par initDialog" << std::endl;
473 setAttribute( Qt::WA_DeleteOnClose, true );
477 myCurrentLineEdit = 0;
481 myGeomObjects = new GEOM::ListOfGO();
482 myGeomObjects->length( 0 );
484 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
486 setWindowTitle( create ? tr( "SMESH_CREATE_GROUP_TITLE" ) : tr( "SMESH_EDIT_GROUP_TITLE" ) );
487 myHelpFileName = create ? "creating_groups.html" : "editing_groups.html";
489 setSizeGripEnabled( true);
491 QGridLayout* aMainLayout = new QGridLayout( this );
492 aMainLayout->setMargin( MARGIN );
493 aMainLayout->setSpacing( SPACING );
495 /***************************************************************/
496 QLabel* meshGroupLab = new QLabel( create ? tr( "SMESH_MESH" ) : tr( "SMESH_GROUP" ), this );
497 myMeshGroupBtn = new QPushButton( this );
498 myMeshGroupBtn->setIcon( image0 );
499 myMeshGroupLine = new QLineEdit( this );
500 myMeshGroupLine->setReadOnly( true );
502 /***************************************************************/
503 QGroupBox* aTypeBox = new QGroupBox( tr( "SMESH_ELEMENTS_TYPE" ), this );
504 myTypeGroup = new QButtonGroup( this );
505 QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( aTypeBox );
506 aTypeBoxLayout->setMargin( MARGIN );
507 aTypeBoxLayout->setSpacing( SPACING );
510 types.append( tr( "MESH_NODE" ) );
511 types.append( tr( "SMESH_ELEM0D" ) );
512 types.append( tr( "SMESH_BALL_ELEM" ) );
513 types.append( tr( "SMESH_EDGE" ) );
514 types.append( tr( "SMESH_FACE" ) );
515 types.append( tr( "SMESH_VOLUME" ) );
517 for ( int i = 0; i < types.count(); i++ )
519 rb = new QRadioButton( types[i], aTypeBox );
520 myTypeGroup->addButton( rb, i );
521 aTypeBoxLayout->addWidget( rb );
523 aTypeBox->setEnabled( create );
526 /***************************************************************/
527 QLabel* aName = new QLabel( tr( "SMESH_NAME" ), this );
528 aName->setMinimumWidth( 50 );
529 myName = new QLineEdit( this );
531 /***************************************************************/
532 QGroupBox* aGrpTypeBox = new QGroupBox( tr( "SMESH_GROUP_TYPE" ), this );
533 myGrpTypeGroup = new QButtonGroup( this );
534 QHBoxLayout* aGrpTypeBoxLayout = new QHBoxLayout( aGrpTypeBox );
535 aGrpTypeBoxLayout->setMargin( MARGIN );
536 aGrpTypeBoxLayout->setSpacing( SPACING );
538 QRadioButton* rb1 = new QRadioButton( tr( "SMESH_GROUP_STANDALONE" ), aGrpTypeBox );
539 QRadioButton* rb2 = new QRadioButton( tr( "SMESH_GROUP_GEOMETRY" ), aGrpTypeBox );
540 QRadioButton* rb3 = new QRadioButton( tr( "SMESH_GROUP_FILTER" ), aGrpTypeBox );
541 myGrpTypeGroup->addButton( rb1, 0 );
542 myGrpTypeGroup->addButton( rb2, 1 );
543 myGrpTypeGroup->addButton( rb3, 2 );
544 aGrpTypeBoxLayout->addWidget( rb1 );
545 aGrpTypeBoxLayout->addWidget( rb2 );
546 aGrpTypeBoxLayout->addWidget( rb3 );
547 aGrpTypeBox->setEnabled( create );
550 /***************************************************************/
551 myWGStack = new QStackedWidget( this );
552 QWidget* wg1 = new QWidget( myWGStack );
553 QWidget* wg2 = new QWidget( myWGStack );
554 QWidget* wg3 = new QWidget( myWGStack );
556 /***************************************************************/
557 QGroupBox* aContentBox = new QGroupBox( tr( "SMESH_CONTENT" ), wg1 );
558 QGridLayout* aContentBoxLayout = new QGridLayout( aContentBox );
559 aContentBoxLayout->setMargin( MARGIN );
560 aContentBoxLayout->setSpacing( SPACING );
562 mySelectAll = new QCheckBox( tr( "SELECT_ALL" ), aContentBox );
563 myAllowElemsModif = new QCheckBox( tr( "ALLOW_ELEM_LIST_MODIF" ), aContentBox );
565 myElementsLab = new QLabel( tr( "SMESH_ID_ELEMENTS" ), aContentBox );
566 myElements = new QListWidget( aContentBox );
567 myElements->setSelectionMode( QListWidget::ExtendedSelection );
569 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), aContentBox );
570 myAddBtn = new QPushButton( tr( "SMESH_BUT_ADD" ), aContentBox );
571 myRemoveBtn = new QPushButton( tr( "SMESH_BUT_REMOVE" ), aContentBox );
572 mySortBtn = new QPushButton( tr( "SMESH_BUT_SORT" ), aContentBox );
574 aContentBoxLayout->addWidget( mySelectAll, 0, 0 );
575 aContentBoxLayout->addWidget( myAllowElemsModif, 1, 0 );
576 aContentBoxLayout->addWidget( myFilterBtn, 1, 1 );
577 aContentBoxLayout->addWidget( myElementsLab, 2, 0 );
578 aContentBoxLayout->addWidget( myElements, 3, 0, 6, 1 );
579 aContentBoxLayout->addWidget( myAddBtn, 3, 1 );
580 aContentBoxLayout->addWidget( myRemoveBtn, 4, 1 );
581 aContentBoxLayout->addWidget( mySortBtn, 8, 1 );
583 aContentBoxLayout->setColumnStretch( 0, 1 );
584 aContentBoxLayout->setRowStretch( 3, 1 );
585 aContentBoxLayout->setRowStretch( 6, 1 );
587 /***************************************************************/
588 mySelectBox = new QGroupBox( tr( "SMESH_SELECT_FROM" ), wg1 );
589 QGridLayout* mySelectBoxLayout = new QGridLayout( mySelectBox );
590 mySelectBoxLayout->setMargin( MARGIN );
591 mySelectBoxLayout->setSpacing( SPACING );
593 mySelectSubMesh = new QCheckBox( tr( "SMESH_SUBMESH" ), mySelectBox );
594 mySubMeshBtn = new QPushButton( mySelectBox );
595 mySubMeshBtn->setIcon( image0 );
596 mySubMeshLine = new QLineEdit( mySelectBox );
597 mySubMeshLine->setReadOnly( true );
598 onSelectSubMesh( false );
600 mySelectGroup = new QCheckBox( tr( "SMESH_GROUP" ), mySelectBox );
601 myGroupBtn = new QPushButton( mySelectBox );
602 myGroupBtn->setIcon( image0 );
603 myGroupLine = new QLineEdit( mySelectBox );
604 myGroupLine->setReadOnly( true );
605 onSelectGroup( false );
607 mySelectBoxLayout->addWidget( mySelectSubMesh, 0, 0 );
608 mySelectBoxLayout->addWidget( mySubMeshBtn, 0, 1 );
609 mySelectBoxLayout->addWidget( mySubMeshLine, 0, 2 );
610 mySelectBoxLayout->addWidget( mySelectGroup, 1, 0 );
611 mySelectBoxLayout->addWidget( myGroupBtn, 1, 1 );
612 mySelectBoxLayout->addWidget( myGroupLine, 1, 2 );
614 /***************************************************************/
615 QVBoxLayout* wg1Layout = new QVBoxLayout( wg1 );
616 wg1Layout->setMargin( 0 );
617 wg1Layout->setSpacing( SPACING );
618 wg1Layout->addWidget( aContentBox );
619 wg1Layout->addWidget( mySelectBox );
620 wg1Layout->setStretchFactor( aContentBox, 10 );
622 /***************************************************************/
623 QLabel* geomObject = new QLabel( tr( "SMESH_OBJECT_GEOM" ), wg2 );
624 myGeomGroupBtn = new QToolButton( wg2 );
625 myGeomGroupBtn->setIcon( image0 );
626 myGeomGroupBtn->setCheckable( true );
627 myGeomGroupLine = new QLineEdit( wg2 );
628 myGeomGroupLine->setReadOnly( true ); //VSR ???
629 onSelectGeomGroup( false );
631 myGeomGroupBtn->setEnabled( create );
632 myGeomGroupLine->setEnabled( create );
634 /***************************************************************/
635 QGridLayout* wg2Layout = new QGridLayout( wg2 );
636 wg2Layout->setMargin( 0 );
637 wg2Layout->setSpacing( SPACING );
638 wg2Layout->addWidget( geomObject, 0, 0 );
639 wg2Layout->addWidget( myGeomGroupBtn, 0, 1 );
640 wg2Layout->addWidget( myGeomGroupLine,0, 2 );
641 wg2Layout->setRowStretch( 1, 5 );
643 /***************************************************************/
644 QPushButton * aFilter2 = new QPushButton( tr( "SMESH_BUT_FILTER" ), wg3 );
645 QGridLayout* wg3Layout = new QGridLayout( wg3 );
646 wg3Layout->setMargin( 0 );
647 wg3Layout->setSpacing( SPACING );
648 wg3Layout->addWidget( aFilter2, 0, 0 );
649 wg3Layout->setRowStretch( 1, 5 );
651 /***************************************************************/
652 myWGStack->insertWidget( 0, wg1 );
653 myWGStack->insertWidget( 1, wg2 );
654 myWGStack->insertWidget( 2, wg3 );
656 /***************************************************************/
657 QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this);
658 QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox);
659 aColorBoxLayout->setMargin(MARGIN);
660 aColorBoxLayout->setSpacing(SPACING);
662 QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox );
663 myColorBtn = new QtxColorButton(aColorBox);
664 myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding,
665 myColorBtn->sizePolicy().verticalPolicy() );
667 aColorBoxLayout->addWidget(aColorLab);
668 aColorBoxLayout->addWidget(myColorBtn);
670 /***************************************************************/
672 QFrame* aButtons = new QFrame(this);
673 aButtons->setFrameStyle( QFrame::Box | QFrame::Sunken );
674 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons);
675 aBtnLayout->setMargin(MARGIN);
676 aBtnLayout->setSpacing(SPACING);
678 myOKBtn = new QPushButton(tr( "SMESH_BUT_APPLY_AND_CLOSE" ), aButtons);
679 myOKBtn->setAutoDefault(true);
680 myOKBtn->setDefault(true);
681 myApplyBtn = new QPushButton(tr( "SMESH_BUT_APPLY" ), aButtons);
682 myApplyBtn->setAutoDefault(true);
683 myCloseBtn = new QPushButton(tr( "SMESH_BUT_CLOSE" ), aButtons);
684 myCloseBtn->setAutoDefault(true);
685 myHelpBtn = new QPushButton(tr( "SMESH_BUT_HELP" ), aButtons);
686 myHelpBtn->setAutoDefault(true);
688 aBtnLayout->addWidget(myOKBtn);
689 aBtnLayout->addSpacing(10);
690 aBtnLayout->addWidget(myApplyBtn);
691 aBtnLayout->addSpacing(10);
692 aBtnLayout->addStretch();
693 aBtnLayout->addWidget(myCloseBtn);
694 aBtnLayout->addWidget(myHelpBtn);
696 /***************************************************************/
697 aMainLayout->addWidget(meshGroupLab, 0, 0);
698 aMainLayout->addWidget(myMeshGroupBtn, 0, 1);
699 aMainLayout->addWidget(myMeshGroupLine, 0, 2);
700 aMainLayout->addWidget(aTypeBox, 1, 0, 1, 3);
701 aMainLayout->addWidget(aName, 2, 0);
702 aMainLayout->addWidget(myName, 2, 2);
703 aMainLayout->addWidget(aGrpTypeBox, 3, 0, 1, 3);
704 aMainLayout->addWidget(myWGStack, 4, 0, 1, 3);
705 aMainLayout->addWidget(aColorBox, 5, 0, 1, 3);
706 aMainLayout->addWidget(aButtons, 6, 0, 1, 3);
708 /* signals and slots connections */
709 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
710 connect(myGrpTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onGrpTypeChanged(int)));
711 connect(myTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
713 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
714 connect(myElements, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
716 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
717 connect(aFilter2, SIGNAL(clicked()), this, SLOT(setFilters()));
718 connect(mySelectAll, SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
719 connect(myAllowElemsModif,SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
720 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
721 connect(myRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
722 connect(mySortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
724 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
725 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
726 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
727 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
728 connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
730 connect(myColorBtn, SIGNAL(changed( QColor )), this, SLOT(onColorChanged( QColor )));
732 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
733 connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
734 connect(myCloseBtn, SIGNAL(clicked()), this, SLOT(reject()));
735 connect(myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
738 mySMESHGUI->SetActiveDialogBox(this);
740 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
741 mySelectionMode = grpNoSelection;
743 myMeshFilter = new SMESH_TypeFilter(SMESH::MESH);
744 mySubMeshFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
745 SMESH_LogicalFilter::LO_OR,
746 /*takeOwnership=*/true);
747 myGroupFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
748 SMESH_LogicalFilter::LO_OR,
749 /*takeOwnership=*/true);
750 myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
752 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
753 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(reject()));
754 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
755 connect(mySMESHGUI, SIGNAL(SignalVisibilityChanged()), this, SLOT(onVisibilityChanged()));
756 connect(mySMESHGUI, SIGNAL(SignalActivatedViewManager()), this, SLOT(onOpenView()));
757 connect(mySMESHGUI, SIGNAL(SignalCloseView()), this, SLOT(onCloseView()));
758 rb1->setChecked(true); // VSR !!!
759 onGrpTypeChanged(0); // VSR!!!
761 if (myMesh->_is_nil() )
762 myTypeGroup->button(0)->setChecked(true);
764 onSelectAll(); //updateButtons();
767 //=================================================================================
768 // function : ~SMESHGUI_AdaptDlg()
769 // purpose : Destroys the object and frees any allocated resources
770 //=================================================================================
771 SMESHGUI_AdaptDlg::~SMESHGUI_AdaptDlg()
773 // no need to delete child widgets, Qt does it all for us
774 if ( myFilterDlg != 0 ) {
775 myFilterDlg->setParent( 0 );
778 if ( myMeshFilter ) delete myMeshFilter;
779 if ( mySubMeshFilter ) delete mySubMeshFilter;
780 if ( myGroupFilter ) delete myGroupFilter;
781 if ( myGeomFilter ) delete myGeomFilter;
784 //=================================================================================
785 // function : GetDefaultName()
786 // purpose : Get the Group Name if Create new Group
787 //=================================================================================
788 QString SMESHGUI_AdaptDlg::GetDefaultName(const QString& theOperation)
790 std::cout << "passage par GetDefaultName" << std::endl;
793 // collect all object names of SMESH component
794 _PTR(Study) aStudy = SMESH::getStudy();
796 std::set<std::string> aSet;
797 _PTR(SComponent) aMeshCompo (aStudy->FindComponent( "SMESH" ));
799 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
801 for (it->InitEx(true); it->More(); it->Next()) {
803 aSet.insert(obj->GetName());
807 // build a unique name
809 bool isUnique = false;
811 aName = theOperation + "_" + QString::number(++aNumber);
812 isUnique = (aSet.count(std::string(aName.toUtf8().constData())) == 0);
818 void SMESHGUI_AdaptDlg::setDefaultName() const
820 std::cout << "passage par setDefaultName" << std::endl;
823 QString aPrefix ="Group_";
827 aResName = aPrefix + QString::number( i++ );
828 anObj = SMESH::getStudy()->FindObject( aResName.toUtf8().constData() );
831 myName->setText(aResName);
834 //=================================================================================
837 //=================================================================================
838 void SMESHGUI_AdaptDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
840 std::cout << "passage par init (SMESH::SMESH_Mesh_ptr theMesh)" << std::endl;
841 mySelectionMgr->installFilter(myMeshFilter);
843 /* init data from current selection */
844 restoreShowEntityMode();
845 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
847 myGroup = SMESH::SMESH_Group::_nil();
848 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
849 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
851 // NPAL19389: create a group with a selection in another group
852 // set actor of myMesh, if it is visible, else try
853 // any visible actor of group or submesh of myMesh
854 SetAppropriateActor();
856 setDefaultGroupColor();
861 mySelectionMgr->selectedObjects( aList );
862 if( !aList.IsEmpty() )
864 QString aName = aList.First()->getName();
865 myMeshGroupLine->setText(aName);//??????
866 myMeshGroupLine->home( false );
869 myCurrentLineEdit = 0;
871 myTypeGroup->button(0)->setChecked(true);
875 //=================================================================================
878 //=================================================================================
879 void SMESHGUI_AdaptDlg::init (SMESH::SMESH_GroupBase_ptr theGroup)
881 std::cout << "passage par init (SMESH::SMESH_GroupBase_ptr theGroup)" << std::endl;
882 restoreShowEntityMode();
883 myMesh = theGroup->GetMesh();
886 myNameChanged = true;
887 myName->blockSignals(true);
888 myName->setText(SMESH::fromUtf8(theGroup->GetName()));
889 myName->blockSignals(false);
892 SALOMEDS::Color aColor = theGroup->GetColor();
893 setGroupColor( aColor );
895 myMeshGroupLine->setText(theGroup->GetName());
898 switch(theGroup->GetType()) {
899 case SMESH::NODE: aType = grpNodeSelection; break;
900 case SMESH::ELEM0D: aType = grp0DSelection; break;
901 case SMESH::BALL: aType = grpBallSelection; break;
902 case SMESH::EDGE: aType = grpEdgeSelection; break;
903 case SMESH::FACE: aType = grpFaceSelection; break;
904 case SMESH::VOLUME: aType = grpVolumeSelection; break;
906 case SMESH::NB_ELEMENT_TYPES: break;
908 myTypeGroup->button(aType)->setChecked(true);
910 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
911 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
912 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_narrow( theGroup );
913 myFilter = SMESH::Filter::_nil();
915 if (myGroup->_is_nil() && myGroupOnGeom->_is_nil() && myGroupOnFilter->_is_nil() )
918 // NPAL19389: create a group with a selection in another group
919 // set actor of myMesh, if it is visible, else set
920 // actor of theGroup, if it is visible, else try
921 // any visible actor of group or submesh of myMesh
922 // commented, because an attempt to set selection on not displayed cells leads to error
923 SetAppropriateActor();
925 /* SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
927 anActor = SMESH::FindActorByObject(theGroup);
928 SMESH::SetPickable(anActor);*/
929 int grpType = (!myGroup->_is_nil() ? 0 : (false ? 0 : myGroupOnGeom->_is_nil() ? 2 : 1));
930 myGrpTypeGroup->button(grpType)->setChecked(true);
931 onGrpTypeChanged(grpType);
934 if ( grpType == 0 ) { // standalone group
935 myCurrentLineEdit = 0;
937 myAllowElemsModif->setChecked( true );
939 setSelectionMode(aType);
941 setShowEntityMode(); // depends on myTypeId
944 if (!theGroup->IsEmpty()) {
945 SMESH::long_array_var anElements = theGroup->GetListOfID();
946 int k = anElements->length();
947 for (int i = 0; i < k; i++) {
948 myIdList.append(anElements[i]);
949 myElements->addItem(QString::number(anElements[i]));
951 myElements->selectAll();
954 else if ( grpType == 1 ) // group on geom
956 QString aShapeName( "" );
957 _PTR(Study) aStudy = SMESH::getStudy();
958 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
959 if (!aGroupShape->_is_nil())
961 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
963 aShapeName = aGroupShapeSO->GetName().c_str();
965 myGeomGroupLine->setText( aShapeName );
967 else // group on filter
969 myFilter = myGroupOnFilter->GetFilter();
970 if ( !myFilter->_is_nil() ) {
971 SMESH::Predicate_var perdicate = myFilter->GetPredicate();
972 if ( perdicate->_is_nil() )
973 myFilter = SMESH::Filter::_nil();
979 myNameChanged = true;
980 myName->blockSignals(true);
981 myName->setText(theGroup->GetName());
982 myName->blockSignals(false);
985 onSelectAll(); //updateButtons();
988 //=================================================================================
989 // function : updateButtons()
991 //=================================================================================
992 void SMESHGUI_AdaptDlg::updateButtons()
994 std::cout << "passage par updateButtons" << std::endl;
995 bool enable = !myName->text().trimmed().isEmpty();
998 if (myGrpTypeId == 0) { // standalone
999 if ( !mySelectAll->isChecked() )
1001 if ( myAllowElemsModif->isChecked() )
1003 enable = ( myElements->count() > 0 );
1005 else if ((enable = !myFilter->_is_nil() ))
1007 SMESH::array_of_ElementType_var types = myFilter->GetTypes();
1008 enable = types->length();
1011 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
1013 else if (myGrpTypeId == 1) // on geom
1015 if (CORBA::is_nil(myGroupOnGeom)) // creation mode
1016 enable = ( myGeomObjects->length() > 0 && !myMesh->_is_nil() );
1018 else if (myGrpTypeId == 2) // on filter
1020 if (( enable = !myFilter->_is_nil() ))
1021 if (CORBA::is_nil(myGroupOnFilter) ) // creation mode
1022 enable = !myMesh->_is_nil();
1026 bool meshHasGeom = ( myMesh->_is_nil() || myMesh->HasShapeToMesh() );
1027 if ( myGrpTypeId != 1 )
1029 myGrpTypeGroup->button(1)->setEnabled( meshHasGeom );
1033 myGeomGroupBtn->setEnabled( meshHasGeom );
1034 myGeomGroupLine->setEnabled( meshHasGeom );
1037 myOKBtn->setEnabled(enable);
1038 myApplyBtn->setEnabled(enable);
1041 //=================================================================================
1042 // function : onNameChanged()
1044 //=================================================================================
1045 void SMESHGUI_AdaptDlg::onNameChanged (const QString& text)
1047 std::cout << "passage par onNameChanged" << std::endl;
1048 myOldName = myName->text();
1050 myNameChanged = !myName->text().trimmed().isEmpty();
1053 //=================================================================================
1054 // function : onTypeChanged()
1055 // purpose : Group elements type radio button management
1056 //=================================================================================
1057 void SMESHGUI_AdaptDlg::onTypeChanged (int id)
1059 if (myTypeId != id) {
1060 myElements->clear();
1062 if ( myGrpTypeId == 0 && myCurrentLineEdit == 0)
1063 setSelectionMode(id);
1065 setSelectionMode( mySelectionMode++ ); // update according to mySelectionMode
1067 onObjectSelectionChanged();
1068 setShowEntityMode();
1072 //=================================================================================
1073 // function : onGrpTypeChanged()
1074 // purpose : Group type radio button management
1075 //=================================================================================
1076 void SMESHGUI_AdaptDlg::onGrpTypeChanged (int id)
1078 if (myGrpTypeId != id) {
1080 myWGStack->setCurrentIndex( id );
1081 myName->blockSignals(true);
1082 myName->setText(myOldName);
1083 myName->blockSignals(false);
1084 onSelectGeomGroup(id != 0);
1089 //=================================================================================
1090 // function : onColorChanged()
1091 // purpose : Color button management
1092 //=================================================================================
1093 void SMESHGUI_AdaptDlg::onColorChanged(QColor theColor)
1098 //=================================================================================
1099 // function : setSelectionMode()
1100 // purpose : Radio button management
1101 //=================================================================================
1102 void SMESHGUI_AdaptDlg::setSelectionMode (int theMode)
1105 if (myMesh->_is_nil())
1107 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
1108 bool isSelectAll = mySelectAll->isChecked() || !myAllowElemsModif->isChecked() || myGrpTypeId != 0;
1109 if (mySelectionMode != theMode) {
1110 // [PAL10408] mySelectionMgr->clearSelected();
1111 mySelectionMgr->clearFilters();
1112 SMESH::RemoveFilters();
1114 if (myActorsList.count() > 0)
1115 for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
1116 it.next()->SetPointRepresentation(false);
1118 SMESH::SetPointRepresentation(false);
1121 case grpNodeSelection:
1122 if ( myGrpTypeId == 0 ) // standalone
1124 if (myActorsList.count() > 0)
1125 for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
1126 it.next()->SetPointRepresentation(true);
1128 SMESH::SetPointRepresentation(true);
1130 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : NodeSelection);
1132 case grpEdgeSelection:
1133 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : EdgeSelection);
1135 case grpBallSelection:
1136 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : BallSelection);
1138 case grp0DSelection:
1139 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : Elem0DSelection);
1141 case grpFaceSelection:
1142 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : FaceSelection);
1144 case grpVolumeSelection:
1145 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : VolumeSelection);
1147 case grpSubMeshSelection: {
1149 SMESH_TypeFilter* f = 0;
1151 case grpNodeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH); break;
1152 case grpEdgeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_EDGE); break;
1153 case grpFaceSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_FACE); break;
1154 case grpVolumeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_SOLID); break;
1155 default: f = new SMESH_TypeFilter(SMESH::SUBMESH);
1157 QList<SUIT_SelectionFilter*> filtList;
1158 filtList.append( f );
1159 filtList.append( new SMESH_TypeFilter(SMESH::SUBMESH_COMPOUND));
1160 mySubMeshFilter->setFilters( filtList );
1162 mySelectionMgr->installFilter( mySubMeshFilter );
1164 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
1167 case grpGroupSelection: {
1169 SMESH_TypeFilter* f = 0;
1171 case grpNodeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_NODE); break;
1172 case grp0DSelection: f = new SMESH_TypeFilter(SMESH::GROUP_0D); break;
1173 case grpBallSelection: f = new SMESH_TypeFilter(SMESH::GROUP_BALL); break;
1174 case grpEdgeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_EDGE); break;
1175 case grpFaceSelection: f = new SMESH_TypeFilter(SMESH::GROUP_FACE); break;
1176 case grpVolumeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_VOLUME); break;
1177 default: f = new SMESH_TypeFilter(SMESH::GROUP);
1179 QList<SUIT_SelectionFilter*> filtList;
1180 filtList.append( f );
1181 myGroupFilter->setFilters( filtList );
1183 mySelectionMgr->installFilter(myGroupFilter);
1184 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
1187 case grpMeshSelection:
1188 mySelectionMgr->installFilter(myMeshFilter);
1189 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
1191 case grpGeomSelection:
1192 mySelectionMgr->installFilter(myGeomFilter);
1193 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
1196 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
1199 if ( aViewWindow ) aViewWindow->Repaint();
1200 mySelectionMode = theMode;
1204 //=================================================================================
1205 // function : onApply()
1207 //=================================================================================
1208 bool SMESHGUI_AdaptDlg::onApply()
1210 if (SMESHGUI::isStudyLocked())
1213 if (myName->text().trimmed().isEmpty())
1216 SMESH::ElementType aType = SMESH::ALL;
1218 case grpNodeSelection: aType = SMESH::NODE; break;
1219 case grp0DSelection: aType = SMESH::ELEM0D; break;
1220 case grpBallSelection: aType = SMESH::BALL; break;
1221 case grpEdgeSelection: aType = SMESH::EDGE; break;
1222 case grpFaceSelection: aType = SMESH::FACE; break;
1223 case grpVolumeSelection: aType = SMESH::VOLUME; break;
1226 bool anIsOk = false;
1227 QStringList anEntryList;
1229 SMESH::SMESH_GroupBase_var resultGroup;
1230 bool isCreation = false, isConversion = false;
1232 SUIT_OverrideCursor wc;
1234 if (myGrpTypeId == 0) // standalone
1236 if (!mySelectAll->isChecked() && !myElements->count() && myAllowElemsModif->isChecked())
1239 mySelectionMgr->clearSelected();
1241 if (myGroup->_is_nil()) { // creation or conversion
1242 // check if group on geometry is not null
1243 if (!myGroupOnGeom->_is_nil() || !myGroupOnFilter->_is_nil()) {
1244 if (myMesh->_is_nil())
1246 if ( myGroupOnGeom->_is_nil() )
1247 myGroup = myMesh->ConvertToStandalone( myGroupOnFilter );
1249 myGroup = myMesh->ConvertToStandalone( myGroupOnGeom );
1251 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1252 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
1253 isConversion = true;
1257 if (myGroup->_is_nil()) { // creation
1258 if (myMesh->_is_nil())
1261 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
1263 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
1266 if ( mySelectAll->isChecked() ) {
1268 myGroup->AddFrom(myMesh.in());
1273 if ( !myFilter->_is_nil() &&
1274 ( myNbChangesOfContents == 1 || !myAllowElemsModif->isChecked()))
1276 myGroup->AddFrom( myFilter );
1280 SMESH::long_array_var anIdList = new SMESH::long_array;
1281 int i, k = myElements->count();
1282 anIdList->length(k);
1283 for (i = 0; i < k; i++) {
1284 anIdList[i] = myElements->item(i)->text().toInt();
1286 myGroup->Add(anIdList.inout());
1293 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
1296 if ( mySelectAll->isChecked() ) {
1299 myGroup->AddFrom(myMesh.in());
1302 QList<int> aAddList;
1304 int i, total = myElements->count();
1305 for (i = 0; i < total; i++) {
1306 int anId = myElements->item(i)->text().toInt();
1307 int idx = myIdList.indexOf(anId);
1309 aAddList.append(anId);
1311 myIdList.removeAt(idx);
1313 if (!aAddList.empty()) {
1314 SMESH::long_array_var anIdList = new SMESH::long_array;
1315 int added = aAddList.count();
1316 anIdList->length(added);
1317 for (i = 0; i < added; i++)
1318 anIdList[i] = aAddList[i];
1319 myGroup->Add(anIdList.inout());
1321 if (!myIdList.empty()) {
1322 SMESH::long_array_var anIdList = new SMESH::long_array;
1323 int removed = myIdList.count();
1324 anIdList->length(removed);
1325 for (i = 0; i < removed; i++)
1326 anIdList[i] = myIdList[i];
1327 myGroup->Remove(anIdList.inout());
1329 /* init for next operation */
1331 for (i = 0; i < total; i++) {
1332 myIdList.append(myElements->item(i)->text().toInt());
1339 else if (myGrpTypeId == 1) // on geom object
1341 if (CORBA::is_nil(myGroupOnGeom)) { // creation
1342 if (myMesh->_is_nil() || !myGeomObjects->length())
1345 _PTR(Study) aStudy = SMESH::getStudy();
1347 if (myGeomObjects->length() == 1) {
1348 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
1349 myName->text().toUtf8(),
1353 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1354 if ( aSMESHGen->_is_nil() || myGeomObjects->length() == 0 )
1357 // create a geometry group
1358 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen( myGeomObjects[0] );
1359 if (geomGen->_is_nil())
1362 GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations();
1366 // check and add all selected GEOM objects: they must be
1367 // a sub-shapes of the main GEOM and must be of one type
1368 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1369 for ( CORBA::ULong i =0; i < myGeomObjects->length(); i++)
1371 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
1373 aGroupType = aSubShapeType;
1374 else if ( aSubShapeType != aGroupType ) {
1375 aGroupType = TopAbs_SHAPE;
1380 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
1381 GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
1382 if ( aGroupVar->_is_nil() )
1384 op->UnionList(aGroupVar, myGeomObjects);
1387 // publish the GEOM group in study
1388 QString aNewGeomGroupName ( "Auto_group_for_" );
1389 aNewGeomGroupName += myName->text();
1390 SALOMEDS::SObject_var aNewGroupSO =
1391 geomGen->AddInStudy(aGroupVar,
1392 aNewGeomGroupName.toUtf8(), aMeshShape);
1395 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
1396 myName->text().toUtf8(),
1399 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
1405 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
1410 if (myGrpTypeId == 2) // group on filter
1412 if ( myFilter->_is_nil() ) return false;
1414 if (CORBA::is_nil(myGroupOnFilter)) // creation
1416 if (myMesh->_is_nil())
1419 myGroupOnFilter = myMesh->CreateGroupFromFilter(aType,
1420 myName->text().toUtf8(),
1422 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
1427 myGroupOnFilter->SetFilter( myFilter );
1429 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
1437 SALOMEDS::Color aColor = getGroupColor();
1438 resultGroup->SetColor(aColor);
1440 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject( resultGroup );
1442 anEntryList.append( aMeshGroupSO->GetID().c_str() );
1444 resultGroup->SetName(myName->text().trimmed().toUtf8());
1448 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
1450 /* init for the next operation */
1452 myElements->clear();
1453 myGroup = SMESH::SMESH_Group::_nil();
1454 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1455 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
1456 myFilter = SMESH::Filter::_nil();
1458 setDefaultGroupColor(); // reset color for case if 'auto-color' feature is enabled.
1464 if ( SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
1466 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
1467 if ( isConversion ) { // need to reset TVisualObj and actor
1468 SMESH::RemoveVisualObjectWithActors( anIO->getEntry(), true );
1469 SMESH::Update( anIO,true);
1470 myActorsList.clear();
1471 anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1472 if ( !anActor ) return false;
1473 myActorsList.append( anActor );
1475 anActor->setName(myName->text().toUtf8());
1478 switch ( myTypeId ) {
1479 case grpNodeSelection: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
1480 case grp0DSelection: anActor->Set0DColor ( aColor.R, aColor.G, aColor.B ); break;
1481 case grpBallSelection: anActor->SetBallColor( aColor.R, aColor.G, aColor.B ); break;
1482 case grpEdgeSelection: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
1483 case grpVolumeSelection:
1484 SMESH::GetColor("SMESH", "volume_color", c , delta, "255,0,170|-100");
1485 anActor->SetVolumeColor( aColor.R, aColor.G, aColor.B, delta ); break;
1487 case grpFaceSelection:
1489 SMESH::GetColor("SMESH", "fill_color", c , delta, "0,170,255|-100");
1490 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, delta ); break;
1493 // update a visible group according to a changed contents
1494 if ( !isConversion && anActor->GetVisibility() )
1496 SMESH::Update( anIO, true );
1497 SMESH::RepaintCurrentView();
1502 SMESHGUI::Modified();
1503 mySMESHGUI->updateObjBrowser(true);
1504 mySelectionMgr->clearSelected();
1506 if( LightApp_Application* anApp =
1507 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
1508 myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
1513 //=================================================================================
1514 // function : onOK()
1516 //=================================================================================
1517 void SMESHGUI_AdaptDlg::onOK()
1519 setIsApplyAndClose( true );
1522 setIsApplyAndClose( false );
1524 if ( myFilterDlg ) myFilterDlg->UnRegisterFilters();
1527 //=================================================================================
1528 // function : onListSelectionChanged()
1529 // purpose : Called when selection in element list is changed
1530 //=================================================================================
1531 void SMESHGUI_AdaptDlg::onListSelectionChanged()
1533 //MESSAGE( "SMESHGUI_AdaptDlg::onListSelectionChanged(); myActorsList.count() = " << myActorsList.count());
1534 if( myIsBusy || myActorsList.count() == 0 ) return;
1537 if (myCurrentLineEdit == 0) {
1538 mySelectionMgr->clearSelected();
1539 TColStd_MapOfInteger aIndexes;
1540 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1541 QListWidgetItem* anItem;
1542 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
1543 mySelector->AddOrRemoveIndex(myActorsList.first()->getIO(), aIndexes, false);
1544 SALOME_ListIO aList;
1545 aList.Append(myActorsList.first()->getIO());
1546 mySelectionMgr->setSelectedObjects(aList,false);
1551 //=================================================================================
1552 // function : onObjectSelectionChanged()
1553 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1554 //=================================================================================
1555 void SMESHGUI_AdaptDlg::onObjectSelectionChanged()
1557 if ( myIsBusy || !isEnabled()) return;
1558 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
1562 SALOME_ListIO aList;
1563 mySelectionMgr->selectedObjects( aList );
1565 int aNbSel = aList.Extent();
1566 myElements->clearSelection();
1568 if (myCurrentLineEdit)
1570 myCurrentLineEdit->setText( "" );
1571 QString aString = "";
1573 if (myCurrentLineEdit == myMeshGroupLine)
1575 mySelectSubMesh->setEnabled(false);
1576 mySelectGroup->setEnabled(false);
1577 myGroupLine->setText( "" );
1578 mySubMeshLine->setText( "" );
1580 myGeomGroupBtn->setEnabled(false);
1581 myGeomGroupLine->setEnabled(false);
1582 myGeomGroupLine->setText( "" );
1583 myGeomObjects = new GEOM::ListOfGO();
1584 myGeomObjects->length(0);
1586 if (myGeomGroupBtn->isChecked())
1587 myGeomGroupBtn->setChecked(false);
1589 myName->setText( "" );
1591 myElements->clear();
1594 myGroup = SMESH::SMESH_Group::_nil();
1595 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1596 restoreShowEntityMode();
1597 myMesh = SMESH::SMESH_Mesh::_nil();
1603 Handle(SALOME_InteractiveObject) IO = aList.First();
1606 restoreShowEntityMode();
1607 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1608 setShowEntityMode();
1610 if (myMesh->_is_nil())
1617 if ( myFilterDlg && !myMesh->_is_nil()){
1618 myFilterDlg->SetMesh( myMesh );
1620 myGroup = SMESH::SMESH_Group::_nil();
1622 // NPAL19389: create a group with a selection in another group
1623 // set actor of myMesh, if it is visible, else try
1624 // any visible actor of group or submesh of myMesh
1625 SetAppropriateActor();
1627 setDefaultGroupColor();
1628 if (myName->text().isEmpty())
1631 aString = aList.First()->getName();
1632 myMeshGroupLine->setText(aString);
1633 myMeshGroupLine->home( false );
1635 mySelectSubMesh->setEnabled(true);
1636 mySelectGroup->setEnabled(true);
1637 myGeomGroupBtn->setEnabled(true);
1638 myGeomGroupLine->setEnabled(true);
1642 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1643 if (aGroup->_is_nil())
1650 myGroup = SMESH::SMESH_Group::_nil();
1651 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1655 mySelectSubMesh->setEnabled(true);
1656 mySelectGroup->setEnabled(true);
1658 myCurrentLineEdit = 0;
1663 if (myGrpTypeId == 0)
1669 myElements->clear();
1670 setSelectionMode(myTypeId);
1678 else if (myCurrentLineEdit == myGeomGroupLine)
1680 myGeomObjects = new GEOM::ListOfGO();
1683 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1685 if (aNbSel == 0 || !aMeshSO)
1687 myGeomObjects->length(0);
1693 myGeomObjects->length(aNbSel);
1695 GEOM::GEOM_Object_var aGeomGroup;
1698 SALOME_ListIteratorOfListIO anIt (aList);
1699 for (; anIt.More(); anIt.Next())
1701 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value());
1703 // Check if the object is a geometry group
1704 if (CORBA::is_nil(aGeomGroup))
1707 // Check if group constructed on the same shape as a mesh or on its child
1709 // The main shape of the group
1710 GEOM::GEOM_Object_var aGroupMainShape;
1711 if (aGeomGroup->GetType() == 37)
1713 GEOM::GEOM_IGroupOperations_wrap anOp =
1714 SMESH::GetGEOMGen( aGeomGroup )->GetIGroupOperations();
1715 aGroupMainShape = anOp->GetMainShape( aGeomGroup );
1716 // aGroupMainShape is an existing servant => GEOM_Object_var not GEOM_Object_wrap
1720 aGroupMainShape = aGeomGroup;
1721 aGroupMainShape->Register();
1723 CORBA::String_var entry = aGroupMainShape->GetStudyEntry();
1724 _PTR(SObject) aGroupMainShapeSO =
1725 SMESH::getStudy()->FindObjectID( entry.in() );
1727 _PTR(SObject) anObj, aRef;
1728 bool isRefOrSubShape = false;
1729 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1730 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1731 isRefOrSubShape = true;
1733 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1734 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1735 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1736 if (aRef->GetID() == aFather->GetID())
1737 isRefOrSubShape = true;
1739 aFather = aFather->GetFather();
1743 if (isRefOrSubShape)
1744 myGeomObjects[i++] = aGeomGroup;
1747 myGeomObjects->length(i);
1759 if (myCurrentLineEdit == mySubMeshLine)
1760 aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1761 else if (myCurrentLineEdit == myGroupLine)
1762 aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1763 else if (myCurrentLineEdit == myGeomGroupLine)
1764 aString = tr( "%1 Objects" ).arg(aNbSel);
1767 aString = aList.First()->getName();
1771 myCurrentLineEdit->setText(aString);
1772 myCurrentLineEdit->home(false);
1773 // 07.06.2008 skl for IPAL19574:
1774 // change name of group only if it is empty
1775 if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1776 myOldName = myName->text();
1777 myName->blockSignals(true);
1778 myName->setText(aString);
1779 myName->blockSignals(false);
1784 else // !myCurrentLineEdit: local selection of nodes or elements
1786 if (aNbSel == 1 && myActorsList.count() > 0 )
1788 // NPAL19389: create a group with a selection in another group
1789 // Switch myActor to the newly selected one, if the last
1790 // is visible and belongs to group or submesh of myMesh
1791 /* Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1792 Handle(SALOME_InteractiveObject) selIO = aList.First();
1793 if (curIO->hasEntry() && selIO->hasEntry()) {
1794 const char* selEntry = selIO->getEntry();
1795 if (strcmp(curIO->getEntry(), selEntry) != 0) {
1796 // different objects: selected and myActor
1797 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1798 if (aViewWindow && aViewWindow->isVisible(selIO)) {
1799 // newly selected actor is visible
1802 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1804 CORBA::String_var meshEntry = aSObject->GetID().c_str();
1805 int len = strlen(meshEntry);
1807 if (strncmp(selEntry, meshEntry, len) == 0) {
1808 // selected object is myMesh or a part of it
1809 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1812 SMESH::SetPickable(myActor);
1821 QString aListStr = "";
1823 if (myTypeId == 0) {
1824 QListIterator<SMESH_Actor*> it( myActorsList );
1825 while ( it.hasNext() ) {
1827 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1831 QListIterator<SMESH_Actor*> it( myActorsList );
1832 while ( it.hasNext() ) {
1834 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1839 QListWidgetItem* anItem;
1840 QList<QListWidgetItem*> listItemsToSel;
1841 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1842 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1843 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1844 foreach(anItem, found)
1845 if (!anItem->isSelected())
1846 listItemsToSel.push_back(anItem);
1848 bool blocked = myElements->signalsBlocked();
1849 myElements->blockSignals(true);
1850 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1851 myElements->blockSignals(blocked);
1852 onListSelectionChanged();
1853 listItemsToSel.clear();
1858 if (myActorsList.count() == 0) {
1859 if (!myGroup->_is_nil()) {
1860 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
1862 myActorsList.append( anActor );
1864 else if(!myGroupOnGeom->_is_nil()) {
1865 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
1867 myActorsList.append( anActor );
1870 SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh );
1872 myActorsList.append( anActor );
1876 // somehow, if we display the mesh, while selecting from another actor,
1877 // the mesh becomes pickable, and there is no way to select any element
1878 if (myActorsList.count() > 0) {
1879 QListIterator<SMESH_Actor*> it( myActorsList );
1880 while ( it.hasNext() ) {
1881 SMESH_Actor* anActor = it.next();
1882 if ( IsActorVisible(anActor) )
1883 anActor->SetPickable(true);
1890 //=================================================================================
1891 // function : onSelectAll()
1892 // purpose : Called when "Select all" is checked
1893 //=================================================================================
1894 void SMESHGUI_AdaptDlg::onSelectAll()
1896 bool noElemsModif = ( mySelectAll->isChecked() || !myAllowElemsModif->isChecked() );
1898 myElementsLab->setEnabled( !noElemsModif );
1899 myElements->setEnabled ( !noElemsModif );
1900 myFilterBtn->setEnabled ( !noElemsModif );
1901 myAddBtn->setEnabled ( !noElemsModif );
1902 myRemoveBtn->setEnabled ( !noElemsModif );
1903 mySortBtn->setEnabled ( !noElemsModif );
1904 mySelectBox->setEnabled ( !noElemsModif );
1905 myAllowElemsModif->setEnabled( !mySelectAll->isChecked() );
1906 if ( noElemsModif ) mySMESHGUI->ResetState();
1907 else mySMESHGUI->SetState(800);
1909 int selMode = mySelectionMode;
1910 mySelectionMode = grpNoSelection;
1911 setSelectionMode( selMode );
1915 //=================================================================================
1916 // function : onSelectSubMesh()
1917 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1918 //=================================================================================
1919 void SMESHGUI_AdaptDlg::onSelectSubMesh(bool on)
1922 if (mySelectGroup->isChecked()) {
1923 mySelectGroup->setChecked(false);
1925 //VSR: else if (mySelectGeomGroup->isChecked()) {
1926 //VSR: mySelectGeomGroup->setChecked(false);
1928 myCurrentLineEdit = mySubMeshLine;
1929 setSelectionMode(grpSubMeshSelection);
1932 mySubMeshLine->setText( "" );
1933 myCurrentLineEdit = 0;
1935 setSelectionMode(myTypeId);
1937 mySubMeshBtn->setEnabled(on);
1938 mySubMeshLine->setEnabled(on);
1942 //=================================================================================
1943 // function : (onSelectGroup)
1944 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1945 //=================================================================================
1946 void SMESHGUI_AdaptDlg::onSelectGroup(bool on)
1949 if (mySelectSubMesh->isChecked()) {
1950 mySelectSubMesh->setChecked(false);
1952 myCurrentLineEdit = myGroupLine;
1953 setSelectionMode(grpGroupSelection);
1956 myGroupLine->setText( "" );
1957 myCurrentLineEdit = 0;
1959 setSelectionMode(myTypeId);
1961 myGroupBtn->setEnabled(on);
1962 myGroupLine->setEnabled(on);
1966 //=================================================================================
1967 // function : (onSelectGeomGroup)
1968 // purpose : Called when group type changed. on == "on geometry" or "on filter"
1969 //=================================================================================
1970 void SMESHGUI_AdaptDlg::onSelectGeomGroup(bool on)
1973 if (mySelectSubMesh->isChecked()) {
1974 mySelectSubMesh->setChecked(false);
1976 else if (mySelectGroup->isChecked()) {
1977 mySelectGroup->setChecked(false);
1979 if ( myGrpTypeId == 1 ) { // on geometry
1980 myCurrentLineEdit = myGeomGroupLine;
1984 myCurrentLineEdit = 0;
1986 setSelectionMode(grpAllSelection);
1989 myGeomGroupBtn->setChecked(false);
1990 myGeomObjects->length(0);
1991 myGeomGroupLine->setText( "" );
1992 myCurrentLineEdit = 0;
1994 setSelectionMode( myTypeId );
1998 //=================================================================================
1999 // function : setCurrentSelection()
2001 //=================================================================================
2002 void SMESHGUI_AdaptDlg::setCurrentSelection()
2004 QPushButton* send = (QPushButton*)sender();
2005 myCurrentLineEdit = 0;
2006 if (send == myMeshGroupBtn) {
2007 disconnect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
2008 mySelectionMgr->clearSelected();
2010 setSelectionMode(grpMeshSelection);
2012 setSelectionMode(grpGroupSelection);
2013 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
2014 myCurrentLineEdit = myMeshGroupLine;
2015 onObjectSelectionChanged();
2017 else if (send == mySubMeshBtn) {
2018 myCurrentLineEdit = mySubMeshLine;
2019 onObjectSelectionChanged();
2021 else if (send == myGroupBtn) {
2022 myCurrentLineEdit = myGroupLine;
2023 onObjectSelectionChanged();
2028 //=================================================================================
2029 // function : setFilters()
2030 // purpose : SLOT. Called when "Filter" button pressed.
2031 //=================================================================================
2032 void SMESHGUI_AdaptDlg::setFilters()
2034 if(myMesh->_is_nil()) {
2035 SUIT_MessageBox::critical(this,
2037 tr("NO_MESH_SELECTED"));
2041 SMESH::ElementType aType = SMESH::ALL;
2044 case grpNodeSelection: aType = SMESH::NODE; break;
2045 case grp0DSelection: aType = SMESH::ELEM0D; break;
2046 case grpBallSelection: aType = SMESH::BALL; break;
2047 case grpEdgeSelection: aType = SMESH::EDGE; break;
2048 case grpFaceSelection: aType = SMESH::FACE; break;
2049 case grpVolumeSelection: aType = SMESH::VOLUME; break;
2053 if ( myFilterDlg == 0 )
2055 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
2056 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
2059 myFilterDlg->Init( aType );
2061 if ( !myGroupOnFilter->_is_nil() )
2063 myFilterDlg->SetFilter( myFilter, aType );
2064 myFilterDlg->Init( aType );
2067 bool isStandalone = ( sender() == myFilterBtn );
2068 myFilterDlg->SetEnabled( /*setInViewer=*/isStandalone,
2069 /*diffSources=*/isStandalone );
2070 myFilterDlg->SetMesh( myMesh );
2071 myFilterDlg->SetGroup( myGroupOnFilter );
2072 myFilterDlg->SetSelection();
2073 myFilterDlg->SetSourceWg( myElements, false );
2075 myFilterDlg->show();
2078 //=================================================================================
2079 // function : onFilterAccepted()
2080 // purpose : SLOT. Called when Filter dlg closed with OK button.
2081 // Uncheck "Select submesh" and "Select group" checkboxes
2082 //=================================================================================
2083 void SMESHGUI_AdaptDlg::onFilterAccepted()
2085 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
2087 mySelectionMode = myTypeId;
2088 mySelectSubMesh->setChecked( false );
2089 mySelectGroup->setChecked( false );
2091 // get a filter from myFilterDlg
2092 myFilter = myFilterDlg->GetFilter();
2093 if ( !myFilter->_is_nil() ) {
2094 SMESH::Predicate_var perdicate = myFilter->GetPredicate();
2095 if ( perdicate->_is_nil() )
2096 myFilter = SMESH::Filter::_nil();
2098 // set mesh to myFilter
2099 if ( !myFilter->_is_nil() ) {
2100 SMESH::SMESH_Mesh_var mesh = myMesh;
2101 if ( mesh->_is_nil() ) {
2102 if ( !myGroup->_is_nil() )
2103 mesh = myGroup->GetMesh();
2104 else if ( !myGroupOnGeom->_is_nil() )
2105 mesh = myGroupOnGeom->GetMesh();
2106 else if ( !myGroupOnFilter->_is_nil() )
2107 mesh = myGroupOnFilter->GetMesh();
2109 myFilter->SetMesh( mesh );
2111 // highlight ids if selection changed in the Viewer (IPAL52924)
2112 myCurrentLineEdit = 0;
2113 onObjectSelectionChanged();
2119 //=================================================================================
2120 // function : onAdd()
2122 //=================================================================================
2123 void SMESHGUI_AdaptDlg::onAdd()
2125 SALOME_ListIO aList;
2126 mySelectionMgr->selectedObjects( aList );
2128 int aNbSel = aList.Extent();
2130 if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return;
2132 SUIT_OverrideCursor wc;
2135 int sizeBefore = myElements->count();
2137 SMESH::ElementType aType = SMESH::ALL;
2139 case grpNodeSelection:
2140 aType = SMESH::NODE;
2141 mySelector->SetSelectionMode(NodeSelection);
2143 case grpBallSelection:
2144 aType = SMESH::BALL;
2145 mySelector->SetSelectionMode(BallSelection);
2147 case grp0DSelection:
2148 aType = SMESH::ELEM0D;
2149 mySelector->SetSelectionMode(Elem0DSelection);
2151 case grpEdgeSelection:
2152 aType = SMESH::EDGE;
2153 mySelector->SetSelectionMode(EdgeSelection);
2155 case grpFaceSelection:
2156 aType = SMESH::FACE;
2157 mySelector->SetSelectionMode(FaceSelection);
2159 case grpVolumeSelection:
2160 aType = SMESH::VOLUME;
2161 mySelector->SetSelectionMode(VolumeSelection);
2164 mySelector->SetSelectionMode(ActorSelection);
2167 QListWidgetItem* anItem = 0;
2168 QList<QListWidgetItem*> listItemsToSel;
2170 if ( myCurrentLineEdit == 0 )
2172 //if (aNbSel != 1) { myIsBusy = false; return; }
2173 QString aListStr = "";
2175 if (myTypeId == 0) {
2176 QListIterator<SMESH_Actor*> it( myActorsList );
2177 while ( it.hasNext() ) {
2179 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
2184 QListIterator<SMESH_Actor*> it( myActorsList );
2185 while ( it.hasNext() ) {
2187 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
2192 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
2193 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
2194 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
2195 if (found.count() == 0) {
2196 anItem = new QListWidgetItem(*it);
2197 myElements->addItem(anItem);
2198 if (!anItem->isSelected())
2199 listItemsToSel.push_back(anItem);
2202 foreach(anItem, found)
2203 if (!anItem->isSelected())
2204 listItemsToSel.push_back(anItem);
2207 bool blocked = myElements->signalsBlocked();
2208 myElements->blockSignals(true);
2209 foreach(anItem, listItemsToSel) anItem->setSelected(true);
2210 myElements->blockSignals(blocked);
2211 onListSelectionChanged();
2212 listItemsToSel.clear();
2215 else if ( myCurrentLineEdit == mySubMeshLine )
2217 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2219 SALOME_ListIO aList;
2220 mySelectionMgr->selectedObjects( aList );
2222 SALOME_ListIteratorOfListIO anIt (aList);
2223 for ( ; anIt.More(); anIt.Next()) {
2224 SMESH::SMESH_subMesh_var aSubMesh =
2225 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
2226 if (!aSubMesh->_is_nil()) {
2227 // check if mesh is the same
2228 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
2230 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
2231 int k = anElements->length();
2232 for (int i = 0; i < k; i++) {
2233 QString aText = QString::number(anElements[i]);
2234 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
2235 if (found.count() == 0) {
2236 anItem = new QListWidgetItem(aText);
2237 myElements->addItem(anItem);
2238 if (!anItem->isSelected())
2239 listItemsToSel.push_back(anItem);
2242 foreach(anItem, found)
2243 if (!anItem->isSelected())
2244 listItemsToSel.push_back(anItem);
2247 bool blocked = myElements->signalsBlocked();
2248 myElements->blockSignals(true);
2249 foreach(anItem, listItemsToSel) anItem->setSelected(true);
2250 myElements->blockSignals(blocked);
2251 onListSelectionChanged();
2252 listItemsToSel.clear();
2254 catch (const SALOME::SALOME_Exception& ex) {
2255 SalomeApp_Tools::QtCatchCorbaException(ex);
2260 mySelectSubMesh->setChecked(false);
2262 onListSelectionChanged();
2265 else if ( myCurrentLineEdit == myGroupLine )
2267 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2268 SALOME_ListIO aList;
2269 mySelectionMgr->selectedObjects( aList );
2271 SALOME_ListIteratorOfListIO anIt (aList);
2272 for ( ; anIt.More(); anIt.Next()) {
2273 SMESH::SMESH_GroupBase_var aGroup =
2274 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
2275 if (!aGroup->_is_nil()) {
2276 // check if mesh is the same
2277 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
2278 SMESH::long_array_var anElements = aGroup->GetListOfID();
2279 int k = anElements->length();
2280 for (int i = 0; i < k; i++) {
2281 QString aText = QString::number(anElements[i]);
2282 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
2283 if (found.count() == 0) {
2284 anItem = new QListWidgetItem(aText);
2285 myElements->addItem(anItem);
2286 if (!anItem->isSelected())
2287 listItemsToSel.push_back(anItem);
2290 foreach(anItem, found)
2291 if (!anItem->isSelected())
2292 listItemsToSel.push_back(anItem);
2295 bool blocked = myElements->signalsBlocked();
2296 myElements->blockSignals(true);
2297 foreach(anItem, listItemsToSel) anItem->setSelected(true);
2298 myElements->blockSignals(blocked);
2299 onListSelectionChanged();
2300 listItemsToSel.clear();
2304 mySelectGroup->setChecked(false);
2306 onListSelectionChanged();
2309 else if ( myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1 )
2311 GEOM::GEOM_IGroupOperations_wrap aGroupOp =
2312 SMESH::GetGEOMGen( myGeomObjects[0] )->GetIGroupOperations();
2314 SMESH::ElementType aGroupType = SMESH::ALL;
2315 switch(aGroupOp->GetType(myGeomObjects[0])) {
2316 case TopAbs_VERTEX: aGroupType = SMESH::NODE; break;
2317 case TopAbs_EDGE: aGroupType = SMESH::EDGE; break;
2318 case TopAbs_FACE: aGroupType = SMESH::FACE; break;
2319 case TopAbs_SOLID: aGroupType = SMESH::VOLUME; break;
2320 default: myIsBusy = false; return;
2323 if (aGroupType == aType) {
2324 _PTR(SObject) aGroupSO =
2325 //SMESH::getStudy()->FindObjectIOR(SMESH::getStudy()->ConvertObjectToIOR(myGeomGroup));
2326 SMESH::getStudy()->FindObjectID(myGeomObjects[0]->GetStudyEntry());
2328 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
2329 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
2330 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();
2331 aBelongToGeom->SetGeom(myGeomObjects[0]);
2332 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
2333 aBelongToGeom->SetElementType(aType);
2334 aFilter->SetPredicate(aBelongToGeom);
2336 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
2338 int k = anElements->length();
2339 for (int i = 0; i < k; i++) {
2340 QString aText = QString::number(anElements[i]);
2341 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
2342 if (found.count() == 0) {
2343 anItem = new QListWidgetItem(aText);
2344 myElements->addItem(anItem);
2345 if (!anItem->isSelected())
2346 listItemsToSel.push_back(anItem);
2349 foreach(anItem, found)
2350 if (!anItem->isSelected())
2351 listItemsToSel.push_back(anItem);
2354 bool blocked = myElements->signalsBlocked();
2355 myElements->blockSignals(true);
2356 foreach(anItem, listItemsToSel) anItem->setSelected(true);
2357 myElements->blockSignals(blocked);
2358 onListSelectionChanged();
2359 listItemsToSel.clear();
2362 //VSR: mySelectGeomGroup->setChecked(false);
2364 onListSelectionChanged();
2367 if ( sizeBefore < myElements->count() )
2368 ++myNbChangesOfContents;
2369 // mySelectionMgr->clearSelected();
2373 //=================================================================================
2374 // function : onRemove()
2376 //=================================================================================
2377 void SMESHGUI_AdaptDlg::onRemove()
2380 int sizeBefore = myElements->count();
2382 if (myCurrentLineEdit == 0) {
2383 QList<QListWidgetItem*> selItems = myElements->selectedItems();
2384 QListWidgetItem* item;
2385 foreach(item, selItems) delete item;
2387 SALOME_ListIO aList;
2388 mySelectionMgr->selectedObjects( aList );
2390 int aNbSel = aList.Extent();
2392 if (aNbSel == 0) { myIsBusy = false; return; }
2394 SMESH::ElementType aType = SMESH::ALL;
2396 case grpNodeSelection: aType = SMESH::NODE; break;
2397 case grp0DSelection: aType = SMESH::ELEM0D; break;
2398 case grpBallSelection: aType = SMESH::BALL; break;
2399 case grpEdgeSelection: aType = SMESH::EDGE; break;
2400 case grpFaceSelection: aType = SMESH::FACE; break;
2401 case grpVolumeSelection: aType = SMESH::VOLUME; break;
2404 if (myCurrentLineEdit == mySubMeshLine) {
2405 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2406 SALOME_ListIO aList;
2407 mySelectionMgr->selectedObjects( aList );
2409 SALOME_ListIteratorOfListIO anIt (aList);
2410 for ( ; anIt.More(); anIt.Next()) {
2411 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
2412 if (!aSubMesh->_is_nil()) {
2413 // check if mesh is the same
2414 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
2415 if (aType == SMESH::NODE) {
2417 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
2418 int k = anElements->length();
2419 for (int i = 0; i < k; i++) {
2420 QList<QListWidgetItem*> found =
2421 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2422 QListWidgetItem* anItem;
2423 foreach(anItem, found) delete anItem;
2426 catch (const SALOME::SALOME_Exception& ex) {
2427 SalomeApp_Tools::QtCatchCorbaException(ex);
2432 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
2433 int k = anElements->length();
2434 for (int i = 0; i < k; i++) {
2435 QList<QListWidgetItem*> found =
2436 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2437 QListWidgetItem* anItem;
2438 foreach(anItem, found) delete anItem;
2441 catch (const SALOME::SALOME_Exception& ex) {
2442 SalomeApp_Tools::QtCatchCorbaException(ex);
2449 else if (myCurrentLineEdit == myGroupLine) {
2450 SALOME_ListIO aList;
2451 mySelectionMgr->selectedObjects( aList );
2453 SALOME_ListIteratorOfListIO anIt (aList);
2454 for ( ; anIt.More(); anIt.Next()) {
2455 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
2456 if (!aGroup->_is_nil()) {
2457 // check if mesh is the same
2458 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
2459 SMESH::long_array_var anElements = aGroup->GetListOfID();
2460 int k = anElements->length();
2461 for (int i = 0; i < k; i++) {
2462 QList<QListWidgetItem*> found =
2463 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2464 QListWidgetItem* anItem;
2465 foreach(anItem, found) delete anItem;
2473 if ( sizeBefore > myElements->count() )
2474 myNbChangesOfContents += 2; // it's used to detect that "Add" was only once
2478 //=================================================================================
2479 // function : onSort()
2481 //=================================================================================
2482 void SMESHGUI_AdaptDlg::onSort()
2484 // PAL5412: sorts items in ascending by "string" value
2485 // myElements->sort(true);
2486 // myElements->update();
2487 int i, k = myElements->count();
2490 QList<int> aSelected;
2491 std::vector<int> anArray(k);
2492 // QMemArray<int> anArray(k);
2494 for (i = 0; i < k; i++) {
2495 int id = myElements->item(i)->text().toInt();
2497 if (myElements->item(i)->isSelected())
2498 aSelected.append(id);
2500 // sort & update list
2501 std::sort(anArray.begin(), anArray.end());
2503 myElements->clear();
2504 QListWidgetItem* anItem;
2505 QList<QListWidgetItem*> listItemsToSel;
2506 for (i = 0; i < k; i++) {
2507 anItem = new QListWidgetItem(QString::number(anArray[i]));
2508 myElements->addItem(anItem);
2509 if (aSelected.contains(anArray[i]))
2510 listItemsToSel.push_back(anItem);
2512 bool blocked = myElements->signalsBlocked();
2513 myElements->blockSignals(true);
2514 foreach(anItem, listItemsToSel) anItem->setSelected(true);
2515 myElements->blockSignals(blocked);
2516 listItemsToSel.clear();
2521 //=================================================================================
2522 // function : onVisibilityChanged()
2524 //=================================================================================
2525 void SMESHGUI_AdaptDlg::onVisibilityChanged()
2527 SetAppropriateActor();
2530 //=================================================================================
2531 // function : SMESHGUI_AdaptDlg::reject
2532 // purpose : SLOT called when "Close" button pressed. Close dialog
2533 //=================================================================================
2534 void SMESHGUI_AdaptDlg::reject()
2536 if (SMESH::GetCurrentVtkView()) {
2537 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
2538 SMESH::SetPointRepresentation(false);
2539 SMESH::SetPickable();
2540 restoreShowEntityMode();
2543 if( isApplyAndClose() && !myObjectToSelect.isEmpty() ) {
2544 SUIT_DataOwnerPtrList aList;
2545 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
2546 mySelectionMgr->setSelected( aList );
2549 mySelectionMgr->clearSelected();
2550 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2551 aViewWindow->SetSelectionMode(ActorSelection);
2552 mySelectionMgr->clearFilters();
2553 mySMESHGUI->ResetState();
2557 if ( myFilterDlg ) myFilterDlg->UnRegisterFilters();
2560 //=================================================================================
2561 // function : onOpenView()
2563 //=================================================================================
2564 void SMESHGUI_AdaptDlg::onOpenView()
2567 SMESH::SetPointRepresentation(false);
2570 mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
2571 mySMESHGUI->EmitSignalDeactivateDialog();
2576 //=================================================================================
2577 // function : onCloseView()
2579 //=================================================================================
2580 void SMESHGUI_AdaptDlg::onCloseView()
2586 //=================================================================================
2587 // function : onHelp()
2589 //=================================================================================
2590 void SMESHGUI_AdaptDlg::onHelp()
2592 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2595 app->onHelpContextModule
2596 ( mySMESHGUI ? app->moduleName( mySMESHGUI->moduleName() ) : QString(""), myHelpFileName );
2601 QString platform = "winapplication";
2603 QString platform = "application";
2605 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
2606 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
2607 arg(app->resourceMgr()->stringValue( "ExternalBrowser", platform)).
2608 arg(myHelpFileName));
2612 //=================================================================================
2613 // function : SMESHGUI_AdaptDlg::onDeactivate
2614 // purpose : SLOT called when dialog must be deactivated
2615 //=================================================================================
2616 void SMESHGUI_AdaptDlg::onDeactivate()
2618 mySMESHGUI->ResetState();
2622 //=================================================================================
2623 // function : SMESHGUI_AdaptDlg::enterEvent
2624 // purpose : Event filter
2625 //=================================================================================
2626 void SMESHGUI_AdaptDlg::enterEvent (QEvent*)
2629 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
2630 if ( aViewWindow && !mySelector) {
2631 mySelector = aViewWindow->GetSelector();
2633 mySMESHGUI->EmitSignalDeactivateDialog();
2635 mySelectionMode = grpNoSelection;
2636 setSelectionMode(myTypeId);
2637 mySMESHGUI->SetActiveDialogBox(this);
2638 if ( mySelectBox->isEnabled() ) mySMESHGUI->SetState(800);
2639 else mySMESHGUI->ResetState();
2643 //=================================================================================
2644 // function : keyPressEvent()
2646 //=================================================================================
2647 void SMESHGUI_AdaptDlg::keyPressEvent( QKeyEvent* e )
2649 QDialog::keyPressEvent( e );
2650 if ( e->isAccepted() )
2653 if ( e->key() == Qt::Key_F1 )
2660 //================================================================================
2662 * \brief Enable showing of the popup when Geometry selection btn is clicked
2663 * \param enable - true to enable
2665 //================================================================================
2667 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
2669 void SMESHGUI_AdaptDlg::updateGeomPopup()
2671 bool enable = false;
2673 if ( !myMesh->_is_nil() )
2674 enable = myMesh->NbEdges() > 0;
2676 if ( myGeomGroupBtn )
2678 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2680 if ( !myGeomPopup ) {
2681 myGeomPopup = new QMenu(this);
2682 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
2683 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
2684 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
2686 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2692 //=================================================================================
2693 // function : onGeomSelectionButton()
2695 //=================================================================================
2696 void SMESHGUI_AdaptDlg::onGeomSelectionButton(bool isBtnOn)
2698 if ( myGeomPopup && isBtnOn )
2700 myCurrentLineEdit = myGeomGroupLine;
2701 QAction* a = myGeomPopup->exec( QCursor::pos() );
2702 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
2703 setSelectionMode(grpGeomSelection);
2707 myCurrentLineEdit = 0;
2708 setSelectionMode(grpAllSelection);
2712 //=================================================================================
2713 // function : onGeomPopup()
2715 //=================================================================================
2716 void SMESHGUI_AdaptDlg::onGeomPopup( QAction* a )
2718 int index = myActions[a];
2719 if ( index == GEOM_BY_MESH_INDEX )
2721 mySelectionMode = grpNoSelection;
2722 if ( !myShapeByMeshOp ) {
2723 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
2724 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2725 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2726 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2727 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2729 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2730 if ( !myMesh->_is_nil() ) {
2732 hide(); // stop processing selection
2734 myShapeByMeshOp->setModule( mySMESHGUI );
2735 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2736 myShapeByMeshOp->SetMesh( myMesh );
2737 myShapeByMeshOp->start();
2742 //================================================================================
2744 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2746 //================================================================================
2748 void SMESHGUI_AdaptDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2750 if ( myShapeByMeshOp == op ) {
2751 mySMESHGUI->getApp()->updateObjectBrowser();
2753 // Select a found geometry object
2754 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2755 if ( !aGeomVar->_is_nil() )
2757 QString ID = aGeomVar->GetStudyEntry();
2758 if ( _PTR(SObject) aGeomSO = SMESH::getStudy()->FindObjectID( ID.toLatin1().data() )) {
2759 SALOME_ListIO anIOList;
2760 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2761 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2762 anIOList.Append( anIO );
2763 mySelectionMgr->setSelectedObjects( anIOList, false );
2764 onObjectSelectionChanged();
2770 //================================================================================
2772 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2774 //================================================================================
2776 void SMESHGUI_AdaptDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2778 if ( myShapeByMeshOp == op )
2781 setSelectionMode(grpGeomSelection);
2785 //=================================================================================
2786 // function : setGroupColor()
2788 //=================================================================================
2789 void SMESHGUI_AdaptDlg::setGroupColor( const SALOMEDS::Color& theColor )
2791 QColor aQColor( (int)( theColor.R * 255.0 ),
2792 (int)( theColor.G * 255.0 ),
2793 (int)( theColor.B * 255.0 ) );
2794 setGroupQColor( aQColor );
2797 //=================================================================================
2798 // function : getGroupColor()
2800 //=================================================================================
2801 SALOMEDS::Color SMESHGUI_AdaptDlg::getGroupColor() const
2803 QColor aQColor = getGroupQColor();
2805 SALOMEDS::Color aColor;
2806 aColor.R = (float)aQColor.red() / 255.0;
2807 aColor.G = (float)aQColor.green() / 255.0;
2808 aColor.B = (float)aQColor.blue() / 255.0;
2813 //=================================================================================
2814 // function : setGroupQColor()
2816 //=================================================================================
2817 void SMESHGUI_AdaptDlg::setGroupQColor( const QColor& theColor )
2819 if( theColor.isValid() )
2820 myColorBtn->setColor( theColor );
2823 //=================================================================================
2824 // function : getGroupQColor()
2826 //=================================================================================
2827 QColor SMESHGUI_AdaptDlg::getGroupQColor() const
2829 return myColorBtn->color();
2832 //=================================================================================
2833 // function : setDefaultGroupColor()
2835 //=================================================================================
2836 void SMESHGUI_AdaptDlg::setDefaultGroupColor()
2838 if( myMesh->_is_nil() )
2841 bool isAutoColor = myMesh->GetAutoColor();
2843 QColor aQColor = myColorBtn->color();
2846 if ( !aQColor.isValid() ) {
2847 int r = 0, g = 0, b = 0;
2848 SMESH::GetColor( "SMESH", "default_grp_color", r, g, b, QColor( 255, 170, 0 ) );
2849 aQColor.setRgb( r, g, b );
2854 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2855 SALOMEDS::Color aColor = SMESHGUI::getPredefinedUniqueColor();
2856 #else // old algorithm for auto-colors
2857 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2859 QList<SALOMEDS::Color> aReservedColors;
2860 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2862 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2863 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2864 aReservedColors.append( aReservedColor );
2867 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2868 #endif // SIMPLE_AUTOCOLOR
2870 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2871 (int)( aColor.G * 255.0 ),
2872 (int)( aColor.B * 255.0 ) );
2876 setGroupQColor( aQColor );
2879 //=================================================================================
2880 // function : SetAppropriateActor()
2881 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2882 // NPAL19389: create a group with a selection in another group.
2883 // if mesh actor is not visible - find any first visible group or sub-mesh
2884 //=================================================================================
2885 bool SMESHGUI_AdaptDlg::SetAppropriateActor()
2887 bool isActor = false;
2888 myActorsList.clear();
2890 if (myMesh->_is_nil()) return false;
2892 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2894 if (myGrpTypeGroup->checkedId() > 0) { // try current group on geometry actor
2895 SMESH_Actor* anActor = 0;
2896 if (!myGroupOnGeom->_is_nil())
2897 anActor = SMESH::FindActorByObject(myGroupOnGeom);
2898 if (!myGroupOnFilter->_is_nil())
2899 anActor = SMESH::FindActorByObject(myGroupOnFilter);
2900 if (anActor && anActor->hasIO())
2903 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2906 myActorsList.append(anActor);
2912 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2913 if (anActor && anActor->hasIO()) {
2915 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2918 myActorsList.append(anActor);
2922 SMESH_Actor* aGroupActor = 0;
2923 if (!isActor && !myGroup->_is_nil()) {
2924 aGroupActor = SMESH::FindActorByObject(myGroup);
2925 if (aGroupActor && aGroupActor->hasIO())
2926 myActorsList.append(aGroupActor);
2929 // try any visible actor of group or sub-mesh of current mesh
2932 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2934 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2935 int len = strlen(meshEntry);
2937 // iterate on all actors in current view window, search for
2938 // any visible actor, that belongs to group or submesh of current mesh
2939 VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
2940 vtkActorCollection *aCollection = aCopy.GetActors();
2941 int nbItems = aCollection->GetNumberOfItems();
2942 for (int i=0; i<nbItems && !isActor; i++)
2944 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
2945 if (anActor && anActor->hasIO()) {
2946 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2947 if (aViewWindow->isVisible(anIO)) {
2948 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0 && !myActorsList.contains(anActor) )
2949 myActorsList.append(anActor);
2956 // Show a standalone group if nothing else is visible (IPAL52227)
2957 if ( myActorsList.count() == 1 &&
2958 myActorsList[0] == aGroupActor &&
2959 aViewWindow && !aViewWindow->isVisible(aGroupActor->getIO()))
2960 SMESH::UpdateView( aViewWindow, SMESH::eDisplay, aGroupActor->getIO()->getEntry() );
2964 if (myActorsList.count() > 0) {
2965 QListIterator<SMESH_Actor*> it( myActorsList );
2966 while ( it.hasNext() ) {
2967 SMESH_Actor* anActor = it.next();
2968 if ( IsActorVisible(anActor) )
2969 anActor->SetPickable(true);
2973 return ( isActor || (myActorsList.count() > 0) );
2976 //=======================================================================
2977 //function : setShowEntityMode
2978 //purpose : make shown only entity corresponding to my type
2979 //=======================================================================
2980 void SMESHGUI_AdaptDlg::setShowEntityMode()
2982 if ( !myMesh->_is_nil() ) {
2983 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2984 if (!myStoredShownEntity)
2985 myStoredShownEntity = actor->GetEntityMode();
2986 switch ( myTypeId ) {
2987 case grpNodeSelection: restoreShowEntityMode(); break;
2988 case grp0DSelection: actor->SetEntityMode( SMESH_Actor::e0DElements ); break;
2989 case grpBallSelection: actor->SetEntityMode( SMESH_Actor::eBallElem ); break;
2990 case grpEdgeSelection: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2991 case grpFaceSelection: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2992 case grpVolumeSelection: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2998 //=======================================================================
2999 //function : restoreShowEntityMode
3000 //purpose : restore ShowEntity mode of myActor
3001 //=======================================================================
3002 void SMESHGUI_AdaptDlg::restoreShowEntityMode()
3004 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
3005 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
3006 actor->SetEntityMode(myStoredShownEntity);
3009 myStoredShownEntity = 0;
3012 //=======================================================================
3013 //function : IsActorVisible
3014 //purpose : return visibility of the actor
3015 //=======================================================================
3016 bool SMESHGUI_AdaptDlg::IsActorVisible( SMESH_Actor* theActor )
3018 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
3019 if (theActor && aViewWindow)
3020 return aViewWindow->isVisible(theActor->getIO());
3024 //================================================================
3025 //function : setIsApplyAndClose
3026 //purpose : Set value of the flag indicating that the dialog is
3027 // accepted by Apply & Close button
3028 //================================================================
3029 void SMESHGUI_AdaptDlg::setIsApplyAndClose( const bool theFlag )
3031 myIsApplyAndClose = theFlag;
3034 //================================================================
3035 //function : isApplyAndClose
3036 //purpose : Get value of the flag indicating that the dialog is
3037 // accepted by Apply & Close button
3038 //================================================================
3039 bool SMESHGUI_AdaptDlg::isApplyAndClose() const
3041 return myIsApplyAndClose;