1 // Copyright (C) 2007-2015 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
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 ( SMESH::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);
127 myObjNameLineEdit->setMinimumWidth(150);
129 aHBox->addWidget( mySelButton );
130 aHBox->addWidget( myObjNameLineEdit );
131 //if (myStretchActivated){
132 // aHBox->addStretch();
135 connect( mySelButton, SIGNAL(clicked()), SLOT(activateSelection()));
138 //================================================================================
140 * \brief SLOT: Installs selection filter that is not done automatically
142 //================================================================================
144 void StdMeshersGUI_ObjectReferenceParamWdg::activateSelection()
146 if ( !mySelectionActivated && mySelectionMgr )
148 mySelectionActivated = true;
149 mySelectionMgr->clearFilters();
150 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
151 aViewWindow->SetSelectionMode(ActorSelection);
153 mySelectionMgr->installFilter( myFilter );
154 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
156 emit selectionActivated();
159 mySelButton->setChecked( mySelectionActivated );
162 //================================================================================
164 * \brief SLOT: stop treating selection changes
166 //================================================================================
168 void StdMeshersGUI_ObjectReferenceParamWdg::deactivateSelection()
170 mySelectionActivated = false;
171 disconnect(mySelectionMgr, 0, this, 0 );
172 mySelectionMgr->removeFilter( myFilter );
174 mySelButton->setChecked( mySelectionActivated );
177 //================================================================================
179 * \brief Connect selection slots
180 * \param other - another StdMeshersGUI_ObjectReferenceParamWdg
182 //================================================================================
184 void StdMeshersGUI_ObjectReferenceParamWdg::AvoidSimultaneousSelection
185 ( StdMeshersGUI_ObjectReferenceParamWdg* other)
187 connect(other, SIGNAL(selectionActivated()), this, SLOT(deactivateSelection()));
188 connect(this, SIGNAL(selectionActivated()), other, SLOT(deactivateSelection()));
191 //================================================================================
193 * \brief Initialize selected object name
194 * \param obj - the current object
196 //================================================================================
198 void StdMeshersGUI_ObjectReferenceParamWdg::SetObject(CORBA::Object_ptr obj)
201 myObjNameLineEdit->setText( myEmptyText );
202 myObjNameLineEdit->setStyleSheet(myEmptyStyleSheet);
206 if ( !CORBA::is_nil( obj ))
207 sobj = SMESH::FindSObject (obj);
209 std::string name = sobj->GetName();
210 myObjNameLineEdit->setText( QString( name.c_str() ).trimmed() );
211 myObjNameLineEdit->setStyleSheet("");
212 myObjects.push_back( CORBA::Object::_duplicate( obj ));
213 myParamValue = sobj->GetID().c_str();
215 emit contentModified();
218 //================================================================================
220 * \brief Initialize selected objects
221 * \param objects - entries of objects
223 //================================================================================
225 void StdMeshersGUI_ObjectReferenceParamWdg::SetObjects(SMESH::string_array_var& objects)
228 myObjNameLineEdit->setText( myEmptyText );
229 myObjNameLineEdit->setStyleSheet(myEmptyStyleSheet);
231 bool selChanged = false;
233 for ( unsigned i = 0; i < objects->length(); ++i )
235 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
236 _PTR(SObject) aSObj = aStudy->FindObjectID(objects[i].in());
237 CORBA::Object_var anObj = SMESH::SObjectToObject(aSObj,aStudy);
238 if ( !CORBA::is_nil( anObj )) {
239 std::string name = aSObj->GetName();
240 QString text = myObjNameLineEdit->text();
241 if ( text != myEmptyText )
245 text += QString( name.c_str() ).trimmed();
246 myObjNameLineEdit->setText( text );
247 myObjNameLineEdit->setStyleSheet("");
248 myObjects.push_back( anObj );
250 myParamValue += objects[i];
255 emit contentModified();
258 //================================================================================
260 * \brief Takes selected object
262 //================================================================================
264 void StdMeshersGUI_ObjectReferenceParamWdg::onSelectionDone()
266 if ( mySelectionActivated ) {
267 CORBA::Object_var obj;
269 mySelectionMgr->selectedObjects(aList);
270 if (aList.Extent() == 1)
272 obj = SMESH::IObjectToObject( aList.First() );
273 SetObject( obj.in() );
275 else if (myMultiSelection)
277 SMESH::string_array_var objIds = new SMESH::string_array;
278 objIds->length( aList.Extent());
279 SALOME_ListIteratorOfListIO io( aList );
281 for ( ; io.More(); io.Next(), ++i )
283 Handle(SALOME_InteractiveObject) anIO = io.Value();
284 if ( anIO->hasEntry() )
285 objIds[i] = anIO->getEntry();
290 SetObjects( objIds );
295 void StdMeshersGUI_ObjectReferenceParamWdg::SetDefaultText(QString defaultText, QString styleSheet)
297 myEmptyText = defaultText;
298 myEmptyStyleSheet = styleSheet;
299 myObjNameLineEdit->setText( myEmptyText );
300 myObjNameLineEdit->setStyleSheet( myEmptyStyleSheet);