1 // Copyright (C) 2007-2010 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
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>
43 #include <QPushButton>
45 #include <QHBoxLayout>
49 //================================================================================
51 * \brief Constructor initialized by filter
52 * \param f - object filter
54 //================================================================================
56 StdMeshersGUI_ObjectReferenceParamWdg::StdMeshersGUI_ObjectReferenceParamWdg
57 ( SUIT_SelectionFilter* f, QWidget* parent)
64 //================================================================================
66 * \brief Constructor initialized by object type
67 * \param MeshObjectType - type of object to select
69 //================================================================================
71 StdMeshersGUI_ObjectReferenceParamWdg::StdMeshersGUI_ObjectReferenceParamWdg
72 ( MeshObjectType objType, QWidget* parent )
75 myFilter = new SMESH_TypeFilter( objType );
78 //================================================================================
82 //================================================================================
84 StdMeshersGUI_ObjectReferenceParamWdg::~StdMeshersGUI_ObjectReferenceParamWdg()
91 //================================================================================
93 * \brief Create a leayout, initialize fields
95 //================================================================================
97 void StdMeshersGUI_ObjectReferenceParamWdg::init()
99 QHBoxLayout* aHBox = new QHBoxLayout(this);
102 aHBox->setSpacing(SPACING);
104 mySMESHGUI = SMESHGUI::GetSMESHGUI();
105 mySelectionMgr = SMESH::GetSelectionMgr( mySMESHGUI );
106 mySelectionActivated = false;
109 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
110 QPixmap iconSlct ( mgr->loadPixmap("SMESH", tr("ICON_SELECT")));
112 mySelButton = new QPushButton(this);
113 mySelButton->setIcon(iconSlct);
114 mySelButton->setCheckable( true );
116 myObjNameLineEdit = new QLineEdit(this);
117 myObjNameLineEdit->setReadOnly(true);
119 aHBox->addWidget( mySelButton );
120 aHBox->addWidget( myObjNameLineEdit );
123 connect( mySelButton, SIGNAL(clicked()), SLOT(activateSelection()));
126 //================================================================================
128 * \brief SLOT: Installs selection filter that is not done automatically
130 //================================================================================
132 void StdMeshersGUI_ObjectReferenceParamWdg::activateSelection()
134 if ( !mySelectionActivated && mySelectionMgr )
136 mySelectionActivated = true;
137 mySelectionMgr->clearFilters();
138 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
139 aViewWindow->SetSelectionMode(ActorSelection);
141 mySelectionMgr->installFilter( myFilter );
142 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
144 emit selectionActivated();
146 mySelButton->setChecked( mySelectionActivated );
149 //================================================================================
151 * \brief SLOT: stop treating selection changes
153 //================================================================================
155 void StdMeshersGUI_ObjectReferenceParamWdg::deactivateSelection()
157 mySelectionActivated = false;
158 disconnect(mySelectionMgr, 0, this, 0 );
159 mySelectionMgr->removeFilter( myFilter );
161 mySelButton->setChecked( mySelectionActivated );
164 //================================================================================
166 * \brief Connect selection slots
167 * \param other - another StdMeshersGUI_ObjectReferenceParamWdg
169 //================================================================================
171 void StdMeshersGUI_ObjectReferenceParamWdg::AvoidSimultaneousSelection
172 ( StdMeshersGUI_ObjectReferenceParamWdg* other)
174 connect(other, SIGNAL(selectionActivated()), this, SLOT(deactivateSelection()));
175 connect(this, SIGNAL(selectionActivated()), other, SLOT(deactivateSelection()));
178 //================================================================================
180 * \brief Initialize selected object name
181 * \param obj - the current object
183 //================================================================================
185 void StdMeshersGUI_ObjectReferenceParamWdg::SetObject(CORBA::Object_ptr obj)
187 myObject = CORBA::Object::_nil();
188 myObjNameLineEdit->setText( "" );
192 if ( !CORBA::is_nil( obj ))
193 sobj = SMESH::FindSObject (obj);
195 std::string name = sobj->GetName();
196 myObjNameLineEdit->setText( name.c_str() );
197 myObject = CORBA::Object::_duplicate( obj );
198 myParamValue = sobj->GetID().c_str();
202 //================================================================================
204 * \brief Takes selected object
206 //================================================================================
208 void StdMeshersGUI_ObjectReferenceParamWdg::onSelectionDone()
210 if ( mySelectionActivated ) {
211 CORBA::Object_var obj;
213 mySelectionMgr->selectedObjects(aList);
214 if (aList.Extent() == 1)
215 obj = SMESH::IObjectToObject( aList.First() );
216 SetObject( obj.in() );