1 // Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESHGUI_CopyMeshDlg.cxx
24 #include "SMESHGUI_CopyMeshDlg.h"
27 #include "SMESHGUI_FilterDlg.h"
28 #include "SMESHGUI_GEOMGenUtils.h"
29 #include "SMESHGUI_IdValidator.h"
30 #include "SMESHGUI_MeshUtils.h"
31 #include "SMESHGUI_Selection.h"
32 #include "SMESHGUI_SpinBox.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESHGUI_VTKUtils.h"
36 #include <SMESH_Actor.h>
37 #include <SMESH_TypeFilter.hxx>
38 #include <SMDS_Mesh.hxx>
40 // SALOME GUI includes
41 #include <LightApp_Application.h>
42 #include <LightApp_SelectionMgr.h>
43 #include <SALOME_ListIO.hxx>
44 #include <SUIT_Desktop.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_OverrideCursor.h>
47 #include <SUIT_ResourceMgr.h>
48 #include <SUIT_Session.h>
49 #include <SVTK_ViewModel.h>
50 #include <SVTK_ViewWindow.h>
51 #include <SalomeApp_Tools.h>
53 // SALOME KERNEL includes
54 #include <SALOMEDSClient_Study.hxx>
55 #include <SALOMEDSClient_SObject.hxx>
58 #include <TColStd_MapOfInteger.hxx>
61 #include <QApplication>
62 #include <QButtonGroup>
66 #include <QPushButton>
67 #include <QRadioButton>
69 #include <QHBoxLayout>
70 #include <QVBoxLayout>
71 #include <QGridLayout>
76 #include <SALOMEconfig.h>
77 #include CORBA_SERVER_HEADER(SMESH_Group)
78 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
82 \brief Simple 'busy state' flag locker.
91 //! Constructor. Sets passed boolean flag to \c true.
92 BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
93 //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
94 ~BusyLocker() { myBusy = false; }
96 bool& myBusy; //! External 'busy state' boolean flag
104 //================================================================================
108 //================================================================================
110 SMESHGUI_CopyMeshDlg::SMESHGUI_CopyMeshDlg( SMESHGUI* theModule )
111 : QDialog( SMESH::GetDesktop( theModule ) ),
112 mySMESHGUI( theModule ),
113 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
114 mySelectedObject(SMESH::SMESH_IDSource::_nil()),
116 myIsApplyAndClose( false )
118 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_COPY_MESH")));
119 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_COPY_MESH_WG")));
122 setAttribute(Qt::WA_DeleteOnClose, true);
123 setWindowTitle(tr("SMESH_COPY_MESH_TITLE"));
124 setSizeGripEnabled(true);
126 QVBoxLayout* SMESHGUI_CopyMeshDlgLayout = new QVBoxLayout(this);
127 SMESHGUI_CopyMeshDlgLayout->setSpacing(SPACING);
128 SMESHGUI_CopyMeshDlgLayout->setMargin(MARGIN);
130 /***************************************************************/
131 ConstructorsBox = new QGroupBox(tr("SMESH_COPY_MESH_TITLE"), this);
132 GroupConstructors = new QButtonGroup(this);
133 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
134 ConstructorsBoxLayout->setSpacing(SPACING);
135 ConstructorsBoxLayout->setMargin(MARGIN);
137 QRadioButton* RadioButton1= new QRadioButton(ConstructorsBox);
138 RadioButton1->setIcon(image1);
139 GroupConstructors->addButton(RadioButton1, 0);
140 QRadioButton* RadioButton2= new QRadioButton(ConstructorsBox);
141 RadioButton2->setIcon(image2);
142 GroupConstructors->addButton(RadioButton2, 1);
144 ConstructorsBoxLayout->addWidget(RadioButton1);
145 ConstructorsBoxLayout->addWidget(RadioButton2);
146 RadioButton1->setChecked(true);
148 /***************************************************************/
149 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
150 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
151 GroupArgumentsLayout->setSpacing(SPACING);
152 GroupArgumentsLayout->setMargin(MARGIN);
154 myIdValidator = new SMESHGUI_IdValidator(this);
156 // Controls for idSource/elements selection
157 myTextLabelElements = new QLabel(tr("OBJECT_NAME"), GroupArguments);
158 myLineEditElements = new QLineEdit(GroupArguments);
159 myLineEditElements->setValidator(myIdValidator);
160 myLineEditElements->setMaxLength(-1);
161 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
162 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
164 // Control for the mesh objects selection
165 myIdSourceCheck = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
167 // Name of a mesh to create
168 QLabel* meshNameLabel = new QLabel(tr("NEW_NAME"), GroupArguments);
169 myMeshNameEdit = new QLineEdit(GroupArguments);
171 // CheckBox for copying groups
172 myCopyGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
173 myCopyGroupsCheck->setChecked(true);
175 // CheckBox for keeping ids ( OBSOLETE )
176 myKeepIdsCheck = new QCheckBox(tr("SMESH_KEEP_IDS"), GroupArguments);
177 myKeepIdsCheck->setChecked(true);
178 myKeepIdsCheck->hide();
181 myGeomLabel = new QLabel( tr("NEW_GEOM"), GroupArguments );
182 myGeomNameEdit = new QLineEdit( GroupArguments );
183 myGeomNameEdit->setReadOnly(true);
185 // CheckBox to reuse hypotheses
186 myReuseHypCheck = new QCheckBox(tr("REUSE_HYPOTHESES"), GroupArguments);
187 myReuseHypCheck->setChecked(true);
189 // CheckBox to copy mesh elements
190 myCopyElementsCheck = new QCheckBox(tr("COPY_ELEMENTS"), GroupArguments);
191 myCopyElementsCheck->setChecked(true);
194 GroupArgumentsLayout->addWidget(myTextLabelElements, 0, 0);
195 GroupArgumentsLayout->addWidget(myLineEditElements, 0, 1, 1, 5);
196 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 6);
197 GroupArgumentsLayout->addWidget(myIdSourceCheck, 1, 0, 1, 6);
198 GroupArgumentsLayout->addWidget(meshNameLabel, 2, 0);
199 GroupArgumentsLayout->addWidget(myMeshNameEdit, 2, 1, 1, 5);
200 GroupArgumentsLayout->addWidget(myGeomLabel, 3, 0);
201 GroupArgumentsLayout->addWidget(myGeomNameEdit, 3, 1, 1, 5);
202 GroupArgumentsLayout->addWidget(myCopyGroupsCheck, 4, 0, 1, 6);
203 GroupArgumentsLayout->addWidget(myReuseHypCheck, 5, 0, 1, 6);
204 GroupArgumentsLayout->addWidget(myCopyElementsCheck, 6, 0, 1, 6);
205 // GroupArgumentsLayout->addWidget(myKeepIdsCheck, 7, 0, 1, 6);
206 GroupArgumentsLayout->setRowStretch( 6, 1 );
208 /***************************************************************/
209 GroupButtons = new QGroupBox(this);
210 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
211 GroupButtonsLayout->setSpacing(SPACING);
212 GroupButtonsLayout->setMargin(MARGIN);
214 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
215 buttonOk->setAutoDefault(true);
216 buttonOk->setDefault(true);
217 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
218 buttonApply->setAutoDefault(true);
219 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
220 buttonCancel->setAutoDefault(true);
221 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
222 buttonHelp->setAutoDefault(true);
224 GroupButtonsLayout->addWidget(buttonOk);
225 GroupButtonsLayout->addSpacing(10);
226 GroupButtonsLayout->addWidget(buttonApply);
227 GroupButtonsLayout->addSpacing(10);
228 GroupButtonsLayout->addStretch();
229 GroupButtonsLayout->addWidget(buttonCancel);
230 GroupButtonsLayout->addWidget(buttonHelp);
232 /***************************************************************/
233 SMESHGUI_CopyMeshDlgLayout->addWidget(ConstructorsBox);
234 SMESHGUI_CopyMeshDlgLayout->addWidget(GroupArguments);
235 SMESHGUI_CopyMeshDlgLayout->addWidget(GroupButtons);
237 /* Initialisations */
238 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
240 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
243 myIdSourceFilter = new SMESH_TypeFilter( SMESH::IDSOURCE );
245 myHelpFileName = "copy_mesh.html";
249 /* signals and slots connections */
250 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
251 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
252 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
253 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
255 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()),
256 this, SLOT (DeactivateActiveDialog()));
257 connect(mySelectionMgr, SIGNAL (currentSelectionChanged()),
258 this, SLOT (SelectionIntoArgument()));
259 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()),/* to close dialog if study change */
260 this, SLOT (reject()));
261 connect(mySMESHGUI, SIGNAL (SignalActivatedViewManager()),
262 this, SLOT (onOpenView()));
263 connect(mySMESHGUI, SIGNAL (SignalCloseView()),
264 this, SLOT (onCloseView()));
266 connect(myLineEditElements, SIGNAL(textChanged(const QString&)),
267 this, SLOT (onTextChange(const QString&)));
268 connect(myIdSourceCheck, SIGNAL(toggled(bool)),
269 this, SLOT (onSelectIdSource(bool)));
270 connect(GroupConstructors, SIGNAL(buttonClicked(int)),
271 this, SLOT (onConstructor(int)));
274 SelectionIntoArgument();
277 //=================================================================================
278 // function : ~SMESHGUI_CopyMeshDlg()
279 // purpose : Destroys the object and frees any allocated resources
280 //=================================================================================
282 SMESHGUI_CopyMeshDlg::~SMESHGUI_CopyMeshDlg()
286 myFilterDlg->setParent( 0 );
287 delete myFilterDlg; myFilterDlg = 0;
289 if ( myIdSourceFilter )
291 if ( mySelectionMgr )
292 mySelectionMgr->removeFilter( myIdSourceFilter );
293 delete myIdSourceFilter; myIdSourceFilter=0;
297 //=================================================================================
300 //=================================================================================
301 void SMESHGUI_CopyMeshDlg::Init (bool ResetControls)
305 if ( !isWithGeomMode() )
306 myMeshNameEdit->setText( SMESH::UniqueMeshName("Mesh"));
310 myLineEditElements->clear();
313 buttonOk->setEnabled(false);
314 buttonApply->setEnabled(false);
317 myMesh = SMESH::SMESH_Mesh::_nil();
319 myIdSourceCheck->setChecked(true);
325 //=======================================================================
326 //function : onConstructor
327 //purpose : switch operation mode
328 //=======================================================================
330 void SMESHGUI_CopyMeshDlg::onConstructor( int withGeom )
332 myGeomLabel ->setVisible( withGeom );
333 myGeomNameEdit ->setVisible( withGeom );
334 myReuseHypCheck ->setVisible( withGeom );
335 myCopyElementsCheck->setVisible( withGeom );
336 myFilterBtn ->setVisible( !withGeom );
337 myIdSourceCheck ->setVisible( !withGeom );
340 myMeshNameEdit->setText( SMESH::UniqueMeshName("Mesh"));
342 onSelectIdSource( /*toSelectMesh=*/ myIdSourceCheck->isChecked() || withGeom );
345 //=======================================================================
346 //function : getErrorMsg
347 //purpose : Return an error message and entries of invalid smesh object
348 //=======================================================================
350 QString SMESHGUI_CopyMeshDlg::getErrorMsg( SMESH::string_array_var theInvalidEntries,
351 QStringList & theEntriesToBrowse )
353 if ( theInvalidEntries->length() == 0 )
354 return tr("OPERATION_FAILED");
356 // theInvalidEntries - SObject's that hold geometry objects whose
357 // counterparts are not found in the newGeometry, followed by SObject's
358 // holding mesh sub-objects that are invalid because they depend on a not found
359 // preceding sub-shape
361 QString msg = tr("SUBSHAPES_NOT_FOUND_MSG") + "\n";
364 for ( CORBA::ULong i = 0; i < theInvalidEntries->length(); ++i )
366 _PTR(SObject) so = SMESH::getStudy()->FindObjectID( theInvalidEntries[i].in() );
368 int objType = SMESHGUI_Selection::type( theInvalidEntries[i].in() );
369 if ( objType < 0 ) // geom object
373 objString += so->GetName().c_str();
375 objString += theInvalidEntries[i].in(); // it's something like "FACE #2"
379 theEntriesToBrowse.push_back( theInvalidEntries[i].in() );
384 objString += tr("SMESH_MESH"); break;
385 case SMESH::HYPOTHESIS:
386 objString += tr("SMESH_HYPOTHESIS"); break;
387 case SMESH::ALGORITHM:
388 objString += tr("SMESH_ALGORITHM"); break;
389 case SMESH::SUBMESH_VERTEX:
390 case SMESH::SUBMESH_EDGE:
391 case SMESH::SUBMESH_FACE:
392 case SMESH::SUBMESH_SOLID:
393 case SMESH::SUBMESH_COMPOUND:
395 objString += tr("SMESH_SUBMESH"); break;
397 objString += tr("SMESH_GROUP"); break;
402 objString += so->GetName().c_str();
404 objString += theInvalidEntries[i].in();
408 if ( !objString.isEmpty() )
414 //=================================================================================
415 // function : ClickOnApply()
417 //=================================================================================
419 bool SMESHGUI_CopyMeshDlg::ClickOnApply()
421 if ( SMESHGUI::isStudyLocked() )
427 QStringList anEntryList;
428 bool toShowObjects = isApplyAndClose();
431 SUIT_OverrideCursor aWaitCursor;
433 SMESH::IDSource_wrap aPartToCopy;
434 if ( myIdSourceCheck->isChecked())
436 aPartToCopy = mySelectedObject;
437 aPartToCopy->Register();
441 QStringList aListElementsId = myLineEditElements->text().split(" ", QString::SkipEmptyParts);
442 SMESH::smIdType_array_var anElementsId = new SMESH::smIdType_array;
443 anElementsId->length(aListElementsId.count());
444 for (int i = 0; i < aListElementsId.count(); i++)
445 anElementsId[i] = aListElementsId[i].toInt();
447 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
448 aPartToCopy = aMeshEditor->MakeIDSource( anElementsId, SMESH::ALL );
450 QByteArray meshName = myMeshNameEdit->text().toUtf8();
451 bool toCopyGroups = ( myCopyGroupsCheck->isChecked() );
452 bool toReuseHyps = ( myReuseHypCheck->isChecked() );
453 bool toCopyElems = ( myCopyElementsCheck->isChecked() );
454 bool toKeepIDs = ( myKeepIdsCheck->isChecked() );
456 SMESH::SMESH_Gen_var gen = SMESHGUI::GetSMESHGen();
457 SMESH::SMESH_Mesh_var newMesh;
458 if ( isWithGeomMode() )
460 SMESH::SMESH_Mesh_var srcMesh = mySelectedObject->GetMesh();
461 SMESH::ListOfGroups_var newGroups;
462 SMESH::submesh_array_var newSubmeshes;
463 SMESH::ListOfHypothesis_var newHypotheses;
464 SMESH::string_array_var invalidEntries;
465 CORBA::Boolean ok = gen->CopyMeshWithGeom( srcMesh, myNewGeometry,
466 meshName.constData(),
467 toCopyGroups, toReuseHyps, toCopyElems,
472 invalidEntries.out() );
475 if ( invalidEntries->length() > 0 )
476 toShowObjects = true;
477 SUIT_MessageBox::warning( this,
478 tr("SMESH_WRN_WARNING"),
479 getErrorMsg( invalidEntries, anEntryList ));
484 newMesh = gen->CopyMesh(aPartToCopy, meshName.constData(), toCopyGroups, toKeepIDs);
486 if ( !newMesh->_is_nil() )
487 if ( _PTR(SObject) aSObject = SMESH::ObjectToSObject( newMesh ) )
489 anEntryList.append( aSObject->GetID().c_str() );
491 if ( isWithGeomMode() )
492 SMESH::SetName( aSObject, meshName );
495 catch(const SALOME::SALOME_Exception & S_ex)
497 SalomeApp_Tools::QtCatchCorbaException(S_ex);
503 mySMESHGUI->updateObjBrowser(true);
504 SMESHGUI::Modified();
506 if( LightApp_Application* anApp =
507 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
508 anApp->browseObjects( anEntryList, toShowObjects );
511 SelectionIntoArgument();
516 //=================================================================================
517 // function : ClickOnOk()
519 //=================================================================================
520 void SMESHGUI_CopyMeshDlg::ClickOnOk()
522 setIsApplyAndClose( true );
527 //=================================================================================
528 // function : reject()
530 //=================================================================================
531 void SMESHGUI_CopyMeshDlg::reject()
533 disconnect(mySelectionMgr, 0, this, 0);
534 if ( mySelectionMgr )
535 mySelectionMgr->removeFilter( myIdSourceFilter );
536 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
537 aViewWindow->SetSelectionMode( ActorSelection );
538 mySMESHGUI->ResetState();
542 //=================================================================================
543 // function : onOpenView()
545 //=================================================================================
546 void SMESHGUI_CopyMeshDlg::onOpenView()
549 SMESH::SetPointRepresentation(false);
552 mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
553 ActivateThisDialog();
557 //=================================================================================
558 // function : onCloseView()
560 //=================================================================================
561 void SMESHGUI_CopyMeshDlg::onCloseView()
563 DeactivateActiveDialog();
567 //=================================================================================
568 // function : ClickOnHelp()
570 //=================================================================================
571 void SMESHGUI_CopyMeshDlg::ClickOnHelp()
573 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
575 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
579 platform = "winapplication";
581 platform = "application";
583 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
584 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
585 arg(app->resourceMgr()->stringValue("ExternalBrowser",
587 arg(myHelpFileName));
591 //=======================================================================
592 // function : onTextChange()
594 //=======================================================================
596 void SMESHGUI_CopyMeshDlg::onTextChange (const QString& theNewText)
598 QLineEdit* send = (QLineEdit*)sender();
601 BusyLocker lock( myBusy );
603 //if (send == myLineEditElements)
606 buttonOk->setEnabled(false);
607 buttonApply->setEnabled(false);
609 // highlight entered elements
610 SMDS_Mesh* aMesh = 0;
612 aMesh = myActor->GetObject()->GetMesh();
614 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
615 if (myActor && aMesh)
617 SVTK_TVtkIDsMap newIndices;
618 if (send == myLineEditElements) {
619 for (int i = 0; i < aListId.count(); i++)
620 if ( const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt()))
622 newIndices.Add(e->GetID());
625 myNbOkElements = newIndices.Extent();
627 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
628 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
629 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
630 aViewWindow->highlight( anIO, true, true );
634 myNbOkElements = aListId.count();
637 if (myNbOkElements) {
638 buttonOk->setEnabled(true);
639 buttonApply->setEnabled(true);
643 //=================================================================================
644 // function : SelectionIntoArgument()
645 // purpose : Called when selection as changed or other case
646 //=================================================================================
648 void SMESHGUI_CopyMeshDlg::SelectionIntoArgument()
651 if (myFilterDlg && myFilterDlg->isVisible()) return; // filter dlg active
652 if (!GroupButtons->isEnabled()) return; // inactive
654 BusyLocker lock( myBusy );
658 QString aString = "";
661 buttonOk->setEnabled(false);
662 buttonApply->setEnabled(false);
663 myFilterBtn->setEnabled(false);
665 // get selected mesh or geometry
667 mySelectionMgr->selectedObjects(aList);
668 int nbSel = aList.Extent();
672 Handle(SALOME_InteractiveObject) IO = aList.First();
674 SMESH::SMESH_Mesh_var mesh = SMESH::GetMeshByIO(IO);
675 GEOM::GEOM_Object_var geom = SMESH::GetGeom(IO);
677 if ( !mesh->_is_nil() )
680 myActor = SMESH::FindActorByEntry(IO->getEntry());
682 myActor = SMESH::FindActorByObject(myMesh);
684 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
685 if ( mySelectedObject->_is_nil() )
688 if ( isWithGeomMode() ) // only mesh selection allowed
690 myMesh = SMESH::SMESH_Mesh::_narrow( mySelectedObject );
691 if ( myMesh->_is_nil() )
693 myLineEditElements->setText("");
698 else if ( !geom->_is_nil() )
700 myNewGeometry = geom;
705 if (myIdSourceCheck->isChecked() || isWithGeomMode() )
707 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
708 if ( aString.isEmpty() ) aString = " ";
709 else aString = aString.trimmed(); // issue 0021327
713 SMESH::GetNameOfSelectedElements( mySelector, IO, aString );
714 myNbOkElements = aString.size();
715 myFilterBtn->setEnabled(true);
718 bool ok = !aString.isEmpty();
719 if ( !mesh->_is_nil() )
721 myLineEditElements->setText( aString );
722 if ( isWithGeomMode() )
723 myMeshNameEdit->setText( aString );
725 else if ( !geom->_is_nil() )
727 myGeomNameEdit->setText( aString );
730 if ( ok && isWithGeomMode() )
731 ok = ( !myMesh->_is_nil() && myMesh->HasShapeToMesh() && !myNewGeometry->_is_nil() );
733 buttonOk->setEnabled(ok);
734 buttonApply->setEnabled(ok);
737 //=======================================================================
738 //function : onSelectIdSource
740 //=======================================================================
741 void SMESHGUI_CopyMeshDlg::onSelectIdSource (bool toSelectMesh)
743 if ( isWithGeomMode() )
744 myTextLabelElements->setText(tr("SMESH_MESH"));
745 else if ( toSelectMesh )
746 myTextLabelElements->setText(tr("OBJECT_NAME"));
748 myTextLabelElements->setText(tr("ELEM_IDS"));
751 myLineEditElements->clear();
754 mySelectionMgr->clearFilters();
755 if ( !isWithGeomMode() )
756 mySelectionMgr->installFilter(myIdSourceFilter);
757 SMESH::SetPointRepresentation(false);
760 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
761 aViewWindow->SetSelectionMode( ActorSelection );
762 myLineEditElements->setReadOnly(true);
763 myLineEditElements->setValidator(0);
767 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
768 aViewWindow->SetSelectionMode( CellSelection );
769 myLineEditElements->setReadOnly(false);
770 myLineEditElements->setValidator(myIdValidator);
771 onTextChange(myLineEditElements->text());
774 SelectionIntoArgument();
777 //=================================================================================
778 // function : isValid
780 //=================================================================================
782 bool SMESHGUI_CopyMeshDlg::isValid()
785 if ( myIdSourceCheck->isChecked() || isWithGeomMode() )
787 ok = ( !mySelectedObject->_is_nil() );
788 if ( isWithGeomMode() )
789 ok = ok && ( !myNewGeometry->_is_nil() );
793 ok = ( myNbOkElements > 0 );
799 //=======================================================================
800 //function : isWithGeomMode
801 //purpose : Return true if the mode is "with geometry"
802 //=======================================================================
804 bool SMESHGUI_CopyMeshDlg::isWithGeomMode()
806 return ( GroupConstructors->checkedId() == 1 );
809 //=================================================================================
810 // function : DeactivateActiveDialog()
812 //=================================================================================
813 void SMESHGUI_CopyMeshDlg::DeactivateActiveDialog()
815 if (ConstructorsBox->isEnabled()) {
816 ConstructorsBox->setEnabled(false);
817 GroupArguments->setEnabled(false);
818 GroupButtons->setEnabled(false);
819 mySMESHGUI->ResetState();
820 mySMESHGUI->SetActiveDialogBox(0);
821 if ( mySelectionMgr )
822 mySelectionMgr->removeFilter( myIdSourceFilter );
826 //=================================================================================
827 // function : ActivateThisDialog()
829 //=================================================================================
830 void SMESHGUI_CopyMeshDlg::ActivateThisDialog()
832 /* Emit a signal to deactivate the active dialog */
833 mySMESHGUI->EmitSignalDeactivateDialog();
834 ConstructorsBox->setEnabled(true);
835 GroupArguments->setEnabled(true);
836 GroupButtons->setEnabled(true);
838 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
840 onSelectIdSource( myIdSourceCheck->isChecked() );
842 SelectionIntoArgument();
846 //=================================================================================
847 // function : enterEvent()
849 //=================================================================================
850 void SMESHGUI_CopyMeshDlg::enterEvent (QEvent*)
852 if ( !ConstructorsBox->isEnabled() ) {
853 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
854 if ( aViewWindow && !mySelector ) {
855 mySelector = aViewWindow->GetSelector();
857 ActivateThisDialog();
860 //=================================================================================
861 // function : keyPressEvent()
863 //=================================================================================
864 void SMESHGUI_CopyMeshDlg::keyPressEvent( QKeyEvent* e )
866 QDialog::keyPressEvent( e );
867 if ( e->isAccepted() )
870 if ( e->key() == Qt::Key_F1 ) {
876 //=================================================================================
877 // function : setFilters()
878 // purpose : SLOT. Called when "Filter" button pressed.
879 //=================================================================================
880 void SMESHGUI_CopyMeshDlg::setFilters()
882 if(myMesh->_is_nil()) {
883 SUIT_MessageBox::critical(this,
885 tr("NO_MESH_SELECTED"));
889 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
892 if ( myMesh->NbEdges() ) types << SMESH::EDGE;
893 if ( myMesh->NbFaces() ) types << SMESH::FACE;
894 if ( myMesh->NbVolumes() ) types << SMESH::VOLUME;
895 if ( myMesh->NbBalls() ) types << SMESH::BALL;
896 if ( myMesh->Nb0DElements()) types << SMESH::ELEM0D;
897 if ( types.count() > 1 ) types << SMESH::ALL;
899 myFilterDlg->Init( types );
900 myFilterDlg->SetSelection();
901 myFilterDlg->SetMesh( myMesh );
902 myFilterDlg->SetSourceWg( myLineEditElements );
907 //================================================================
908 // function : setIsApplyAndClose
909 // Purpose : Set value of the flag indicating that the dialog is
910 // accepted by Apply & Close button
911 //================================================================
912 void SMESHGUI_CopyMeshDlg::setIsApplyAndClose( const bool theFlag )
914 myIsApplyAndClose = theFlag;
917 //================================================================
918 // function : isApplyAndClose
919 // Purpose : Get value of the flag indicating that the dialog is
920 // accepted by Apply & Close button
921 //================================================================
922 bool SMESHGUI_CopyMeshDlg::isApplyAndClose() const
924 return myIsApplyAndClose;