1 // Copyright (C) 2007-2010 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.
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 : StdMeshersGUI_ObjectReferenceParamWdg.cxx
24 // Author : Open CASCADE S.A.S.
27 #include "StdMeshersGUI_ObjectReferenceParamWdg.h"
30 #include <SMESHGUI_VTKUtils.h>
31 #include <SMESH_TypeFilter.hxx>
33 // SALOME GUI includes
34 #include <SUIT_ResourceMgr.h>
35 #include <LightApp_SelectionMgr.h>
36 #include <SVTK_ViewWindow.h>
37 #include <SALOME_ListIO.hxx>
38 #include <SALOME_ListIteratorOfListIO.hxx>
40 // SALOME KERNEL incldues
41 #include <SALOMEDSClient_SObject.hxx>
42 #include <SALOMEDSClient_Study.hxx>
45 #include <QPushButton>
47 #include <QHBoxLayout>
51 //================================================================================
53 * \brief Constructor initialized by filter
54 * \param f - object filter
56 //================================================================================
58 StdMeshersGUI_ObjectReferenceParamWdg::StdMeshersGUI_ObjectReferenceParamWdg
59 ( SUIT_SelectionFilter* f, QWidget* parent, bool multiSelection)
60 : QWidget( parent ), myMultiSelection( multiSelection )
66 //================================================================================
68 * \brief Constructor initialized by object type
69 * \param MeshObjectType - type of object to select
71 //================================================================================
73 StdMeshersGUI_ObjectReferenceParamWdg::StdMeshersGUI_ObjectReferenceParamWdg
74 ( MeshObjectType objType, QWidget* parent, bool multiSelection )
75 : QWidget( parent ), myMultiSelection( multiSelection )
77 myFilter = new SMESH_TypeFilter( objType );
80 //================================================================================
84 //================================================================================
86 StdMeshersGUI_ObjectReferenceParamWdg::~StdMeshersGUI_ObjectReferenceParamWdg()
90 mySelectionMgr->removeFilter( myFilter );
96 //================================================================================
98 * \brief Create a leayout, initialize fields
100 //================================================================================
102 void StdMeshersGUI_ObjectReferenceParamWdg::init()
104 QHBoxLayout* aHBox = new QHBoxLayout(this);
107 aHBox->setSpacing(SPACING);
109 mySMESHGUI = SMESHGUI::GetSMESHGUI();
110 mySelectionMgr = SMESH::GetSelectionMgr( mySMESHGUI );
111 mySelectionActivated = false;
114 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
115 QPixmap iconSlct ( mgr->loadPixmap("SMESH", tr("ICON_SELECT")));
117 mySelButton = new QPushButton(this);
118 mySelButton->setIcon(iconSlct);
119 mySelButton->setCheckable( true );
121 myObjNameLineEdit = new QLineEdit(this);
122 myObjNameLineEdit->setReadOnly(true);
124 aHBox->addWidget( mySelButton );
125 aHBox->addWidget( myObjNameLineEdit );
128 connect( mySelButton, SIGNAL(clicked()), SLOT(activateSelection()));
131 //================================================================================
133 * \brief SLOT: Installs selection filter that is not done automatically
135 //================================================================================
137 void StdMeshersGUI_ObjectReferenceParamWdg::activateSelection()
139 if ( !mySelectionActivated && mySelectionMgr )
141 mySelectionActivated = true;
142 mySelectionMgr->clearFilters();
143 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
144 aViewWindow->SetSelectionMode(ActorSelection);
146 mySelectionMgr->installFilter( myFilter );
147 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
149 emit selectionActivated();
151 mySelButton->setChecked( mySelectionActivated );
154 //================================================================================
156 * \brief SLOT: stop treating selection changes
158 //================================================================================
160 void StdMeshersGUI_ObjectReferenceParamWdg::deactivateSelection()
162 mySelectionActivated = false;
163 disconnect(mySelectionMgr, 0, this, 0 );
164 mySelectionMgr->removeFilter( myFilter );
166 mySelButton->setChecked( mySelectionActivated );
169 //================================================================================
171 * \brief Connect selection slots
172 * \param other - another StdMeshersGUI_ObjectReferenceParamWdg
174 //================================================================================
176 void StdMeshersGUI_ObjectReferenceParamWdg::AvoidSimultaneousSelection
177 ( StdMeshersGUI_ObjectReferenceParamWdg* other)
179 connect(other, SIGNAL(selectionActivated()), this, SLOT(deactivateSelection()));
180 connect(this, SIGNAL(selectionActivated()), other, SLOT(deactivateSelection()));
183 //================================================================================
185 * \brief Initialize selected object name
186 * \param obj - the current object
188 //================================================================================
190 void StdMeshersGUI_ObjectReferenceParamWdg::SetObject(CORBA::Object_ptr obj)
193 myObjNameLineEdit->setText( "" );
197 if ( !CORBA::is_nil( obj ))
198 sobj = SMESH::FindSObject (obj);
200 std::string name = sobj->GetName();
201 myObjNameLineEdit->setText( name.c_str() );
202 myObjects.push_back( CORBA::Object::_duplicate( obj ));
203 myParamValue = sobj->GetID().c_str();
207 //================================================================================
209 * \brief Initialize selected objects
210 * \param objects - entries of objects
212 //================================================================================
214 void StdMeshersGUI_ObjectReferenceParamWdg::SetObjects(SMESH::string_array_var& objects)
217 myObjNameLineEdit->setText( "" );
220 for ( unsigned i = 0; i < objects->length(); ++i )
222 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
223 _PTR(SObject) aSObj = aStudy->FindObjectID(objects[i].in());
224 CORBA::Object_var anObj = SMESH::SObjectToObject(aSObj,aStudy);
225 if ( !CORBA::is_nil( anObj )) {
226 std::string name = aSObj->GetName();
227 QString text = myObjNameLineEdit->text();
228 if ( !text.isEmpty() )
230 text += name.c_str();
231 myObjNameLineEdit->setText( text );
232 myObjects.push_back( anObj );
234 myParamValue += objects[i];
239 //================================================================================
241 * \brief Takes selected object
243 //================================================================================
245 void StdMeshersGUI_ObjectReferenceParamWdg::onSelectionDone()
247 if ( mySelectionActivated ) {
248 CORBA::Object_var obj;
250 mySelectionMgr->selectedObjects(aList);
251 if (aList.Extent() == 1)
253 obj = SMESH::IObjectToObject( aList.First() );
254 SetObject( obj.in() );
256 else if (myMultiSelection)
258 SMESH::string_array_var objIds = new SMESH::string_array;
259 objIds->length( aList.Extent());
260 SALOME_ListIteratorOfListIO io( aList );
262 for ( ; io.More(); io.Next(), ++i )
264 Handle(SALOME_InteractiveObject) anIO = io.Value();
265 if ( anIO->hasEntry() )
266 objIds[i] = anIO->getEntry();
271 SetObjects( objIds );