1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
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
19 // File : SMESHGUI_FaceGroupsSeparatedByEdges.cxx
21 #include "SMESHGUI_FaceGroupsSeparatedByEdgesDlg.h"
24 #include "SMESHGUI_SpinBox.h"
25 #include "SMESHGUI_MeshEditPreview.h"
26 #include "SMESHGUI_Utils.h"
28 // SALOME GUI includes
29 #include <LightApp_Application.h>
30 #include <LightApp_SelectionMgr.h>
31 #include <SALOME_Actor.h>
32 #include <SALOME_ListIO.hxx>
33 #include <SUIT_MessageBox.h>
34 #include <SUIT_OverrideCursor.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SUIT_Session.h>
37 #include <SalomeApp_Tools.h>
39 #include <SALOMEDS_SObject.hxx>
42 #include <SALOMEconfig.h>
43 #include CORBA_SERVER_HEADER(SMESH_Group)
47 #include <QGridLayout>
49 #include <QHBoxLayout>
51 #include <QPushButton>
52 #include <QRadioButton>
53 #include <QToolButton>
55 #include <Standard_ErrorHandler.hxx>
61 \class SMESHGUI_FaceGroupsSeparatedByEdgesDlg
62 \brief Dialog to create face groups divided by sharp edges
65 SMESHGUI_FaceGroupsSeparatedByEdgesDlg::
66 SMESHGUI_FaceGroupsSeparatedByEdgesDlg( SMESHGUI* theModule ) :
67 SMESHGUI_PreviewDlg( theModule ),
68 mySelectionMgr( SMESH::GetSelectionMgr( theModule ))
71 setAttribute(Qt::WA_DeleteOnClose, true);
72 setWindowTitle(tr("CAPTION"));
73 setSizeGripEnabled(true);
75 QVBoxLayout* dlgLayout = new QVBoxLayout(this);
76 dlgLayout->setSpacing(SPACING);
77 dlgLayout->setMargin(MARGIN);
79 /***************************************************************/
80 GroupArgs = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
81 QGridLayout* GroupArgsLayout = new QGridLayout(GroupArgs);
82 GroupArgsLayout->setSpacing(SPACING);
83 GroupArgsLayout->setMargin(MARGIN);
86 QLabel* meshNameLabel = new QLabel(tr("SMESH_MESH"), GroupArgs);
87 myMeshName = new QLineEdit( GroupArgs );
88 myMeshName->setReadOnly( true );
91 QLabel* angleLabel = new QLabel( tr("SHARP_ANGLE"), GroupArgs );
92 myAngle = new SMESHGUI_SpinBox( GroupArgs );
93 myAngle->RangeStepAndValidator( 0, 180.0, 10.0, "angle_precision");
96 myCreateEdgesCheck = new QCheckBox( tr("CREATE_EDGES" ), GroupArgs);
97 myUseExistingCheck = new QCheckBox( tr("USE_EXISTING_EDGES"), GroupArgs);
98 myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArgs);
100 // set previous values
101 if ( SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr() )
103 myAngle->setValue( resMgr->doubleValue( "SMESH", "prev_sharp_angle", 30. ));
104 myCreateEdgesCheck->setChecked( resMgr->booleanValue( "SMESH", "prev_create_edges", false ));
105 myUseExistingCheck->setChecked( resMgr->booleanValue( "SMESH", "prev_use_existing_edges", false ));
109 GroupArgsLayout->addWidget( meshNameLabel, 0, 0);
110 GroupArgsLayout->addWidget( myMeshName, 0, 1);
111 GroupArgsLayout->addWidget( angleLabel, 1, 0);
112 GroupArgsLayout->addWidget( myAngle, 1, 1);
113 GroupArgsLayout->addWidget( myCreateEdgesCheck, 2, 0);
114 GroupArgsLayout->addWidget( myUseExistingCheck, 3, 0);
115 GroupArgsLayout->addWidget( myPreviewCheckBox, 4, 0);
117 /***************************************************************/
118 GroupButtons = new QGroupBox(this);
119 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
120 GroupButtonsLayout->setSpacing(SPACING);
121 GroupButtonsLayout->setMargin(MARGIN);
123 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
124 buttonOk->setAutoDefault(true);
125 buttonOk->setDefault(true);
126 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
127 buttonApply->setAutoDefault(true);
128 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
129 buttonCancel->setAutoDefault(true);
130 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
131 buttonHelp->setAutoDefault(true);
133 GroupButtonsLayout->addWidget(buttonOk);
134 GroupButtonsLayout->addSpacing(10);
135 GroupButtonsLayout->addWidget(buttonApply);
136 GroupButtonsLayout->addSpacing(10);
137 GroupButtonsLayout->addStretch();
138 GroupButtonsLayout->addWidget(buttonCancel);
139 GroupButtonsLayout->addWidget(buttonHelp);
141 /***************************************************************/
142 dlgLayout->addWidget(GroupArgs);
143 dlgLayout->addWidget(GroupButtons);
145 mySMESHGUI->SetActiveDialogBox(this);
147 /* signals and slots connections */
148 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
149 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
150 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
151 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
153 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
154 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
155 /* to close dialog if study change */
156 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(reject()));
157 connect(mySMESHGUI, SIGNAL(SignalActivatedViewManager()), this, SLOT(onOpenView()));
158 connect(mySMESHGUI, SIGNAL(SignalCloseView()), this, SLOT(onCloseView()));
160 connect( myAngle, SIGNAL(valueChanged(double)), this, SLOT( onArgChange() ));
161 connect( myCreateEdgesCheck, SIGNAL(toggled(bool)), this, SLOT( onArgChange() ));
162 connect( myUseExistingCheck, SIGNAL(toggled(bool)), this, SLOT( onArgChange() ));
164 connectPreviewControl();
165 mySimulation->GetActor()->GetProperty()->SetLineWidth( 5 );
167 SelectionIntoArgument();
170 SMESHGUI_FaceGroupsSeparatedByEdgesDlg::~SMESHGUI_FaceGroupsSeparatedByEdgesDlg()
174 //=================================================================================
175 // function : ClickOnApply()
177 //=================================================================================
179 bool SMESHGUI_FaceGroupsSeparatedByEdgesDlg::ClickOnApply()
181 if ( mySMESHGUI->isStudyLocked() )
184 SUIT_OverrideCursor aWaitCursor;
186 QStringList aParameters, anEntryList;
187 aParameters << myAngle->text();
191 SMESH::ListOfGroups_var groups =
192 myMesh->FaceGroupsSeparatedByEdges( myAngle->value(),
193 myCreateEdgesCheck->isChecked(),
194 myUseExistingCheck->isChecked());
196 for ( CORBA::ULong i = 0; i < groups->length(); ++i )
197 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( groups[i].in() ))
198 anEntryList.append( aSObject->GetID().c_str() );
200 SUIT_MessageBox::information(this, tr("SMESH_INFORMATION"),
201 tr("NB_GROUPS_CREATED").arg( groups->length() ));
203 catch ( const SALOME::SALOME_Exception& S_ex ) {
204 SalomeApp_Tools::QtCatchCorbaException( S_ex );
209 mySMESHGUI->updateObjBrowser(true); // new groups may appear
210 if( LightApp_Application* anApp =
211 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
213 anApp->browseObjects( anEntryList, isApplyAndClose() );
216 SMESHGUI::Modified();
220 //=================================================================================
221 // function : ClickOnOk()
223 //=================================================================================
225 void SMESHGUI_FaceGroupsSeparatedByEdgesDlg::ClickOnOk()
227 setIsApplyAndClose( true );
232 //=================================================================================
233 // function : reject()
235 //=================================================================================
236 void SMESHGUI_FaceGroupsSeparatedByEdgesDlg::reject()
238 disconnect(mySelectionMgr, 0, this, 0);
239 mySMESHGUI->ResetState();
242 //=================================================================================
243 // function : ClickOnHelp()
245 //=================================================================================
247 void SMESHGUI_FaceGroupsSeparatedByEdgesDlg::ClickOnHelp()
249 static QString myHelpFileName( "face_groups_by_sharp_edges.html" );
251 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
253 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
257 platform = "winapplication";
259 platform = "application";
261 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
262 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
263 arg(app->resourceMgr()->stringValue("ExternalBrowser",
265 arg(myHelpFileName));
269 //=================================================================================
270 // function : SelectionIntoArgument()
271 // purpose : Called when selection as changed or other case
272 //=================================================================================
274 void SMESHGUI_FaceGroupsSeparatedByEdgesDlg::SelectionIntoArgument()
276 if (!GroupButtons->isEnabled()) // inactive
281 mySelectionMgr->selectedObjects(aList);
283 for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() )
285 Handle(SALOME_InteractiveObject) IO = it.Value();
286 CORBA::Object_var anObj = SMESH::IObjectToObject( IO );
287 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( anObj );
288 if ( aMesh->_is_nil() || aMesh->NbFaces() == 0 )
291 if ( !aMesh->_is_equivalent( myMesh ))
292 onDisplaySimulation( false );
295 myMeshName->setText( IO->getName() );
298 bool ok = !myMesh->_is_nil();
300 buttonOk->setEnabled( ok );
301 buttonApply->setEnabled( ok );
303 onDisplaySimulation( ok );
306 //=================================================================================
307 // function : DeactivateActiveDialog()
309 //=================================================================================
311 void SMESHGUI_FaceGroupsSeparatedByEdgesDlg::DeactivateActiveDialog()
313 if (GroupArgs->isEnabled())
315 GroupArgs->setEnabled(false);
316 GroupButtons->setEnabled(false);
317 mySMESHGUI->ResetState();
318 mySMESHGUI->SetActiveDialogBox(0);
322 //=================================================================================
323 // function : ActivateThisDialog()
325 //=================================================================================
327 void SMESHGUI_FaceGroupsSeparatedByEdgesDlg::ActivateThisDialog()
329 /* Emit a signal to deactivate the active dialog */
330 mySMESHGUI->EmitSignalDeactivateDialog();
331 GroupArgs->setEnabled(true);
332 GroupButtons->setEnabled(true);
334 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
336 SelectionIntoArgument();
339 //=================================================================================
340 // function : onDisplaySimulation
341 // purpose : Show/Hide preview
342 //=================================================================================
344 void SMESHGUI_FaceGroupsSeparatedByEdgesDlg::onDisplaySimulation( bool toDisplayPreview )
346 SUIT_OverrideCursor aWaitCursor;
348 // save current values
349 if ( SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr() )
351 resMgr->setValue( "SMESH", "prev_sharp_angle", myAngle->value() );
352 resMgr->setValue( "SMESH", "prev_create_edges", myCreateEdgesCheck->isChecked() );
353 resMgr->setValue( "SMESH", "prev_use_existing_edges", myUseExistingCheck->isChecked() );
356 if ( myPreviewCheckBox->isChecked() && toDisplayPreview && !myMesh->_is_nil() )
360 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
361 SMESH::ListOfEdges_var edges = aMeshEditor->FindSharpEdges( myAngle->value(),
362 myUseExistingCheck->isChecked());
363 SMESH::MeshPreviewStruct_var previewData = aMeshEditor->GetPreviewData();
365 mySimulation->SetData( previewData.in() );