1 // Copyright (C) 2007-2011 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, bool stretch )
60 : QWidget( parent ), myMultiSelection( multiSelection )
63 myStretchActivated = stretch;
67 //================================================================================
69 * \brief Constructor initialized by object type
70 * \param MeshObjectType - type of object to select
72 //================================================================================
74 StdMeshersGUI_ObjectReferenceParamWdg::StdMeshersGUI_ObjectReferenceParamWdg
75 ( MeshObjectType objType, QWidget* parent, bool multiSelection )
76 : QWidget( parent ), myMultiSelection( multiSelection )
78 myFilter = new SMESH_TypeFilter( objType );
81 //================================================================================
85 //================================================================================
87 StdMeshersGUI_ObjectReferenceParamWdg::~StdMeshersGUI_ObjectReferenceParamWdg()
91 mySelectionMgr->removeFilter( myFilter );
97 //================================================================================
99 * \brief Create a leayout, initialize fields
101 //================================================================================
103 void StdMeshersGUI_ObjectReferenceParamWdg::init()
105 QHBoxLayout* aHBox = new QHBoxLayout(this);
108 aHBox->setSpacing(SPACING);
110 mySMESHGUI = SMESHGUI::GetSMESHGUI();
111 mySelectionMgr = SMESH::GetSelectionMgr( mySMESHGUI );
112 mySelectionActivated = false;
115 myEmptyStyleSheet ="";
117 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
118 QPixmap iconSlct ( mgr->loadPixmap("SMESH", tr("ICON_SELECT")));
120 mySelButton = new QPushButton(this);
121 mySelButton->setIcon(iconSlct);
122 mySelButton->setCheckable( true );
124 myObjNameLineEdit = new QLineEdit(this);
125 myObjNameLineEdit->setReadOnly(true);
126 myObjNameLineEdit->setStyleSheet(myEmptyStyleSheet);
128 aHBox->addWidget( mySelButton );
129 aHBox->addWidget( myObjNameLineEdit );
130 if (myStretchActivated){
134 connect( mySelButton, SIGNAL(clicked()), SLOT(activateSelection()));
137 //================================================================================
139 * \brief SLOT: Installs selection filter that is not done automatically
141 //================================================================================
143 void StdMeshersGUI_ObjectReferenceParamWdg::activateSelection()
145 if ( !mySelectionActivated && mySelectionMgr )
147 mySelectionActivated = true;
148 mySelectionMgr->clearFilters();
149 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
150 aViewWindow->SetSelectionMode(ActorSelection);
152 mySelectionMgr->installFilter( myFilter );
153 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
155 emit selectionActivated();
158 mySelButton->setChecked( mySelectionActivated );
161 //================================================================================
163 * \brief SLOT: stop treating selection changes
165 //================================================================================
167 void StdMeshersGUI_ObjectReferenceParamWdg::deactivateSelection()
169 mySelectionActivated = false;
170 disconnect(mySelectionMgr, 0, this, 0 );
171 mySelectionMgr->removeFilter( myFilter );
173 mySelButton->setChecked( mySelectionActivated );
176 //================================================================================
178 * \brief Connect selection slots
179 * \param other - another StdMeshersGUI_ObjectReferenceParamWdg
181 //================================================================================
183 void StdMeshersGUI_ObjectReferenceParamWdg::AvoidSimultaneousSelection
184 ( StdMeshersGUI_ObjectReferenceParamWdg* other)
186 connect(other, SIGNAL(selectionActivated()), this, SLOT(deactivateSelection()));
187 connect(this, SIGNAL(selectionActivated()), other, SLOT(deactivateSelection()));
190 //================================================================================
192 * \brief Initialize selected object name
193 * \param obj - the current object
195 //================================================================================
197 void StdMeshersGUI_ObjectReferenceParamWdg::SetObject(CORBA::Object_ptr obj)
200 myObjNameLineEdit->setText( myEmptyText );
201 myObjNameLineEdit->setStyleSheet(myEmptyStyleSheet);
205 if ( !CORBA::is_nil( obj ))
206 sobj = SMESH::FindSObject (obj);
208 std::string name = sobj->GetName();
209 myObjNameLineEdit->setText( name.c_str() );
210 myObjNameLineEdit->setStyleSheet("");
211 myObjects.push_back( CORBA::Object::_duplicate( obj ));
212 myParamValue = sobj->GetID().c_str();
213 emit contentModified();
217 //================================================================================
219 * \brief Initialize selected objects
220 * \param objects - entries of objects
222 //================================================================================
224 void StdMeshersGUI_ObjectReferenceParamWdg::SetObjects(SMESH::string_array_var& objects)
227 myObjNameLineEdit->setText( myEmptyText );
228 myObjNameLineEdit->setStyleSheet(myEmptyStyleSheet);
230 bool selChanged = false;
232 for ( unsigned i = 0; i < objects->length(); ++i )
234 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
235 _PTR(SObject) aSObj = aStudy->FindObjectID(objects[i].in());
236 CORBA::Object_var anObj = SMESH::SObjectToObject(aSObj,aStudy);
237 if ( !CORBA::is_nil( anObj )) {
238 std::string name = aSObj->GetName();
239 QString text = myObjNameLineEdit->text();
240 if ( text != myEmptyText )
244 text += name.c_str();
245 myObjNameLineEdit->setText( text );
246 myObjNameLineEdit->setStyleSheet("");
247 myObjects.push_back( anObj );
249 myParamValue += objects[i];
254 emit contentModified();
257 //================================================================================
259 * \brief Takes selected object
261 //================================================================================
263 void StdMeshersGUI_ObjectReferenceParamWdg::onSelectionDone()
265 if ( mySelectionActivated ) {
266 CORBA::Object_var obj;
268 mySelectionMgr->selectedObjects(aList);
269 if (aList.Extent() == 1)
271 obj = SMESH::IObjectToObject( aList.First() );
272 SetObject( obj.in() );
274 else if (myMultiSelection)
276 SMESH::string_array_var objIds = new SMESH::string_array;
277 objIds->length( aList.Extent());
278 SALOME_ListIteratorOfListIO io( aList );
280 for ( ; io.More(); io.Next(), ++i )
282 Handle(SALOME_InteractiveObject) anIO = io.Value();
283 if ( anIO->hasEntry() )
284 objIds[i] = anIO->getEntry();
289 SetObjects( objIds );
294 void StdMeshersGUI_ObjectReferenceParamWdg::SetDefaultText(QString defaultText, QString styleSheet)
296 myEmptyText = defaultText;
297 myEmptyStyleSheet = styleSheet;
298 myObjNameLineEdit->setText( myEmptyText );
299 myObjNameLineEdit->setStyleSheet( myEmptyStyleSheet);