3 // Copyright (C) 2003 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.
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
24 // File : StdMeshersGUI_ObjectReferenceParamWdg.cxx
27 #include "StdMeshersGUI_ObjectReferenceParamWdg.h"
29 #include <qpushbutton.h>
30 #include <qlineedit.h>
34 #include "SMESHGUI_Utils.h"
35 #include "SMESHGUI_VTKUtils.h"
36 #include "SMESH_TypeFilter.hxx"
37 #include "SUIT_ResourceMgr.h"
38 #include "LightApp_SelectionMgr.h"
39 #include "SVTK_ViewWindow.h"
40 #include "SALOME_ListIO.hxx"
41 #include "SALOMEDSClient_SObject.hxx"
43 //================================================================================
45 * \brief Constructor initialized by filter
46 * \param f - object filter
48 //================================================================================
50 StdMeshersGUI_ObjectReferenceParamWdg::StdMeshersGUI_ObjectReferenceParamWdg
51 ( SUIT_SelectionFilter* f, QWidget* parent)
52 : QHGroupBox( parent )
58 //================================================================================
60 * \brief Constructor initialized by object type
61 * \param MeshObjectType - type of object to select
63 //================================================================================
65 StdMeshersGUI_ObjectReferenceParamWdg::StdMeshersGUI_ObjectReferenceParamWdg
66 ( MeshObjectType objType, QWidget* parent )
67 : QHGroupBox( parent )
69 myFilter = new SMESH_TypeFilter( objType );
72 //================================================================================
76 //================================================================================
78 StdMeshersGUI_ObjectReferenceParamWdg::~StdMeshersGUI_ObjectReferenceParamWdg()
85 //================================================================================
87 * \brief Create a leayout, initialize fields
89 //================================================================================
91 void StdMeshersGUI_ObjectReferenceParamWdg::init()
93 setFrameStyle(QFrame::NoFrame);
96 mySMESHGUI = SMESHGUI::GetSMESHGUI();
97 mySelectionMgr = SMESH::GetSelectionMgr( mySMESHGUI );
98 mySelectionActivated = false;
101 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
102 QPixmap iconSlct ( mgr->loadPixmap("SMESH", tr("ICON_SELECT")));
104 mySelButton = new QPushButton(this);
105 mySelButton->setPixmap(iconSlct);
106 mySelButton->setToggleButton( true );
108 myObjNameLineEdit = new QLineEdit(this);
109 myObjNameLineEdit->setReadOnly(true);
111 connect( mySelButton, SIGNAL(clicked()), SLOT(activateSelection()));
114 //================================================================================
116 * \brief SLOT: Installs selection filter that is not done automatically
118 //================================================================================
120 void StdMeshersGUI_ObjectReferenceParamWdg::activateSelection()
122 if ( !mySelectionActivated && mySelectionMgr )
124 mySelectionActivated = true;
125 mySelectionMgr->clearFilters();
126 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
127 aViewWindow->SetSelectionMode(ActorSelection);
129 mySelectionMgr->installFilter( myFilter );
130 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
132 emit selectionActivated();
134 mySelButton->setOn( mySelectionActivated );
137 //================================================================================
139 * \brief SLOT: stop treating selection changes
141 //================================================================================
143 void StdMeshersGUI_ObjectReferenceParamWdg::deactivateSelection()
145 mySelectionActivated = false;
146 disconnect(mySelectionMgr, 0, this, 0 );
147 mySelectionMgr->removeFilter( myFilter );
149 mySelButton->setOn( mySelectionActivated );
152 //================================================================================
154 * \brief Connect selection slots
155 * \param other - another StdMeshersGUI_ObjectReferenceParamWdg
157 //================================================================================
159 void StdMeshersGUI_ObjectReferenceParamWdg::AvoidSimultaneousSelection
160 ( StdMeshersGUI_ObjectReferenceParamWdg* other)
162 connect(other, SIGNAL(selectionActivated()), this, SLOT(deactivateSelection()));
163 connect(this, SIGNAL(selectionActivated()), other, SLOT(deactivateSelection()));
166 //================================================================================
168 * \brief Initialize selected object name
169 * \param obj - the current object
171 //================================================================================
173 void StdMeshersGUI_ObjectReferenceParamWdg::SetObject(CORBA::Object_ptr obj)
175 myObject = CORBA::Object::_nil();
176 myObjNameLineEdit->setText( "" );
180 if ( !CORBA::is_nil( obj ))
181 sobj = SMESH::FindSObject (obj);
183 string name = sobj->GetName();
184 myObjNameLineEdit->setText( name.c_str() );
185 myObject = CORBA::Object::_duplicate( obj );
186 myParamValue = sobj->GetID();
190 //================================================================================
192 * \brief Takes selected object
194 //================================================================================
196 void StdMeshersGUI_ObjectReferenceParamWdg::onSelectionDone()
198 if ( mySelectionActivated ) {
199 CORBA::Object_var obj;
201 mySelectionMgr->selectedObjects(aList);
202 if (aList.Extent() == 1)
203 obj = SMESH::IObjectToObject( aList.First() );
204 SetObject( obj.in() );