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