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 // SMESH StdMeshersGUI
23 // File : StdMeshersGUI_ObjectReferenceParamWdg.cxx
26 #include "StdMeshersGUI_ObjectReferenceParamWdg.h"
28 #include <qpushbutton.h>
29 #include <qlineedit.h>
33 #include "SMESHGUI_Utils.h"
34 #include "SMESHGUI_VTKUtils.h"
35 #include "SMESH_TypeFilter.hxx"
36 #include "SUIT_ResourceMgr.h"
37 #include "LightApp_SelectionMgr.h"
38 #include "SVTK_ViewWindow.h"
39 #include "SALOME_ListIO.hxx"
40 #include "SALOMEDSClient_SObject.hxx"
44 //================================================================================
46 * \brief Constructor initialized by filter
47 * \param f - object filter
49 //================================================================================
51 StdMeshersGUI_ObjectReferenceParamWdg::StdMeshersGUI_ObjectReferenceParamWdg
52 ( SUIT_SelectionFilter* f, QWidget* parent)
53 : QHGroupBox( parent )
59 //================================================================================
61 * \brief Constructor initialized by object type
62 * \param MeshObjectType - type of object to select
64 //================================================================================
66 StdMeshersGUI_ObjectReferenceParamWdg::StdMeshersGUI_ObjectReferenceParamWdg
67 ( MeshObjectType objType, QWidget* parent )
68 : QHGroupBox( parent )
70 myFilter = new SMESH_TypeFilter( objType );
73 //================================================================================
77 //================================================================================
79 StdMeshersGUI_ObjectReferenceParamWdg::~StdMeshersGUI_ObjectReferenceParamWdg()
86 //================================================================================
88 * \brief Create a leayout, initialize fields
90 //================================================================================
92 void StdMeshersGUI_ObjectReferenceParamWdg::init()
94 setFrameStyle(QFrame::NoFrame);
97 mySMESHGUI = SMESHGUI::GetSMESHGUI();
98 mySelectionMgr = SMESH::GetSelectionMgr( mySMESHGUI );
99 mySelectionActivated = false;
102 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
103 QPixmap iconSlct ( mgr->loadPixmap("SMESH", tr("ICON_SELECT")));
105 mySelButton = new QPushButton(this);
106 mySelButton->setPixmap(iconSlct);
107 mySelButton->setToggleButton( true );
109 myObjNameLineEdit = new QLineEdit(this);
110 myObjNameLineEdit->setReadOnly(true);
112 connect( mySelButton, SIGNAL(clicked()), SLOT(activateSelection()));
115 //================================================================================
117 * \brief SLOT: Installs selection filter that is not done automatically
119 //================================================================================
121 void StdMeshersGUI_ObjectReferenceParamWdg::activateSelection()
123 if ( !mySelectionActivated && mySelectionMgr )
125 mySelectionActivated = true;
126 mySelectionMgr->clearFilters();
127 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
128 aViewWindow->SetSelectionMode(ActorSelection);
130 mySelectionMgr->installFilter( myFilter );
131 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
133 emit selectionActivated();
135 mySelButton->setOn( mySelectionActivated );
138 //================================================================================
140 * \brief SLOT: stop treating selection changes
142 //================================================================================
144 void StdMeshersGUI_ObjectReferenceParamWdg::deactivateSelection()
146 mySelectionActivated = false;
147 disconnect(mySelectionMgr, 0, this, 0 );
148 mySelectionMgr->removeFilter( myFilter );
150 mySelButton->setOn( mySelectionActivated );
153 //================================================================================
155 * \brief Connect selection slots
156 * \param other - another StdMeshersGUI_ObjectReferenceParamWdg
158 //================================================================================
160 void StdMeshersGUI_ObjectReferenceParamWdg::AvoidSimultaneousSelection
161 ( StdMeshersGUI_ObjectReferenceParamWdg* other)
163 connect(other, SIGNAL(selectionActivated()), this, SLOT(deactivateSelection()));
164 connect(this, SIGNAL(selectionActivated()), other, SLOT(deactivateSelection()));
167 //================================================================================
169 * \brief Initialize selected object name
170 * \param obj - the current object
172 //================================================================================
174 void StdMeshersGUI_ObjectReferenceParamWdg::SetObject(CORBA::Object_ptr obj)
176 myObject = CORBA::Object::_nil();
177 myObjNameLineEdit->setText( "" );
181 if ( !CORBA::is_nil( obj ))
182 sobj = SMESH::FindSObject (obj);
184 string name = sobj->GetName();
185 myObjNameLineEdit->setText( name.c_str() );
186 myObject = CORBA::Object::_duplicate( obj );
187 myParamValue = sobj->GetID();
191 //================================================================================
193 * \brief Takes selected object
195 //================================================================================
197 void StdMeshersGUI_ObjectReferenceParamWdg::onSelectionDone()
199 if ( mySelectionActivated ) {
200 CORBA::Object_var obj;
202 mySelectionMgr->selectedObjects(aList);
203 if (aList.Extent() == 1)
204 obj = SMESH::IObjectToObject( aList.First() );
205 SetObject( obj.in() );