Back to index

salome-smesh  6.5.0
SMESHGUI_MakeNodeAtPointDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // File   : SMESHGUI_MakeNodeAtPointDlg.cxx
00024 // Author : Edward AGAPOV, Open CASCADE S.A.S.
00025 // SMESH includes
00026 //
00027 #include "SMESHGUI_MakeNodeAtPointDlg.h"
00028 
00029 #include "SMESHGUI.h"
00030 #include "SMESHGUI_IdValidator.h"
00031 #include "SMESHGUI_MeshUtils.h"
00032 #include "SMESHGUI_VTKUtils.h"
00033 #include "SMESHGUI_SpinBox.h"
00034 #include "SMESHGUI_MeshEditPreview.h"
00035 
00036 #include <SMDS_Mesh.hxx>
00037 #include <SMESH_Actor.h>
00038 #include <SMESH_ActorUtils.h>
00039 #include <SMESH_NumberFilter.hxx>
00040 #include <SMESH_LogicalFilter.hxx>
00041 
00042 // SALOME GEOM includes
00043 #include <GEOMBase.h>
00044 
00045 // SALOME GUI includes
00046 #include <LightApp_SelectionMgr.h>
00047 #include <SALOME_ListIO.hxx>
00048 #include <SUIT_Desktop.h>
00049 #include <SVTK_ViewModel.h>
00050 #include <SVTK_ViewWindow.h>
00051 #include <SalomeApp_Tools.h>
00052 #include <SalomeApp_TypeFilter.h>
00053 #include <SUIT_ResourceMgr.h>
00054 #include <SUIT_OverrideCursor.h>
00055 #include <SUIT_MessageBox.h>
00056 
00057 // OCCT includes
00058 #include <TColStd_MapOfInteger.hxx>
00059 #include <TopoDS_Vertex.hxx>
00060 #include <BRep_Tool.hxx>
00061 #include <gp_Pnt.hxx>
00062 
00063 // Qt includes
00064 #include <QGroupBox>
00065 #include <QGridLayout>
00066 #include <QHBoxLayout>
00067 #include <QVBoxLayout>
00068 #include <QLineEdit>
00069 #include <QPushButton>
00070 #include <QLabel>
00071 #include <QRadioButton>
00072 #include <QCheckBox>
00073 #include <QButtonGroup>
00074 
00075 // VTK includes
00076 #include <vtkProperty.h>
00077 
00078 // IDL includes
00079 #include <SALOMEconfig.h>
00080 #include CORBA_SERVER_HEADER(SMESH_Mesh)
00081 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
00082 
00083 #define SPACING 6
00084 #define MARGIN  11
00085 
00090 SMESHGUI_MakeNodeAtPointDlg::SMESHGUI_MakeNodeAtPointDlg()
00091   : SMESHGUI_Dialog( 0, false, true )
00092 {
00093   setWindowTitle(tr("CAPTION"));
00094 
00095   QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
00096   aDlgLay->setMargin(0);
00097   aDlgLay->setSpacing(SPACING);
00098 
00099   QWidget* aMainFrame = createMainFrame  (mainFrame());
00100 
00101   aDlgLay->addWidget(aMainFrame);
00102 
00103   aDlgLay->setStretchFactor(aMainFrame, 1);
00104 }
00105 
00106 //=======================================================================
00107 // function : createMainFrame()
00108 // purpose  : Create frame containing dialog's input fields
00109 //=======================================================================
00110 QWidget* SMESHGUI_MakeNodeAtPointDlg::createMainFrame (QWidget* theParent)
00111 {
00112   QWidget* aFrame = new QWidget(theParent);
00113 
00114   SUIT_ResourceMgr* rm = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
00115   QPixmap iconMoveNode (rm->loadPixmap("SMESH", tr("ICON_DLG_MOVE_NODE")));
00116   QPixmap iconSelect   (rm->loadPixmap("SMESH", tr("ICON_SELECT")));
00117 
00118   // constructor
00119 
00120   QGroupBox* aPixGrp = new QGroupBox(tr("MOVE_NODE"), aFrame);
00121   QButtonGroup* aBtnGrp = new QButtonGroup(this);
00122   QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
00123   aPixGrpLayout->setMargin(MARGIN);
00124   aPixGrpLayout->setSpacing(SPACING);
00125 
00126   QRadioButton* aRBut = new QRadioButton(aPixGrp);
00127   aRBut->setIcon(iconMoveNode);
00128   aRBut->setChecked(true);
00129   aPixGrpLayout->addWidget(aRBut);
00130   aBtnGrp->addButton(aRBut, 0);
00131 
00132   // coordinates
00133 
00134   QGroupBox* aCoordGrp = new QGroupBox(tr("DESTINATION"), aFrame);
00135   QHBoxLayout* aCoordGrpLayout = new QHBoxLayout(aCoordGrp);
00136   aCoordGrpLayout->setMargin(MARGIN);
00137   aCoordGrpLayout->setSpacing(SPACING);
00138 
00139   myCoordBtn = new QPushButton(aCoordGrp);
00140   myCoordBtn->setIcon(iconSelect);
00141   myCoordBtn->setCheckable(true);
00142 
00143   QLabel* aXLabel = new QLabel(tr("SMESH_X"), aCoordGrp);
00144   myX = new SMESHGUI_SpinBox(aCoordGrp);
00145 
00146   QLabel* aYLabel = new QLabel(tr("SMESH_Y"), aCoordGrp);
00147   myY = new SMESHGUI_SpinBox(aCoordGrp);
00148 
00149   QLabel* aZLabel = new QLabel(tr("SMESH_Z"), aCoordGrp);
00150   myZ = new SMESHGUI_SpinBox(aCoordGrp);
00151 
00152   myX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
00153   myY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
00154   myZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
00155 
00156   aCoordGrpLayout->addWidget(myCoordBtn);
00157   aCoordGrpLayout->addWidget(aXLabel);
00158   aCoordGrpLayout->addWidget(myX);
00159   aCoordGrpLayout->addWidget(aYLabel);
00160   aCoordGrpLayout->addWidget(myY);
00161   aCoordGrpLayout->addWidget(aZLabel);
00162   aCoordGrpLayout->addWidget(myZ);
00163   aCoordGrpLayout->setStretchFactor(myX, 1);
00164   aCoordGrpLayout->setStretchFactor(myY, 1);
00165   aCoordGrpLayout->setStretchFactor(myZ, 1);
00166 
00167   // node ID
00168 
00169   myNodeToMoveGrp = new QGroupBox(tr("NODE_2MOVE"), aFrame);
00170 
00171   QLabel* idLabel = new QLabel(tr("NODE_2MOVE_ID"), myNodeToMoveGrp);
00172   myIdBtn = new QPushButton(myNodeToMoveGrp);
00173   myIdBtn->setIcon(iconSelect);
00174   myIdBtn->setCheckable(true);
00175   myId = new QLineEdit(myNodeToMoveGrp);
00176   myId->setValidator(new SMESHGUI_IdValidator(this, 1));
00177 
00178   QWidget* aCoordWidget = new QWidget(myNodeToMoveGrp);
00179 
00180   QLabel* aCurrentXLabel = new QLabel(tr("SMESH_X"), aCoordWidget);
00181   myCurrentX = new SMESHGUI_SpinBox(aCoordWidget);
00182   myCurrentX->setButtonSymbols(QAbstractSpinBox::NoButtons);
00183   myCurrentX->setReadOnly(true);
00184 
00185   QLabel* aCurrentYLabel = new QLabel(tr("SMESH_Y"), aCoordWidget);
00186   myCurrentY = new SMESHGUI_SpinBox(aCoordWidget);
00187   myCurrentY->setButtonSymbols(QAbstractSpinBox::NoButtons);
00188   myCurrentY->setReadOnly(true);
00189 
00190   QLabel* aCurrentZLabel = new QLabel(tr("SMESH_Z"), aCoordWidget);
00191   myCurrentZ = new SMESHGUI_SpinBox(aCoordWidget);
00192   myCurrentZ->setButtonSymbols(QAbstractSpinBox::NoButtons);
00193   myCurrentZ->setReadOnly(true);
00194 
00195   QLabel* aDXLabel = new QLabel(tr("SMESH_DX"), aCoordWidget);
00196   myDX = new SMESHGUI_SpinBox(aCoordWidget);
00197   myDX->setButtonSymbols(QAbstractSpinBox::NoButtons);
00198   myDX->setReadOnly(true);
00199 
00200   QLabel* aDYLabel = new QLabel(tr("SMESH_DY"), aCoordWidget);
00201   myDY = new SMESHGUI_SpinBox(aCoordWidget);
00202   myDY->setButtonSymbols(QAbstractSpinBox::NoButtons);
00203   myDY->setReadOnly(true);
00204 
00205   QLabel* aDZLabel = new QLabel(tr("SMESH_DZ"), aCoordWidget);
00206   myDZ = new SMESHGUI_SpinBox(aCoordWidget);
00207   myDZ->setButtonSymbols(QAbstractSpinBox::NoButtons);
00208   myDZ->setReadOnly(true);
00209 
00210   myCurrentX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
00211   myCurrentY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
00212   myCurrentZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
00213   myDX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
00214   myDY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
00215   myDZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
00216 
00217   QGridLayout* aCoordLayout = new QGridLayout(aCoordWidget);
00218   aCoordLayout->setMargin(0);
00219   aCoordLayout->setSpacing(SPACING);
00220   aCoordLayout->addWidget(aCurrentXLabel, 0, 0);
00221   aCoordLayout->addWidget(myCurrentX,     0, 1);
00222   aCoordLayout->addWidget(aCurrentYLabel, 0, 2);
00223   aCoordLayout->addWidget(myCurrentY,     0, 3);
00224   aCoordLayout->addWidget(aCurrentZLabel, 0, 4);
00225   aCoordLayout->addWidget(myCurrentZ,     0, 5);
00226   aCoordLayout->addWidget(aDXLabel,       1, 0);
00227   aCoordLayout->addWidget(myDX,           1, 1);
00228   aCoordLayout->addWidget(aDYLabel,       1, 2);
00229   aCoordLayout->addWidget(myDY,           1, 3);
00230   aCoordLayout->addWidget(aDZLabel,       1, 4);
00231   aCoordLayout->addWidget(myDZ,           1, 5);
00232   aCoordLayout->setColumnStretch(1, 1);
00233   aCoordLayout->setColumnStretch(3, 1);
00234   aCoordLayout->setColumnStretch(5, 1);
00235 
00236   myAutoSearchChkBox = new QCheckBox( tr("AUTO_SEARCH"), myNodeToMoveGrp);
00237   myPreviewChkBox = new QCheckBox( tr("PREVIEW"), myNodeToMoveGrp);
00238 
00239   QGridLayout* myNodeToMoveGrpLayout = new QGridLayout(myNodeToMoveGrp);
00240   myNodeToMoveGrpLayout->setSpacing(SPACING);
00241   myNodeToMoveGrpLayout->setMargin(MARGIN);
00242 
00243   myNodeToMoveGrpLayout->addWidget( idLabel, 0, 0 );
00244   myNodeToMoveGrpLayout->addWidget( myIdBtn, 0, 1 );
00245   myNodeToMoveGrpLayout->addWidget( myId,    0, 2 );
00246   myNodeToMoveGrpLayout->addWidget( aCoordWidget,       1, 0, 1, 3 );
00247   myNodeToMoveGrpLayout->addWidget( myAutoSearchChkBox, 2, 0, 1, 3 );
00248   myNodeToMoveGrpLayout->addWidget( myPreviewChkBox,    3, 0, 1, 3 );
00249 
00250   QVBoxLayout* aLay = new QVBoxLayout(aFrame);
00251   aLay->addWidget(aPixGrp);
00252   aLay->addWidget(aCoordGrp);
00253   aLay->addWidget(myNodeToMoveGrp);
00254 
00255   connect(myCoordBtn,         SIGNAL (toggled(bool)), this, SLOT(ButtonToggled(bool)));
00256   connect(myIdBtn,            SIGNAL (toggled(bool)), this, SLOT(ButtonToggled(bool)));
00257   connect(myAutoSearchChkBox, SIGNAL (toggled(bool)), this, SLOT(ButtonToggled(bool)));
00258 
00259   myIdBtn->setChecked(true);
00260   myAutoSearchChkBox->setChecked(true);
00261 
00262   return aFrame;
00263 }
00264 
00265 //================================================================================
00270 //================================================================================
00271 
00272 void SMESHGUI_MakeNodeAtPointDlg::ButtonToggled (bool on)
00273 {
00274   const QObject* aSender = sender();
00275   if ( on ) {
00276     if ( aSender == myCoordBtn ) // button to set coord by node selection
00277     {
00278       if ( myIdBtn->isEnabled() )
00279         myIdBtn->setChecked( !on );
00280     }
00281     else if ( aSender == myIdBtn ) // button to select a node to move
00282     {
00283       myCoordBtn->setChecked( !on );
00284     }
00285   }      
00286   if ( aSender == myAutoSearchChkBox ) // automatic node search
00287   {
00288     if ( on ) {
00289       myCurrentX->SetValue(0);
00290       myCurrentY->SetValue(0);
00291       myCurrentZ->SetValue(0);
00292       myDX->SetValue(0);
00293       myDY->SetValue(0);
00294       myDZ->SetValue(0);
00295       myId->setText("");
00296       myId->setReadOnly ( true );
00297       myIdBtn->setChecked( false );
00298       myIdBtn->setEnabled( false );
00299       myCoordBtn->setChecked( true );
00300     }
00301     else {
00302       myId->setReadOnly ( false );
00303       myIdBtn->setEnabled( true );
00304     }
00305   }
00306 }
00307 
00308 //================================================================================
00312 //================================================================================
00313 
00314 SMESHGUI_MakeNodeAtPointOp::SMESHGUI_MakeNodeAtPointOp()
00315 {
00316   mySimulation = 0;
00317   myDlg = new SMESHGUI_MakeNodeAtPointDlg;
00318   myFilter = 0;
00319   myHelpFileName = "mesh_through_point_page.html";
00320 
00321   // connect signals and slots
00322   connect(myDlg->myX, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
00323   connect(myDlg->myY, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
00324   connect(myDlg->myZ, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
00325   connect(myDlg->myId,SIGNAL (textChanged(const QString&)),SLOT(redisplayPreview()));
00326   connect(myDlg->myPreviewChkBox,   SIGNAL (toggled(bool)),SLOT(redisplayPreview()));
00327   connect(myDlg->myAutoSearchChkBox,SIGNAL (toggled(bool)),SLOT(redisplayPreview()));
00328 
00329   // IPAL22913: TC6.5.0: selected in "Move node" dialog box node is not highlighted
00330   // note: this slot seems to be lost together with removed obsolete SMESHGUI_MoveNodesDlg class
00331   connect(myDlg->myId,SIGNAL (textChanged(const QString&)),SLOT(onTextChange(const QString&)));
00332 }
00333 
00334 //=======================================================================
00335 // function : startOperation()
00336 // purpose  : Init dialog fields, connect signals and slots, show dialog
00337 //=======================================================================
00338 void SMESHGUI_MakeNodeAtPointOp::startOperation()
00339 {
00340   myNoPreview = false;
00341   myMeshActor = 0;
00342 
00343   // init simulation with a current View
00344   if ( mySimulation ) delete mySimulation;
00345   mySimulation = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( getSMESHGUI() ));
00346   vtkProperty* aProp = vtkProperty::New();
00347   aProp->SetRepresentationToWireframe();
00348   aProp->SetColor(250, 0, 250);
00349   aProp->SetPointSize(5);
00350   aProp->SetLineWidth( SMESH::GetFloat("SMESH:element_width",1) + 1);
00351   mySimulation->GetActor()->SetProperty(aProp);
00352   aProp->Delete();
00353 
00354   // SalomeApp_TypeFilter depends on a current study
00355   if ( myFilter ) delete myFilter;
00356   QList<SUIT_SelectionFilter*> filters;
00357   filters.append( new SalomeApp_TypeFilter((SalomeApp_Study*)study(), "SMESH" ));
00358   TColStd_MapOfInteger vertexType;
00359   vertexType.Add( TopAbs_VERTEX );
00360   filters.append( new SMESH_NumberFilter("GEOM", TopAbs_VERTEX, 1, vertexType ));
00361   myFilter = new SMESH_LogicalFilter( filters, SMESH_LogicalFilter::LO_OR );
00362 
00363   // IPAL19360
00364   SMESHGUI_SelectionOp::startOperation(); // this method should be called only after filter creation
00365   //activateSelection(); // set filters   // called inside of previous statement
00366 
00367   myDlg->myX->SetValue(0);
00368   myDlg->myY->SetValue(0);
00369   myDlg->myZ->SetValue(0);
00370   myDlg->myCurrentX->SetValue(0);
00371   myDlg->myCurrentY->SetValue(0);
00372   myDlg->myCurrentZ->SetValue(0);
00373   myDlg->myDX->SetValue(0);
00374   myDlg->myDY->SetValue(0);
00375   myDlg->myDZ->SetValue(0);
00376   myDlg->myId->setText("");
00377   myDlg->show();
00378 
00379   onSelectionDone(); // init myMeshActor
00380 
00381   if ( myMeshActor ) {
00382 //     myMeshOldDisplayMode = myMeshActor->GetRepresentation();
00383 //     myMeshActor->SetRepresentation( VTK_WIREFRAME );
00384     myMeshActor->SetPointRepresentation(true);
00385     SMESH::RepaintCurrentView();
00386     redisplayPreview();
00387   }
00388 }
00389 
00390 //================================================================================
00394 //================================================================================
00395 
00396 void SMESHGUI_MakeNodeAtPointOp::stopOperation()
00397 {
00398   myNoPreview = true;
00399   mySimulation->SetVisibility(false);
00400   if ( myMeshActor ) {
00401 //     myMeshActor->SetRepresentation( myMeshOldDisplayMode );
00402     myMeshActor->SetPointRepresentation(false);
00403     SMESH::RepaintCurrentView();
00404     myMeshActor = 0;
00405   }
00406   selectionMgr()->removeFilter( myFilter );
00407   SMESHGUI_SelectionOp::stopOperation();
00408 }
00409 
00410 //================================================================================
00414 //================================================================================
00415 
00416 bool SMESHGUI_MakeNodeAtPointOp::onApply()
00417 {
00418   if( isStudyLocked() )
00419     return false;
00420 
00421   if ( !myMeshActor ) {
00422     SUIT_MessageBox::warning( dlg(), tr( "SMESH_WRN_WARNING" ),
00423                               tr("INVALID_MESH") );
00424     dlg()->show();
00425     return false;
00426   }
00427 
00428   QString msg;
00429   if ( !isValid( msg ) ) { // node id is invalid
00430     if( !msg.isEmpty() )
00431       SUIT_MessageBox::warning( dlg(), tr( "SMESH_WRN_WARNING" ),
00432                                 tr("INVALID_ID") );
00433     dlg()->show();
00434     return false;
00435   }
00436 
00437   QStringList aParameters;
00438   aParameters << myDlg->myX->text();
00439   aParameters << myDlg->myY->text();
00440   aParameters << myDlg->myZ->text();
00441 
00442   try {
00443     SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(myMeshActor->getIO());
00444     if (aMesh->_is_nil()) {
00445       SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_ERROR"),
00446                                    tr("SMESHG_NO_MESH") );
00447       return true;
00448     }
00449     SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
00450     if (aMeshEditor->_is_nil())
00451       return true;
00452 
00453     aMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
00454 
00455     bool ok;
00456     int anId = myDlg->myId->text().toInt( &ok );
00457     if( !ok || anId < 1 )
00458       anId = aMeshEditor->FindNodeClosestTo(myDlg->myX->GetValue(),
00459                                             myDlg->myY->GetValue(),
00460                                             myDlg->myZ->GetValue());
00461 
00462     int aResult = aMeshEditor->MoveNode(anId,
00463                                         myDlg->myX->GetValue(),
00464                                         myDlg->myY->GetValue(),
00465                                         myDlg->myZ->GetValue() );
00466 
00467     if (aResult)
00468     {
00469       myDlg->myCurrentX->SetValue(0);
00470       myDlg->myCurrentY->SetValue(0);
00471       myDlg->myCurrentZ->SetValue(0);
00472       myDlg->myDX->SetValue(0);
00473       myDlg->myDY->SetValue(0);
00474       myDlg->myDZ->SetValue(0);
00475       myDlg->myId->setText("");
00476 
00477       SALOME_ListIO aList;
00478       selectionMgr()->setSelectedObjects(aList,false);
00479       aList.Append(myMeshActor->getIO());
00480       selectionMgr()->setSelectedObjects(aList,false);
00481       SMESH::UpdateView();
00482       SMESHGUI::Modified();
00483     }
00484   }
00485   catch (const SALOME::SALOME_Exception& S_ex) {
00486     SalomeApp_Tools::QtCatchCorbaException(S_ex);
00487   }
00488   catch (...) {
00489   }
00490 
00491   return true;
00492 }
00493 
00494 //================================================================================
00498 //================================================================================
00499 
00500 bool SMESHGUI_MakeNodeAtPointOp::isValid( QString& msg )
00501 {
00502   bool ok = true;
00503   if ( myMeshActor &&
00504        !myDlg->myAutoSearchChkBox->isChecked() )
00505   {
00506     ok = false;
00507     int id = myDlg->myId->text().toInt();
00508     if ( id > 0 )
00509       if (SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh())
00510         ok = aMesh->FindNode( id );
00511     if( !ok )
00512       msg += tr("INVALID_ID") + "\n";
00513   }
00514 
00515   ok = myDlg->myX->isValid( msg, !myNoPreview ) && ok;
00516   ok = myDlg->myY->isValid( msg, !myNoPreview ) && ok;
00517   ok = myDlg->myZ->isValid( msg, !myNoPreview ) && ok;
00518 
00519   return ok;
00520 }
00521 
00522 //================================================================================
00526 //================================================================================
00527 
00528 void SMESHGUI_MakeNodeAtPointOp::onSelectionDone()
00529 {
00530   if ( !myDlg->isVisible() || !myDlg->isEnabled() )
00531     return;
00532   try {
00533     SALOME_ListIO aList;
00534     selectionMgr()->selectedObjects(aList, SVTK_Viewer::Type());
00535     if (aList.Extent() != 1)
00536       return;
00537     Handle(SALOME_InteractiveObject) anIO = aList.First();
00538     SMESH_Actor* aMeshActor = SMESH::FindActorByEntry(anIO->getEntry());
00539 
00540     if (!aMeshActor) { // coord by geom
00541       if ( myDlg->myCoordBtn->isChecked() ) {
00542         GEOM::GEOM_Object_var geom = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
00543         if ( !geom->_is_nil() ) {
00544           TopoDS_Vertex aShape;
00545           if ( GEOMBase::GetShape(geom, aShape) &&
00546                aShape.ShapeType() == TopAbs_VERTEX ) {
00547             gp_Pnt P = BRep_Tool::Pnt(aShape);
00548             myNoPreview = true;
00549             myDlg->myX->SetValue(P.X());
00550             myDlg->myY->SetValue(P.Y());
00551             myDlg->myZ->SetValue(P.Z());
00552             myNoPreview = false;
00553             redisplayPreview();
00554           }
00555         }
00556         return;
00557       }
00558     }
00559 
00560     if ( !myMeshActor )
00561       myMeshActor = aMeshActor;
00562 
00563     QString aString;
00564     int nbElems = SMESH::GetNameOfSelectedElements(selector(),anIO, aString);
00565     if (nbElems == 1) {
00566       if (SMDS_Mesh* aMesh = aMeshActor->GetObject()->GetMesh()) {
00567         if (const SMDS_MeshNode* aNode = aMesh->FindNode(aString.toInt())) {
00568           myNoPreview = true;
00569           if ( myDlg->myCoordBtn->isChecked() ) { // set coord
00570             myDlg->myX->SetValue(aNode->X());
00571             myDlg->myY->SetValue(aNode->Y());
00572             myDlg->myZ->SetValue(aNode->Z());
00573             myNoPreview = false;
00574             redisplayPreview();
00575           }
00576           else if ( myDlg->myIdBtn->isChecked() &&
00577                     myDlg->myIdBtn->isEnabled() ) { // set node to move
00578             myDlg->myId->setText(aString);
00579             myNoPreview = false;
00580             redisplayPreview();
00581           }
00582 
00583           if (const SMDS_MeshNode* aCurrentNode = aMesh->FindNode(myDlg->myId->text().toInt())) {
00584             double x = aCurrentNode->X();
00585             double y = aCurrentNode->Y();
00586             double z = aCurrentNode->Z();
00587             double dx = myDlg->myX->GetValue() - x;
00588             double dy = myDlg->myY->GetValue() - y;
00589             double dz = myDlg->myZ->GetValue() - z;
00590             myDlg->myCurrentX->SetValue(x);
00591             myDlg->myCurrentY->SetValue(y);
00592             myDlg->myCurrentZ->SetValue(z);
00593             myDlg->myDX->SetValue(dx);
00594             myDlg->myDY->SetValue(dy);
00595             myDlg->myDZ->SetValue(dz);
00596           }
00597         }
00598       }
00599     }
00600   } catch (...) {
00601   }
00602 }
00603 
00604 //================================================================================
00608 //================================================================================
00609 
00610 void SMESHGUI_MakeNodeAtPointOp::redisplayPreview()
00611 {
00612   if ( myNoPreview )
00613     return;
00614   myNoPreview = true;
00615 
00616   SMESH::MeshPreviewStruct_var aMeshPreviewStruct;
00617 
00618   bool moveShown = false;
00619   if ( myMeshActor)
00620   {
00621     const bool autoSearch = myDlg->myAutoSearchChkBox->isChecked();
00622     const bool preview    = myDlg->myPreviewChkBox->isChecked();
00623     if ( autoSearch )
00624     {
00625       myDlg->myCurrentX->SetValue(0);
00626       myDlg->myCurrentY->SetValue(0);
00627       myDlg->myCurrentZ->SetValue(0);
00628       myDlg->myDX->SetValue(0);
00629       myDlg->myDY->SetValue(0);
00630       myDlg->myDZ->SetValue(0);
00631       myDlg->myId->setText("");
00632     }
00633     QString msg;
00634     if ( autoSearch || isValid( msg ) )
00635     {
00636       try {
00637         SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(myMeshActor->getIO());
00638         if (!aMesh->_is_nil()) {
00639           SMESH::SMESH_MeshEditor_var aPreviewer = aMesh->GetMeshEditPreviewer();
00640           if (!aPreviewer->_is_nil())
00641           {
00642             SUIT_OverrideCursor aWaitCursor;
00643 
00644             int anId = 0;
00645             if ( autoSearch )
00646               anId = aPreviewer->FindNodeClosestTo(myDlg->myX->GetValue(),
00647                                                    myDlg->myY->GetValue(),
00648                                                    myDlg->myZ->GetValue());
00649             else
00650               anId = myDlg->myId->text().toInt();
00651 
00652             // find id and/or just compute preview
00653             aPreviewer->MoveNode(anId,
00654                                  myDlg->myX->GetValue(),
00655                                  myDlg->myY->GetValue(),
00656                                  myDlg->myZ->GetValue());
00657             if ( autoSearch ) { // set found id
00658               QString idTxt("%1");
00659               if ( anId > 0 )
00660                 idTxt = idTxt.arg( anId );
00661               else
00662                 idTxt = "";
00663               myDlg->myId->setText( idTxt );
00664             }
00665 
00666             SMESH::double_array* aXYZ = aMesh->GetNodeXYZ( anId );
00667             if( aXYZ && aXYZ->length() >= 3 )
00668             {
00669               double x = aXYZ->operator[](0);
00670               double y = aXYZ->operator[](1);
00671               double z = aXYZ->operator[](2);
00672               double dx = myDlg->myX->GetValue() - x;
00673               double dy = myDlg->myY->GetValue() - y;
00674               double dz = myDlg->myZ->GetValue() - z;
00675               myDlg->myCurrentX->SetValue(x);
00676               myDlg->myCurrentY->SetValue(y);
00677               myDlg->myCurrentZ->SetValue(z);
00678               myDlg->myDX->SetValue(dx);
00679               myDlg->myDY->SetValue(dy);
00680               myDlg->myDZ->SetValue(dz);
00681             }
00682 
00683             if ( preview ) { // fill preview data
00684               aMeshPreviewStruct = aPreviewer->GetPreviewData();
00685               moveShown = ( anId > 0 );
00686             }
00687           }
00688         }
00689       }catch (...) {
00690       }
00691     }
00692   }
00693 
00694   if ( !moveShown )
00695   {
00696     aMeshPreviewStruct = new SMESH::MeshPreviewStruct();
00697 
00698     aMeshPreviewStruct->nodesXYZ.length(1);
00699     aMeshPreviewStruct->nodesXYZ[0].x = myDlg->myX->GetValue();
00700     aMeshPreviewStruct->nodesXYZ[0].y = myDlg->myY->GetValue();
00701     aMeshPreviewStruct->nodesXYZ[0].z = myDlg->myZ->GetValue();
00702 
00703     aMeshPreviewStruct->elementTypes.length(1);
00704     aMeshPreviewStruct->elementTypes[0].SMDS_ElementType = SMESH::NODE;
00705     aMeshPreviewStruct->elementTypes[0].isPoly = false;
00706     aMeshPreviewStruct->elementTypes[0].nbNodesInElement = 1;
00707 
00708     aMeshPreviewStruct->elementConnectivities.length(1);
00709     aMeshPreviewStruct->elementConnectivities[0] = 0;
00710   }
00711 
00712   // display data
00713   if ( aMeshPreviewStruct.operator->() )
00714   {
00715     mySimulation->SetData(aMeshPreviewStruct._retn());
00716   }
00717   else
00718 {
00719     mySimulation->SetVisibility(false);
00720   }
00721 
00722   myNoPreview = false;
00723 }
00724 
00725 //================================================================================
00729 //================================================================================
00730 
00731 void SMESHGUI_MakeNodeAtPointOp::onTextChange( const QString& theText )
00732 {
00733   if( myMeshActor )
00734   {
00735     if( SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh() )
00736     {
00737       Handle(SALOME_InteractiveObject) anIO = myMeshActor->getIO();
00738       SALOME_ListIO aList;
00739       aList.Append( anIO );
00740       selectionMgr()->setSelectedObjects( aList, false );
00741 
00742       if( const SMDS_MeshNode* aNode = aMesh->FindNode( theText.toInt() ) )
00743       {
00744         TColStd_MapOfInteger aListInd;
00745         aListInd.Add( aNode->GetID() );
00746         selector()->AddOrRemoveIndex( anIO, aListInd, false );
00747         if( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() ) )
00748           aViewWindow->highlight( anIO, true, true );
00749       }
00750     }
00751   }
00752 }
00753 
00754 //================================================================================
00758 //================================================================================
00759 
00760 void SMESHGUI_MakeNodeAtPointOp::activateSelection()
00761 {
00762   selectionMgr()->clearFilters();
00763   SMESH::SetPointRepresentation(false);
00764   selectionMgr()->installFilter( myFilter );
00765   setSelectionMode( NodeSelection );
00766 }
00767 
00768 //================================================================================
00772 //================================================================================
00773 
00774 SMESHGUI_MakeNodeAtPointOp::~SMESHGUI_MakeNodeAtPointOp()
00775 {
00776   if ( myDlg )        delete myDlg;
00777   if ( mySimulation ) delete mySimulation;
00778   if ( myFilter )     delete myFilter;
00779 }
00780 
00781 //================================================================================
00786 //================================================================================
00787 
00788 LightApp_Dialog* SMESHGUI_MakeNodeAtPointOp::dlg() const
00789 {
00790   return myDlg;
00791 }
00792