3 // Copyright (C) 2003 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
24 // File : StdMeshersGUI_ObjectReferenceParamWdg.cxx
27 #include "StdMeshersGUI_ObjectReferenceParamWdg.h"
29 #include <qpushbutton.h>
30 #include <qlineedit.h>
34 #include "SMESHGUI_Utils.h"
35 #include "SMESHGUI_VTKUtils.h"
36 #include "SMESH_TypeFilter.hxx"
37 #include "SUIT_ResourceMgr.h"
38 #include "LightApp_SelectionMgr.h"
39 #include "SVTK_ViewWindow.h"
40 #include "SALOME_ListIO.hxx"
41 #include "SALOMEDSClient_SObject.hxx"
45 //================================================================================
47 * \brief Constructor initialized by filter
48 * \param f - object filter
50 //================================================================================
52 StdMeshersGUI_ObjectReferenceParamWdg::StdMeshersGUI_ObjectReferenceParamWdg
53 ( SUIT_SelectionFilter* f, QWidget* parent)
54 : QHGroupBox( parent )
60 //================================================================================
62 * \brief Constructor initialized by object type
63 * \param MeshObjectType - type of object to select
65 //================================================================================
67 StdMeshersGUI_ObjectReferenceParamWdg::StdMeshersGUI_ObjectReferenceParamWdg
68 ( MeshObjectType objType, QWidget* parent )
69 : QHGroupBox( parent )
71 myFilter = new SMESH_TypeFilter( objType );
74 //================================================================================
78 //================================================================================
80 StdMeshersGUI_ObjectReferenceParamWdg::~StdMeshersGUI_ObjectReferenceParamWdg()
87 //================================================================================
89 * \brief Create a leayout, initialize fields
91 //================================================================================
93 void StdMeshersGUI_ObjectReferenceParamWdg::init()
95 setFrameStyle(QFrame::NoFrame);
98 mySMESHGUI = SMESHGUI::GetSMESHGUI();
99 mySelectionMgr = SMESH::GetSelectionMgr( mySMESHGUI );
100 mySelectionActivated = false;
103 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
104 QPixmap iconSlct ( mgr->loadPixmap("SMESH", tr("ICON_SELECT")));
106 mySelButton = new QPushButton(this);
107 mySelButton->setPixmap(iconSlct);
108 mySelButton->setToggleButton( true );
110 myObjNameLineEdit = new QLineEdit(this);
111 myObjNameLineEdit->setReadOnly(true);
113 connect( mySelButton, SIGNAL(clicked()), SLOT(activateSelection()));
116 //================================================================================
118 * \brief SLOT: Installs selection filter that is not done automatically
120 //================================================================================
122 void StdMeshersGUI_ObjectReferenceParamWdg::activateSelection()
124 if ( !mySelectionActivated && mySelectionMgr )
126 mySelectionActivated = true;
127 mySelectionMgr->clearFilters();
128 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
129 aViewWindow->SetSelectionMode(ActorSelection);
131 mySelectionMgr->installFilter( myFilter );
132 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
134 emit selectionActivated();
136 mySelButton->setOn( mySelectionActivated );
139 //================================================================================
141 * \brief SLOT: stop treating selection changes
143 //================================================================================
145 void StdMeshersGUI_ObjectReferenceParamWdg::deactivateSelection()
147 mySelectionActivated = false;
148 disconnect(mySelectionMgr, 0, this, 0 );
149 mySelectionMgr->removeFilter( myFilter );
151 mySelButton->setOn( mySelectionActivated );
154 //================================================================================
156 * \brief Connect selection slots
157 * \param other - another StdMeshersGUI_ObjectReferenceParamWdg
159 //================================================================================
161 void StdMeshersGUI_ObjectReferenceParamWdg::AvoidSimultaneousSelection
162 ( StdMeshersGUI_ObjectReferenceParamWdg* other)
164 connect(other, SIGNAL(selectionActivated()), this, SLOT(deactivateSelection()));
165 connect(this, SIGNAL(selectionActivated()), other, SLOT(deactivateSelection()));
168 //================================================================================
170 * \brief Initialize selected object name
171 * \param obj - the current object
173 //================================================================================
175 void StdMeshersGUI_ObjectReferenceParamWdg::SetObject(CORBA::Object_ptr obj)
177 myObject = CORBA::Object::_nil();
178 myObjNameLineEdit->setText( "" );
182 if ( !CORBA::is_nil( obj ))
183 sobj = SMESH::FindSObject (obj);
185 string name = sobj->GetName();
186 myObjNameLineEdit->setText( name.c_str() );
187 myObject = CORBA::Object::_duplicate( obj );
188 myParamValue = sobj->GetID();
192 //================================================================================
194 * \brief Takes selected object
196 //================================================================================
198 void StdMeshersGUI_ObjectReferenceParamWdg::onSelectionDone()
200 if ( mySelectionActivated ) {
201 CORBA::Object_var obj;
203 mySelectionMgr->selectedObjects(aList);
204 if (aList.Extent() == 1)
205 obj = SMESH::IObjectToObject( aList.First() );
206 SetObject( obj.in() );