]> SALOME platform Git repositories - modules/smesh.git/blob - src/StdMeshersGUI/StdMeshersGUI_ObjectReferenceParamWdg.cxx
Salome HOME
Win32 Porting.
[modules/smesh.git] / src / StdMeshersGUI / StdMeshersGUI_ObjectReferenceParamWdg.cxx
1 //  SMESH StdMeshersGUI
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : StdMeshersGUI_ObjectReferenceParamWdg.cxx
25 //  Module : SMESH
26
27 #include "StdMeshersGUI_ObjectReferenceParamWdg.h"
28
29 #include <qpushbutton.h>
30 #include <qlineedit.h>
31 #include <qvariant.h>
32
33 #include "SMESHGUI.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"
42
43 using namespace std;
44
45 //================================================================================
46 /*!
47  * \brief Constructor initialized by filter
48   * \param f - object filter
49  */
50 //================================================================================
51
52 StdMeshersGUI_ObjectReferenceParamWdg::StdMeshersGUI_ObjectReferenceParamWdg
53 ( SUIT_SelectionFilter* f, QWidget* parent)
54   : QHGroupBox( parent )
55 {
56   myFilter = f;
57   init();
58 }
59
60 //================================================================================
61 /*!
62  * \brief Constructor initialized by object type
63   * \param MeshObjectType - type of object to select
64  */
65 //================================================================================
66
67 StdMeshersGUI_ObjectReferenceParamWdg::StdMeshersGUI_ObjectReferenceParamWdg
68 ( MeshObjectType objType, QWidget* parent )
69   : QHGroupBox( parent )
70 {
71   myFilter = new SMESH_TypeFilter( objType );
72   init();
73 }
74 //================================================================================
75 /*!
76  * \brief Destructor
77  */
78 //================================================================================
79
80 StdMeshersGUI_ObjectReferenceParamWdg::~StdMeshersGUI_ObjectReferenceParamWdg()
81 {
82   if ( myFilter )
83     delete myFilter;
84 }
85
86
87 //================================================================================
88 /*!
89  * \brief Create a leayout, initialize fields
90  */
91 //================================================================================
92
93 void StdMeshersGUI_ObjectReferenceParamWdg::init()
94 {
95   setFrameStyle(QFrame::NoFrame);
96   setInsideMargin(0);
97
98   mySMESHGUI     = SMESHGUI::GetSMESHGUI();
99   mySelectionMgr = SMESH::GetSelectionMgr( mySMESHGUI );
100   mySelectionActivated = false;
101   myParamValue = "";
102
103   SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
104   QPixmap iconSlct ( mgr->loadPixmap("SMESH", tr("ICON_SELECT")));
105
106   mySelButton = new QPushButton(this);
107   mySelButton->setPixmap(iconSlct);
108   mySelButton->setToggleButton( true );
109
110   myObjNameLineEdit = new QLineEdit(this);
111   myObjNameLineEdit->setReadOnly(true);
112
113   connect( mySelButton, SIGNAL(clicked()), SLOT(activateSelection()));
114 }
115
116 //================================================================================
117 /*!
118  * \brief SLOT: Installs selection filter that is not done automatically
119  */
120 //================================================================================
121
122 void StdMeshersGUI_ObjectReferenceParamWdg::activateSelection()
123 {
124   if ( !mySelectionActivated && mySelectionMgr )
125   {
126     mySelectionActivated = true;
127     mySelectionMgr->clearFilters();
128     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
129       aViewWindow->SetSelectionMode(ActorSelection);
130     if ( myFilter )
131       mySelectionMgr->installFilter( myFilter );
132     connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
133   }
134   emit selectionActivated();
135
136   mySelButton->setOn( mySelectionActivated );
137 }
138
139 //================================================================================
140 /*!
141  * \brief SLOT: stop treating selection changes
142  */
143 //================================================================================
144
145 void StdMeshersGUI_ObjectReferenceParamWdg::deactivateSelection()
146 {
147   mySelectionActivated = false;
148   disconnect(mySelectionMgr, 0, this, 0 );
149   mySelectionMgr->removeFilter( myFilter );
150
151   mySelButton->setOn( mySelectionActivated );
152 }
153
154 //================================================================================
155 /*!
156  * \brief Connect selection slots
157   * \param other - another StdMeshersGUI_ObjectReferenceParamWdg
158  */
159 //================================================================================
160
161 void StdMeshersGUI_ObjectReferenceParamWdg::AvoidSimultaneousSelection
162                                    ( StdMeshersGUI_ObjectReferenceParamWdg* other)
163 {
164   connect(other, SIGNAL(selectionActivated()), this, SLOT(deactivateSelection()));
165   connect(this, SIGNAL(selectionActivated()), other, SLOT(deactivateSelection()));
166 }
167
168 //================================================================================
169 /*!
170  * \brief Initialize selected object name
171  * \param obj - the current object
172  */
173 //================================================================================
174
175 void StdMeshersGUI_ObjectReferenceParamWdg::SetObject(CORBA::Object_ptr obj)
176 {
177   myObject = CORBA::Object::_nil();
178   myObjNameLineEdit->setText( "" );
179   myParamValue = "";
180
181   _PTR(SObject) sobj;
182   if ( !CORBA::is_nil( obj ))
183     sobj = SMESH::FindSObject (obj);
184   if ( sobj ) {
185     string name = sobj->GetName();
186     myObjNameLineEdit->setText( name.c_str() );
187     myObject = CORBA::Object::_duplicate( obj );
188     myParamValue = sobj->GetID();
189   }
190 }
191
192 //================================================================================
193 /*!
194  * \brief Takes selected object
195  */
196 //================================================================================
197
198 void StdMeshersGUI_ObjectReferenceParamWdg::onSelectionDone()
199 {
200   if ( mySelectionActivated ) {
201     CORBA::Object_var obj;
202     SALOME_ListIO aList;
203     mySelectionMgr->selectedObjects(aList);
204     if (aList.Extent() == 1)
205       obj = SMESH::IObjectToObject( aList.First() );
206     SetObject( obj.in() );
207   }
208 }