Salome HOME
IMP: SMESH: Japanese translations
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ReorientFacesDlg.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File   : SMESHGUI_ReorientFacesDlg.cxx
24 // Author : Edward AGAPOV, Open CASCADE S.A.S.
25 // SMESH includes
26 //
27 #include "SMESHGUI_ReorientFacesDlg.h"
28
29 #include "SMESHGUI.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"
35
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>
42
43 // SALOME GEOM includes
44 #include <GEOMBase.h>
45
46 // SALOME GUI includes
47 #include <LightApp_SelectionMgr.h>
48 #include <SALOME_ListIO.hxx>
49 #include <SALOME_ListIteratorOfListIO.hxx>
50 #include <SUIT_Desktop.h>
51 #include <SUIT_MessageBox.h>
52 #include <SUIT_OverrideCursor.h>
53 #include <SUIT_ResourceMgr.h>
54 #include <SVTK_ViewModel.h>
55 #include <SVTK_ViewWindow.h>
56 #include <SalomeApp_Tools.h>
57 #include <SalomeApp_TypeFilter.h>
58
59 // SALOME KERNEL includes
60 #include <SALOMEDS_SObject.hxx>
61
62 // OCCT includes
63 #include <BRep_Tool.hxx>
64 #include <TColStd_MapOfInteger.hxx>
65 #include <TColgp_SequenceOfXYZ.hxx>
66 #include <TopoDS_Vertex.hxx>
67 #include <gp_Pnt.hxx>
68
69 // Qt includes
70 #include <QGroupBox>
71 #include <QGridLayout>
72 #include <QHBoxLayout>
73 #include <QVBoxLayout>
74 #include <QLineEdit>
75 #include <QPushButton>
76 #include <QLabel>
77 #include <QRadioButton>
78 #include <QCheckBox>
79 #include <QButtonGroup>
80
81 // VTK includes
82 #include <vtkProperty.h>
83
84 // IDL includes
85 #include <SALOMEconfig.h>
86 #include CORBA_SERVER_HEADER(SMESH_Mesh)
87 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
88
89 // std
90 #include <limits>
91
92 #define SPACING 6
93 #define MARGIN  11
94
95 enum { CONSTRUCTOR_POINT=0, CONSTRUCTOR_FACE,
96        EObject, EPoint, EFace, EDirection };
97
98 //=======================================================================
99 /*!
100  * \brief Dialog to reorient faces acoording to vector
101  */
102 //=======================================================================
103
104 SMESHGUI_ReorientFacesDlg::SMESHGUI_ReorientFacesDlg()
105   : SMESHGUI_Dialog( 0, false, true )
106 {
107   setWindowTitle(tr("CAPTION"));
108
109   QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
110   aDlgLay->setMargin(0);
111   aDlgLay->setSpacing(SPACING);
112
113   QWidget* aMainFrame = createMainFrame  (mainFrame());
114
115   aDlgLay->addWidget(aMainFrame);
116
117   aDlgLay->setStretchFactor(aMainFrame, 1);
118 }
119
120 //================================================================================
121 /*!
122  * \brief Create frame containing dialog's input fields
123  */
124 //================================================================================
125
126 QWidget* SMESHGUI_ReorientFacesDlg::createMainFrame (QWidget* theParent)
127 {
128   QWidget* aFrame = new QWidget(theParent);
129
130   // constructors
131
132   QPixmap iconReoriPoint (resMgr()->loadPixmap("SMESH", tr("ICON_DLG_REORIENT2D_POINT")));
133   QPixmap iconReoriFace  (resMgr()->loadPixmap("SMESH", tr("ICON_DLG_REORIENT2D_FACE")));
134
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);
140
141   QRadioButton* aPntBut = new QRadioButton(aConstructorBox);
142   aPntBut->setIcon(iconReoriPoint);
143   aPntBut->setChecked(true);
144   aConstructorGrpLayout->addWidget(aPntBut);
145   myConstructorGrp->addButton(aPntBut, CONSTRUCTOR_POINT);
146
147   QRadioButton* aFaceBut= new QRadioButton(aConstructorBox);
148   aFaceBut->setIcon(iconReoriFace);
149   aConstructorGrpLayout->addWidget(aFaceBut);
150   myConstructorGrp->addButton(aFaceBut, CONSTRUCTOR_FACE);
151
152   // Create other controls
153
154   setObjectPixmap( "SMESH", tr( "ICON_SELECT" ) );
155
156   createObject( tr("OBJECT")   , aFrame, EObject );
157   createObject( tr("POINT")    , aFrame, EPoint );
158   createObject( tr("FACE")     , aFrame, EFace );
159   createObject( tr("DIRECTION"), aFrame, EDirection );
160   setNameIndication( EObject, OneName );
161   setNameIndication( EFace, OneName );
162   setReadOnly( EFace, false );
163   if ( QLineEdit* le = qobject_cast<QLineEdit*>( objectWg( EFace, Control ) ))
164     le->setValidator( new SMESHGUI_IdValidator( this,1 ));
165
166   const int width = aFaceBut->fontMetrics().width( tr("DIRECTION"));
167   objectWg( EDirection, Label )->setFixedWidth( width );
168   objectWg( EObject   , Label )->setFixedWidth( width );
169   objectWg( EPoint    , Label )->setFixedWidth( width );
170   objectWg( EFace     , Label )->setFixedWidth( width );
171
172   QLabel* aXLabel = new QLabel(tr("SMESH_X"), aFrame);
173   myX = new SMESHGUI_SpinBox(aFrame);
174   QLabel* aYLabel = new QLabel(tr("SMESH_Y"), aFrame);
175   myY = new SMESHGUI_SpinBox(aFrame);
176   QLabel* aZLabel = new QLabel(tr("SMESH_Z"), aFrame);
177   myZ = new SMESHGUI_SpinBox(aFrame);
178
179   myX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
180   myY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
181   myZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
182   myX->SetValue(0);
183   myY->SetValue(0);
184   myZ->SetValue(0);
185
186   QLabel* aDXLabel = new QLabel(tr("SMESH_DX"), aFrame);
187   myDX = new SMESHGUI_SpinBox(aFrame);
188   QLabel* aDYLabel = new QLabel(tr("SMESH_DY"), aFrame);
189   myDY = new SMESHGUI_SpinBox(aFrame);
190   QLabel* aDZLabel = new QLabel(tr("SMESH_DZ"), aFrame);
191   myDZ = new SMESHGUI_SpinBox(aFrame);
192   myDX->SetValue(1);
193   myDY->SetValue(0);
194   myDZ->SetValue(0);
195
196   myDX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
197   myDY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
198   myDZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
199
200   // Layouting
201
202   QGroupBox* anObjectGrp = new QGroupBox(tr("FACES"), aFrame);
203   QHBoxLayout* anObjectGrpLayout = new QHBoxLayout(anObjectGrp);
204   anObjectGrpLayout->setMargin(MARGIN);
205   anObjectGrpLayout->setSpacing(SPACING);
206   anObjectGrpLayout->addWidget( objectWg( EObject, Label ));
207   anObjectGrpLayout->addWidget( objectWg( EObject, Btn ));
208   anObjectGrpLayout->addWidget( objectWg( EObject, Control ));
209
210   myPointFrm = new QFrame(aFrame);
211   QHBoxLayout* aPointGrpLayout = new QHBoxLayout(myPointFrm);
212   aPointGrpLayout->setMargin(0);
213   objectWg( EPoint, Control )->hide();
214   aPointGrpLayout->addWidget( objectWg( EPoint, Label ) );
215   aPointGrpLayout->addWidget( objectWg( EPoint, Btn ) );
216   aPointGrpLayout->addWidget( aXLabel );
217   aPointGrpLayout->addWidget( myX     );
218   aPointGrpLayout->addWidget( aYLabel );
219   aPointGrpLayout->addWidget( myY     );
220   aPointGrpLayout->addWidget( aZLabel );
221   aPointGrpLayout->addWidget( myZ     );
222
223   myFaceFrm = new QFrame(aFrame);
224   QHBoxLayout* aFaceGrpLayout = new QHBoxLayout(myFaceFrm);
225   aFaceGrpLayout->setMargin(0);
226   aFaceGrpLayout->addWidget( objectWg( EFace, Label ) );
227   aFaceGrpLayout->addWidget( objectWg( EFace, Btn ) );
228   aFaceGrpLayout->addWidget( objectWg( EFace, Control ) );
229
230   QFrame* aDirectFrm = new QFrame(aFrame);
231   QHBoxLayout* aDirectGrpLayout = new QHBoxLayout(aDirectFrm);
232   aDirectGrpLayout->setMargin(0);
233   objectWg( EDirection, Control )->hide();
234   aDirectGrpLayout->addWidget( objectWg( EDirection, Label ) );
235   aDirectGrpLayout->addWidget( objectWg( EDirection, Btn ) );
236   aDirectGrpLayout->addWidget(aDXLabel );
237   aDirectGrpLayout->addWidget(myDX );
238   aDirectGrpLayout->addWidget(aDYLabel );
239   aDirectGrpLayout->addWidget(myDY );
240   aDirectGrpLayout->addWidget(aDZLabel );
241   aDirectGrpLayout->addWidget(myDZ );
242   
243
244   QGroupBox* anOrientGrp = new QGroupBox(tr("ORIENTATION"), aFrame);
245   QVBoxLayout* anOrientGrpLayout = new QVBoxLayout ( anOrientGrp );
246   anOrientGrpLayout->addWidget(myPointFrm);
247   anOrientGrpLayout->addWidget(myFaceFrm);
248   anOrientGrpLayout->addWidget(aDirectFrm);
249   
250
251   QVBoxLayout* aLay = new QVBoxLayout(aFrame);
252   aLay->addWidget(aConstructorBox);
253   aLay->addWidget(anObjectGrp);
254   aLay->addWidget(anOrientGrp);
255
256   connect( myConstructorGrp, SIGNAL(buttonClicked (int)), this, SLOT(constructorChange(int)));
257
258   return aFrame;
259 }
260
261 //================================================================================
262 /*!
263  * \brief Show point or face
264  */
265 //================================================================================
266
267 void SMESHGUI_ReorientFacesDlg::constructorChange(int id)
268 {
269   if ( id == CONSTRUCTOR_FACE )
270   {
271     myPointFrm->hide();
272     myFaceFrm->show();
273     activateObject( EFace );
274   }
275   else
276   {
277     myFaceFrm->hide();
278     myPointFrm->show();
279     activateObject( EPoint );
280   }
281 }
282
283 //================================================================================
284 /*!
285  * \brief Constructor
286 */
287 //================================================================================
288
289 SMESHGUI_ReorientFacesOp::SMESHGUI_ReorientFacesOp()
290   :SMESHGUI_SelectionOp( ActorSelection )
291 {
292   //myVectorPreview = 0;
293   myHelpFileName = "reorient_faces_page.html";
294
295   myDlg = new SMESHGUI_ReorientFacesDlg;
296   myDlg->constructorChange( CONSTRUCTOR_POINT );
297
298   // connect signals and slots
299   connect( myDlg->objectWg( EFace, LightApp_Dialog::Control ), SIGNAL(textChanged(const QString&)),
300            this, SLOT(onTextChange(const QString&)));
301   // connect(myDlg->myX, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
302   // connect(myDlg->myY, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
303   // connect(myDlg->myZ, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
304   // connect(myDlg->myDX, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
305   // connect(myDlg->myDY, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
306   // connect(myDlg->myDZ, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
307
308 }
309
310 //=======================================================================
311 // function : startOperation()
312 // purpose  : Init dialog fields, connect signals and slots, show dialog
313 //=======================================================================
314
315 void SMESHGUI_ReorientFacesOp::startOperation()
316 {
317   myObjectActor = 0;
318
319   // init simulation with a current View
320   //if ( myVectorPreview ) delete myVectorPreview;
321   // myVectorPreview = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( getSMESHGUI() ));
322   // vtkProperty* aProp = vtkProperty::New();
323   // aProp->SetRepresentationToWireframe();
324   // aProp->SetColor(250, 0, 250);
325   // aProp->SetPointSize(5);
326   // aProp->SetLineWidth( SMESH::GetFloat("SMESH:element_width",1) + 1);
327   // myVectorPreview->GetActor()->SetProperty(aProp);
328   // aProp->Delete();
329
330   SMESHGUI_SelectionOp::startOperation();
331
332   myDlg->show();
333
334   mySelectionMode = 0;
335   myDlg->activateObject( EObject );
336 }
337
338 //================================================================================
339 /*!
340  * \brief Stops operation
341  */
342 //================================================================================
343
344 void SMESHGUI_ReorientFacesOp::stopOperation()
345 {
346   //myVectorPreview->SetVisibility(false);
347   if ( myObjectActor ) {
348     myObjectActor->SetPointRepresentation(false);
349     SMESH::RepaintCurrentView();
350     myObjectActor = 0;
351   }
352   SMESHGUI_SelectionOp::stopOperation();
353   myDlg->deactivateAll();
354 }
355
356 //================================================================================
357 /*!
358  * \brief Set selection mode corresponding to a pressed selection button
359  */
360 //================================================================================
361
362 void SMESHGUI_ReorientFacesOp::onActivateObject( int what )
363 {
364   if ( what == mySelectionMode )
365     return;
366   mySelectionMode = what;
367   switch ( mySelectionMode )
368   {
369   case EPoint:
370   case EDirection:
371     SMESH::SetPointRepresentation(true);
372     setSelectionMode( NodeSelection );
373     SMESH::SetPickable();
374     break;
375   case EObject:
376     SMESH::SetPointRepresentation(false);
377     setSelectionMode( ActorSelection );
378     break;
379   case EFace:
380     SMESH::SetPointRepresentation(false);
381     setSelectionMode( FaceSelection );
382     if ( myObjectActor )
383       SMESH::SetPickable( myObjectActor );
384     else
385       SMESH::SetPickable();
386     break;
387   }
388   SMESHGUI_SelectionOp::onActivateObject( what );
389 }
390
391 //================================================================================
392 /*!
393  * \brief Creates a filter corresponding to a pressed selection button
394  */
395 //================================================================================
396
397 SUIT_SelectionFilter* SMESHGUI_ReorientFacesOp::createFilter( const int what ) const
398 {
399   switch ( what )
400   {
401   case EObject:
402     {
403       QList<SUIT_SelectionFilter*> filters;
404       filters.append( new SMESH_TypeFilter( SMESH::MESH ));
405       filters.append( new SMESH_TypeFilter( SMESH::SUBMESH_FACE ));
406       filters.append( new SMESH_TypeFilter( SMESH::GROUP_FACE ));
407       return new SMESH_LogicalFilter( filters, SMESH_LogicalFilter::LO_OR );
408     }
409   case EPoint:
410     {
411       QList<SUIT_SelectionFilter*> filters;
412       filters.append( new SMESH_TypeFilter( SMESH::IDSOURCE ));
413       filters.append( new SMESH_NumberFilter( "GEOM",TopAbs_VERTEX, 1, TopAbs_VERTEX ));
414       return new SMESH_LogicalFilter( filters, SMESH_LogicalFilter::LO_OR );
415     }
416   case EFace:
417   case EDirection:
418     {
419       return new SMESH_TypeFilter( SMESH::IDSOURCE );
420     }
421   }
422   return NULL;
423 }
424
425 //================================================================================
426 /*!
427  * \brief get data from selection
428  */
429 //================================================================================
430
431 void SMESHGUI_ReorientFacesOp::selectionDone()
432 {
433   if ( !myDlg->isVisible() || !myDlg->isEnabled() )
434     return;
435
436   myDlg->clearSelection( mySelectionMode );
437
438   SALOME_ListIO aList;
439   selectionMgr()->selectedObjects(aList);
440   const int nbSelected = aList.Extent();
441   if ( nbSelected == 0 )
442     return;
443
444   Handle(SALOME_InteractiveObject) anIO = aList.First();
445
446   try
447   {
448     switch ( mySelectionMode )
449     {
450     case EObject: { // get an actor of object
451
452       if ( nbSelected == 1 )
453       {
454         myDlg->selectObject( EObject, anIO->getName(), 0, anIO->getEntry(), true );
455         // typeById( aList.First()->getEntry(),
456         //           SMESHGUI_SelectionOp::Object ),
457         myObjectActor = SMESH::FindActorByEntry( anIO->getEntry() );
458       }
459       break;
460     }
461     case EFace: {  // get a face ID
462
463       if ( nbSelected == 1 )
464       {
465         TColStd_IndexedMapOfInteger faceIndices;
466         selector()->GetIndex( anIO, faceIndices );
467         if ( faceIndices.Extent() == 1 )
468         {
469           SMESH_Actor* savedActor = myObjectActor;
470           myObjectActor = 0; // to prevent work of onTextChange()
471           myDlg->setObjectText( EFace, QString("%1").arg( faceIndices(1) ));
472           myObjectActor = savedActor;
473
474           if ( !myObjectActor )
475           {
476             myDlg->selectObject( EObject, anIO->getName(), 0, anIO->getEntry(), true );
477             // typeById( aList.First()->getEntry(),
478             //           SMESHGUI_SelectionOp::Object ),
479             myObjectActor = SMESH::FindActorByEntry( anIO->getEntry() );
480           }
481         }
482       }
483       break;
484     }
485     case EPoint:
486     case EDirection: {  // set XYZ by selected nodes or vertices
487
488       if ( mySelectionMode == EPoint && aList.Extent() > 1 )
489         return;
490
491       TColgp_SequenceOfXYZ points;
492       for( SALOME_ListIteratorOfListIO anIt( aList ); anIt.More(); anIt.Next() )
493       {
494         anIO = anIt.Value();
495         GEOM::GEOM_Object_var geom = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
496         if ( !geom->_is_nil() ) {
497           TopoDS_Vertex aShape;
498           if ( GEOMBase::GetShape(geom, aShape) && aShape.ShapeType() == TopAbs_VERTEX ) {
499             gp_Pnt P = BRep_Tool::Pnt(aShape);
500             points.Append( P.XYZ() );
501           }
502         }
503         else
504         {
505           TColStd_IndexedMapOfInteger nodeIndices;
506           selector()->GetIndex( anIO, nodeIndices );
507           if ( nodeIndices.Extent() > 0 && nodeIndices.Extent() <=2 )
508           {
509             if ( SMESH_Actor* aMeshActor = SMESH::FindActorByEntry(anIO->getEntry()))
510               if (SMDS_Mesh* aMesh = aMeshActor->GetObject()->GetMesh())
511               {
512                 if (const SMDS_MeshNode* aNode = aMesh->FindNode( nodeIndices(1)))
513                   points.Append( gp_XYZ( aNode->X(), aNode->Y(), aNode->Z()));
514                 if ( nodeIndices.Extent() == 2 )
515                   if (const SMDS_MeshNode* aNode = aMesh->FindNode( nodeIndices(2)))
516                     points.Append( gp_XYZ( aNode->X(), aNode->Y(), aNode->Z()));
517               }
518           }
519         }
520       }
521       gp_XYZ xyz;
522       if ( points.Length() == 1 )
523         xyz = points(1);
524       else if ( points.Length() == 2 )
525         xyz = points(2) - points(1);
526       else
527         return;
528       if ( points.Length() == 1 && mySelectionMode == EPoint )
529       {
530         myDlg->myX->SetValue( xyz.X() );
531         myDlg->myY->SetValue( xyz.Y() );
532         myDlg->myZ->SetValue( xyz.Z() );
533         redisplayPreview();
534       }
535       if ( mySelectionMode == EDirection )
536       {
537         myDlg->myDX->SetValue( xyz.X() );
538         myDlg->myDY->SetValue( xyz.Y() );
539         myDlg->myDZ->SetValue( xyz.Z() );
540         redisplayPreview();
541       }
542       break;
543     } // case EPoint || EDirection
544     } // switch
545   }
546   catch (...)
547   {
548   }
549 }
550
551 //================================================================================
552 /*!
553  * \brief SLOT called when the face id is changed
554  */
555 //================================================================================
556
557 void SMESHGUI_ReorientFacesOp::onTextChange( const QString& theText )
558 {
559   if( myObjectActor )
560   {
561     sender()->blockSignals( true );
562     if ( mySelectionMode != EFace )
563     {
564       myDlg->activateObject( EFace );
565       myDlg->setObjectText( EFace, theText );
566     }
567     TColStd_MapOfInteger ids;
568     if ( !theText.isEmpty() && theText.toInt() > 0 )
569       ids.Add( theText.toInt() );
570
571     SMESHGUI_SelectionOp::addOrRemoveIndex( myObjectActor->getIO(), ids, false );
572     SMESHGUI_SelectionOp::highlight( myObjectActor->getIO(), true, true );
573     sender()->blockSignals( false );
574   }
575 }
576
577 //================================================================================
578 /*!
579  * \brief perform it's intention action: reorient faces of myObject
580  */
581 //================================================================================
582
583 bool SMESHGUI_ReorientFacesOp::onApply()
584 {
585   if( isStudyLocked() )
586     return false;
587
588   QString msg;
589   if ( !isValid( msg ) ) { // node id is invalid
590     if( !msg.isEmpty() )
591       SUIT_MessageBox::warning( dlg(), tr( "SMESH_WRN_WARNING" ), msg );
592     dlg()->show();
593     return false;
594   }
595
596   QStringList aParameters;
597   aParameters << myDlg->myDX->text();
598   aParameters << myDlg->myDY->text();
599   aParameters << myDlg->myDZ->text();
600   aParameters << myDlg->myX->text();
601   aParameters << myDlg->myY->text();
602   aParameters << myDlg->myZ->text();
603
604   try {
605     SUIT_OverrideCursor wc;
606     SMESH::SMESH_Mesh_var aMesh = myObject->GetMesh();
607     if ( aMesh->_is_nil() ) return false;
608
609     SMESH::DirStruct direction;
610     direction.PS.x = myDlg->myDX->GetValue();
611     direction.PS.y = myDlg->myDY->GetValue();
612     direction.PS.z = myDlg->myDZ->GetValue();
613
614     long face = myDlg->objectText( EFace ).toInt();
615     if ( myDlg->myConstructorGrp->checkedId() == CONSTRUCTOR_POINT )
616       face = -1;
617
618     SMESH::PointStruct point;
619     point.x = myDlg->myX->GetValue();
620     point.y = myDlg->myY->GetValue();
621     point.z = myDlg->myZ->GetValue();
622
623     SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
624     if (aMeshEditor->_is_nil()) return false;
625
626     aMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
627
628     int aResult = aMeshEditor->Reorient2D( myObject, direction, face, point );
629     if (aResult)
630     {
631       SALOME_ListIO aList;
632       selectionMgr()->setSelectedObjects(aList,false);
633       SMESH::UpdateView();
634       SMESHGUI::Modified();
635     }
636     wc.suspend();
637     SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INFORMATION"),
638                                  tr("NB_REORIENTED").arg(aResult));
639   }
640   catch (const SALOME::SALOME_Exception& S_ex) {
641     SalomeApp_Tools::QtCatchCorbaException(S_ex);
642   }
643   catch (...) {
644   }
645
646   return true;
647 }
648
649 //================================================================================
650 /*!
651  * \brief Check data validity
652  */
653 //================================================================================
654
655 bool SMESHGUI_ReorientFacesOp::isValid( QString& msg )
656 {
657   // check object
658   QString objectEntry = myDlg->selectedObject( EObject );
659   _PTR(SObject) pSObject = studyDS()->FindObjectID( objectEntry.toLatin1().data() );
660   myObject = SMESH::SMESH_IDSource::_narrow( _CAST( SObject,pSObject )->GetObject() );
661   if ( myObject->_is_nil() )
662   {
663     msg = tr("NO_OBJECT_SELECTED");
664     return false;
665   }
666   bool hasFaces = false;
667   SMESH::array_of_ElementType_var types = myObject->GetTypes();
668   for ( size_t i = 0; i < types->length() && !hasFaces; ++i )
669     hasFaces = ( types[i] == SMESH::FACE );
670   if ( !hasFaces )
671   {
672     msg = tr("NO_FACES");
673     return false;
674   }
675
676   // check vector
677   gp_Vec vec( myDlg->myDX->GetValue(),
678               myDlg->myDY->GetValue(),
679               myDlg->myDZ->GetValue() );
680   if ( vec.Magnitude() < std::numeric_limits<double>::min() )
681   {
682     msg = tr("ZERO_SIZE_VECTOR");
683     return false;
684   }
685
686   // check face ID
687   if ( myDlg->myConstructorGrp->checkedId() == CONSTRUCTOR_FACE )
688   {
689     int faceID = myDlg->objectText( EFace ).toInt();
690     bool faceOK = ( faceID > 0 );
691     if ( faceOK )
692     {
693       if ( myObjectActor )
694       {
695         faceOK = ( myObjectActor->GetObject()->GetElemDimension( faceID ) == 2 );
696       }
697       else
698       {
699         SMESH::SMESH_Mesh_var aMesh = myObject->GetMesh();
700         if ( !aMesh->_is_nil() ) 
701           faceOK = ( aMesh->GetElementType( faceID, true ) == SMESH::FACE );
702       }
703     }
704     if ( !faceOK )
705     {
706       msg = tr("INVALID_FACE");
707       return false;
708     }
709   }
710
711   return true;
712 }
713
714 //================================================================================
715 /*!
716  * \brief Destructor
717 */
718 //================================================================================
719
720 SMESHGUI_ReorientFacesOp::~SMESHGUI_ReorientFacesOp()
721 {
722   if ( myDlg )        delete myDlg;
723   //if ( myVectorPreview ) delete myVectorPreview;
724 }
725
726 //================================================================================
727 /*!
728  * \brief Gets dialog of this operation
729  * \retval LightApp_Dialog* - pointer to dialog of this operation
730  */
731 //================================================================================
732
733 LightApp_Dialog* SMESHGUI_ReorientFacesOp::dlg() const
734 {
735   return myDlg;
736 }
737
738 //================================================================================
739 /*!
740  * \brief update preview
741  */
742 //================================================================================
743
744 void SMESHGUI_ReorientFacesOp::redisplayPreview()
745 {
746 //   SMESH::MeshPreviewStruct_var aMeshPreviewStruct;
747
748 //   bool moveShown = false;
749 //   if ( myObjectActor)
750 //   {
751 //     const bool autoSearch = myDlg->myAutoSearchChkBox->isChecked();
752 //     const bool preview    = myDlg->myPreviewChkBox->isChecked();
753 //     if ( autoSearch )
754 //     {
755 //       myDlg->myCurrentX->SetValue(0);
756 //       myDlg->myCurrentY->SetValue(0);
757 //       myDlg->myCurrentZ->SetValue(0);
758 //       myDlg->myDX->SetValue(0);
759 //       myDlg->myDY->SetValue(0);
760 //       myDlg->myDZ->SetValue(0);
761 //       myDlg->myId->setText("");
762 //     }
763 //     QString msg;
764 //     if ( autoSearch || isValid( msg ) )
765 //     {
766 //       try {
767 //         SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(myObjectActor->getIO());
768 //         if (!aMesh->_is_nil()) {
769 //           SMESH::SMESH_MeshEditor_var aPreviewer = aMesh->GetMeshEditPreviewer();
770 //           if (!aPreviewer->_is_nil())
771 //           {
772 //             SUIT_OverrideCursor aWaitCursor;
773
774 //             int anId = 0;
775 //             if ( autoSearch )
776 //               anId = aPreviewer->FindNodeClosestTo(myDlg->myX->GetValue(),
777 //                                                    myDlg->myY->GetValue(),
778 //                                                    myDlg->myZ->GetValue());
779 //             else
780 //               anId = myDlg->myId->text().toInt();
781
782 //             // find id and/or just compute preview
783 //             aPreviewer->MoveNode(anId,
784 //                                  myDlg->myX->GetValue(),
785 //                                  myDlg->myY->GetValue(),
786 //                                  myDlg->myZ->GetValue());
787 //             if ( autoSearch ) { // set found id
788 //               QString idTxt("%1");
789 //               if ( anId > 0 )
790 //                 idTxt = idTxt.arg( anId );
791 //               else
792 //                 idTxt = "";
793 //               myDlg->myId->setText( idTxt );
794 //             }
795
796 //             SMESH::double_array* aXYZ = aMesh->GetNodeXYZ( anId );
797 //             if( aXYZ && aXYZ->length() >= 3 )
798 //             {
799 //               double x = aXYZ->operator[](0);
800 //               double y = aXYZ->operator[](1);
801 //               double z = aXYZ->operator[](2);
802 //               double dx = myDlg->myX->GetValue() - x;
803 //               double dy = myDlg->myY->GetValue() - y;
804 //               double dz = myDlg->myZ->GetValue() - z;
805 //               myDlg->myCurrentX->SetValue(x);
806 //               myDlg->myCurrentY->SetValue(y);
807 //               myDlg->myCurrentZ->SetValue(z);
808 //               myDlg->myDX->SetValue(dx);
809 //               myDlg->myDY->SetValue(dy);
810 //               myDlg->myDZ->SetValue(dz);
811 //             }
812
813 //             if ( preview ) { // fill preview data
814 //               aMeshPreviewStruct = aPreviewer->GetPreviewData();
815 //               moveShown = ( anId > 0 );
816 //             }
817 //           }
818 //         }
819 //       }catch (...) {
820 //       }
821 //     }
822 //   }
823
824 //   if ( !moveShown )
825 //   {
826 //     aMeshPreviewStruct = new SMESH::MeshPreviewStruct();
827
828 //     aMeshPreviewStruct->nodesXYZ.length(1);
829 //     aMeshPreviewStruct->nodesXYZ[0].x = myDlg->myX->GetValue();
830 //     aMeshPreviewStruct->nodesXYZ[0].y = myDlg->myY->GetValue();
831 //     aMeshPreviewStruct->nodesXYZ[0].z = myDlg->myZ->GetValue();
832
833 //     aMeshPreviewStruct->elementTypes.length(1);
834 //     aMeshPreviewStruct->elementTypes[0].SMDS_ElementType = SMESH::NODE;
835 //     aMeshPreviewStruct->elementTypes[0].isPoly = false;
836 //     aMeshPreviewStruct->elementTypes[0].nbNodesInElement = 1;
837
838 //     aMeshPreviewStruct->elementConnectivities.length(1);
839 //     aMeshPreviewStruct->elementConnectivities[0] = 0;
840 //   }
841
842 //   // display data
843 //   if ( aMeshPreviewStruct.operator->() )
844 //   {
845 //     myVectorPreview->SetData(aMeshPreviewStruct._retn());
846 //   }
847 //   else
848 //   {
849 //     myVectorPreview->SetVisibility(false);
850 //   }
851
852 }