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 // GEOM GEOMGUI : GUI for Geometry component
23 // File : BlocksGUI_BlockDlg.cxx
24 // Author : Julia DOROVSKIKH
28 #include "BlocksGUI_BlockDlg.h"
30 #include "SUIT_Session.h"
31 #include "SalomeApp_Application.h"
32 #include "LightApp_SelectionMgr.h"
34 #include "GEOMImpl_Types.hxx"
40 //=================================================================================
41 // class : BlocksGUI_BlockDlg()
42 // purpose : Constructs a BlocksGUI_BlockDlg which is a child of 'parent'.
43 //=================================================================================
44 BlocksGUI_BlockDlg::BlocksGUI_BlockDlg (GeometryGUI* theGeometryGUI, QWidget* parent, bool modal)
45 : GEOMBase_Skeleton(theGeometryGUI, parent, "BlockDlg", modal,
46 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
48 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BLOCK_2F")));
49 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BLOCK_6F")));
50 QPixmap imageS (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
52 setCaption(tr("GEOM_BLOCK_TITLE"));
54 /***************************************************************/
55 GroupConstructors->setTitle(tr("GEOM_BLOCK"));
57 RadioButton1->setPixmap(image0);
58 RadioButton2->setPixmap(image1);
59 RadioButton3->close(TRUE);
62 Group2F = new DlgRef_2Sel_QTD(this, "Group2F");
63 Group2F->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
64 Group2F->TextLabel1->setText(tr("FACE_1"));
65 Group2F->TextLabel2->setText(tr("FACE_2"));
66 Group2F->PushButton1->setPixmap(imageS);
67 Group2F->PushButton2->setPixmap(imageS);
69 // Create second group
70 Group6F = new DlgRef_6Sel_QTD(this, "Group2F");
71 Group6F->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
72 Group6F->TextLabel1->setText(tr("FACE_1"));
73 Group6F->TextLabel2->setText(tr("FACE_2"));
74 Group6F->TextLabel3->setText(tr("FACE_3"));
75 Group6F->TextLabel4->setText(tr("FACE_4"));
76 Group6F->TextLabel5->setText(tr("FACE_5"));
77 Group6F->TextLabel6->setText(tr("FACE_6"));
78 Group6F->PushButton1->setPixmap(imageS);
79 Group6F->PushButton2->setPixmap(imageS);
80 Group6F->PushButton3->setPixmap(imageS);
81 Group6F->PushButton4->setPixmap(imageS);
82 Group6F->PushButton5->setPixmap(imageS);
83 Group6F->PushButton6->setPixmap(imageS);
85 // Add groups to layout
86 Layout1->addWidget(Group2F, 2, 0);
87 Layout1->addWidget(Group6F, 2, 0);
88 /***************************************************************/
90 setHelpFileName("build_by_blocks_page.html#hexa_solid_anchor");
95 //=================================================================================
96 // function : ~BlocksGUI_BlockDlg()
97 // purpose : Destroys the object and frees any allocated resources
98 //=================================================================================
99 BlocksGUI_BlockDlg::~BlocksGUI_BlockDlg()
101 // no need to delete child widgets, Qt does it all for us
104 //=================================================================================
107 //=================================================================================
108 void BlocksGUI_BlockDlg::Init()
111 Group2F->LineEdit1->setReadOnly(true);
112 Group2F->LineEdit2->setReadOnly(true);
114 Group6F->LineEdit1->setReadOnly(true);
115 Group6F->LineEdit2->setReadOnly(true);
116 Group6F->LineEdit3->setReadOnly(true);
117 Group6F->LineEdit4->setReadOnly(true);
118 Group6F->LineEdit5->setReadOnly(true);
119 Group6F->LineEdit6->setReadOnly(true);
121 // signals and slots connections
122 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
123 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
124 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
126 connect(Group2F->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
127 connect(Group2F->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
129 connect(Group6F->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
130 connect(Group6F->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
131 connect(Group6F->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
132 connect(Group6F->PushButton4, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
133 connect(Group6F->PushButton5, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
134 connect(Group6F->PushButton6, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
136 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
137 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
139 // init controls and fields
140 initName(tr("GEOM_BLOCK"));
142 myConstructorId = -1;
143 ConstructorsClicked(0);
146 //=================================================================================
147 // function : ConstructorsClicked()
148 // purpose : Radio button management
149 //=================================================================================
150 void BlocksGUI_BlockDlg::ConstructorsClicked (int constructorId)
152 if (myConstructorId == constructorId)
155 myConstructorId = constructorId;
157 switch (constructorId) {
163 myEditCurrentArgument = Group2F->LineEdit1;
164 Group2F->LineEdit1->setText(tr(""));
165 Group2F->LineEdit2->setText(tr(""));
172 myEditCurrentArgument = Group6F->LineEdit1;
173 Group6F->LineEdit1->setText(tr(""));
174 Group6F->LineEdit2->setText(tr(""));
175 Group6F->LineEdit3->setText(tr(""));
176 Group6F->LineEdit4->setText(tr(""));
177 Group6F->LineEdit5->setText(tr(""));
178 Group6F->LineEdit6->setText(tr(""));
185 myFace1 = myFace2 = GEOM::GEOM_Object::_nil();
186 myFace3 = myFace4 = myFace5 = myFace6 = myFace1;
188 globalSelection(GEOM_FACE);
189 SelectionIntoArgument();
190 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
191 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
194 //=================================================================================
195 // function : ClickOnOk()
197 //=================================================================================
198 void BlocksGUI_BlockDlg::ClickOnOk()
204 //=================================================================================
205 // function : ClickOnApply()
207 //=================================================================================
208 bool BlocksGUI_BlockDlg::ClickOnApply()
217 //=================================================================================
218 // function : SelectionIntoArgument()
219 // purpose : Called when selection as changed or other case
220 //=================================================================================
221 void BlocksGUI_BlockDlg::SelectionIntoArgument()
224 myEditCurrentArgument->setText("");
226 if (IObjectCount() != 1)
228 if (myEditCurrentArgument == Group2F->LineEdit1 ||
229 myEditCurrentArgument == Group6F->LineEdit1)
230 myFace1 = GEOM::GEOM_Object::_nil();
231 else if (myEditCurrentArgument == Group2F->LineEdit2 ||
232 myEditCurrentArgument == Group6F->LineEdit2)
233 myFace2 = GEOM::GEOM_Object::_nil();
234 else if (myEditCurrentArgument == Group6F->LineEdit3)
235 myFace3 = GEOM::GEOM_Object::_nil();
236 else if (myEditCurrentArgument == Group6F->LineEdit4)
237 myFace4 = GEOM::GEOM_Object::_nil();
238 else if (myEditCurrentArgument == Group6F->LineEdit5)
239 myFace5 = GEOM::GEOM_Object::_nil();
240 else if (myEditCurrentArgument == Group6F->LineEdit6)
241 myFace6 = GEOM::GEOM_Object::_nil();
246 Standard_Boolean testResult = Standard_False;
247 GEOM::GEOM_Object_var aSelectedObject =
248 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
250 if (!testResult || CORBA::is_nil( aSelectedObject ))
253 if (myEditCurrentArgument == Group2F->LineEdit1 ||
254 myEditCurrentArgument == Group6F->LineEdit1)
255 myFace1 = aSelectedObject;
256 else if (myEditCurrentArgument == Group2F->LineEdit2 ||
257 myEditCurrentArgument == Group6F->LineEdit2)
258 myFace2 = aSelectedObject;
259 else if (myEditCurrentArgument == Group6F->LineEdit3)
260 myFace3 = aSelectedObject;
261 else if (myEditCurrentArgument == Group6F->LineEdit4)
262 myFace4 = aSelectedObject;
263 else if (myEditCurrentArgument == Group6F->LineEdit5)
264 myFace5 = aSelectedObject;
265 else if (myEditCurrentArgument == Group6F->LineEdit6)
266 myFace6 = aSelectedObject;
268 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
273 //=================================================================================
274 // function : SetEditCurrentArgument()
276 //=================================================================================
277 void BlocksGUI_BlockDlg::SetEditCurrentArgument()
279 QPushButton* aSender = (QPushButton*)sender();
281 if (aSender == Group2F->PushButton1) {
282 myEditCurrentArgument = Group2F->LineEdit1;
283 } else if (aSender == Group2F->PushButton2) {
284 myEditCurrentArgument = Group2F->LineEdit2;
286 } else if (aSender == Group6F->PushButton1) {
287 myEditCurrentArgument = Group6F->LineEdit1;
288 } else if (aSender == Group6F->PushButton2) {
289 myEditCurrentArgument = Group6F->LineEdit2;
290 } else if (aSender == Group6F->PushButton3) {
291 myEditCurrentArgument = Group6F->LineEdit3;
292 } else if (aSender == Group6F->PushButton4) {
293 myEditCurrentArgument = Group6F->LineEdit4;
294 } else if (aSender == Group6F->PushButton5) {
295 myEditCurrentArgument = Group6F->LineEdit5;
296 } else if (aSender == Group6F->PushButton6) {
297 myEditCurrentArgument = Group6F->LineEdit6;
300 globalSelection(GEOM_FACE);
302 myEditCurrentArgument->setFocus();
303 SelectionIntoArgument();
306 //=================================================================================
307 // function : ActivateThisDialog()
309 //=================================================================================
310 void BlocksGUI_BlockDlg::ActivateThisDialog()
312 GEOMBase_Skeleton::ActivateThisDialog();
313 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
314 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
316 globalSelection(GEOM_FACE);
318 SelectionIntoArgument();
321 //=================================================================================
322 // function : enterEvent()
324 //=================================================================================
325 void BlocksGUI_BlockDlg::enterEvent (QEvent* e)
327 if (!GroupConstructors->isEnabled())
328 ActivateThisDialog();
331 //=================================================================================
332 // function : createOperation
334 //=================================================================================
335 GEOM::GEOM_IOperations_ptr BlocksGUI_BlockDlg::createOperation()
337 return getGeomEngine()->GetIBlocksOperations(getStudyId());
340 //=================================================================================
341 // function : isValid
343 //=================================================================================
344 bool BlocksGUI_BlockDlg::isValid (QString&)
346 switch (getConstructorId()) {
348 return !(myFace1->_is_nil() || myFace2->_is_nil());
350 return !(myFace1->_is_nil() || myFace2->_is_nil() ||
351 myFace3->_is_nil() || myFace4->_is_nil() ||
352 myFace5->_is_nil() || myFace6->_is_nil());
359 //=================================================================================
360 // function : execute
362 //=================================================================================
363 bool BlocksGUI_BlockDlg::execute (ObjectList& objects)
367 GEOM::GEOM_Object_var anObj;
369 switch (getConstructorId()) {
371 if (!CORBA::is_nil(myFace1) && !CORBA::is_nil(myFace2)) {
372 anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->
373 MakeHexa2Faces(myFace1, myFace2);
378 if (!CORBA::is_nil(myFace1) && !CORBA::is_nil(myFace2) &&
379 !CORBA::is_nil(myFace3) && !CORBA::is_nil(myFace4) &&
380 !CORBA::is_nil(myFace5) && !CORBA::is_nil(myFace6)) {
381 anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->
382 MakeHexa(myFace1, myFace2, myFace3, myFace4, myFace5, myFace6);
388 if (!anObj->_is_nil())
389 objects.push_back(anObj._retn());