1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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>
39 // SALOME KERNEL incldues
40 #include <SALOMEDSClient_SObject.hxx>
41 #include <SALOMEDSClient_Study.hxx>
44 #include <QPushButton>
46 #include <QHBoxLayout>
50 //================================================================================
52 * \brief Constructor initialized by filter
53 * \param f - object filter
55 //================================================================================
57 StdMeshersGUI_ObjectReferenceParamWdg::StdMeshersGUI_ObjectReferenceParamWdg
58 ( SUIT_SelectionFilter* f, QWidget* parent, bool multiSelection, bool stretch )
59 : QWidget( parent ), myMultiSelection( multiSelection )
62 myStretchActivated = stretch;
66 //================================================================================
68 * \brief Constructor initialized by object type
69 * \param MeshObjectType - type of object to select
71 //================================================================================
73 StdMeshersGUI_ObjectReferenceParamWdg::StdMeshersGUI_ObjectReferenceParamWdg
74 ( SMESH::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 myEmptyStyleSheet ="";
116 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
117 QPixmap iconSlct ( mgr->loadPixmap("SMESH", tr("ICON_SELECT")));
119 mySelButton = new QPushButton(this);
120 mySelButton->setIcon(iconSlct);
121 mySelButton->setCheckable( true );
123 myObjNameLineEdit = new QLineEdit(this);
124 myObjNameLineEdit->setReadOnly(true);
125 myObjNameLineEdit->setStyleSheet(myEmptyStyleSheet);
127 aHBox->addWidget( mySelButton );
128 aHBox->addWidget( myObjNameLineEdit );
129 if (myStretchActivated){
133 connect( mySelButton, SIGNAL(clicked()), SLOT(activateSelection()));
136 //================================================================================
138 * \brief SLOT: Installs selection filter that is not done automatically
140 //================================================================================
142 void StdMeshersGUI_ObjectReferenceParamWdg::activateSelection()
144 if ( !mySelectionActivated && mySelectionMgr )
146 mySelectionActivated = true;
147 mySelectionMgr->clearFilters();
148 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
149 aViewWindow->SetSelectionMode(ActorSelection);
151 mySelectionMgr->installFilter( myFilter );
152 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
154 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( QString( name.c_str() ).trimmed() );
209 myObjNameLineEdit->setStyleSheet("");
210 myObjects.push_back( CORBA::Object::_duplicate( obj ));
211 myParamValue = sobj->GetID().c_str();
213 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 += QString( name.c_str() ).trimmed();
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);