1 // Copyright (C) 2007-2014 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 // File : SMESHGUI_ReorientFacesDlg.cxx
24 // Author : Edward AGAPOV, Open CASCADE S.A.S.
27 #include "SMESHGUI_ReorientFacesDlg.h"
30 #include "SMESHGUI_IdValidator.h"
31 #include "SMESHGUI_MeshUtils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_SpinBox.h"
34 #include "SMESHGUI_MeshEditPreview.h"
36 #include <SMDS_Mesh.hxx>
37 #include <SMESH_Actor.h>
38 #include <SMESH_ActorUtils.h>
39 #include <SMESH_NumberFilter.hxx>
40 #include <SMESH_LogicalFilter.hxx>
41 #include <SMESH_TypeFilter.hxx>
43 // SALOME GEOM includes
46 // SALOME GUI includes
47 #include <LightApp_SelectionMgr.h>
48 #include <SALOME_ListIO.hxx>
49 #include <SUIT_Desktop.h>
50 #include <SUIT_MessageBox.h>
51 #include <SUIT_OverrideCursor.h>
52 #include <SUIT_ResourceMgr.h>
53 #include <SVTK_ViewModel.h>
54 #include <SVTK_ViewWindow.h>
55 #include <SalomeApp_Tools.h>
56 #include <SalomeApp_TypeFilter.h>
58 // SALOME KERNEL includes
59 #include <SALOMEDS_SObject.hxx>
62 #include <BRep_Tool.hxx>
63 #include <TColStd_MapOfInteger.hxx>
64 #include <TColgp_SequenceOfXYZ.hxx>
65 #include <TopoDS_Vertex.hxx>
70 #include <QGridLayout>
71 #include <QHBoxLayout>
72 #include <QVBoxLayout>
74 #include <QPushButton>
76 #include <QRadioButton>
78 #include <QButtonGroup>
81 #include <vtkProperty.h>
84 #include <SALOMEconfig.h>
85 #include CORBA_SERVER_HEADER(SMESH_Mesh)
86 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
94 enum { CONSTRUCTOR_POINT=0, CONSTRUCTOR_FACE, CONSTRUCTOR_VOLUME,
95 EObject, EPoint, EFace, EDirection, EVolumes };
97 //=======================================================================
99 * \brief Dialog to reorient faces acoording to vector
101 //=======================================================================
103 SMESHGUI_ReorientFacesDlg::SMESHGUI_ReorientFacesDlg()
104 : SMESHGUI_Dialog( 0, false, true )
106 setWindowTitle(tr("CAPTION"));
108 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
109 aDlgLay->setMargin(0);
110 aDlgLay->setSpacing(SPACING);
112 QWidget* aMainFrame = createMainFrame (mainFrame());
114 aDlgLay->addWidget(aMainFrame);
116 aDlgLay->setStretchFactor(aMainFrame, 1);
119 //================================================================================
121 * \brief Create frame containing dialog's input fields
123 //================================================================================
125 QWidget* SMESHGUI_ReorientFacesDlg::createMainFrame (QWidget* theParent)
127 QWidget* aFrame = new QWidget(theParent);
131 QPixmap iconReoriPoint (resMgr()->loadPixmap("SMESH", tr("ICON_DLG_REORIENT2D_POINT")));
132 QPixmap iconReoriFace (resMgr()->loadPixmap("SMESH", tr("ICON_DLG_REORIENT2D_FACE")));
133 QPixmap iconReoriVolum (resMgr()->loadPixmap("SMESH", tr("ICON_DLG_REORIENT2D_VOLUME")));
135 QGroupBox* aConstructorBox = new QGroupBox(tr("REORIENT_FACES"), aFrame);
136 myConstructorGrp = new QButtonGroup(aConstructorBox);
137 QHBoxLayout* aConstructorGrpLayout = new QHBoxLayout(aConstructorBox);
138 aConstructorGrpLayout->setMargin(MARGIN);
139 aConstructorGrpLayout->setSpacing(SPACING);
141 QRadioButton* aPntBut = new QRadioButton(aConstructorBox);
142 aPntBut->setIcon(iconReoriPoint);
143 aPntBut->setChecked(true);
144 aConstructorGrpLayout->addWidget(aPntBut);
145 myConstructorGrp->addButton(aPntBut, CONSTRUCTOR_POINT);
147 QRadioButton* aFaceBut= new QRadioButton(aConstructorBox);
148 aFaceBut->setIcon(iconReoriFace);
149 aConstructorGrpLayout->addWidget(aFaceBut);
150 myConstructorGrp->addButton(aFaceBut, CONSTRUCTOR_FACE);
152 QRadioButton* aVolBut= new QRadioButton(aConstructorBox);
153 aVolBut->setIcon(iconReoriVolum);
154 aConstructorGrpLayout->addWidget(aVolBut);
155 myConstructorGrp->addButton(aVolBut, CONSTRUCTOR_VOLUME);
157 // Create other controls
159 setObjectPixmap( "SMESH", tr( "ICON_SELECT" ) );
161 createObject( tr("OBJECT") , aFrame, EObject );
162 createObject( tr("POINT") , aFrame, EPoint );
163 createObject( tr("FACE") , aFrame, EFace );
164 createObject( tr("DIRECTION"), aFrame, EDirection );
165 createObject( tr("VOLUMES"), aFrame, EVolumes );
166 setNameIndication( EObject, OneName );
167 setNameIndication( EFace, OneName );
168 setReadOnly( EFace, false );
169 if ( QLineEdit* le = qobject_cast<QLineEdit*>( objectWg( EFace, Control ) ))
170 le->setValidator( new SMESHGUI_IdValidator( this,1 ));
172 int width = aFaceBut->fontMetrics().width( tr("DIRECTION"));
173 objectWg( EDirection, Label )->setFixedWidth( width );
174 objectWg( EObject , Label )->setFixedWidth( width );
175 objectWg( EPoint , Label )->setFixedWidth( width );
176 objectWg( EFace , Label )->setFixedWidth( width );
177 objectWg( EVolumes , Label )->setFixedWidth( width );
179 myOutsideChk = new QCheckBox( tr("OUTSIDE_VOLUME_NORMAL"), aFrame);
180 myOutsideChk->setChecked( true );
182 QLabel* aXLabel = new QLabel(tr("SMESH_X"), aFrame);
183 myX = new SMESHGUI_SpinBox(aFrame);
184 QLabel* aYLabel = new QLabel(tr("SMESH_Y"), aFrame);
185 myY = new SMESHGUI_SpinBox(aFrame);
186 QLabel* aZLabel = new QLabel(tr("SMESH_Z"), aFrame);
187 myZ = new SMESHGUI_SpinBox(aFrame);
189 myX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
190 myY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
191 myZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
196 QLabel* aDXLabel = new QLabel(tr("SMESH_DX"), aFrame);
197 myDX = new SMESHGUI_SpinBox(aFrame);
198 QLabel* aDYLabel = new QLabel(tr("SMESH_DY"), aFrame);
199 myDY = new SMESHGUI_SpinBox(aFrame);
200 QLabel* aDZLabel = new QLabel(tr("SMESH_DZ"), aFrame);
201 myDZ = new SMESHGUI_SpinBox(aFrame);
206 myDX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
207 myDY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
208 myDZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
210 width = Max( aFaceBut->fontMetrics().width( tr("SMESH_X")),
211 aFaceBut->fontMetrics().width( tr("SMESH_DX")));
212 aXLabel->setFixedWidth( width );
213 aYLabel->setFixedWidth( width );
214 aZLabel->setFixedWidth( width );
215 aDXLabel->setFixedWidth( width );
216 aDYLabel->setFixedWidth( width );
217 aDZLabel->setFixedWidth( width );
221 QGroupBox* anObjectGrp = new QGroupBox(tr("FACES"), aFrame);
222 QHBoxLayout* anObjectGrpLayout = new QHBoxLayout(anObjectGrp);
223 anObjectGrpLayout->setMargin(MARGIN);
224 anObjectGrpLayout->setSpacing(SPACING);
225 anObjectGrpLayout->addWidget( objectWg( EObject, Label ));
226 anObjectGrpLayout->addWidget( objectWg( EObject, Btn ));
227 anObjectGrpLayout->addWidget( objectWg( EObject, Control ));
229 myPointFrm = new QFrame(aFrame);
230 QHBoxLayout* aPointGrpLayout = new QHBoxLayout(myPointFrm);
231 aPointGrpLayout->setMargin(0);
232 objectWg( EPoint, Control )->hide();
233 aPointGrpLayout->addWidget( objectWg( EPoint, Label ) );
234 aPointGrpLayout->addWidget( objectWg( EPoint, Btn ) );
235 aPointGrpLayout->addWidget( aXLabel, 0 );
236 aPointGrpLayout->addWidget( myX, 1 );
237 aPointGrpLayout->addWidget( aYLabel, 0 );
238 aPointGrpLayout->addWidget( myY, 1 );
239 aPointGrpLayout->addWidget( aZLabel, 0 );
240 aPointGrpLayout->addWidget( myZ, 1 );
242 myFaceFrm = new QFrame(aFrame);
243 QHBoxLayout* aFaceGrpLayout = new QHBoxLayout(myFaceFrm);
244 aFaceGrpLayout->setMargin(0);
245 aFaceGrpLayout->addWidget( objectWg( EFace, Label ) );
246 aFaceGrpLayout->addWidget( objectWg( EFace, Btn ) );
247 aFaceGrpLayout->addWidget( objectWg( EFace, Control ) );
249 myVolumFrm = new QFrame(aFrame);
250 QGridLayout* aVolumGrpLayout = new QGridLayout(myVolumFrm);
251 aVolumGrpLayout->setMargin(0);
252 aVolumGrpLayout->setSpacing(SPACING);
253 aVolumGrpLayout->addWidget( objectWg( EVolumes, Label ), 0, 0 );
254 aVolumGrpLayout->addWidget( objectWg( EVolumes, Btn ), 0, 1 );
255 aVolumGrpLayout->addWidget( objectWg( EVolumes, Control ), 0, 2 );
256 aVolumGrpLayout->addWidget( myOutsideChk, 1, 0, 1, 3 );
258 myDirFrm = new QFrame(aFrame);
259 QHBoxLayout* aDirectGrpLayout = new QHBoxLayout(myDirFrm);
260 aDirectGrpLayout->setMargin(0);
261 objectWg( EDirection, Control )->hide();
262 aDirectGrpLayout->addWidget( objectWg( EDirection, Label ) );
263 aDirectGrpLayout->addWidget( objectWg( EDirection, Btn ) );
264 aDirectGrpLayout->addWidget( aDXLabel, 0 );
265 aDirectGrpLayout->addWidget( myDX, 1 );
266 aDirectGrpLayout->addWidget( aDYLabel, 0 );
267 aDirectGrpLayout->addWidget( myDY, 1 );
268 aDirectGrpLayout->addWidget( aDZLabel, 0 );
269 aDirectGrpLayout->addWidget( myDZ, 1 );
272 QGroupBox* anOrientGrp = new QGroupBox(tr("ORIENTATION"), aFrame);
273 QVBoxLayout* anOrientGrpLayout = new QVBoxLayout ( anOrientGrp );
274 anOrientGrpLayout->addWidget(myPointFrm);
275 anOrientGrpLayout->addWidget(myFaceFrm);
276 anOrientGrpLayout->addWidget(myVolumFrm);
277 anOrientGrpLayout->addWidget(myDirFrm);
280 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
281 aLay->addWidget(aConstructorBox);
282 aLay->addWidget(anObjectGrp);
283 aLay->addWidget(anOrientGrp);
285 connect( myConstructorGrp, SIGNAL(buttonClicked (int)), this, SLOT(constructorChange(int)));
290 //================================================================================
292 * \brief Show point or face
294 //================================================================================
296 void SMESHGUI_ReorientFacesDlg::constructorChange(int id)
298 if ( id == CONSTRUCTOR_FACE )
304 activateObject( EFace );
306 else if ( id == CONSTRUCTOR_POINT )
312 activateObject( EPoint );
314 else // CONSTRUCTOR_VOLUME
320 activateObject( EVolumes );
324 //================================================================================
328 //================================================================================
330 SMESHGUI_ReorientFacesOp::SMESHGUI_ReorientFacesOp()
331 :SMESHGUI_SelectionOp( ActorSelection )
333 //myVectorPreview = 0;
334 myHelpFileName = "reorient_faces_page.html";
336 myDlg = new SMESHGUI_ReorientFacesDlg;
337 myDlg->constructorChange( CONSTRUCTOR_POINT );
339 // connect signals and slots
340 connect( myDlg->objectWg( EFace, LightApp_Dialog::Control ), SIGNAL(textChanged(const QString&)),
341 this, SLOT(onTextChange(const QString&)));
342 // connect(myDlg->myX, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
343 // connect(myDlg->myY, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
344 // connect(myDlg->myZ, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
345 // connect(myDlg->myDX, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
346 // connect(myDlg->myDY, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
347 // connect(myDlg->myDZ, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
351 //=======================================================================
352 // function : startOperation()
353 // purpose : Init dialog fields, connect signals and slots, show dialog
354 //=======================================================================
356 void SMESHGUI_ReorientFacesOp::startOperation()
360 // init simulation with a current View
361 //if ( myVectorPreview ) delete myVectorPreview;
362 // myVectorPreview = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( getSMESHGUI() ));
363 // vtkProperty* aProp = vtkProperty::New();
364 // aProp->SetRepresentationToWireframe();
365 // aProp->SetColor(250, 0, 250);
366 // aProp->SetPointSize(5);
367 // aProp->SetLineWidth( SMESH::GetFloat("SMESH:element_width",1) + 1);
368 // myVectorPreview->GetActor()->SetProperty(aProp);
371 SMESHGUI_SelectionOp::startOperation();
376 myDlg->activateObject( EObject );
379 //================================================================================
381 * \brief Stops operation
383 //================================================================================
385 void SMESHGUI_ReorientFacesOp::stopOperation()
387 //myVectorPreview->SetVisibility(false);
388 if ( myObjectActor ) {
389 myObjectActor->SetPointRepresentation(false);
390 SMESH::RepaintCurrentView();
393 SMESHGUI_SelectionOp::stopOperation();
394 myDlg->deactivateAll();
397 //================================================================================
399 * \brief Set selection mode corresponding to a pressed selection button
401 //================================================================================
403 void SMESHGUI_ReorientFacesOp::onActivateObject( int what )
405 if ( what == mySelectionMode )
407 mySelectionMode = what;
408 switch ( mySelectionMode )
412 SMESH::SetPointRepresentation(true);
413 setSelectionMode( NodeSelection );
414 SMESH::SetPickable();
418 SMESH::SetPointRepresentation(false);
419 setSelectionMode( ActorSelection );
422 SMESH::SetPointRepresentation(false);
423 setSelectionMode( FaceSelection );
425 SMESH::SetPickable( myObjectActor );
427 SMESH::SetPickable();
430 SMESHGUI_SelectionOp::onActivateObject( what );
433 //================================================================================
435 * \brief Creates a filter corresponding to a pressed selection button
437 //================================================================================
439 SUIT_SelectionFilter* SMESHGUI_ReorientFacesOp::createFilter( const int what ) const
445 QList<SUIT_SelectionFilter*> filters;
446 filters.append( new SMESH_TypeFilter( SMESH::MESH ));
447 filters.append( new SMESH_TypeFilter( SMESH::SUBMESH_FACE ));
448 filters.append( new SMESH_TypeFilter( SMESH::GROUP_FACE ));
449 return new SMESH_LogicalFilter( filters, SMESH_LogicalFilter::LO_OR );
453 QList<SUIT_SelectionFilter*> filters;
454 filters.append( new SMESH_TypeFilter( SMESH::MESH ));
455 filters.append( new SMESH_TypeFilter( SMESH::SUBMESH_SOLID ));
456 filters.append( new SMESH_TypeFilter( SMESH::GROUP_VOLUME ));
457 return new SMESH_LogicalFilter( filters, SMESH_LogicalFilter::LO_OR );
461 QList<SUIT_SelectionFilter*> filters;
462 filters.append( new SMESH_TypeFilter( SMESH::IDSOURCE ));
463 filters.append( new SMESH_NumberFilter( "GEOM",TopAbs_VERTEX, 1, TopAbs_VERTEX ));
464 return new SMESH_LogicalFilter( filters, SMESH_LogicalFilter::LO_OR );
469 return new SMESH_TypeFilter( SMESH::IDSOURCE );
475 //================================================================================
477 * \brief get data from selection
479 //================================================================================
481 void SMESHGUI_ReorientFacesOp::selectionDone()
483 if ( !myDlg->isVisible() || !myDlg->isEnabled() )
486 if ( mySelectionMode == EVolumes )
488 SMESHGUI_SelectionOp::selectionDone();
492 myDlg->clearSelection( mySelectionMode );
495 selectionMgr()->selectedObjects(aList);
496 const int nbSelected = aList.Extent();
497 if ( nbSelected == 0 )
500 Handle(SALOME_InteractiveObject) anIO = aList.First();
504 switch ( mySelectionMode )
506 case EObject: { // get an actor of object
508 if ( nbSelected == 1 )
510 myDlg->selectObject( EObject, anIO->getName(), 0, anIO->getEntry(), true );
511 // typeById( aList.First()->getEntry(),
512 // SMESHGUI_SelectionOp::Object ),
513 myObjectActor = SMESH::FindActorByEntry( anIO->getEntry() );
517 case EFace: { // get a face ID
519 if ( nbSelected == 1 )
521 TColStd_IndexedMapOfInteger faceIndices;
522 selector()->GetIndex( anIO, faceIndices );
523 if ( faceIndices.Extent() == 1 )
525 SMESH_Actor* savedActor = myObjectActor;
526 myObjectActor = 0; // to prevent work of onTextChange()
527 myDlg->setObjectText( EFace, QString("%1").arg( faceIndices(1) ));
528 myObjectActor = savedActor;
530 if ( !myObjectActor )
532 myDlg->selectObject( EObject, anIO->getName(), 0, anIO->getEntry(), true );
533 // typeById( aList.First()->getEntry(),
534 // SMESHGUI_SelectionOp::Object ),
535 myObjectActor = SMESH::FindActorByEntry( anIO->getEntry() );
542 case EDirection: { // set XYZ by selected nodes or vertices
544 if ( mySelectionMode == EPoint && aList.Extent() > 1 )
547 TColgp_SequenceOfXYZ points;
548 for( SALOME_ListIteratorOfListIO anIt( aList ); anIt.More(); anIt.Next() )
551 GEOM::GEOM_Object_var geom = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
552 if ( !geom->_is_nil() ) {
553 TopoDS_Vertex aShape;
554 if ( GEOMBase::GetShape(geom, aShape) && aShape.ShapeType() == TopAbs_VERTEX ) {
555 gp_Pnt P = BRep_Tool::Pnt(aShape);
556 points.Append( P.XYZ() );
561 TColStd_IndexedMapOfInteger nodeIndices;
562 selector()->GetIndex( anIO, nodeIndices );
563 if ( nodeIndices.Extent() > 0 && nodeIndices.Extent() <=2 )
565 if ( SMESH_Actor* aMeshActor = SMESH::FindActorByEntry(anIO->getEntry()))
566 if (SMDS_Mesh* aMesh = aMeshActor->GetObject()->GetMesh())
568 if (const SMDS_MeshNode* aNode = aMesh->FindNode( nodeIndices(1)))
569 points.Append( gp_XYZ( aNode->X(), aNode->Y(), aNode->Z()));
570 if ( nodeIndices.Extent() == 2 )
571 if (const SMDS_MeshNode* aNode = aMesh->FindNode( nodeIndices(2)))
572 points.Append( gp_XYZ( aNode->X(), aNode->Y(), aNode->Z()));
578 if ( points.Length() == 1 )
580 else if ( points.Length() == 2 )
581 xyz = points(2) - points(1);
584 if ( points.Length() == 1 && mySelectionMode == EPoint )
586 myDlg->myX->SetValue( xyz.X() );
587 myDlg->myY->SetValue( xyz.Y() );
588 myDlg->myZ->SetValue( xyz.Z() );
591 if ( mySelectionMode == EDirection )
593 myDlg->myDX->SetValue( xyz.X() );
594 myDlg->myDY->SetValue( xyz.Y() );
595 myDlg->myDZ->SetValue( xyz.Z() );
599 } // case EPoint || EDirection
607 //================================================================================
609 * \brief SLOT called when the face id is changed
611 //================================================================================
613 void SMESHGUI_ReorientFacesOp::onTextChange( const QString& theText )
617 sender()->blockSignals( true );
618 if ( mySelectionMode != EFace )
620 myDlg->activateObject( EFace );
621 myDlg->setObjectText( EFace, theText );
623 TColStd_MapOfInteger ids;
624 if ( !theText.isEmpty() && theText.toInt() > 0 )
625 ids.Add( theText.toInt() );
627 SMESHGUI_SelectionOp::addOrRemoveIndex( myObjectActor->getIO(), ids, false );
628 SMESHGUI_SelectionOp::highlight( myObjectActor->getIO(), true, true );
629 sender()->blockSignals( false );
633 //================================================================================
635 * \brief perform it's intention action: reorient faces of myObject
637 //================================================================================
639 bool SMESHGUI_ReorientFacesOp::onApply()
641 if( isStudyLocked() )
645 if ( !isValid( msg ) ) { // node id is invalid
647 SUIT_MessageBox::warning( dlg(), tr( "SMESH_WRN_WARNING" ), msg );
652 QStringList aParameters;
653 aParameters << myDlg->myDX->text();
654 aParameters << myDlg->myDY->text();
655 aParameters << myDlg->myDZ->text();
656 aParameters << myDlg->myX->text();
657 aParameters << myDlg->myY->text();
658 aParameters << myDlg->myZ->text();
661 SUIT_OverrideCursor wc;
663 SMESH::SMESH_Mesh_var aMesh = myObject->GetMesh();
664 if ( aMesh->_is_nil() ) return false;
666 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
667 if (aMeshEditor->_is_nil()) return false;
670 if ( myDlg->myConstructorGrp->checkedId() == CONSTRUCTOR_VOLUME )
672 SMESH::ListOfIDSources_var faceGroups = new SMESH::ListOfIDSources;
673 faceGroups->length(1);
674 faceGroups[0] = myObject;
676 bool outsideNormal = myDlg->myOutsideChk->isChecked();
678 aResult = aMeshEditor->Reorient2DBy3D( faceGroups, myVolumeObj, outsideNormal );
682 SMESH::DirStruct direction;
683 direction.PS.x = myDlg->myDX->GetValue();
684 direction.PS.y = myDlg->myDY->GetValue();
685 direction.PS.z = myDlg->myDZ->GetValue();
687 long face = myDlg->objectText( EFace ).toInt();
688 if ( myDlg->myConstructorGrp->checkedId() == CONSTRUCTOR_POINT )
691 SMESH::PointStruct point;
692 point.x = myDlg->myX->GetValue();
693 point.y = myDlg->myY->GetValue();
694 point.z = myDlg->myZ->GetValue();
696 aMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
698 aResult = aMeshEditor->Reorient2D( myObject, direction, face, point );
704 selectionMgr()->setSelectedObjects(aList,false);
706 SMESHGUI::Modified();
709 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INFORMATION"),
710 tr("NB_REORIENTED").arg(aResult));
712 catch (const SALOME::SALOME_Exception& S_ex) {
713 SalomeApp_Tools::QtCatchCorbaException(S_ex);
721 //================================================================================
723 * \brief Check data validity
725 //================================================================================
727 bool SMESHGUI_ReorientFacesOp::isValid( QString& msg )
730 QString objectEntry = myDlg->selectedObject( EObject );
731 _PTR(SObject) pSObject = studyDS()->FindObjectID( objectEntry.toLatin1().data() );
732 myObject = SMESH::SMESH_IDSource::_narrow( _CAST( SObject,pSObject )->GetObject() );
733 if ( myObject->_is_nil() )
735 msg = tr("NO_OBJECT_SELECTED");
738 bool hasFaces = false;
739 SMESH::array_of_ElementType_var types = myObject->GetTypes();
740 for ( size_t i = 0; i < types->length() && !hasFaces; ++i )
741 hasFaces = ( types[i] == SMESH::FACE );
744 msg = tr("NO_FACES");
748 // check volume object
749 if ( myDlg->myConstructorGrp->checkedId() == CONSTRUCTOR_VOLUME )
751 objectEntry = myDlg->selectedObject( EVolumes );
752 _PTR(SObject) pSObject = studyDS()->FindObjectID( objectEntry.toLatin1().data() );
753 myVolumeObj = SMESH::SObjectToInterface< SMESH::SMESH_IDSource>( pSObject );
754 if ( myVolumeObj->_is_nil() )
756 msg = tr("NO_VOLUME_OBJECT_SELECTED");
759 bool hasVolumes = false;
760 types = myVolumeObj->GetTypes();
761 for ( size_t i = 0; i < types->length() && !hasVolumes; ++i )
762 hasVolumes = ( types[i] == SMESH::VOLUME );
765 msg = tr("NO_VOLUMES");
770 gp_Vec vec( myDlg->myDX->GetValue(),
771 myDlg->myDY->GetValue(),
772 myDlg->myDZ->GetValue() );
773 if ( vec.Magnitude() < std::numeric_limits<double>::min() )
775 msg = tr("ZERO_SIZE_VECTOR");
780 if ( myDlg->myConstructorGrp->checkedId() == CONSTRUCTOR_FACE )
782 int faceID = myDlg->objectText( EFace ).toInt();
783 bool faceOK = ( faceID > 0 );
788 faceOK = ( myObjectActor->GetObject()->GetElemDimension( faceID ) == 2 );
792 SMESH::SMESH_Mesh_var aMesh = myObject->GetMesh();
793 if ( !aMesh->_is_nil() )
794 faceOK = ( aMesh->GetElementType( faceID, true ) == SMESH::FACE );
799 msg = tr("INVALID_FACE");
807 //================================================================================
811 //================================================================================
813 SMESHGUI_ReorientFacesOp::~SMESHGUI_ReorientFacesOp()
815 if ( myDlg ) delete myDlg;
816 //if ( myVectorPreview ) delete myVectorPreview;
819 //================================================================================
821 * \brief Gets dialog of this operation
822 * \retval LightApp_Dialog* - pointer to dialog of this operation
824 //================================================================================
826 LightApp_Dialog* SMESHGUI_ReorientFacesOp::dlg() const
831 //================================================================================
833 * \brief update preview
835 //================================================================================
837 void SMESHGUI_ReorientFacesOp::redisplayPreview()
839 // SMESH::MeshPreviewStruct_var aMeshPreviewStruct;
841 // bool moveShown = false;
842 // if ( myObjectActor)
844 // const bool autoSearch = myDlg->myAutoSearchChkBox->isChecked();
845 // const bool preview = myDlg->myPreviewChkBox->isChecked();
848 // myDlg->myCurrentX->SetValue(0);
849 // myDlg->myCurrentY->SetValue(0);
850 // myDlg->myCurrentZ->SetValue(0);
851 // myDlg->myDX->SetValue(0);
852 // myDlg->myDY->SetValue(0);
853 // myDlg->myDZ->SetValue(0);
854 // myDlg->myId->setText("");
857 // if ( autoSearch || isValid( msg ) )
860 // SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(myObjectActor->getIO());
861 // if (!aMesh->_is_nil()) {
862 // SMESH::SMESH_MeshEditor_var aPreviewer = aMesh->GetMeshEditPreviewer();
863 // if (!aPreviewer->_is_nil())
865 // SUIT_OverrideCursor aWaitCursor;
869 // anId = aPreviewer->FindNodeClosestTo(myDlg->myX->GetValue(),
870 // myDlg->myY->GetValue(),
871 // myDlg->myZ->GetValue());
873 // anId = myDlg->myId->text().toInt();
875 // // find id and/or just compute preview
876 // aPreviewer->MoveNode(anId,
877 // myDlg->myX->GetValue(),
878 // myDlg->myY->GetValue(),
879 // myDlg->myZ->GetValue());
880 // if ( autoSearch ) { // set found id
881 // QString idTxt("%1");
883 // idTxt = idTxt.arg( anId );
886 // myDlg->myId->setText( idTxt );
889 // SMESH::double_array* aXYZ = aMesh->GetNodeXYZ( anId );
890 // if( aXYZ && aXYZ->length() >= 3 )
892 // double x = aXYZ->operator[](0);
893 // double y = aXYZ->operator[](1);
894 // double z = aXYZ->operator[](2);
895 // double dx = myDlg->myX->GetValue() - x;
896 // double dy = myDlg->myY->GetValue() - y;
897 // double dz = myDlg->myZ->GetValue() - z;
898 // myDlg->myCurrentX->SetValue(x);
899 // myDlg->myCurrentY->SetValue(y);
900 // myDlg->myCurrentZ->SetValue(z);
901 // myDlg->myDX->SetValue(dx);
902 // myDlg->myDY->SetValue(dy);
903 // myDlg->myDZ->SetValue(dz);
906 // if ( preview ) { // fill preview data
907 // aMeshPreviewStruct = aPreviewer->GetPreviewData();
908 // moveShown = ( anId > 0 );
919 // aMeshPreviewStruct = new SMESH::MeshPreviewStruct();
921 // aMeshPreviewStruct->nodesXYZ.length(1);
922 // aMeshPreviewStruct->nodesXYZ[0].x = myDlg->myX->GetValue();
923 // aMeshPreviewStruct->nodesXYZ[0].y = myDlg->myY->GetValue();
924 // aMeshPreviewStruct->nodesXYZ[0].z = myDlg->myZ->GetValue();
926 // aMeshPreviewStruct->elementTypes.length(1);
927 // aMeshPreviewStruct->elementTypes[0].SMDS_ElementType = SMESH::NODE;
928 // aMeshPreviewStruct->elementTypes[0].isPoly = false;
929 // aMeshPreviewStruct->elementTypes[0].nbNodesInElement = 1;
931 // aMeshPreviewStruct->elementConnectivities.length(1);
932 // aMeshPreviewStruct->elementConnectivities[0] = 0;
936 // if ( aMeshPreviewStruct.operator->() )
938 // myVectorPreview->SetData(aMeshPreviewStruct._retn());
942 // myVectorPreview->SetVisibility(false);