1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 CEA
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // See http://www.salome-platform.org or email : webmaster.salome@opencascade.org
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 "SalomeApp_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 (QWidget* parent,
46 : GEOMBase_Skeleton(parent, "BlockDlg", modal,
47 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
49 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BLOCK_2F")));
50 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BLOCK_6F")));
51 QPixmap imageS (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
53 setCaption(tr("GEOM_BLOCK_TITLE"));
55 /***************************************************************/
56 GroupConstructors->setTitle(tr("GEOM_BLOCK"));
58 RadioButton1->setPixmap(image0);
59 RadioButton2->setPixmap(image1);
60 RadioButton3->close(TRUE);
63 Group2F = new DlgRef_2Sel_QTD(this, "Group2F");
64 Group2F->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
65 Group2F->TextLabel1->setText(tr("FACE_1"));
66 Group2F->TextLabel2->setText(tr("FACE_2"));
67 Group2F->PushButton1->setPixmap(imageS);
68 Group2F->PushButton2->setPixmap(imageS);
70 // Create second group
71 Group6F = new DlgRef_6Sel_QTD(this, "Group2F");
72 Group6F->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
73 Group6F->TextLabel1->setText(tr("FACE_1"));
74 Group6F->TextLabel2->setText(tr("FACE_2"));
75 Group6F->TextLabel3->setText(tr("FACE_3"));
76 Group6F->TextLabel4->setText(tr("FACE_4"));
77 Group6F->TextLabel5->setText(tr("FACE_5"));
78 Group6F->TextLabel6->setText(tr("FACE_6"));
79 Group6F->PushButton1->setPixmap(imageS);
80 Group6F->PushButton2->setPixmap(imageS);
81 Group6F->PushButton3->setPixmap(imageS);
82 Group6F->PushButton4->setPixmap(imageS);
83 Group6F->PushButton5->setPixmap(imageS);
84 Group6F->PushButton6->setPixmap(imageS);
86 // Add groups to layout
87 Layout1->addWidget(Group2F, 2, 0);
88 Layout1->addWidget(Group6F, 2, 0);
89 /***************************************************************/
94 //=================================================================================
95 // function : ~BlocksGUI_BlockDlg()
96 // purpose : Destroys the object and frees any allocated resources
97 //=================================================================================
98 BlocksGUI_BlockDlg::~BlocksGUI_BlockDlg()
100 // no need to delete child widgets, Qt does it all for us
103 //=================================================================================
106 //=================================================================================
107 void BlocksGUI_BlockDlg::Init()
110 Group2F->LineEdit1->setReadOnly(true);
111 Group2F->LineEdit2->setReadOnly(true);
113 Group6F->LineEdit1->setReadOnly(true);
114 Group6F->LineEdit2->setReadOnly(true);
115 Group6F->LineEdit3->setReadOnly(true);
116 Group6F->LineEdit4->setReadOnly(true);
117 Group6F->LineEdit5->setReadOnly(true);
118 Group6F->LineEdit6->setReadOnly(true);
120 // signals and slots connections
121 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
122 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
123 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
125 connect(Group2F->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
126 connect(Group2F->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
128 connect(Group6F->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
129 connect(Group6F->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
130 connect(Group6F->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
131 connect(Group6F->PushButton4, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
132 connect(Group6F->PushButton5, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
133 connect(Group6F->PushButton6, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
135 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
136 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
138 // init controls and fields
139 initName(tr("GEOM_BLOCK"));
141 myConstructorId = -1;
142 ConstructorsClicked(0);
145 //=================================================================================
146 // function : ConstructorsClicked()
147 // purpose : Radio button management
148 //=================================================================================
149 void BlocksGUI_BlockDlg::ConstructorsClicked (int constructorId)
151 if (myConstructorId == constructorId)
154 myConstructorId = constructorId;
156 switch (constructorId) {
162 myEditCurrentArgument = Group2F->LineEdit1;
163 Group2F->LineEdit1->setText(tr(""));
164 Group2F->LineEdit2->setText(tr(""));
171 myEditCurrentArgument = Group6F->LineEdit1;
172 Group6F->LineEdit1->setText(tr(""));
173 Group6F->LineEdit2->setText(tr(""));
174 Group6F->LineEdit3->setText(tr(""));
175 Group6F->LineEdit4->setText(tr(""));
176 Group6F->LineEdit5->setText(tr(""));
177 Group6F->LineEdit6->setText(tr(""));
184 myFace1 = myFace2 = GEOM::GEOM_Object::_nil();
185 myFace3 = myFace4 = myFace5 = myFace6 = myFace1;
187 globalSelection(GEOM_FACE);
188 SelectionIntoArgument();
189 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
190 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
193 //=================================================================================
194 // function : ClickOnOk()
196 //=================================================================================
197 void BlocksGUI_BlockDlg::ClickOnOk()
203 //=================================================================================
204 // function : ClickOnApply()
206 //=================================================================================
207 bool BlocksGUI_BlockDlg::ClickOnApply()
216 //=================================================================================
217 // function : SelectionIntoArgument()
218 // purpose : Called when selection as changed or other case
219 //=================================================================================
220 void BlocksGUI_BlockDlg::SelectionIntoArgument()
223 myEditCurrentArgument->setText("");
225 if (IObjectCount() != 1)
227 if (myEditCurrentArgument == Group2F->LineEdit1 ||
228 myEditCurrentArgument == Group6F->LineEdit1)
229 myFace1 = GEOM::GEOM_Object::_nil();
230 else if (myEditCurrentArgument == Group2F->LineEdit2 ||
231 myEditCurrentArgument == Group6F->LineEdit2)
232 myFace2 = GEOM::GEOM_Object::_nil();
233 else if (myEditCurrentArgument == Group6F->LineEdit3)
234 myFace3 = GEOM::GEOM_Object::_nil();
235 else if (myEditCurrentArgument == Group6F->LineEdit4)
236 myFace4 = GEOM::GEOM_Object::_nil();
237 else if (myEditCurrentArgument == Group6F->LineEdit5)
238 myFace5 = GEOM::GEOM_Object::_nil();
239 else if (myEditCurrentArgument == Group6F->LineEdit6)
240 myFace6 = GEOM::GEOM_Object::_nil();
245 Standard_Boolean testResult = Standard_False;
246 GEOM::GEOM_Object_var aSelectedObject =
247 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
249 if (!testResult || CORBA::is_nil( aSelectedObject ))
252 if (myEditCurrentArgument == Group2F->LineEdit1 ||
253 myEditCurrentArgument == Group6F->LineEdit1)
254 myFace1 = aSelectedObject;
255 else if (myEditCurrentArgument == Group2F->LineEdit2 ||
256 myEditCurrentArgument == Group6F->LineEdit2)
257 myFace2 = aSelectedObject;
258 else if (myEditCurrentArgument == Group6F->LineEdit3)
259 myFace3 = aSelectedObject;
260 else if (myEditCurrentArgument == Group6F->LineEdit4)
261 myFace4 = aSelectedObject;
262 else if (myEditCurrentArgument == Group6F->LineEdit5)
263 myFace5 = aSelectedObject;
264 else if (myEditCurrentArgument == Group6F->LineEdit6)
265 myFace6 = aSelectedObject;
267 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
272 //=================================================================================
273 // function : SetEditCurrentArgument()
275 //=================================================================================
276 void BlocksGUI_BlockDlg::SetEditCurrentArgument()
278 QPushButton* aSender = (QPushButton*)sender();
280 if (aSender == Group2F->PushButton1) {
281 myEditCurrentArgument = Group2F->LineEdit1;
282 } else if (aSender == Group2F->PushButton2) {
283 myEditCurrentArgument = Group2F->LineEdit2;
285 } else if (aSender == Group6F->PushButton1) {
286 myEditCurrentArgument = Group6F->LineEdit1;
287 } else if (aSender == Group6F->PushButton2) {
288 myEditCurrentArgument = Group6F->LineEdit2;
289 } else if (aSender == Group6F->PushButton3) {
290 myEditCurrentArgument = Group6F->LineEdit3;
291 } else if (aSender == Group6F->PushButton4) {
292 myEditCurrentArgument = Group6F->LineEdit4;
293 } else if (aSender == Group6F->PushButton5) {
294 myEditCurrentArgument = Group6F->LineEdit5;
295 } else if (aSender == Group6F->PushButton6) {
296 myEditCurrentArgument = Group6F->LineEdit6;
299 globalSelection(GEOM_FACE);
301 myEditCurrentArgument->setFocus();
302 SelectionIntoArgument();
305 //=================================================================================
306 // function : ActivateThisDialog()
308 //=================================================================================
309 void BlocksGUI_BlockDlg::ActivateThisDialog()
311 GEOMBase_Skeleton::ActivateThisDialog();
312 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
313 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
315 globalSelection(GEOM_FACE);
317 SelectionIntoArgument();
320 //=================================================================================
321 // function : enterEvent()
323 //=================================================================================
324 void BlocksGUI_BlockDlg::enterEvent (QEvent* e)
326 if (!GroupConstructors->isEnabled())
327 ActivateThisDialog();
330 //=================================================================================
331 // function : DeactivateActiveDialog()
332 // purpose : public slot to deactivate if active
333 //=================================================================================
334 //void BlocksGUI_BlockDlg::DeactivateActiveDialog()
336 // GEOMBase_Skeleton::DeactivateActiveDialog();
339 //=================================================================================
340 // function : createOperation
342 //=================================================================================
343 GEOM::GEOM_IOperations_ptr BlocksGUI_BlockDlg::createOperation()
345 return getGeomEngine()->GetIBlocksOperations(getStudyId());
348 //=================================================================================
349 // function : isValid
351 //=================================================================================
352 bool BlocksGUI_BlockDlg::isValid (QString&)
354 switch (getConstructorId()) {
356 return !(myFace1->_is_nil() || myFace2->_is_nil());
358 return !(myFace1->_is_nil() || myFace2->_is_nil() ||
359 myFace3->_is_nil() || myFace4->_is_nil() ||
360 myFace5->_is_nil() || myFace6->_is_nil());
367 //=================================================================================
368 // function : execute
370 //=================================================================================
371 bool BlocksGUI_BlockDlg::execute (ObjectList& objects)
375 GEOM::GEOM_Object_var anObj;
377 switch (getConstructorId()) {
379 if (!CORBA::is_nil(myFace1) && !CORBA::is_nil(myFace2)) {
380 anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->
381 MakeHexa2Faces(myFace1, myFace2);
386 if (!CORBA::is_nil(myFace1) && !CORBA::is_nil(myFace2) &&
387 !CORBA::is_nil(myFace3) && !CORBA::is_nil(myFace4) &&
388 !CORBA::is_nil(myFace5) && !CORBA::is_nil(myFace6)) {
389 anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->
390 MakeHexa(myFace1, myFace2, myFace3, myFace4, myFace5, myFace6);
396 if (!anObj->_is_nil())
397 objects.push_back(anObj._retn());