1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : StdMeshersGUI_ObjectReferenceParamWdg.cxx
21 // Author : Open CASCADE S.A.S.
25 #include "StdMeshersGUI_ObjectReferenceParamWdg.h"
28 #include <SMESHGUI_VTKUtils.h>
29 #include <SMESH_TypeFilter.hxx>
31 // SALOME GUI includes
32 #include <SUIT_ResourceMgr.h>
33 #include <LightApp_SelectionMgr.h>
34 #include <SVTK_ViewWindow.h>
35 #include <SALOME_ListIO.hxx>
37 // SALOME KERNEL incldues
38 #include <SALOMEDSClient_SObject.hxx>
41 #include <QPushButton>
43 #include <QHBoxLayout>
47 //================================================================================
49 * \brief Constructor initialized by filter
50 * \param f - object filter
52 //================================================================================
54 StdMeshersGUI_ObjectReferenceParamWdg::StdMeshersGUI_ObjectReferenceParamWdg
55 ( SUIT_SelectionFilter* f, QWidget* parent)
62 //================================================================================
64 * \brief Constructor initialized by object type
65 * \param MeshObjectType - type of object to select
67 //================================================================================
69 StdMeshersGUI_ObjectReferenceParamWdg::StdMeshersGUI_ObjectReferenceParamWdg
70 ( MeshObjectType objType, QWidget* parent )
73 myFilter = new SMESH_TypeFilter( objType );
76 //================================================================================
80 //================================================================================
82 StdMeshersGUI_ObjectReferenceParamWdg::~StdMeshersGUI_ObjectReferenceParamWdg()
89 //================================================================================
91 * \brief Create a leayout, initialize fields
93 //================================================================================
95 void StdMeshersGUI_ObjectReferenceParamWdg::init()
97 QHBoxLayout* aHBox = new QHBoxLayout(this);
100 aHBox->setSpacing(SPACING);
102 mySMESHGUI = SMESHGUI::GetSMESHGUI();
103 mySelectionMgr = SMESH::GetSelectionMgr( mySMESHGUI );
104 mySelectionActivated = false;
107 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
108 QPixmap iconSlct ( mgr->loadPixmap("SMESH", tr("ICON_SELECT")));
110 mySelButton = new QPushButton(this);
111 mySelButton->setIcon(iconSlct);
112 mySelButton->setCheckable( true );
114 myObjNameLineEdit = new QLineEdit(this);
115 myObjNameLineEdit->setReadOnly(true);
117 aHBox->addWidget( mySelButton );
118 aHBox->addWidget( myObjNameLineEdit );
121 connect( mySelButton, SIGNAL(clicked()), SLOT(activateSelection()));
124 //================================================================================
126 * \brief SLOT: Installs selection filter that is not done automatically
128 //================================================================================
130 void StdMeshersGUI_ObjectReferenceParamWdg::activateSelection()
132 if ( !mySelectionActivated && mySelectionMgr )
134 mySelectionActivated = true;
135 mySelectionMgr->clearFilters();
136 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
137 aViewWindow->SetSelectionMode(ActorSelection);
139 mySelectionMgr->installFilter( myFilter );
140 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
142 emit selectionActivated();
144 mySelButton->setChecked( mySelectionActivated );
147 //================================================================================
149 * \brief SLOT: stop treating selection changes
151 //================================================================================
153 void StdMeshersGUI_ObjectReferenceParamWdg::deactivateSelection()
155 mySelectionActivated = false;
156 disconnect(mySelectionMgr, 0, this, 0 );
157 mySelectionMgr->removeFilter( myFilter );
159 mySelButton->setChecked( mySelectionActivated );
162 //================================================================================
164 * \brief Connect selection slots
165 * \param other - another StdMeshersGUI_ObjectReferenceParamWdg
167 //================================================================================
169 void StdMeshersGUI_ObjectReferenceParamWdg::AvoidSimultaneousSelection
170 ( StdMeshersGUI_ObjectReferenceParamWdg* other)
172 connect(other, SIGNAL(selectionActivated()), this, SLOT(deactivateSelection()));
173 connect(this, SIGNAL(selectionActivated()), other, SLOT(deactivateSelection()));
176 //================================================================================
178 * \brief Initialize selected object name
179 * \param obj - the current object
181 //================================================================================
183 void StdMeshersGUI_ObjectReferenceParamWdg::SetObject(CORBA::Object_ptr obj)
185 myObject = CORBA::Object::_nil();
186 myObjNameLineEdit->setText( "" );
190 if ( !CORBA::is_nil( obj ))
191 sobj = SMESH::FindSObject (obj);
193 string name = sobj->GetName();
194 myObjNameLineEdit->setText( name.c_str() );
195 myObject = CORBA::Object::_duplicate( obj );
196 myParamValue = sobj->GetID().c_str();
200 //================================================================================
202 * \brief Takes selected object
204 //================================================================================
206 void StdMeshersGUI_ObjectReferenceParamWdg::onSelectionDone()
208 if ( mySelectionActivated ) {
209 CORBA::Object_var obj;
211 mySelectionMgr->selectedObjects(aList);
212 if (aList.Extent() == 1)
213 obj = SMESH::IObjectToObject( aList.First() );
214 SetObject( obj.in() );