1 // Copyright (C) 2007-2024 CEA, EDF, 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 includes
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 )
59 : QWidget( parent ), myMultiSelection( multiSelection )
65 //================================================================================
67 * \brief Constructor initialized by object type
68 * \param MeshObjectType - type of object to select
70 //================================================================================
72 StdMeshersGUI_ObjectReferenceParamWdg::StdMeshersGUI_ObjectReferenceParamWdg
73 ( SMESH::MeshObjectType objType, QWidget* parent, bool multiSelection )
74 : QWidget( parent ), myMultiSelection( multiSelection )
76 myFilter = new SMESH_TypeFilter( objType );
80 //================================================================================
84 //================================================================================
86 StdMeshersGUI_ObjectReferenceParamWdg::~StdMeshersGUI_ObjectReferenceParamWdg()
90 mySelectionMgr->removeFilter( myFilter );
95 //================================================================================
97 * \brief Create a leayout, initialize fields
99 //================================================================================
101 void StdMeshersGUI_ObjectReferenceParamWdg::init()
103 QHBoxLayout* aHBox = new QHBoxLayout(this);
106 aHBox->setSpacing(SPACING);
108 mySMESHGUI = SMESHGUI::GetSMESHGUI();
109 mySelectionMgr = SMESH::GetSelectionMgr( mySMESHGUI );
110 mySelectionActivated = false;
113 myEmptyStyleSheet ="";
115 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
116 QPixmap iconSlct ( mgr->loadPixmap("SMESH", tr("ICON_SELECT")));
118 mySelButton = new QPushButton(this);
119 mySelButton->setIcon(iconSlct);
120 mySelButton->setCheckable( true );
122 myObjNameLineEdit = new QLineEdit(this);
123 myObjNameLineEdit->setReadOnly(true);
124 myObjNameLineEdit->setStyleSheet(myEmptyStyleSheet);
125 myObjNameLineEdit->setMinimumWidth(150);
127 aHBox->addWidget( mySelButton );
128 aHBox->addWidget( myObjNameLineEdit );
130 connect( mySelButton, SIGNAL(clicked()), SLOT(activateSelection()));
133 //================================================================================
135 * \brief SLOT: Installs selection filter that is not done automatically
137 //================================================================================
139 void StdMeshersGUI_ObjectReferenceParamWdg::activateSelection()
141 if ( !mySelectionActivated && mySelectionMgr )
143 mySelectionActivated = true;
144 mySelectionMgr->clearFilters();
145 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
146 aViewWindow->SetSelectionMode(ActorSelection);
148 mySelectionMgr->installFilter( myFilter );
149 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
151 emit selectionActivated();
154 mySelButton->setChecked( mySelectionActivated );
157 //================================================================================
159 * \brief SLOT: stop treating selection changes
161 //================================================================================
163 void StdMeshersGUI_ObjectReferenceParamWdg::deactivateSelection()
165 mySelectionActivated = false;
166 disconnect(mySelectionMgr, 0, this, 0 );
167 mySelectionMgr->removeFilter( myFilter );
169 mySelButton->setChecked( mySelectionActivated );
172 //================================================================================
174 * \brief Connect selection slots
175 * \param other - another StdMeshersGUI_ObjectReferenceParamWdg
177 //================================================================================
179 void StdMeshersGUI_ObjectReferenceParamWdg::AvoidSimultaneousSelection
180 ( StdMeshersGUI_ObjectReferenceParamWdg* other)
182 connect(other, SIGNAL(selectionActivated()), this, SLOT(deactivateSelection()));
183 connect(this, SIGNAL(selectionActivated()), other, SLOT(deactivateSelection()));
186 //================================================================================
188 * \brief Initialize selected object name
189 * \param obj - the current object
191 //================================================================================
193 void StdMeshersGUI_ObjectReferenceParamWdg::SetObject(CORBA::Object_ptr obj)
196 myObjNameLineEdit->setText( myEmptyText );
197 myObjNameLineEdit->setStyleSheet(myEmptyStyleSheet);
201 if ( !CORBA::is_nil( obj ))
202 sobj = SMESH::FindSObject (obj);
204 std::string name = sobj->GetName();
205 myObjNameLineEdit->setText( QString( name.c_str() ).trimmed() );
206 myObjNameLineEdit->setStyleSheet("");
207 myObjects.push_back( CORBA::Object::_duplicate( obj ));
208 myParamValue = sobj->GetID().c_str();
210 emit contentModified();
213 //================================================================================
215 * \brief Initialize selected objects
216 * \param objects - entries of objects
218 //================================================================================
220 void StdMeshersGUI_ObjectReferenceParamWdg::SetObjects(SMESH::string_array_var& objects)
223 myObjNameLineEdit->setText( myEmptyText );
224 myObjNameLineEdit->setStyleSheet(myEmptyStyleSheet);
226 bool selChanged = false;
228 for ( unsigned i = 0; i < objects->length(); ++i )
230 _PTR(Study) aStudy = SMESH::getStudy();
231 _PTR(SObject) aSObj = aStudy->FindObjectID(objects[i].in());
232 CORBA::Object_var anObj = SMESH::SObjectToObject(aSObj);
233 if ( !CORBA::is_nil( anObj )) {
234 std::string name = aSObj->GetName();
235 QString text = myObjNameLineEdit->text();
236 if ( text != myEmptyText )
240 text += QString( name.c_str() ).trimmed();
241 myObjNameLineEdit->setText( text );
242 myObjNameLineEdit->setStyleSheet("");
243 myObjects.push_back( anObj );
245 myParamValue += objects[i];
250 emit contentModified();
253 //================================================================================
255 * \brief Takes selected object
257 //================================================================================
259 void StdMeshersGUI_ObjectReferenceParamWdg::onSelectionDone()
261 if ( mySelectionActivated ) {
262 CORBA::Object_var obj;
264 mySelectionMgr->selectedObjects(aList);
265 if (aList.Extent() == 1)
267 obj = SMESH::IObjectToObject( aList.First() );
268 SetObject( obj.in() );
270 else if (myMultiSelection)
272 SMESH::string_array_var objIds = new SMESH::string_array;
273 objIds->length( aList.Extent());
274 SALOME_ListIteratorOfListIO io( aList );
276 for ( ; io.More(); io.Next(), ++i )
278 Handle(SALOME_InteractiveObject) anIO = io.Value();
279 if ( anIO->hasEntry() )
280 objIds[i] = anIO->getEntry();
285 SetObjects( objIds );
290 void StdMeshersGUI_ObjectReferenceParamWdg::SetDefaultText(QString defaultText, QString styleSheet)
292 myEmptyText = defaultText;
293 myEmptyStyleSheet = styleSheet;
294 myObjNameLineEdit->setText( myEmptyText );
295 myObjNameLineEdit->setStyleSheet( myEmptyStyleSheet);