Salome HOME
Update copyrights 2014.
[modules/geom.git] / src / MeasureGUI / MeasureGUI_GetNonBlocksDlg.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : MeasureGUI_GetNonBlocksDlg.cxx
25
26 #include "MeasureGUI_GetNonBlocksDlg.h"
27
28 #include <DlgRef.h>
29 #include <GEOMBase.h>
30
31 #include <GeometryGUI.h>
32
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SalomeApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
37 #include <SalomeApp_Tools.h>
38
39 //=================================================================================
40 // class    : MeasureGUI_GetNonBlocksDlg()
41 // purpose  : Constructs a MeasureGUI_GetNonBlocksDlg which is a child of 'parent',
42 //            with the name 'name' and widget flags set to 'f'.
43 //            The dialog will by default be modeless, unless you set 'modal' to
44 //            true to construct a modal dialog.
45 //=================================================================================
46 MeasureGUI_GetNonBlocksDlg::MeasureGUI_GetNonBlocksDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
47   : GEOMBase_Skeleton(theGeometryGUI, parent, false)
48 {
49   QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_GETNONBLOCKS")));
50   QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
51
52   setWindowTitle(tr("GEOM_GETNONBLOCKS_TITLE"));
53
54   /***************************************************************/
55   mainFrame()->GroupConstructors->setTitle(tr("GEOM_GETNONBLOCKS"));
56   mainFrame()->RadioButton1->setIcon(image0);
57   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
58   mainFrame()->RadioButton2->close();
59   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
60   mainFrame()->RadioButton3->close();
61
62   myGrp = new DlgRef_1Sel (centralWidget());
63   myGrp->GroupBox1->setTitle(tr("GEOM_GETNONBLOCKS"));
64   myGrp->TextLabel1->setText(tr("GEOM_OBJECT"));
65   myGrp->PushButton1->setIcon(image1);
66   myGrp->LineEdit1->setReadOnly(true);
67
68   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
69   layout->setMargin(0); layout->setSpacing(6);
70   layout->addWidget(myGrp);
71
72   /***************************************************************/
73
74   myHelpFileName = "get_non_blocks_page.html";
75
76   /* Initialisation */
77   Init();
78 }
79
80 //=================================================================================
81 // function : ~MeasureGUI_GetNonBlocksDlg()
82 // purpose  : Destroys the object and frees any allocated resources
83 //=================================================================================
84 MeasureGUI_GetNonBlocksDlg::~MeasureGUI_GetNonBlocksDlg()
85 {
86 }
87
88 //=================================================================================
89 // function : Init()
90 // purpose  :
91 //=================================================================================
92 void MeasureGUI_GetNonBlocksDlg::Init()
93 {
94   showOnlyPreviewControl();
95
96   /* init variables */
97   myEditCurrentArgument = myGrp->LineEdit1;
98
99    /* signals and slots connections */
100   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
101   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
102
103   connect(myGrp->LineEdit1,   SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
104   connect(myGrp->PushButton1, SIGNAL(clicked()),       this, SLOT(SetEditCurrentArgument()));
105
106   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
107            SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
108
109   //initName(tr("GEOM_NONBLOCKS"));
110   mainFrame()->ResultName->setText(tr("GEOM_NONBLOCKS"));
111   globalSelection();
112   SelectionIntoArgument();
113 }
114
115 //=================================================================================
116 // function : ClickOnOk()
117 // purpose  :
118 //=================================================================================
119 void MeasureGUI_GetNonBlocksDlg::ClickOnOk()
120 {
121   if (ClickOnApply())
122     ClickOnCancel();
123 }
124
125 //=================================================================================
126 // function : ClickOnApply()
127 // purpose  :
128 //=================================================================================
129 bool MeasureGUI_GetNonBlocksDlg::ClickOnApply()
130 {
131   if (!onAccept())
132     return false;
133
134   //initName();
135   return true;
136 }
137
138 //=================================================================================
139 // function : SelectionIntoArgument()
140 // purpose  : Called when selection as changed or other case
141 //=================================================================================
142 void MeasureGUI_GetNonBlocksDlg::SelectionIntoArgument()
143 {
144   erasePreview();
145   myObj = GEOM::GEOM_Object::_nil();
146
147   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
148   SALOME_ListIO aSelList;
149   aSelMgr->selectedObjects(aSelList);
150
151   if (aSelList.Extent() != 1) {
152     processObject();
153     return;
154   }
155
156   GEOM::GEOM_Object_var aSelectedObject =
157     GEOMBase::ConvertIOinGEOMObject(aSelList.First());
158
159   if (aSelectedObject->_is_nil()) {
160     processObject();
161     return;
162   }
163
164   myObj = aSelectedObject;
165   processObject();
166 }
167
168 //=================================================================================
169 // function : SetEditCurrentArgument()
170 // purpose  :
171 //=================================================================================
172 void MeasureGUI_GetNonBlocksDlg::SetEditCurrentArgument()
173 {
174   myGrp->LineEdit1->setFocus();
175   myEditCurrentArgument = myGrp->LineEdit1;
176   SelectionIntoArgument();
177 }
178
179 //=================================================================================
180 // function : LineEditReturnPressed()
181 // purpose  :
182 //=================================================================================
183 void MeasureGUI_GetNonBlocksDlg::LineEditReturnPressed()
184 {
185   QLineEdit* send = (QLineEdit*)sender();
186   if (send == myGrp->LineEdit1) {
187     myEditCurrentArgument = myGrp->LineEdit1;
188     GEOMBase_Skeleton::LineEditReturnPressed();
189   }
190 }
191
192 //=================================================================================
193 // function : ActivateThisDialog()
194 // purpose  :
195 //=================================================================================
196 void MeasureGUI_GetNonBlocksDlg::ActivateThisDialog()
197 {
198   GEOMBase_Skeleton::ActivateThisDialog();
199
200   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
201            SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
202
203   globalSelection();
204   processPreview();
205 }
206
207 //=================================================================================
208 // function : processObject()
209 // purpose  : Fill dialog fields in accordance with myObj
210 //=================================================================================
211 void MeasureGUI_GetNonBlocksDlg::processObject()
212 {
213   if (myObj->_is_nil()) {
214     erasePreview();
215   }
216   else {
217     myGrp->LineEdit1->setText(GEOMBase::GetName(myObj));
218
219     processPreview();
220   }
221 }
222
223 //=================================================================================
224 // function : enterEvent()
225 // purpose  :
226 //=================================================================================
227 void MeasureGUI_GetNonBlocksDlg::enterEvent (QEvent*)
228 {
229   if (!mainFrame()->GroupConstructors->isEnabled())
230     ActivateThisDialog();
231 }
232
233 //=================================================================================
234 // function : createOperation
235 // purpose  :
236 //=================================================================================
237 GEOM::GEOM_IOperations_ptr MeasureGUI_GetNonBlocksDlg::createOperation()
238 {
239   return getGeomEngine()->GetIBlocksOperations(getStudyId());
240 }
241
242 //=================================================================================
243 // function : isValid
244 // purpose  :
245 //=================================================================================
246 bool MeasureGUI_GetNonBlocksDlg::isValid (QString&)
247 {
248   return !myObj->_is_nil();
249 }
250
251 //=================================================================================
252 // function : execute
253 // purpose  :
254 //=================================================================================
255 bool MeasureGUI_GetNonBlocksDlg::execute (ObjectList& objects)
256 {
257   GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow(getOperation());
258   GEOM::GEOM_Object_var aNonQuads;
259   GEOM::GEOM_Object_var anObj = anOper->GetNonBlocks(myObj, aNonQuads);
260   //mainFrame()->ResultName->setText(tr("GEOM_NONBLOCKS"));
261
262   if (!anObj->_is_nil())
263     objects.push_back(anObj._retn());
264   if (!aNonQuads->_is_nil())
265     objects.push_back(aNonQuads._retn());
266
267   return true;
268 }
269
270 //================================================================
271 // Function : getFather
272 // Purpose  : Get father object for object to be added in study
273 //            ( called with addInStudy method )
274 //================================================================
275 GEOM::GEOM_Object_ptr MeasureGUI_GetNonBlocksDlg::getFather (GEOM::GEOM_Object_ptr)
276 {
277   return myObj;
278 }