1 // Copyright (C) 2007-2008 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
22 // File : StdMeshersGUI_ObjectReferenceParamWdg.cxx
23 // Author : Open CASCADE S.A.S.
26 #include "StdMeshersGUI_ObjectReferenceParamWdg.h"
29 #include <SMESHGUI_VTKUtils.h>
30 #include <SMESH_TypeFilter.hxx>
32 // SALOME GUI includes
33 #include <SUIT_ResourceMgr.h>
34 #include <LightApp_SelectionMgr.h>
35 #include <SVTK_ViewWindow.h>
36 #include <SALOME_ListIO.hxx>
38 // SALOME KERNEL incldues
39 #include <SALOMEDSClient_SObject.hxx>
42 #include <QPushButton>
44 #include <QHBoxLayout>
48 //================================================================================
50 * \brief Constructor initialized by filter
51 * \param f - object filter
53 //================================================================================
55 StdMeshersGUI_ObjectReferenceParamWdg::StdMeshersGUI_ObjectReferenceParamWdg
56 ( SUIT_SelectionFilter* f, QWidget* parent)
63 //================================================================================
65 * \brief Constructor initialized by object type
66 * \param MeshObjectType - type of object to select
68 //================================================================================
70 StdMeshersGUI_ObjectReferenceParamWdg::StdMeshersGUI_ObjectReferenceParamWdg
71 ( MeshObjectType objType, QWidget* parent )
74 myFilter = new SMESH_TypeFilter( objType );
77 //================================================================================
81 //================================================================================
83 StdMeshersGUI_ObjectReferenceParamWdg::~StdMeshersGUI_ObjectReferenceParamWdg()
90 //================================================================================
92 * \brief Create a leayout, initialize fields
94 //================================================================================
96 void StdMeshersGUI_ObjectReferenceParamWdg::init()
98 QHBoxLayout* aHBox = new QHBoxLayout(this);
101 aHBox->setSpacing(SPACING);
103 mySMESHGUI = SMESHGUI::GetSMESHGUI();
104 mySelectionMgr = SMESH::GetSelectionMgr( mySMESHGUI );
105 mySelectionActivated = false;
108 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
109 QPixmap iconSlct ( mgr->loadPixmap("SMESH", tr("ICON_SELECT")));
111 mySelButton = new QPushButton(this);
112 mySelButton->setIcon(iconSlct);
113 mySelButton->setCheckable( true );
115 myObjNameLineEdit = new QLineEdit(this);
116 myObjNameLineEdit->setReadOnly(true);
118 aHBox->addWidget( mySelButton );
119 aHBox->addWidget( myObjNameLineEdit );
122 connect( mySelButton, SIGNAL(clicked()), SLOT(activateSelection()));
125 //================================================================================
127 * \brief SLOT: Installs selection filter that is not done automatically
129 //================================================================================
131 void StdMeshersGUI_ObjectReferenceParamWdg::activateSelection()
133 if ( !mySelectionActivated && mySelectionMgr )
135 mySelectionActivated = true;
136 mySelectionMgr->clearFilters();
137 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
138 aViewWindow->SetSelectionMode(ActorSelection);
140 mySelectionMgr->installFilter( myFilter );
141 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
143 emit selectionActivated();
145 mySelButton->setChecked( mySelectionActivated );
148 //================================================================================
150 * \brief SLOT: stop treating selection changes
152 //================================================================================
154 void StdMeshersGUI_ObjectReferenceParamWdg::deactivateSelection()
156 mySelectionActivated = false;
157 disconnect(mySelectionMgr, 0, this, 0 );
158 mySelectionMgr->removeFilter( myFilter );
160 mySelButton->setChecked( mySelectionActivated );
163 //================================================================================
165 * \brief Connect selection slots
166 * \param other - another StdMeshersGUI_ObjectReferenceParamWdg
168 //================================================================================
170 void StdMeshersGUI_ObjectReferenceParamWdg::AvoidSimultaneousSelection
171 ( StdMeshersGUI_ObjectReferenceParamWdg* other)
173 connect(other, SIGNAL(selectionActivated()), this, SLOT(deactivateSelection()));
174 connect(this, SIGNAL(selectionActivated()), other, SLOT(deactivateSelection()));
177 //================================================================================
179 * \brief Initialize selected object name
180 * \param obj - the current object
182 //================================================================================
184 void StdMeshersGUI_ObjectReferenceParamWdg::SetObject(CORBA::Object_ptr obj)
186 myObject = CORBA::Object::_nil();
187 myObjNameLineEdit->setText( "" );
191 if ( !CORBA::is_nil( obj ))
192 sobj = SMESH::FindSObject (obj);
194 std::string name = sobj->GetName();
195 myObjNameLineEdit->setText( name.c_str() );
196 myObject = CORBA::Object::_duplicate( obj );
197 myParamValue = sobj->GetID().c_str();
201 //================================================================================
203 * \brief Takes selected object
205 //================================================================================
207 void StdMeshersGUI_ObjectReferenceParamWdg::onSelectionDone()
209 if ( mySelectionActivated ) {
210 CORBA::Object_var obj;
212 mySelectionMgr->selectedObjects(aList);
213 if (aList.Extent() == 1)
214 obj = SMESH::IObjectToObject( aList.First() );
215 SetObject( obj.in() );