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, 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();
157 mySelButton->setChecked( mySelectionActivated );
160 //================================================================================
162 * \brief SLOT: stop treating selection changes
164 //================================================================================
166 void StdMeshersGUI_ObjectReferenceParamWdg::deactivateSelection()
168 mySelectionActivated = false;
169 disconnect(mySelectionMgr, 0, this, 0 );
170 mySelectionMgr->removeFilter( myFilter );
172 mySelButton->setChecked( mySelectionActivated );
175 //================================================================================
177 * \brief Connect selection slots
178 * \param other - another StdMeshersGUI_ObjectReferenceParamWdg
180 //================================================================================
182 void StdMeshersGUI_ObjectReferenceParamWdg::AvoidSimultaneousSelection
183 ( StdMeshersGUI_ObjectReferenceParamWdg* other)
185 connect(other, SIGNAL(selectionActivated()), this, SLOT(deactivateSelection()));
186 connect(this, SIGNAL(selectionActivated()), other, SLOT(deactivateSelection()));
189 //================================================================================
191 * \brief Initialize selected object name
192 * \param obj - the current object
194 //================================================================================
196 void StdMeshersGUI_ObjectReferenceParamWdg::SetObject(CORBA::Object_ptr obj)
199 myObjNameLineEdit->setText( myEmptyText );
200 myObjNameLineEdit->setStyleSheet(myEmptyStyleSheet);
204 if ( !CORBA::is_nil( obj ))
205 sobj = SMESH::FindSObject (obj);
207 std::string name = sobj->GetName();
208 myObjNameLineEdit->setText( name.c_str() );
209 myObjNameLineEdit->setStyleSheet("");
210 myObjects.push_back( CORBA::Object::_duplicate( obj ));
211 myParamValue = sobj->GetID().c_str();
212 emit contentModified();
216 //================================================================================
218 * \brief Initialize selected objects
219 * \param objects - entries of objects
221 //================================================================================
223 void StdMeshersGUI_ObjectReferenceParamWdg::SetObjects(SMESH::string_array_var& objects)
226 myObjNameLineEdit->setText( myEmptyText );
227 myObjNameLineEdit->setStyleSheet(myEmptyStyleSheet);
229 bool selChanged = false;
231 for ( unsigned i = 0; i < objects->length(); ++i )
233 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
234 _PTR(SObject) aSObj = aStudy->FindObjectID(objects[i].in());
235 CORBA::Object_var anObj = SMESH::SObjectToObject(aSObj,aStudy);
236 if ( !CORBA::is_nil( anObj )) {
237 std::string name = aSObj->GetName();
238 QString text = myObjNameLineEdit->text();
239 if ( text != myEmptyText )
243 text += name.c_str();
244 myObjNameLineEdit->setText( text );
245 myObjNameLineEdit->setStyleSheet("");
246 myObjects.push_back( anObj );
248 myParamValue += objects[i];
253 emit contentModified();
256 //================================================================================
258 * \brief Takes selected object
260 //================================================================================
262 void StdMeshersGUI_ObjectReferenceParamWdg::onSelectionDone()
264 if ( mySelectionActivated ) {
265 CORBA::Object_var obj;
267 mySelectionMgr->selectedObjects(aList);
268 if (aList.Extent() == 1)
270 obj = SMESH::IObjectToObject( aList.First() );
271 SetObject( obj.in() );
273 else if (myMultiSelection)
275 SMESH::string_array_var objIds = new SMESH::string_array;
276 objIds->length( aList.Extent());
277 SALOME_ListIteratorOfListIO io( aList );
279 for ( ; io.More(); io.Next(), ++i )
281 Handle(SALOME_InteractiveObject) anIO = io.Value();
282 if ( anIO->hasEntry() )
283 objIds[i] = anIO->getEntry();
288 SetObjects( objIds );
293 void StdMeshersGUI_ObjectReferenceParamWdg::SetDefaultText(QString defaultText, QString styleSheet)
295 myEmptyText = defaultText;
296 myEmptyStyleSheet = styleSheet;
297 myObjNameLineEdit->setText( myEmptyText );
298 myObjNameLineEdit->setStyleSheet( myEmptyStyleSheet);