X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESHGUI%2FSMESHGUI_NodesDlg.cxx;h=872c2015fecb53886601558f1e2d917e827531a4;hp=16bfc5dc797873051efb43bd85880e1c3a463db8;hb=e4737e85f0da6d3f90fd08f6be1c2825195fe16f;hpb=8b4ba0cdff7660465a9ea7b26ef0df0757afed97 diff --git a/src/SMESHGUI/SMESHGUI_NodesDlg.cxx b/src/SMESHGUI/SMESHGUI_NodesDlg.cxx index 16bfc5dc7..872c2015f 100644 --- a/src/SMESHGUI/SMESHGUI_NodesDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_NodesDlg.cxx @@ -1,33 +1,64 @@ -using namespace std; -// File : SMESHGUI_NodesDlg.cxx -// Created : Tue May 14 21:35:46 2002 -// Author : Nicolas REJNERI - -// Project : SALOME -// Module : SMESH -// Copyright : Open CASCADE 2002 +// SMESH SMESHGUI : GUI for SMESH component +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SMESHGUI_NodesDlg.cxx +// Author : Nicolas REJNERI +// Module : SMESH // $Header$ #include "SMESHGUI_NodesDlg.h" + #include "SMESHGUI.h" +#include "SMESHGUI_Utils.h" +#include "SMESHGUI_MeshUtils.h" + +#include "SMESHGUI_VTKUtils.h" +#include "SMESH_ActorUtils.h" + +#include "VTKViewer_ViewFrame.h" +#include "SALOME_Actor.h" + #include "SMESHGUI_SpinBox.h" #include "QAD_Application.h" #include "QAD_Desktop.h" -#include "utilities.h" +#include "QAD_WaitCursor.h" #include "QAD_MessageBox.h" #include "SMESH_Actor.h" -#include -#include +#include "SMDS_Mesh.hxx" +#include "SMDS_MeshNode.hxx" // VTK Includes -#include -#include -#include -#include +#include #include -#include +#include +#include +#include +#include +#include +#include +#include // QT Includes #include @@ -46,6 +77,150 @@ using namespace std; #include #include +#include "utilities.h" + +using namespace std; + + +namespace SMESH{ + + void AddNode(SMESH::SMESH_Mesh_ptr theMesh, float x, float y, float z){ + QAD_WaitCursor wc; + try{ + SALOMEDS::SObject_var aSobj = SMESH::FindSObject(theMesh); + CORBA::String_var anEntry = aSobj->GetID(); + SMESH::SMESH_MeshEditor_var aMeshEditor = theMesh->GetMeshEditor(); + aMeshEditor->AddNode(x,y,z); + SALOMEDS::Study_var aStudy = GetActiveStudyDocument(); + CORBA::Long anId = aStudy->StudyId(); + if(TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,anEntry.in())){ + aVisualObj->Update(true); + } + }catch(SALOME::SALOME_Exception& exc) { + INFOS("Follow exception was cought:\n\t"<getActiveStudyFrame()), + myViewFrame(GetVtkViewFrame(theStudy->getActiveStudyFrame())) + { + vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New(); + + // Create points + myPoints = vtkPoints::New(); + myPoints->SetNumberOfPoints( 1 ); + myPoints->SetPoint(0,0.0,0.0,0.0); + + // Create cells + vtkIdList *anIdList = vtkIdList::New(); + anIdList->SetNumberOfIds( 1 ); + + vtkCellArray *aCells = vtkCellArray::New(); + aCells->Allocate( 2, 0 ); + + vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New(); + aCellTypesArray->SetNumberOfComponents( 1 ); + aCellTypesArray->Allocate( 1 ); + + anIdList->SetId( 0, 0 ); + aCells->InsertNextCell( anIdList ); + aCellTypesArray->InsertNextValue( VTK_VERTEX ); + + vtkIntArray* aCellLocationsArray = vtkIntArray::New(); + aCellLocationsArray->SetNumberOfComponents( 1 ); + aCellLocationsArray->SetNumberOfTuples( 1 ); + + aCells->InitTraversal(); + vtkIdType npts; + aCellLocationsArray->SetValue( 0, aCells->GetTraversalLocation( npts ) ); + + aGrid->SetCells( aCellTypesArray, aCellLocationsArray, aCells ); + + aGrid->SetPoints( myPoints ); + aGrid->SetCells( aCellTypesArray, aCellLocationsArray,aCells ); + aCellLocationsArray->Delete(); + aCellTypesArray->Delete(); + aCells->Delete(); + anIdList->Delete(); + + // Create and display actor + myMapper = vtkDataSetMapper::New(); + myMapper->SetInput( aGrid ); + aGrid->Delete(); + + myPreviewActor = SALOME_Actor::New(); + myPreviewActor->SetInfinitive(true); + myPreviewActor->VisibilityOff(); + myPreviewActor->PickableOff(); + myPreviewActor->SetMapper( myMapper ); + + vtkProperty* aProp = vtkProperty::New(); + aProp->SetRepresentationToPoints(); + + float anRGB[3]; + anRGB[0] = GetFloat("SMESH:SettingsNodeColorRed",0)/255.; + anRGB[1] = GetFloat("SMESH:SettingsNodeColorGreen",255)/255.; + anRGB[2] = GetFloat("SMESH:SettingsNodeColorBlue",0)/255.; + aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]); + + float aPointSize = GetFloat("SMESH:SettingsNodesSize",3); + aProp->SetPointSize(aPointSize); + + myPreviewActor->SetProperty( aProp ); + aProp->Delete(); + + myViewFrame->AddActor( myPreviewActor ); + + } + + + void SetPosition(float x, float y, float z){ + myPoints->SetPoint(0,x,y,z); + myPoints->Modified(); + SetVisibility(true); + } + + + void SetVisibility(bool theVisibility){ + myPreviewActor->SetVisibility(theVisibility); + RepaintCurrentView(); + } + + + ~TNodeSimulation(){ + if(FindVtkViewFrame(myStudy,myStudyFrame)){ + myViewFrame->RemoveActor(myPreviewActor); + } + myPreviewActor->Delete(); + + myMapper->RemoveAllInputs(); + myMapper->Delete(); + + myPoints->Delete(); + } + + }; + +} + //================================================================================= // class : SMESHGUI_NodesDlg() @@ -56,9 +231,11 @@ SMESHGUI_NodesDlg::SMESHGUI_NodesDlg( QWidget* parent, SALOME_Selection* Sel, bool modal, WFlags fl ) - : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ) + : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | + Qt::WDestructiveClose) { - + mySimulation = new SMESH::TNodeSimulation(SMESH::GetActiveStudy()); + QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_NODE"))); if ( !name ) setName( "SMESHGUI_NodesDlg" ); @@ -159,7 +336,9 @@ SMESHGUI_NodesDlg::SMESHGUI_NodesDlg( QWidget* parent, // purpose : Destructor //======================================================================= SMESHGUI_NodesDlg::~SMESHGUI_NodesDlg() -{} +{ + delete mySimulation; +} //================================================================================= @@ -191,14 +370,14 @@ void SMESHGUI_NodesDlg::Init(SALOME_Selection* Sel) connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ); connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) ); - connect( SpinBox_X, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ; - connect( SpinBox_Y, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ; - connect( SpinBox_Z, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ; - - connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); - connect( myMeshGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ; - /* to close dialog if study change */ - connect( myMeshGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ; + connect( SpinBox_X, SIGNAL ( valueChanged(double) ), SLOT( ValueChangedInSpinBox(double) )) ; + connect( SpinBox_Y, SIGNAL ( valueChanged(double) ), SLOT( ValueChangedInSpinBox(double) )) ; + connect( SpinBox_Z, SIGNAL ( valueChanged(double) ), SLOT( ValueChangedInSpinBox(double) )) ; + + connect( mySelection, SIGNAL( currentSelectionChanged() ), SLOT( SelectionIntoArgument() )); + connect( myMeshGUI, SIGNAL ( SignalDeactivateActiveDialog() ), SLOT( DeactivateActiveDialog() )) ; + /* to close dialog if study frame change */ + connect( myMeshGUI, SIGNAL ( SignalStudyFrameChanged() ), SLOT( ClickOnCancel() ) ) ; /* Move widget on the botton right corner of main widget */ int x, y ; @@ -206,6 +385,10 @@ void SMESHGUI_NodesDlg::Init(SALOME_Selection* Sel) this->move( x, y ) ; this->show() ; + // set selection mode + SMESH::SetPointRepresentation(true); + QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true ); + SelectionIntoArgument(); } @@ -215,12 +398,13 @@ void SMESHGUI_NodesDlg::Init(SALOME_Selection* Sel) //================================================================================= void SMESHGUI_NodesDlg::ValueChangedInSpinBox( double newValue ) { - double vx = SpinBox_X->GetValue() ; - double vy = SpinBox_Y->GetValue() ; - double vz = SpinBox_Z->GetValue() ; - myMeshGUI->DisplaySimulationNode( myMesh, vx, vy, vz ); - //myMeshGUI->ViewNodes(); + if(!myMesh->_is_nil()){ + double vx = SpinBox_X->GetValue() ; + double vy = SpinBox_Y->GetValue() ; + double vz = SpinBox_Z->GetValue() ; + mySimulation->SetPosition(vx,vy,vz); + } return ; } @@ -230,32 +414,54 @@ void SMESHGUI_NodesDlg::ValueChangedInSpinBox( double newValue ) //================================================================================= void SMESHGUI_NodesDlg::ClickOnOk() { - this->ClickOnApply() ; - this->ClickOnCancel() ; - - return ; + if ( ClickOnApply() ) + ClickOnCancel() ; } //======================================================================= // function : ClickOnApply() // purpose : //======================================================================= -void SMESHGUI_NodesDlg::ClickOnApply() +bool SMESHGUI_NodesDlg::ClickOnApply() { - if ( myMeshGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_VTK ) { - return; + if (myMeshGUI->ActiveStudyLocked()) + return false; + + if ( myMesh->_is_nil() ) { + QAD_MessageBox::warn1(QAD_Application::getDesktop(), + tr("SMESH_WRN_WARNING"), + tr("MESH_IS_NOT_SELECTED"), + tr("SMESH_BUT_OK")); + return false; } - - if ( Constructor1->isChecked() ) { - /* Recup args and call method */ - double x = SpinBox_X->GetValue() ; - double y = SpinBox_Y->GetValue() ; - double z = SpinBox_Z->GetValue() ; - myMeshGUI->EraseSimulationActors() ; - myMeshGUI->AddNode( myMesh, x, y, z ) ; - myMeshGUI->ViewNodes(); - mySelection->ClearIObjects(); + + /* Recup args and call method */ + double x = SpinBox_X->GetValue() ; + double y = SpinBox_Y->GetValue() ; + double z = SpinBox_Z->GetValue() ; + mySimulation->SetVisibility(false); + SMESH::AddNode(myMesh,x,y,z) ; + SMESH::SetPointRepresentation(true); + + // select myMesh + if ( mySelection->IObjectCount() != 1 ) { + if(VTKViewer_ViewFrame* aViewFrame = SMESH::GetCurrentVtkView()) { + vtkActorCollection *aCollection = aViewFrame->getRenderer()->GetActors(); + aCollection->InitTraversal(); + while(vtkActor *anAct = aCollection->GetNextActor()){ + if(SMESH_Actor *anActor = dynamic_cast(anAct)) + if(anActor->hasIO()) + if(SMESH_MeshObj *aMeshObj = dynamic_cast(anActor->GetObject().get())) + if(myMesh->_is_equivalent( aMeshObj->GetMeshServer() )) + { + mySelection->ClearIObjects(); + mySelection->AddIObject( anActor->getIO(), false ); + break; + } + } + } } + return true; } @@ -265,10 +471,12 @@ void SMESHGUI_NodesDlg::ClickOnApply() //======================================================================= void SMESHGUI_NodesDlg::ClickOnCancel() { - QAD_Application::getDesktop()->SetSelectionMode( 4 ); + mySelection->ClearIObjects(); + mySimulation->SetVisibility(false); + SMESH::SetPointRepresentation(false); + QAD_Application::getDesktop()->SetSelectionMode( ActorSelection ); disconnect( mySelection, 0, this, 0 ); - myMeshGUI->ResetState() ; - myMeshGUI->EraseSimulationActors() ; + myMeshGUI->ResetState(); reject() ; return ; } @@ -280,64 +488,34 @@ void SMESHGUI_NodesDlg::ClickOnCancel() //================================================================================= void SMESHGUI_NodesDlg::SelectionIntoArgument() { - int nbSel = mySelection->IObjectCount(); - if(nbSel != 1) { - SpinBox_X->SetValue(0.0) ; - SpinBox_Y->SetValue(0.0) ; - SpinBox_Z->SetValue(0.0) ; - return; - } - - Standard_Boolean res; - myMesh = myMeshGUI->ConvertIOinMesh( mySelection->firstIObject(), res ); - if (!res) { - SpinBox_X->SetValue(0.0) ; - SpinBox_Y->SetValue(0.0) ; - SpinBox_Z->SetValue(0.0) ; - return ; - } - - if ( mySelection->SelectionMode() != 1 ) { - SpinBox_X->SetValue(0.0) ; - SpinBox_Y->SetValue(0.0) ; - SpinBox_Z->SetValue(0.0) ; - QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"), - tr ("SMESH_WRN_SELECTIONMODE_NODES"), tr ("SMESH_BUT_YES") ); + if ( !GroupConstructors->isEnabled() ) return; - } - QString aString = ""; - int nbNodes = myMeshGUI->GetNameOfSelectedNodes(mySelection, aString) ; - if(nbNodes != 1) { - SpinBox_X->SetValue(0.0) ; - SpinBox_Y->SetValue(0.0) ; - SpinBox_Z->SetValue(0.0) ; - return ; - } - - if ( nbNodes == 1 ) { - TColStd_MapOfInteger myMapIndex; - mySelection->GetIndex( mySelection->firstIObject(), myMapIndex); - TColStd_MapIteratorOfMapOfInteger ite( myMapIndex ); - int idNodes[1]; - for ( ; ite.More(); ite.Next() ) { - idNodes[0] = ite.Key(); + mySimulation->SetVisibility(false); + SMESH::SetPointRepresentation(true); + + if(mySelection->IObjectCount() == 1){ + Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject(); + if(anIO->hasEntry()){ + myMesh = SMESH::GetMeshByIO(anIO); + if(myMesh->_is_nil()) return; + QString aText; + if(SMESH::GetNameOfSelectedNodes( mySelection, aText ) == 1){ + if(SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh.in())){ + if(SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh()){ + if(const SMDS_MeshNode* aNode = aMesh->FindNode(aText.toInt())){ + SpinBox_X->SetValue( aNode->X() ); + SpinBox_Y->SetValue( aNode->Y() ) ; + SpinBox_Z->SetValue( aNode->Z() ) ; + } + } + } + } + mySimulation->SetPosition(SpinBox_X->GetValue(), + SpinBox_Y->GetValue(), + SpinBox_Z->GetValue()); } - - Standard_Boolean result; - SMESH_Actor* ac = myMeshGUI->FindActor( myMesh, result, true ); - vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource ); - float *p0 = ugrid->GetPoint(idNodes[0]); - - SpinBox_X->SetValue( p0[0] ) ; - SpinBox_Y->SetValue( p0[1] ) ; - SpinBox_Z->SetValue( p0[2] ) ; - - myMeshGUI->DisplaySimulationNode( myMesh, p0[0], p0[1], p0[2] ); - // myMeshGUI->ViewNodes(); - } - - return ; + } } @@ -348,9 +526,18 @@ void SMESHGUI_NodesDlg::SelectionIntoArgument() void SMESHGUI_NodesDlg::closeEvent(QCloseEvent* e) { this->ClickOnCancel() ; /* same than click on cancel button */ - return ; } +//======================================================================= +//function : hideEvent +//purpose : caused by ESC key +//======================================================================= + +void SMESHGUI_NodesDlg::hideEvent ( QHideEvent * e ) +{ + if ( !isMinimized() ) + ClickOnCancel(); +} //================================================================================= // function : enterEvent() @@ -358,10 +545,8 @@ void SMESHGUI_NodesDlg::closeEvent(QCloseEvent* e) //================================================================================= void SMESHGUI_NodesDlg::enterEvent( QEvent* e) { - if ( GroupConstructors->isEnabled() ) - return ; - ActivateThisDialog() ; - return ; + if ( !GroupConstructors->isEnabled() ) + ActivateThisDialog() ; } @@ -375,11 +560,10 @@ void SMESHGUI_NodesDlg::DeactivateActiveDialog() GroupConstructors->setEnabled(false) ; GroupCoordinates->setEnabled(false) ; GroupButtons->setEnabled(false) ; - myMeshGUI->EraseSimulationActors() ; + mySimulation->SetVisibility(false) ; myMeshGUI->ResetState() ; myMeshGUI->SetActiveDialogBox(0) ; } - return ; } @@ -393,5 +577,9 @@ void SMESHGUI_NodesDlg::ActivateThisDialog( ) GroupConstructors->setEnabled(true) ; GroupCoordinates->setEnabled(true) ; GroupButtons->setEnabled(true) ; - return ; + + SMESH::SetPointRepresentation(true); + QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true ); + + SelectionIntoArgument(); }