1 // Copyright (C) 2007-2012 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 // GEOM GEOMGUI : GUI for Geometry component
23 // File : MeasureGUI_GetNonBlocksDlg.cxx
25 #include "MeasureGUI_GetNonBlocksDlg.h"
30 #include <GeometryGUI.h>
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>
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)
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")));
51 setWindowTitle(tr("GEOM_GETNONBLOCKS_TITLE"));
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();
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);
67 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
68 layout->setMargin(0); layout->setSpacing(6);
69 layout->addWidget(myGrp);
71 /***************************************************************/
73 myHelpFileName = "get_non_blocks_page.html";
79 //=================================================================================
80 // function : ~MeasureGUI_GetNonBlocksDlg()
81 // purpose : Destroys the object and frees any allocated resources
82 //=================================================================================
83 MeasureGUI_GetNonBlocksDlg::~MeasureGUI_GetNonBlocksDlg()
87 //=================================================================================
90 //=================================================================================
91 void MeasureGUI_GetNonBlocksDlg::Init()
93 showOnlyPreviewControl();
96 myEditCurrentArgument = myGrp->LineEdit1;
98 /* signals and slots connections */
99 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
100 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
102 connect(myGrp->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
103 connect(myGrp->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
105 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
106 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
108 //initName(tr("GEOM_NONBLOCKS"));
109 mainFrame()->ResultName->setText(tr("GEOM_NONBLOCKS"));
111 SelectionIntoArgument();
114 //=================================================================================
115 // function : ClickOnOk()
117 //=================================================================================
118 void MeasureGUI_GetNonBlocksDlg::ClickOnOk()
124 //=================================================================================
125 // function : ClickOnApply()
127 //=================================================================================
128 bool MeasureGUI_GetNonBlocksDlg::ClickOnApply()
137 //=================================================================================
138 // function : SelectionIntoArgument()
139 // purpose : Called when selection as changed or other case
140 //=================================================================================
141 void MeasureGUI_GetNonBlocksDlg::SelectionIntoArgument()
144 myObj = GEOM::GEOM_Object::_nil();
146 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
147 SALOME_ListIO aSelList;
148 aSelMgr->selectedObjects(aSelList);
150 if (aSelList.Extent() != 1) {
155 GEOM::GEOM_Object_var aSelectedObject =
156 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
158 if (aSelectedObject->_is_nil()) {
163 myObj = aSelectedObject;
167 //=================================================================================
168 // function : SetEditCurrentArgument()
170 //=================================================================================
171 void MeasureGUI_GetNonBlocksDlg::SetEditCurrentArgument()
173 myGrp->LineEdit1->setFocus();
174 myEditCurrentArgument = myGrp->LineEdit1;
175 SelectionIntoArgument();
178 //=================================================================================
179 // function : LineEditReturnPressed()
181 //=================================================================================
182 void MeasureGUI_GetNonBlocksDlg::LineEditReturnPressed()
184 QLineEdit* send = (QLineEdit*)sender();
185 if (send == myGrp->LineEdit1) {
186 myEditCurrentArgument = myGrp->LineEdit1;
187 GEOMBase_Skeleton::LineEditReturnPressed();
191 //=================================================================================
192 // function : ActivateThisDialog()
194 //=================================================================================
195 void MeasureGUI_GetNonBlocksDlg::ActivateThisDialog()
197 GEOMBase_Skeleton::ActivateThisDialog();
199 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
200 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
206 //=================================================================================
207 // function : processObject()
208 // purpose : Fill dialog fields in accordance with myObj
209 //=================================================================================
210 void MeasureGUI_GetNonBlocksDlg::processObject()
212 if (myObj->_is_nil()) {
216 myGrp->LineEdit1->setText(GEOMBase::GetName(myObj));
222 //=================================================================================
223 // function : enterEvent()
225 //=================================================================================
226 void MeasureGUI_GetNonBlocksDlg::enterEvent (QEvent*)
228 if (!mainFrame()->GroupConstructors->isEnabled())
229 ActivateThisDialog();
232 //=================================================================================
233 // function : createOperation
235 //=================================================================================
236 GEOM::GEOM_IOperations_ptr MeasureGUI_GetNonBlocksDlg::createOperation()
238 return getGeomEngine()->GetIBlocksOperations(getStudyId());
241 //=================================================================================
242 // function : isValid
244 //=================================================================================
245 bool MeasureGUI_GetNonBlocksDlg::isValid (QString&)
247 return !myObj->_is_nil();
250 //=================================================================================
251 // function : execute
253 //=================================================================================
254 bool MeasureGUI_GetNonBlocksDlg::execute (ObjectList& objects)
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"));
261 if (!anObj->_is_nil())
262 objects.push_back(anObj._retn());
263 if (!aNonQuads->_is_nil())
264 objects.push_back(aNonQuads._retn());
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)