1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, 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
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_ExtrusionDlg.cxx
25 // Author : Michael ZORIN, Open CASCADE S.A.S.
28 #include "SMESHGUI_ExtrusionDlg.h"
31 #include "SMESHGUI_FilterDlg.h"
32 #include "SMESHGUI_IdValidator.h"
33 #include "SMESHGUI_MeshEditPreview.h"
34 #include "SMESHGUI_MeshUtils.h"
35 #include "SMESHGUI_SpinBox.h"
36 #include "SMESHGUI_Utils.h"
37 #include "SMESHGUI_VTKUtils.h"
39 #include <SMDS_Mesh.hxx>
40 #include <SMESH_Actor.h>
41 #include <SMESH_LogicalFilter.hxx>
42 #include <SMESH_TypeFilter.hxx>
44 // SALOME GUI includes
45 #include <LightApp_Application.h>
46 #include <LightApp_SelectionMgr.h>
47 #include <SUIT_Desktop.h>
48 #include <SUIT_MessageBox.h>
49 #include <SUIT_OverrideCursor.h>
50 #include <SUIT_ResourceMgr.h>
51 #include <SUIT_Session.h>
52 #include <SVTK_ViewModel.h>
53 #include <SVTK_ViewWindow.h>
54 #include <SalomeApp_IntSpinBox.h>
57 #include <BRep_Tool.hxx>
58 #include <TColStd_IndexedMapOfInteger.hxx>
59 #include <TColStd_MapOfInteger.hxx>
60 #include <TopoDS_Vertex.hxx>
64 #include <QApplication>
65 #include <QButtonGroup>
67 #include <QGridLayout>
69 #include <QHBoxLayout>
73 #include <QListWidget>
74 #include <QPushButton>
75 #include <QRadioButton>
76 #include <QToolButton>
77 #include <QVBoxLayout>
80 #include <SALOMEconfig.h>
81 #include CORBA_SERVER_HEADER(SMESH_Group)
82 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
83 #include <SMESH_NumberFilter.hxx>
90 const char* getLabelText( int typeIndex, bool objSelection )
92 const char* typeLbl[3] = { "SMESH_ID_NODES", "SMESH_ID_EDGES", "SMESH_ID_FACES" };
93 const char* obj = "SMESH_OBJECTS";
94 return objSelection ? obj : typeLbl[ typeIndex ];
98 //================================================================================
102 //================================================================================
104 SMESHGUI_3TypesSelector::SMESHGUI_3TypesSelector( QWidget * parent ):
107 SMESHGUI* gui = SMESHGUI::GetSMESHGUI();
108 mySelectionMgr = SMESH::GetSelectionMgr( gui );
109 mySelector = SMESH::GetViewWindow( gui )->GetSelector();
111 myIdValidator = new SMESHGUI_IdValidator(this);
113 QPixmap image( SMESH::GetResourceMgr( gui )->loadPixmap("SMESH", tr("ICON_SELECT")));
115 mySelectBtnGrp = new QButtonGroup( this );
116 mySelectBtnGrp->setExclusive( true );
118 QVBoxLayout* mainLayout = new QVBoxLayout( this );
119 mainLayout->setSpacing( SPACING );
120 mainLayout->setMargin( 0 );
122 const char* groupLbl[3] = { "SMESH_NODES", "SMESH_EDGES", "SMESH_FACES" };
124 for ( int i = 0; i < 3; ++i )
126 myGroups[i] = new QGroupBox( tr( groupLbl[i] ), this );
127 mainLayout->addWidget( myGroups[i] );
128 QGridLayout* layout = new QGridLayout( myGroups[i] );
129 layout->setSpacing( SPACING );
130 layout->setMargin( MARGIN );
132 QPushButton* selBtn = new QPushButton( myGroups[i] );
133 selBtn->setIcon( image );
134 selBtn->setCheckable( true );
135 mySelectBtnGrp->addButton( selBtn, i );
136 myLabel [i] = new QLabel( myGroups[i] );
137 myLineEdit [i] = new QLineEdit( myGroups[i] );
138 myMeshChk [i] = new QCheckBox( tr("SMESH_SELECT_WHOLE_MESH"), myGroups[i] );
139 myFilterBtn[i] = new QPushButton( tr( "SMESH_BUT_FILTER" ), myGroups[i] );
141 myLineEdit[i]->setMaxLength(-1);
142 myLabel [i]->setText( tr( getLabelText( i, true )));
144 layout->addWidget(myLabel [i], 0, 0);
145 layout->addWidget(selBtn, 0, 1);
146 layout->addWidget(myLineEdit [i], 0, 2, 1, 2);
147 layout->addWidget(myFilterBtn[i], 0, 4);
148 layout->addWidget(myMeshChk [i], 1, 0, 1, 5);
149 layout->setColumnStretch( 2, 10 );
151 connect( myMeshChk [i], SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
152 connect( myFilterBtn[i], SIGNAL(clicked()), SLOT(setFilters()));
153 connect( myLineEdit [i], SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
154 myIDSource[i] = new SMESH::ListOfIDSources;
156 connect( mySelectBtnGrp, SIGNAL(buttonClicked (int)), SLOT(onSelectType(int)));
157 connect(mySelectionMgr, SIGNAL( currentSelectionChanged()), SLOT(selectionIntoArgument()));
159 // Costruction of the logical filter for the elements: mesh/sub-mesh/group
160 QList<SUIT_SelectionFilter*> aListOfFilters;
161 aListOfFilters.append(new SMESH_TypeFilter (SMESH::MESH));
162 aListOfFilters.append(new SMESH_TypeFilter (SMESH::SUBMESH_VERTEX));
163 aListOfFilters.append(new SMESH_TypeFilter (SMESH::GROUP_NODE));
165 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR, /*takeOwnership=*/true);
166 aListOfFilters.append(0);
167 aListOfFilters[0] = new SMESH_TypeFilter (SMESH::MESH);
168 aListOfFilters[1] = new SMESH_TypeFilter (SMESH::SUBMESH_EDGE);
169 aListOfFilters[2] = new SMESH_TypeFilter (SMESH::GROUP_EDGE);
170 aListOfFilters[3] = new SMESH_TypeFilter (SMESH::IDSOURCE_EDGE); // for sub-mesh on group of EDGEs
172 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR, /*takeOwnership=*/true);
173 aListOfFilters[0] = new SMESH_TypeFilter (SMESH::MESH);
174 aListOfFilters[1] = new SMESH_TypeFilter (SMESH::SUBMESH_FACE);
175 aListOfFilters[2] = new SMESH_TypeFilter (SMESH::GROUP_FACE);
176 aListOfFilters[3] = new SMESH_TypeFilter (SMESH::IDSOURCE_FACE); // for sub-mesh on group of FACEs
178 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR, /*takeOwnership=*/true);
182 myMeshChk[0]->setChecked( true );
183 myMeshChk[1]->setChecked( true );
184 myMeshChk[2]->setChecked( true );
185 mySelectBtnGrp->button(0)->click();
188 //================================================================================
192 //================================================================================
194 SMESHGUI_3TypesSelector::~SMESHGUI_3TypesSelector()
206 myFilterDlg->setParent( 0 );
210 disconnect(mySelectionMgr, 0, this, 0);
213 //================================================================================
215 * \brief Slot called when selection changes
217 //================================================================================
219 void SMESHGUI_3TypesSelector::selectionIntoArgument()
223 // return if dialog box is inactive
227 // get a current element type
228 int iType = mySelectBtnGrp->checkedId();
229 if ( iType < 0 || iType > 2 )
232 QString aString = "";
237 myLineEdit[ iType ]->setText(aString);
238 myIDSource[ iType ]->length (nbObjects);
240 if ( !myGroups[ iType ]->isEnabled() )
243 SMESH::SetPointRepresentation(false);
245 SALOME_ListIO selected;
246 mySelectionMgr->selectedObjects( selected );
248 if ( myMeshChk[ iType ]->isChecked() ) // objects selection
249 myIDSource[ iType ]->length( selected.Extent() ); // reserve
250 myIDSource[ iType ]->length(0);
252 SALOME_ListIteratorOfListIO It( selected );
253 for ( ; It.More(); It.Next() )
255 Handle(SALOME_InteractiveObject) IO = It.Value();
258 SMESH::SMESH_Mesh_var mesh = SMESH::GetMeshByIO(IO);
259 if ( mesh->_is_nil() )
261 if ( !myMesh->_is_nil() &&
262 IsAnythingSelected() &&
263 myMesh->GetId() != mesh->GetId() )
264 continue; // other mesh
267 myActor = SMESH::FindActorByEntry( IO->getEntry() );
269 if ( myMeshChk[ iType ]->isChecked() ) // objects selection
271 SMESH::SMESH_IDSource_var idSrc = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
272 if ( idSrc->_is_nil() )
274 mesh = SMESH::SMESH_Mesh::_narrow( idSrc );
275 if ( !mesh->_is_nil() ) // if a mesh is selected, stop iteration
278 myIDSource[ iType ]->length( nbObjects );
279 myIDSource[ iType ][ 0 ] = idSrc;
280 aString = IO->getName();
283 else // several groups can be selected
285 myIDSource[ iType ]->length( nbObjects + 1 );
286 myIDSource[ iType ][ nbObjects++ ] = idSrc;
287 aString += " " + QString( IO->getName() ) + " ";
290 else // get indices of selected elements
292 SVTK_TIndexedMapOfVtkId aMapIndex;
293 mySelector->GetIndex(IO,aMapIndex);
294 int nbElements = aMapIndex.Extent();
295 if ( nbElements > 0 )
297 SMESH::smIdType_array_var ids = new SMESH::smIdType_array;
298 ids->length( nbElements );
299 for ( int i = 0; i < nbElements; ++i )
300 aString += QString(" %1").arg( ids[ i ] = aMapIndex( i+1 ));
301 addTmpIdSource( ids, iType, nbObjects++ );
307 myIDSource[ iType ]->length( nbObjects );
310 myLineEdit[ iType ]->setText(aString);
313 emit selectionChanged();
316 //================================================================================
318 * \brief Slot called when text changes in myLineEdit
320 //================================================================================
322 void SMESHGUI_3TypesSelector::onTextChange( const QString& theNewText )
327 // get a current element type
329 QLineEdit* le = (QLineEdit*) sender();
330 for ( ; iType < 3; ++iType )
331 if ( myLineEdit[ iType ] == le )
333 if ( iType < 0 || iType > 2 )
335 if ( !myGroups[ iType ]->isEnabled() )
340 // highlight entered elements/nodes
342 myIDSource[ iType ]->length( 0 );
344 if ( !myMesh->_is_nil() )
346 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
347 if ( aListId.count() > 0 )
349 SMDS_Mesh* aMesh = myActor ? myActor->GetObject()->GetMesh() : 0;
351 SMESH::ElementType SMESHType = SMESH::ElementType ( iType+1 );
352 SMDSAbs_ElementType SMDSType = SMDSAbs_ElementType( iType+1 );
353 const bool isNode = ( SMDSType == SMDSAbs_Node );
355 SMESH::smIdType_array_var ids = new SMESH::smIdType_array;
356 ids->length( aListId.count() );
357 SVTK_TVtkIDsMap newIndices;
358 for (int i = 0; i < aListId.count(); i++) {
359 int id = aListId[ i ].toInt();
360 bool validId = false;
363 const SMDS_MeshElement * e;
364 if ( isNode ) e = aMesh->FindNode( id );
365 else e = aMesh->FindElement( id );
366 validId = ( e && e->GetType() == SMDSType );
368 validId = ( myMesh->GetElementType( id, !isNode ) == SMESHType );
371 if ( validId && newIndices.Add( id ))
372 ids[ newIndices.Extent()-1 ] = id;
374 if ( !newIndices.IsEmpty() ) {
375 ids->length( newIndices.Extent() );
376 addTmpIdSource( ids, iType, 0 );
378 mySelector->AddOrRemoveIndex(myIO, newIndices, false);
379 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView() )
380 aViewWindow->highlight( myIO, true, true );
384 emit selectionChanged();
389 //================================================================================
391 * \brief Creates from ids and stores a temporary IDSource
393 //================================================================================
395 void SMESHGUI_3TypesSelector::addTmpIdSource( SMESH::smIdType_array_var& ids, int iType, int index )
397 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
398 SMESH::SMESH_IDSource_var idSrc =
399 aMeshEditor->MakeIDSource( ids, SMESH::ElementType( iType+1 ));
401 if ( (int) myIDSource[ iType ]->length() <= index )
402 myIDSource[ iType ]->length( index + 1 );
403 myIDSource[ iType ][ index ] = idSrc;
405 myTmpIDSourceList.push_back( idSrc );
408 //================================================================================
410 * \brief Slot called when myMeshChk is checked
412 //================================================================================
414 void SMESHGUI_3TypesSelector::onSelectMesh( bool on )
416 QCheckBox* send = (QCheckBox*)sender();
417 for ( int iType = 0; iType < 3; ++iType )
418 if ( send == myMeshChk[ iType ])
420 myLabel[ iType ]->setText( tr( getLabelText( iType, on )));
421 myFilterBtn[ iType ]->setEnabled( !on );
422 myIDSource [ iType ]->length(0);
424 myLineEdit [ iType ]->setText("");
426 myLineEdit [ iType ]->setReadOnly( on );
427 myLineEdit [ iType ]->setValidator( on ? 0 : myIdValidator );
428 mySelectBtnGrp->button(iType)->click();
437 //================================================================================
439 * \brief Slot called when a selection button is clicked
441 //================================================================================
443 void SMESHGUI_3TypesSelector::onSelectType(int iType)
445 if ( iType < 0 || iType > 2 )
448 myIDSource[ iType ]->length(0);
449 myLineEdit[ iType ]->setText("");
451 disconnect(mySelectionMgr, 0, this, 0);
452 mySelectionMgr->clearFilters();
454 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
455 if ( myMeshChk[ iType ]->isChecked() )
457 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
458 mySelectionMgr->installFilter( myFilter[ iType ]);
460 else if ( aViewWindow )
463 case SMESH::NODE: aViewWindow->SetSelectionMode(NodeSelection); break;
464 case SMESH::EDGE: aViewWindow->SetSelectionMode(EdgeSelection); break;
465 case SMESH::FACE: aViewWindow->SetSelectionMode(FaceSelection); break;
469 myLineEdit[ iType ]->setFocus();
471 connect(mySelectionMgr, SIGNAL( currentSelectionChanged()), SLOT( selectionIntoArgument()));
472 selectionIntoArgument();
475 //================================================================================
477 * \brief Slot called when "Set filter" is clicked
479 //================================================================================
481 void SMESHGUI_3TypesSelector::setFilters()
483 if ( myMesh->_is_nil() ) {
484 SUIT_MessageBox::critical(this,
486 tr("NO_MESH_SELECTED"));
492 types.append( SMESH::NODE );
493 types.append( SMESH::EDGE );
494 types.append( SMESH::FACE );
495 myFilterDlg = new SMESHGUI_FilterDlg( SMESHGUI::GetSMESHGUI(), types );
498 QPushButton* send = (QPushButton*)sender();
499 for ( int iType = 0; iType < 3; ++iType )
500 if ( send == myFilterBtn[ iType ])
502 mySelectBtnGrp->button(iType)->click();
504 myFilterDlg->Init( SMESH::ElementType( iType+1 ) );
505 myFilterDlg->SetSelection();
506 myFilterDlg->SetMesh( myMesh );
507 myFilterDlg->SetSourceWg( myLineEdit[ iType ]);
513 //================================================================================
515 * \brief Clear selection
517 //================================================================================
519 void SMESHGUI_3TypesSelector::Clear()
522 for ( int iType = 0; iType < 3; ++iType )
524 myIDSource[ iType ]->length(0);
525 myLineEdit[ iType ]->setText("");
528 selectionIntoArgument();
531 //================================================================================
533 * \brief Enable/disable controls of a type
535 //================================================================================
537 void SMESHGUI_3TypesSelector::SetEnabled( bool enable, SMESH::ElementType type )
540 for ( int iType = 0; iType < 3; ++iType )
541 if ( iType+1 == type || type == SMESH::ALL )
543 myGroups[ iType ]->setEnabled( enable );
545 myIDSource[ iType ]->length(0);
546 myLineEdit[ iType ]->setText("");
550 selectionIntoArgument();
553 //================================================================================
555 * \brief Checks if anything is selected
557 //================================================================================
559 bool SMESHGUI_3TypesSelector::IsAnythingSelected( SMESH::ElementType type )
563 for ( int iType = 0; iType < 3; ++iType )
564 if ( iType+1 == type || type == SMESH::ALL )
565 nbSel += myIDSource[ iType ]->length();
570 //================================================================================
572 * \brief Returns selected elements and most complex type of selected elements
574 //================================================================================
576 SMESH::ElementType SMESHGUI_3TypesSelector::GetSelected( SMESH::ListOfIDSources & nodes,
577 SMESH::ListOfIDSources & edges,
578 SMESH::ListOfIDSources & faces )
580 nodes = myIDSource[0];
581 edges = myIDSource[1];
582 faces = myIDSource[2];
584 if ( myIDSource[2]->length() > 0 ) return SMESH::FACE;
585 if ( myIDSource[1]->length() > 0 ) return SMESH::EDGE;
586 if ( myIDSource[0]->length() > 0 ) return SMESH::NODE;
590 //=================================================================================
591 // function : SMESHGUI_ExtrusionDlg()
592 // purpose : constructor
593 //=================================================================================
595 SMESHGUI_ExtrusionDlg::SMESHGUI_ExtrusionDlg (SMESHGUI* theModule)
596 : SMESHGUI_PreviewDlg( theModule ),
597 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
599 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
600 QPixmap selectImage ( mgr->loadPixmap("SMESH", tr("ICON_SELECT")));
601 QPixmap addImage ( mgr->loadPixmap("SMESH", tr("ICON_APPEND")));
602 QPixmap removeImage ( mgr->loadPixmap("SMESH", tr("ICON_REMOVE")));
605 setAttribute( Qt::WA_DeleteOnClose, true );
606 setWindowTitle(tr("EXTRUSION_ALONG_LINE"));
607 setSizeGripEnabled(true);
609 QVBoxLayout* SMESHGUI_ExtrusionDlgLayout = new QVBoxLayout(this);
610 SMESHGUI_ExtrusionDlgLayout->setSpacing(SPACING);
611 SMESHGUI_ExtrusionDlgLayout->setMargin(MARGIN);
613 /***************************************************************/
614 GroupArguments = new QGroupBox(tr("SMESH_EXTRUSION"), this);
615 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
616 GroupArgumentsLayout->setSpacing(SPACING);
617 GroupArgumentsLayout->setMargin(MARGIN);
619 // Controls for elements selection
620 SelectorWdg = new SMESHGUI_3TypesSelector( GroupArguments );
622 ExtrMethod_RBut0 = new QRadioButton(GroupArguments);
623 ExtrMethod_RBut0->setText( tr("SMESH_EXTRUSION_TO_DISTANCE") );
624 ExtrMethod_RBut1 = new QRadioButton(GroupArguments);
625 ExtrMethod_RBut1->setText( tr("SMESH_EXTRUSION_ALONG_VECTOR") );
626 ExtrMethod_RBut2 = new QRadioButton(GroupArguments);
627 ExtrMethod_RBut2->setText( tr("SMESH_EXTRUSION_BY_NORMAL") );
629 //Control for the Distance selection
630 TextLabelDistance = new QLabel(tr("SMESH_DISTANCE"), GroupArguments);
632 TextLabelDx = new QLabel(tr("SMESH_X"), GroupArguments);
633 SpinBox_Dx = new SMESHGUI_SpinBox(GroupArguments);
635 TextLabelDy = new QLabel(tr("SMESH_Y"), GroupArguments);
636 SpinBox_Dy = new SMESHGUI_SpinBox(GroupArguments);
638 TextLabelDz = new QLabel(tr("SMESH_Z"), GroupArguments);
639 SpinBox_Dz = new SMESHGUI_SpinBox(GroupArguments);
641 // Controls for vector selection
643 TextLabelVector = new QLabel(tr("SMESH_VECTOR"), GroupArguments);
645 SelectVectorButton = new QPushButton( GroupArguments );
646 SelectVectorButton->setIcon( selectImage );
647 SelectVectorButton->setCheckable( true );
648 SelectorWdg->GetButtonGroup()->addButton( SelectVectorButton );
650 TextLabelVx = new QLabel(tr("SMESH_DX"), GroupArguments);
651 SpinBox_Vx = new SMESHGUI_SpinBox(GroupArguments);
653 TextLabelVy = new QLabel(tr("SMESH_DY"), GroupArguments);
654 SpinBox_Vy = new SMESHGUI_SpinBox(GroupArguments);
656 TextLabelVz = new QLabel(tr("SMESH_DZ"), GroupArguments);
657 SpinBox_Vz = new SMESHGUI_SpinBox(GroupArguments);
659 TextLabelDist = new QLabel(tr("SMESH_DISTANCE"), GroupArguments);
660 SpinBox_VDist = new SMESHGUI_SpinBox(GroupArguments);
662 // Controls for nb. steps defining
663 TextLabelNbSteps = new QLabel(tr("SMESH_NUMBEROFSTEPS"), GroupArguments);
664 SpinBox_NbSteps = new SalomeApp_IntSpinBox(GroupArguments);
666 // CheckBox for groups generation
667 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
669 // CheckBox for ByAverageNormal arg of ExtrusionByNormal()
670 ByAverageNormalCheck = new QCheckBox(tr("BY_AVERAGE_NORMAL"), GroupArguments);
672 // CheckBox for UseInputElemsOnly arg of ExtrusionByNormal()
673 UseInputElemsOnlyCheck = new QCheckBox(tr("USE_INPUT_ELEMS_ONLY"), GroupArguments);
676 myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
680 BasePointGrp = new QGroupBox(tr("BASE_POINT"), GroupArguments);
681 BasePointGrp->setCheckable(true);
682 BasePointGrp->setChecked(false);
683 QHBoxLayout* BasePointGrpLayout = new QHBoxLayout(BasePointGrp);
684 BasePointGrpLayout->setSpacing(SPACING); BasePointGrpLayout->setMargin(MARGIN);
686 SelectBasePointButton = new QPushButton(BasePointGrp);
687 SelectBasePointButton->setIcon(selectImage);
688 SelectBasePointButton->setCheckable(true);
689 SelectorWdg->GetButtonGroup()->addButton( SelectBasePointButton );
691 QLabel* XLab = new QLabel(tr("SMESH_X"), BasePointGrp);
692 BasePoint_XSpin = new SMESHGUI_SpinBox(BasePointGrp);
693 BasePoint_XSpin->SetValue(0.);
694 QLabel* YLab = new QLabel(tr("SMESH_Y"), BasePointGrp);
695 BasePoint_YSpin = new SMESHGUI_SpinBox(BasePointGrp);
696 BasePoint_YSpin->SetValue(0.);
697 QLabel* ZLab = new QLabel(tr("SMESH_Z"), BasePointGrp);
698 BasePoint_ZSpin = new SMESHGUI_SpinBox(BasePointGrp);
699 BasePoint_ZSpin->SetValue(0.);
701 BasePointGrpLayout->addWidget(SelectBasePointButton);
702 BasePointGrpLayout->addWidget(XLab);
703 BasePointGrpLayout->addWidget(BasePoint_XSpin, 1);
704 BasePointGrpLayout->addWidget(YLab);
705 BasePointGrpLayout->addWidget(BasePoint_YSpin, 1);
706 BasePointGrpLayout->addWidget(ZLab);
707 BasePointGrpLayout->addWidget(BasePoint_ZSpin, 1);
711 ScalesGrp = new QGroupBox(tr("SMESH_SCALES"), GroupArguments);
712 ScalesGrp->setCheckable(true);
713 ScalesGrp->setChecked(false);
714 QGridLayout* ScalesGrpLayout = new QGridLayout( ScalesGrp );
715 ScalesGrpLayout->setSpacing(SPACING); ScalesGrpLayout->setMargin(MARGIN);
717 ScalesList = new QListWidget( ScalesGrp );
718 ScalesList->setSelectionMode(QListWidget::ExtendedSelection);
720 AddScaleButton = new QToolButton( ScalesGrp );
721 AddScaleButton->setIcon( addImage );
723 RemoveScaleButton = new QToolButton( ScalesGrp );
724 RemoveScaleButton->setIcon( removeImage );
726 ScaleSpin = new SMESHGUI_SpinBox( ScalesGrp );
727 ScaleSpin->SetValue(2);
729 LinearScalesCheck = new QCheckBox(tr("LINEAR_SCALES"), ScalesGrp );
731 ScalesGrpLayout->addWidget(ScalesList, 0, 0, 4, 1);
732 ScalesGrpLayout->addWidget(AddScaleButton, 0, 1);
733 ScalesGrpLayout->addWidget(RemoveScaleButton, 2, 1);
734 ScalesGrpLayout->addWidget(ScaleSpin, 0, 2);
735 ScalesGrpLayout->addWidget(LinearScalesCheck, 4, 0, 1, 3);
736 ScalesGrpLayout->setRowMinimumHeight(1, 10);
737 ScalesGrpLayout->setRowStretch(3, 10);
741 AnglesGrp = new QGroupBox(tr("SMESH_ANGLES"), GroupArguments);
742 AnglesGrp->setCheckable(true);
743 AnglesGrp->setChecked(false);
744 QGridLayout* AnglesGrpLayout = new QGridLayout( AnglesGrp );
745 AnglesGrpLayout->setSpacing(SPACING); AnglesGrpLayout->setMargin(MARGIN);
747 AnglesList = new QListWidget( AnglesGrp );
748 AnglesList->setSelectionMode(QListWidget::ExtendedSelection);
750 AddAngleButton = new QToolButton( AnglesGrp );
751 AddAngleButton->setIcon( addImage );
753 RemoveAngleButton = new QToolButton( AnglesGrp );
754 RemoveAngleButton->setIcon( removeImage );
756 AngleSpin = new SMESHGUI_SpinBox( AnglesGrp );
757 AngleSpin->SetValue(10);
759 LinearAnglesCheck = new QCheckBox(tr("LINEAR_ANGLES"), AnglesGrp );
761 AnglesGrpLayout->addWidget(AnglesList, 0, 0, 4, 1);
762 AnglesGrpLayout->addWidget(AddAngleButton, 0, 1);
763 AnglesGrpLayout->addWidget(RemoveAngleButton, 2, 1);
764 AnglesGrpLayout->addWidget(AngleSpin, 0, 2);
765 AnglesGrpLayout->addWidget(LinearAnglesCheck, 4, 0, 1, 3);
766 AnglesGrpLayout->setRowMinimumHeight(1, 10);
767 AnglesGrpLayout->setRowStretch(3, 10);
769 // Controls for advanced parameters
770 QGridLayout* AdvancedGrpLayout = new QGridLayout();
771 AdvancedGrpLayout->setSpacing(SPACING);
774 AdvancedGrpLayout->addWidget(TextLabelDistance, 0, 0);
775 AdvancedGrpLayout->addWidget(TextLabelDx, 0, 2);
776 AdvancedGrpLayout->addWidget(SpinBox_Dx, 0, 3);
777 AdvancedGrpLayout->addWidget(TextLabelDy, 0, 4);
778 AdvancedGrpLayout->addWidget(SpinBox_Dy, 0, 5);
779 AdvancedGrpLayout->addWidget(TextLabelDz, 0, 6);
780 AdvancedGrpLayout->addWidget(SpinBox_Dz, 0, 7);
781 AdvancedGrpLayout->addWidget(TextLabelVector, 1, 0);
782 AdvancedGrpLayout->addWidget(SelectVectorButton, 1, 1);
783 AdvancedGrpLayout->addWidget(TextLabelVx, 1, 2);
784 AdvancedGrpLayout->addWidget(SpinBox_Vx, 1, 3);
785 AdvancedGrpLayout->addWidget(TextLabelVy, 1, 4);
786 AdvancedGrpLayout->addWidget(SpinBox_Vy, 1, 5);
787 AdvancedGrpLayout->addWidget(TextLabelVz, 1, 6);
788 AdvancedGrpLayout->addWidget(SpinBox_Vz, 1, 7);
789 AdvancedGrpLayout->addWidget(TextLabelDist, 2, 0);
790 AdvancedGrpLayout->addWidget(SpinBox_VDist, 2, 3);
791 AdvancedGrpLayout->addWidget(TextLabelNbSteps, 3, 0, 1, 3);
792 AdvancedGrpLayout->addWidget(SpinBox_NbSteps, 3, 3);
793 AdvancedGrpLayout->addWidget(ByAverageNormalCheck, 4, 0, 1, 4);
794 AdvancedGrpLayout->addWidget(UseInputElemsOnlyCheck, 4, 4, 1, 4);
796 // Controls for advanced parameters
797 QGroupBox* RbGrp = new QGroupBox();
798 QHBoxLayout* RBLayout = new QHBoxLayout(RbGrp);
799 RBLayout->setSpacing(SPACING); RBLayout->setMargin(MARGIN);
800 RBLayout->addWidget(ExtrMethod_RBut0);
801 RBLayout->addWidget(ExtrMethod_RBut1);
802 RBLayout->addWidget(ExtrMethod_RBut2);
805 GroupArgumentsLayout->addWidget(RbGrp, 0, 0, 1, 4);
806 GroupArgumentsLayout->addWidget(SelectorWdg, 1, 0, 3, 2);
807 GroupArgumentsLayout->addLayout(AdvancedGrpLayout, 1, 2, 1, 2);
808 GroupArgumentsLayout->addWidget(BasePointGrp, 2, 2, 1, 2);
809 GroupArgumentsLayout->addWidget(ScalesGrp, 3, 2, 1, 1);
810 GroupArgumentsLayout->addWidget(AnglesGrp, 3, 3, 1, 1);
811 GroupArgumentsLayout->addWidget(myPreviewCheckBox, 4, 0);
812 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 4, 1);
813 GroupArgumentsLayout->setRowStretch(5, 10);
814 SelectorWdg->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
815 SelectorWdg->setMinimumWidth(320);
817 /***************************************************************/
818 GroupButtons = new QGroupBox(this);
819 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
820 GroupButtonsLayout->setSpacing(SPACING);
821 GroupButtonsLayout->setMargin(MARGIN);
823 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
824 buttonOk->setAutoDefault(true);
825 buttonOk->setDefault(true);
826 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
827 buttonApply->setAutoDefault(true);
828 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
829 buttonCancel->setAutoDefault(true);
830 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
831 buttonHelp->setAutoDefault(true);
833 GroupButtonsLayout->addWidget(buttonOk);
834 GroupButtonsLayout->addSpacing(10);
835 GroupButtonsLayout->addWidget(buttonApply);
836 GroupButtonsLayout->addSpacing(10);
837 GroupButtonsLayout->addStretch();
838 GroupButtonsLayout->addWidget(buttonCancel);
839 GroupButtonsLayout->addWidget(buttonHelp);
841 /***************************************************************/
842 SMESHGUI_ExtrusionDlgLayout->addWidget(GroupArguments);
843 SMESHGUI_ExtrusionDlgLayout->addWidget(GroupButtons);
845 /* Initialisations */
846 SpinBox_Vx->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.1, "length_precision");
847 SpinBox_Vy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.1, "length_precision");
848 SpinBox_Vz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.1, "length_precision");
850 SpinBox_Dx->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
851 SpinBox_Dy->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
852 SpinBox_Dz->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
854 SpinBox_NbSteps->setRange(1, 999999);
855 SpinBox_VDist->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
857 BasePoint_XSpin->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
858 BasePoint_YSpin->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
859 BasePoint_ZSpin->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
860 ScaleSpin->RangeStepAndValidator (COORD_MIN, COORD_MAX, 1.0, "length_precision");
861 AngleSpin->RangeStepAndValidator (-180.0, 180.0, 5.0, "angle_precision");
863 ExtrMethod_RBut0->setChecked(true);
864 UseInputElemsOnlyCheck->setChecked(true);
865 MakeGroupsCheck->setChecked(true);
867 mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
869 mySMESHGUI->SetActiveDialogBox(this);
871 myHelpFileName = "extrusion.html";
875 /***************************************************************/
876 // signals and slots connections
877 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
878 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
879 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
880 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
882 connect(ExtrMethod_RBut0, SIGNAL(clicked()), this, SLOT(ClickOnRadio()));
883 connect(ExtrMethod_RBut1, SIGNAL(clicked()), this, SLOT(ClickOnRadio()));
884 connect(ExtrMethod_RBut2, SIGNAL(clicked()), this, SLOT(ClickOnRadio()));
886 // to update state of the Ok & Apply buttons
887 connect(SpinBox_Vx, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
888 connect(SpinBox_Vy, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
889 connect(SpinBox_Vz, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
890 connect(SpinBox_Dx, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
891 connect(SpinBox_Dy, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
892 connect(SpinBox_Dz, SIGNAL(valueChanged(double)), SLOT(CheckIsEnable()));
894 connect(AddScaleButton, SIGNAL(clicked()), this, SLOT(OnScaleAdded()));
895 connect(RemoveScaleButton, SIGNAL(clicked()), this, SLOT(OnScaleRemoved()));
896 connect(AddAngleButton, SIGNAL(clicked()), this, SLOT(OnScaleAdded()));
897 connect(RemoveAngleButton, SIGNAL(clicked()), this, SLOT(OnScaleRemoved()));
899 connect(SelectVectorButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
900 connect(SelectBasePointButton,SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
901 connect(BasePointGrp, SIGNAL(toggled(bool)), this, SLOT(SetEditCurrentArgument()));
902 connect(BasePointGrp, SIGNAL(toggled(bool)), SelectBasePointButton, SLOT(click()));
903 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog()));
904 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(toDisplaySimulation()));
905 connect(SelectorWdg, SIGNAL(selectionChanged()), this, SLOT(toDisplaySimulation()));
906 connect(SelectorWdg, SIGNAL(selectionChanged()), this, SLOT(CheckIsEnable()));
907 /* to close dialog if study change */
908 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(reject()));
909 connect(mySMESHGUI, SIGNAL(SignalActivatedViewManager()), this, SLOT(onOpenView()));
910 connect(mySMESHGUI, SIGNAL(SignalCloseView()), this, SLOT(onCloseView()));
912 connect(SpinBox_Dx, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
913 connect(SpinBox_Dy, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
914 connect(SpinBox_Dz, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
915 connect(SpinBox_Vx, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
916 connect(SpinBox_Vy, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
917 connect(SpinBox_Vz, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
918 connect(SpinBox_VDist, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
919 connect(SpinBox_NbSteps, SIGNAL(valueChanged(int)), this, SLOT(toDisplaySimulation()));
920 connect(ByAverageNormalCheck, SIGNAL(toggled(bool)), this, SLOT(toDisplaySimulation()));
921 connect(UseInputElemsOnlyCheck, SIGNAL(toggled(bool)), this, SLOT(toDisplaySimulation()));
922 connect(AddScaleButton, SIGNAL(clicked()), this, SLOT(toDisplaySimulation()));
923 connect(RemoveScaleButton, SIGNAL(clicked()), this, SLOT(toDisplaySimulation()));
924 connect(LinearScalesCheck, SIGNAL(toggled(bool)), this, SLOT(toDisplaySimulation()));
925 connect(AddAngleButton, SIGNAL(clicked()), this, SLOT(toDisplaySimulation()));
926 connect(RemoveAngleButton, SIGNAL(clicked()), this, SLOT(toDisplaySimulation()));
927 connect(LinearAnglesCheck, SIGNAL(toggled(bool)), this, SLOT(toDisplaySimulation()));
928 connect(BasePointGrp, SIGNAL(toggled(bool)), this, SLOT(toDisplaySimulation()));
929 connect(BasePoint_XSpin, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
930 connect(BasePoint_YSpin, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
931 connect(BasePoint_ZSpin, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
932 connect(ScalesGrp, SIGNAL(toggled(bool)), this, SLOT(toDisplaySimulation()));
933 connect(AnglesGrp, SIGNAL(toggled(bool)), this, SLOT(toDisplaySimulation()));
935 //To Connect preview check box
936 connectPreviewControl();
938 /***************************************************************/
943 //=================================================================================
944 // function : ~SMESHGUI_ExtrusionDlg()
945 // purpose : destructor
946 //=================================================================================
947 SMESHGUI_ExtrusionDlg::~SMESHGUI_ExtrusionDlg()
951 //=================================================================================
953 // purpose : initialization
954 //=================================================================================
955 void SMESHGUI_ExtrusionDlg::Init (bool ResetControls)
959 SpinBox_NbSteps->setValue(1);
960 SpinBox_VDist->setValue(10);
961 SpinBox_Dx->SetValue(0);
962 SpinBox_Dy->SetValue(0);
963 SpinBox_Dz->SetValue(0);
964 SpinBox_Vx->SetValue(0);
965 SpinBox_Vy->SetValue(0);
966 SpinBox_Vz->SetValue(0);
968 myPreviewCheckBox->setChecked(false);
969 onDisplaySimulation(false);
971 SelectorWdg->Clear();
975 //=================================================================================
976 // function : CheckIsEnable()
977 // purpose : Check whether the Ok and Apply buttons should be enabled or not
978 //=================================================================================
979 void SMESHGUI_ExtrusionDlg::CheckIsEnable()
981 bool anIsEnable = SelectorWdg->IsAnythingSelected() && isValuesValid();
983 buttonOk->setEnabled(anIsEnable);
984 buttonApply->setEnabled(anIsEnable);
987 //=================================================================================
988 // function : isValuesValid()
989 // purpose : Return true in case if values entered into dialog are valid
990 //=================================================================================
991 bool SMESHGUI_ExtrusionDlg::isValuesValid()
993 double aX, aY, aZ, aModule = 0;
994 if ( ExtrMethod_RBut0->isChecked() )
996 aX = SpinBox_Dx->GetValue();
997 aY = SpinBox_Dy->GetValue();
998 aZ = SpinBox_Dz->GetValue();
999 aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
1001 else if ( ExtrMethod_RBut1->isChecked() )
1003 aX = SpinBox_Vx->GetValue();
1004 aY = SpinBox_Vy->GetValue();
1005 aZ = SpinBox_Vz->GetValue();
1006 aModule = sqrt(aX*aX + aY*aY + aZ*aZ);
1007 double aVDist = (double)SpinBox_VDist->value();
1010 else if ( ExtrMethod_RBut2->isChecked() )
1012 aModule = Abs((double)SpinBox_VDist->value());
1015 return aModule > 1.0E-38;
1018 //=======================================================================
1019 //function : getScaleParams
1020 //purpose : return 3 scaling parameters
1021 //=======================================================================
1023 void SMESHGUI_ExtrusionDlg::getScaleParams( SMESH::double_array*& scales,
1024 SMESH::double_array*& basePoint,
1025 bool & scalesVariation,
1026 SMESH::double_array*& angles,
1027 bool & anglesVariation )
1029 scales = new SMESH::double_array;
1030 if ( ScalesGrp->isChecked() )
1032 scales->length( myScalesList.count() );
1033 for ( int i = 0; i < myScalesList.count(); ++i )
1034 (*scales)[i] = myScalesList[i];
1036 angles = new SMESH::double_array;
1037 if ( AnglesGrp->isChecked() )
1039 angles->length( myAnglesList.count() );
1040 for ( int i = 0; i < myAnglesList.count(); ++i )
1041 (*angles)[i] = myAnglesList[i]*M_PI/180.;
1043 basePoint = new SMESH::double_array;
1044 if ( BasePointGrp->isChecked() )
1046 basePoint->length( 3 );
1047 (*basePoint)[0] = BasePoint_XSpin->GetValue();
1048 (*basePoint)[1] = BasePoint_YSpin->GetValue();
1049 (*basePoint)[2] = BasePoint_ZSpin->GetValue();
1052 scalesVariation = ( scales->length() > 0 && LinearScalesCheck->isChecked() );
1053 anglesVariation = ( angles->length() > 0 && LinearAnglesCheck->isChecked() );
1056 //=================================================================================
1057 // function : ClickOnRadio()
1058 // purpose : Radio button management
1059 //=================================================================================
1061 void SMESHGUI_ExtrusionDlg::ClickOnRadio()
1063 if ( ExtrMethod_RBut0->isChecked() )
1065 TextLabelDistance->show();
1066 TextLabelDx->show();
1068 TextLabelDy->show();
1070 TextLabelDz->show();
1073 TextLabelVector->hide();
1074 TextLabelVx->hide();
1076 TextLabelVy->hide();
1078 TextLabelVz->hide();
1080 TextLabelDist->hide();
1081 SpinBox_VDist->hide();
1082 SelectVectorButton->hide();
1084 ByAverageNormalCheck->hide();
1085 UseInputElemsOnlyCheck->hide();
1087 SelectorWdg->SetEnabled( true, SMESH::ALL );
1089 else if ( ExtrMethod_RBut1->isChecked() )
1091 TextLabelDistance->hide();
1092 TextLabelDx->hide();
1094 TextLabelDy->hide();
1096 TextLabelDz->hide();
1099 TextLabelVector->show();
1100 TextLabelVx->show();
1102 TextLabelVy->show();
1104 TextLabelVz->show();
1106 TextLabelDist->show();
1107 SpinBox_VDist->show();
1108 SelectVectorButton->show();
1110 ByAverageNormalCheck->hide();
1111 UseInputElemsOnlyCheck->hide();
1113 SelectorWdg->SetEnabled( true, SMESH::ALL );
1115 else if ( ExtrMethod_RBut2->isChecked() )
1117 TextLabelDistance->hide();
1118 TextLabelDx->hide();
1120 TextLabelDy->hide();
1122 TextLabelDz->hide();
1125 TextLabelVector->hide();
1126 TextLabelVx->hide();
1128 TextLabelVy->hide();
1130 TextLabelVz->hide();
1133 TextLabelDist->show();
1134 SpinBox_VDist->show();
1135 SelectVectorButton->hide();
1137 ByAverageNormalCheck->show();
1138 UseInputElemsOnlyCheck->show();
1140 SelectorWdg->SetEnabled( false, SMESH::NODE );
1141 SelectorWdg->SetEnabled( false, SMESH::EDGE );
1144 BasePointGrp->setEnabled( !ExtrMethod_RBut2->isChecked() );
1145 ScalesGrp ->setEnabled( !ExtrMethod_RBut2->isChecked() );
1146 AnglesGrp ->setEnabled( !ExtrMethod_RBut2->isChecked() );
1151 onDisplaySimulation(true);
1153 qApp->processEvents();
1155 resize( minimumSizeHint() );
1158 //=================================================================================
1159 // function : ClickOnApply()
1160 // purpose : Called when user presses <Apply> button
1161 //=================================================================================
1163 bool SMESHGUI_ExtrusionDlg::ClickOnApply()
1165 if (SMESHGUI::isStudyLocked())
1171 if ( SelectorWdg->IsAnythingSelected() )
1173 SMESH::DirStruct aVector;
1174 getExtrusionVector(aVector);
1176 QStringList aParameters;
1177 if ( ExtrMethod_RBut0->isChecked() )
1179 aParameters << SpinBox_Dx->text();
1180 aParameters << SpinBox_Dy->text();
1181 aParameters << SpinBox_Dz->text();
1183 else if ( ExtrMethod_RBut1->isChecked() )
1185 // only 3 coords in a python dump command :(
1186 // aParameters << SpinBox_Vx->text();
1187 // aParameters << SpinBox_Vy->text();
1188 // aParameters << SpinBox_Vz->text();
1189 // aParameters << SpinBox_VDist->text();
1191 else if ( ExtrMethod_RBut2->isChecked() )
1193 aParameters << SpinBox_VDist->text();
1196 long aNbSteps = (long)SpinBox_NbSteps->value();
1197 aParameters << SpinBox_NbSteps->text();
1199 for (int i = 0; i < myScalesList.count(); i++)
1200 aParameters << ScalesList->item(i)->text();
1202 for (int i = 0; i < myAnglesList.count(); i++)
1203 aParameters << AnglesList->item(i)->text();
1205 bool meshHadNewTypeBefore = true;
1207 const bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
1211 SUIT_OverrideCursor aWaitCursor;
1213 SMESH::SMESH_Mesh_var mesh = SelectorWdg->GetMesh();
1215 SMESH::ListOfIDSources_var nodes = new SMESH::ListOfIDSources();
1216 SMESH::ListOfIDSources_var edges = new SMESH::ListOfIDSources();
1217 SMESH::ListOfIDSources_var faces = new SMESH::ListOfIDSources();
1218 maxSelType = SelectorWdg->GetSelected( nodes, edges, faces );
1220 // is it necessary to switch on the next Display Mode?
1221 SMESH::ElementType newType = (SMESH::ElementType)( maxSelType + 1 );
1222 SMESH::array_of_ElementType_var oldTypes = mesh->GetTypes();
1223 meshHadNewTypeBefore = false;
1224 for ( size_t i = 0; i < oldTypes->length() && !meshHadNewTypeBefore; ++i )
1225 meshHadNewTypeBefore = ( oldTypes[i] >= newType );
1227 SMESH::SMESH_MeshEditor_var meshEditor = mesh->GetMeshEditor();
1228 SMESH::ListOfGroups_var groups;
1230 mesh->SetParameters( aParameters.join(":").toUtf8().constData() );
1232 if ( ExtrMethod_RBut2->isVisible() &&
1233 ExtrMethod_RBut2->isChecked() ) // Extrusion by normal
1235 double stepSize = (double) SpinBox_VDist->value();
1236 long nbSteps = (long) SpinBox_NbSteps->value();
1237 bool useInputElemsOnly = UseInputElemsOnlyCheck->isChecked();
1238 bool byAverageNormal = ByAverageNormalCheck->isChecked();
1239 int dim = (maxSelType == SMESH::FACE) ? 2 : 1;
1241 groups = meshEditor->ExtrusionByNormal( faces, stepSize, nbSteps, byAverageNormal,
1242 useInputElemsOnly, makeGroups, dim );
1246 SMESH::double_array_var scales, basePoint, angles;
1247 bool scalesVariation, anglesVariation;
1248 getScaleParams( scales.out(), basePoint.out(), scalesVariation,
1249 angles.out(), anglesVariation );
1250 groups = meshEditor->ExtrusionSweepObjects( nodes, edges, faces,
1251 aVector, aNbSteps, makeGroups,
1252 scales, scalesVariation, basePoint,
1253 angles, anglesVariation );
1259 SMESH_Actor* actor = SelectorWdg->GetActor();
1260 if ( actor && !meshHadNewTypeBefore )
1262 unsigned int aMode = actor->GetEntityMode();
1263 switch ( maxSelType ) {
1264 case SMESH::NODE: // extrude node -> edges
1265 actor->SetRepresentation(SMESH_Actor::eEdge);
1266 actor->SetEntityMode( aMode |= SMESH_Actor::eEdges ); break;
1267 case SMESH::EDGE: // edge -> faces
1268 actor->SetRepresentation(SMESH_Actor::eSurface);
1269 actor->SetEntityMode( aMode |= SMESH_Actor::eFaces ); break;
1270 case SMESH::FACE: // faces -> volumes
1271 actor->SetRepresentation(SMESH_Actor::eSurface);
1272 actor->SetEntityMode( aMode |= SMESH_Actor::eVolumes ); break;
1276 SMESH::Update( actor->getIO(), actor->GetVisibility() );
1278 mySMESHGUI->updateObjBrowser(true); // new groups may appear
1280 mySelectionMgr->clearSelected();
1283 SMESHGUI::Modified();
1288 //=================================================================================
1289 // function : ClickOnOk()
1290 // purpose : Called when user presses <OK> button
1291 //=================================================================================
1292 void SMESHGUI_ExtrusionDlg::ClickOnOk()
1298 //=================================================================================
1299 // function : reject()
1300 // purpose : Called when dialog box is closed
1301 //=================================================================================
1302 void SMESHGUI_ExtrusionDlg::reject()
1304 disconnect(mySelectionMgr, 0, this, 0);
1305 mySelectionMgr->clearFilters();
1306 //mySelectionMgr->clearSelected();
1307 if (SMESH::GetCurrentVtkView()) {
1308 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1309 SMESH::SetPointRepresentation(false);
1310 SMESH::SetPickable();
1312 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1313 aViewWindow->SetSelectionMode(ActorSelection);
1314 mySMESHGUI->ResetState();
1319 //=================================================================================
1320 // function : onOpenView()
1322 //=================================================================================
1323 void SMESHGUI_ExtrusionDlg::onOpenView()
1326 SMESH::SetPointRepresentation(false);
1329 mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
1330 ActivateThisDialog();
1334 //=================================================================================
1335 // function : onCloseView()
1337 //=================================================================================
1338 void SMESHGUI_ExtrusionDlg::onCloseView()
1340 DeactivateActiveDialog();
1344 //=================================================================================
1345 // function : ClickOnHelp()
1347 //=================================================================================
1348 void SMESHGUI_ExtrusionDlg::ClickOnHelp()
1350 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1352 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
1356 platform = "winapplication";
1358 platform = "application";
1360 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
1361 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
1362 arg(app->resourceMgr()->stringValue("ExternalBrowser",
1364 arg(myHelpFileName));
1368 //=================================================================================
1369 // function : SelectionIntoArgument()
1370 // purpose : Called when selection has changed or other case
1371 //=================================================================================
1372 void SMESHGUI_ExtrusionDlg::SelectionIntoArgument()
1374 // return if dialog box is inactive
1375 if (!GroupButtons->isEnabled())
1378 SALOME_ListIO aList;
1379 mySelectionMgr->selectedObjects(aList);
1380 if ( aList.IsEmpty() || aList.Extent() > 1 )
1383 if ( SelectVectorButton->isChecked() )
1385 Handle(SALOME_InteractiveObject) IO = aList.First();
1386 SVTK_TIndexedMapOfVtkId aMapIndex;
1387 mySelector->GetIndex(IO,aMapIndex);
1388 if ( aMapIndex.Extent() != 1 )
1390 SMESH_Actor* anActor = SMESH::FindActorByEntry( IO->getEntry() );
1391 SMDS_Mesh* aMesh = anActor ? anActor->GetObject()->GetMesh() : 0;
1395 const SMDS_MeshFace* face =
1396 aMesh->DownCast< SMDS_MeshFace >(aMesh->FindElement(aMapIndex(1)));
1400 gp_XYZ aNormale = SMESH::getNormale(face);
1401 SpinBox_Vx->SetValue(aNormale.X());
1402 SpinBox_Vy->SetValue(aNormale.Y());
1403 SpinBox_Vz->SetValue(aNormale.Z());
1405 else if ( SelectBasePointButton->isChecked() )
1407 if (!BasePointGrp->isChecked())
1410 // try to get shape from selection
1411 Handle(SALOME_InteractiveObject) IO = aList.First();
1413 // check if geom vertex is selected
1414 GEOM::GEOM_Object_var aGeomObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(IO);
1415 TopoDS_Vertex aVertex;
1416 if (!aGeomObj->_is_nil()) {
1417 if (aGeomObj->IsShape() && GEOMBase::GetShape(aGeomObj, aVertex) && !aVertex.IsNull()) {
1418 gp_Pnt aPnt = BRep_Tool::Pnt(aVertex);
1419 BasePoint_XSpin->SetValue(aPnt.X());
1420 BasePoint_YSpin->SetValue(aPnt.Y());
1421 BasePoint_ZSpin->SetValue(aPnt.Z());
1425 if ( aVertex.IsNull() )
1427 // check if smesh node is selected
1428 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(IO);
1429 if (aMesh->_is_nil())
1433 int aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
1434 // return if more than one node is selected
1438 SMESH_Actor* aMeshActor = SMESH::FindActorByObject(aMesh);
1442 SMDS_Mesh* mesh = aMeshActor->GetObject()->GetMesh();
1446 const SMDS_MeshNode* n = mesh->FindNode(aString.toLong());
1450 BasePoint_XSpin->SetValue(n->X());
1451 BasePoint_YSpin->SetValue(n->Y());
1452 BasePoint_ZSpin->SetValue(n->Z());
1456 onDisplaySimulation(true);
1460 //=================================================================================
1461 // function : SetEditCurrentArgument()
1463 //=================================================================================
1464 void SMESHGUI_ExtrusionDlg::SetEditCurrentArgument()
1466 QPushButton* send = (QPushButton*)sender();
1468 disconnect(mySelectionMgr, 0, this, 0);
1469 mySelectionMgr->clearSelected();
1470 mySelectionMgr->clearFilters();
1472 if (send == SelectVectorButton)
1474 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1475 aViewWindow->SetSelectionMode(FaceSelection);
1477 else if ( send == SelectBasePointButton )
1479 SMESH::SetPointRepresentation(true);
1480 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1481 aViewWindow->SetSelectionMode(NodeSelection);
1483 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter(SMESH::IDSOURCE);
1484 SMESH_NumberFilter* aVertexFilter = new SMESH_NumberFilter ("GEOM", TopAbs_VERTEX,
1486 QList<SUIT_SelectionFilter*> aListOfFilters;
1487 aListOfFilters << aMeshOrSubMeshFilter << aVertexFilter;
1489 mySelectionMgr->installFilter(new SMESH_LogicalFilter
1490 (aListOfFilters, SMESH_LogicalFilter::LO_OR, true));
1493 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
1494 SelectionIntoArgument();
1497 //=================================================================================
1498 // function : DeactivateActiveDialog()
1499 // purpose : Deactivates this dialog
1500 //=================================================================================
1501 void SMESHGUI_ExtrusionDlg::DeactivateActiveDialog()
1503 if (GroupButtons->isEnabled())
1505 GroupArguments->setEnabled(false);
1506 GroupButtons->setEnabled(false);
1507 SelectorWdg->setEnabled(false);
1508 mySMESHGUI->ResetState();
1509 mySMESHGUI->SetActiveDialogBox(0);
1513 //=================================================================================
1514 // function : ActivateThisDialog()
1515 // purpose : Activates this dialog
1516 //=================================================================================
1517 void SMESHGUI_ExtrusionDlg::ActivateThisDialog()
1519 // Emit a signal to deactivate the active dialog
1520 mySMESHGUI->EmitSignalDeactivateDialog();
1521 GroupArguments->setEnabled(true);
1522 GroupButtons->setEnabled(true);
1523 SelectorWdg->setEnabled(true);
1525 mySMESHGUI->SetActiveDialogBox(this);
1528 //=================================================================================
1529 // function : enterEvent()
1531 //=================================================================================
1532 void SMESHGUI_ExtrusionDlg::enterEvent (QEvent*)
1534 if ( !GroupButtons->isEnabled() ) {
1535 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
1536 if ( aViewWindow && !mySelector) {
1537 mySelector = aViewWindow->GetSelector();
1539 ActivateThisDialog();
1543 //=================================================================================
1544 // function : keyPressEvent()
1546 //=================================================================================
1547 void SMESHGUI_ExtrusionDlg::keyPressEvent( QKeyEvent* e )
1549 QDialog::keyPressEvent( e );
1550 if ( e->isAccepted() )
1553 if ( e->key() == Qt::Key_F1 ) {
1559 //=================================================================================
1560 // function : isValid
1562 //=================================================================================
1563 bool SMESHGUI_ExtrusionDlg::isValid()
1567 if ( ExtrMethod_RBut0->isChecked() ) {
1568 ok = SpinBox_Dx->isValid( msg, true ) && ok;
1569 ok = SpinBox_Dy->isValid( msg, true ) && ok;
1570 ok = SpinBox_Dz->isValid( msg, true ) && ok;
1571 } else if ( ExtrMethod_RBut1->isChecked() ) {
1572 ok = SpinBox_Vx->isValid( msg, true ) && ok;
1573 ok = SpinBox_Vy->isValid( msg, true ) && ok;
1574 ok = SpinBox_Vz->isValid( msg, true ) && ok;
1575 ok = SpinBox_VDist->isValid( msg, true ) && ok;
1577 ok = SpinBox_NbSteps->isValid( msg, true ) && ok;
1579 if ( BasePointGrp->isChecked()) {
1580 ok = BasePoint_XSpin->isValid( msg, true ) && ok;
1581 ok = BasePoint_YSpin->isValid( msg, true ) && ok;
1582 ok = BasePoint_ZSpin->isValid( msg, true ) && ok;
1586 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1587 if ( !msg.isEmpty() )
1589 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1595 //=================================================================================
1596 // function : onDisplaySimulation
1597 // purpose : Show/Hide preview
1598 //=================================================================================
1599 void SMESHGUI_ExtrusionDlg::onDisplaySimulation( bool toDisplayPreview )
1601 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1602 if ( SelectorWdg->IsAnythingSelected() && isValid() && isValuesValid())
1605 SMESH::DirStruct aVector;
1606 getExtrusionVector(aVector);
1608 //Get Number of the steps
1609 long aNbSteps = (long)SpinBox_NbSteps->value();
1612 SUIT_OverrideCursor aWaitCursor;
1614 SMESH::SMESH_Mesh_var mesh = SelectorWdg->GetMesh();
1615 SMESH::SMESH_MeshEditor_var meshEditor = mesh->GetMeshEditPreviewer();
1616 SMESH::ListOfGroups_var groups;
1618 SMESH::ListOfIDSources_var nodes = new SMESH::ListOfIDSources();
1619 SMESH::ListOfIDSources_var edges = new SMESH::ListOfIDSources();
1620 SMESH::ListOfIDSources_var faces = new SMESH::ListOfIDSources();
1621 const int maxSelType = SelectorWdg->GetSelected( nodes, edges, faces );
1622 const bool makeGroups = false;
1624 if ( ExtrMethod_RBut2->isVisible() &&
1625 ExtrMethod_RBut2->isChecked() ) // Extrusion by normal
1627 double stepSize = (double) SpinBox_VDist->value();
1628 long nbSteps = (long) SpinBox_NbSteps->value();
1629 bool useInputElemsOnly = UseInputElemsOnlyCheck->isChecked();
1630 bool byAverageNormal = ByAverageNormalCheck->isChecked();
1631 int dim = (maxSelType == SMESH::FACE) ? 2 : 1;
1633 groups = meshEditor->ExtrusionByNormal( faces, stepSize, nbSteps, byAverageNormal,
1634 useInputElemsOnly, makeGroups, dim );
1638 SMESH::double_array_var scales, basePoint, angles;
1639 bool scalesVariation, anglesVariation;
1640 getScaleParams( scales.out(), basePoint.out(), scalesVariation,
1641 angles.out(), anglesVariation );
1642 groups = meshEditor->ExtrusionSweepObjects( nodes, edges, faces,
1643 aVector, aNbSteps, makeGroups,
1644 scales, scalesVariation, basePoint,
1645 angles, anglesVariation );
1647 SMESH::MeshPreviewStruct_var aMeshPreviewStruct = meshEditor->GetPreviewData();
1648 mySimulation->SetData(aMeshPreviewStruct);
1661 //=================================================================================
1662 // function : getExtrusionVector()
1663 // purpose : get direction of the extrusion
1664 //=================================================================================
1665 void SMESHGUI_ExtrusionDlg::getExtrusionVector(SMESH::DirStruct& aVector)
1667 if ( ExtrMethod_RBut0->isChecked() )
1669 aVector.PS.x = SpinBox_Dx->GetValue();
1670 aVector.PS.y = SpinBox_Dy->GetValue();
1671 aVector.PS.z = SpinBox_Dz->GetValue();
1673 else if ( ExtrMethod_RBut1->isChecked() )
1675 gp_XYZ aNormale(SpinBox_Vx->GetValue(),
1676 SpinBox_Vy->GetValue(),
1677 SpinBox_Vz->GetValue());
1678 aNormale /= aNormale.Modulus();
1679 double aVDist = (double)SpinBox_VDist->value();
1681 aVector.PS.x = aNormale.X()*aVDist;
1682 aVector.PS.y = aNormale.Y()*aVDist;
1683 aVector.PS.z = aNormale.Z()*aVDist;
1687 //=======================================================================
1688 // function : OnScaleAdded()
1689 // purpose : Called when user adds Scale or Angle to the list
1690 //=======================================================================
1691 void SMESHGUI_ExtrusionDlg::OnScaleAdded()
1693 if ( sender() == AddScaleButton )
1696 if( !ScaleSpin->isValid( msg, true ) ) {
1697 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1698 if ( !msg.isEmpty() )
1700 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1703 ScalesList->addItem(ScaleSpin->text());
1704 myScalesList.append(ScaleSpin->GetValue());
1707 if ( sender() == AddAngleButton )
1710 if( !AngleSpin->isValid( msg, true ) ) {
1711 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1712 if ( !msg.isEmpty() )
1714 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1717 AnglesList->addItem(AngleSpin->text());
1718 myAnglesList.append(AngleSpin->GetValue());
1722 //=======================================================================
1723 // function : OnScaleRemoved()
1724 // purpose : Called when user removes Scales or Angles from the list
1725 //=======================================================================
1726 void SMESHGUI_ExtrusionDlg::OnScaleRemoved()
1728 QListWidget* widget;
1729 QList<double>* list;
1730 if ( sender() == RemoveScaleButton )
1732 widget = ScalesList;
1733 list = & myScalesList;
1737 widget = AnglesList;
1738 list = & myAnglesList;
1741 QList<QListWidgetItem*> aList = widget->selectedItems();
1742 QListWidgetItem* anItem;
1744 foreach(anItem, aList) {
1745 row = widget->row(anItem);
1746 list->removeAt(row);
1749 widget->setCurrentRow( row, QItemSelectionModel::Select );