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 "QAD_Desktop.h"
32 #include "GEOMImpl_Types.hxx"
36 //=================================================================================
37 // class : BlocksGUI_BlockDlg()
38 // purpose : Constructs a BlocksGUI_BlockDlg which is a child of 'parent'.
39 //=================================================================================
40 BlocksGUI_BlockDlg::BlocksGUI_BlockDlg (QWidget* parent,
41 SALOME_Selection* Sel,
43 : GEOMBase_Skeleton(parent, "BlockDlg", Sel, modal,
44 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
46 QPixmap image0 (QAD_Desktop::getResourceManager()->loadPixmap("GEOM", tr("ICON_DLG_BLOCK_2F")));
47 QPixmap image1 (QAD_Desktop::getResourceManager()->loadPixmap("GEOM", tr("ICON_DLG_BLOCK_6F")));
48 QPixmap imageS (QAD_Desktop::getResourceManager()->loadPixmap("GEOM", tr("ICON_SELECT")));
50 setCaption(tr("GEOM_BLOCK_TITLE"));
52 /***************************************************************/
53 GroupConstructors->setTitle(tr("GEOM_BLOCK"));
55 RadioButton1->setPixmap(image0);
56 RadioButton2->setPixmap(image1);
57 RadioButton3->close(TRUE);
60 Group2F = new DlgRef_2Sel_QTD(this, "Group2F");
61 Group2F->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
62 Group2F->TextLabel1->setText(tr("FACE_1"));
63 Group2F->TextLabel2->setText(tr("FACE_2"));
64 Group2F->PushButton1->setPixmap(imageS);
65 Group2F->PushButton2->setPixmap(imageS);
67 // Create second group
68 Group6F = new DlgRef_6Sel_QTD(this, "Group2F");
69 Group6F->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
70 Group6F->TextLabel1->setText(tr("FACE_1"));
71 Group6F->TextLabel2->setText(tr("FACE_2"));
72 Group6F->TextLabel3->setText(tr("FACE_3"));
73 Group6F->TextLabel4->setText(tr("FACE_4"));
74 Group6F->TextLabel5->setText(tr("FACE_5"));
75 Group6F->TextLabel6->setText(tr("FACE_6"));
76 Group6F->PushButton1->setPixmap(imageS);
77 Group6F->PushButton2->setPixmap(imageS);
78 Group6F->PushButton3->setPixmap(imageS);
79 Group6F->PushButton4->setPixmap(imageS);
80 Group6F->PushButton5->setPixmap(imageS);
81 Group6F->PushButton6->setPixmap(imageS);
83 // Add groups to layout
84 Layout1->addWidget(Group2F, 2, 0);
85 Layout1->addWidget(Group6F, 2, 0);
86 /***************************************************************/
91 //=================================================================================
92 // function : ~BlocksGUI_BlockDlg()
93 // purpose : Destroys the object and frees any allocated resources
94 //=================================================================================
95 BlocksGUI_BlockDlg::~BlocksGUI_BlockDlg()
97 // no need to delete child widgets, Qt does it all for us
100 //=================================================================================
103 //=================================================================================
104 void BlocksGUI_BlockDlg::Init()
107 Group2F->LineEdit1->setReadOnly(true);
108 Group2F->LineEdit2->setReadOnly(true);
110 Group6F->LineEdit1->setReadOnly(true);
111 Group6F->LineEdit2->setReadOnly(true);
112 Group6F->LineEdit3->setReadOnly(true);
113 Group6F->LineEdit4->setReadOnly(true);
114 Group6F->LineEdit5->setReadOnly(true);
115 Group6F->LineEdit6->setReadOnly(true);
117 // signals and slots connections
118 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
119 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
120 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
122 connect(Group2F->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
123 connect(Group2F->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
125 connect(Group6F->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
126 connect(Group6F->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
127 connect(Group6F->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
128 connect(Group6F->PushButton4, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
129 connect(Group6F->PushButton5, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
130 connect(Group6F->PushButton6, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
132 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
134 // init controls and fields
135 initName(tr("GEOM_BLOCK"));
137 myConstructorId = -1;
138 ConstructorsClicked(0);
141 //=================================================================================
142 // function : ConstructorsClicked()
143 // purpose : Radio button management
144 //=================================================================================
145 void BlocksGUI_BlockDlg::ConstructorsClicked (int constructorId)
147 if (myConstructorId == constructorId)
150 myConstructorId = constructorId;
152 switch (constructorId) {
158 myEditCurrentArgument = Group2F->LineEdit1;
159 Group2F->LineEdit1->setText(tr(""));
160 Group2F->LineEdit2->setText(tr(""));
167 myEditCurrentArgument = Group6F->LineEdit1;
168 Group6F->LineEdit1->setText(tr(""));
169 Group6F->LineEdit2->setText(tr(""));
170 Group6F->LineEdit3->setText(tr(""));
171 Group6F->LineEdit4->setText(tr(""));
172 Group6F->LineEdit5->setText(tr(""));
173 Group6F->LineEdit6->setText(tr(""));
180 myFace1 = myFace2 = GEOM::GEOM_Object::_nil();
181 myFace3 = myFace4 = myFace5 = myFace6 = myFace1;
183 globalSelection(GEOM_FACE);
184 SelectionIntoArgument();
185 // connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
188 //=================================================================================
189 // function : ClickOnOk()
191 //=================================================================================
192 void BlocksGUI_BlockDlg::ClickOnOk()
198 //=================================================================================
199 // function : ClickOnApply()
201 //=================================================================================
202 bool BlocksGUI_BlockDlg::ClickOnApply()
211 //=================================================================================
212 // function : SelectionIntoArgument()
213 // purpose : Called when selection as changed or other case
214 //=================================================================================
215 void BlocksGUI_BlockDlg::SelectionIntoArgument()
218 myEditCurrentArgument->setText("");
220 if (mySelection->IObjectCount() != 1)
222 if (myEditCurrentArgument == Group2F->LineEdit1 ||
223 myEditCurrentArgument == Group6F->LineEdit1)
224 myFace1 = GEOM::GEOM_Object::_nil();
225 else if (myEditCurrentArgument == Group2F->LineEdit2 ||
226 myEditCurrentArgument == Group6F->LineEdit2)
227 myFace2 = GEOM::GEOM_Object::_nil();
228 else if (myEditCurrentArgument == Group6F->LineEdit3)
229 myFace3 = GEOM::GEOM_Object::_nil();
230 else if (myEditCurrentArgument == Group6F->LineEdit4)
231 myFace4 = GEOM::GEOM_Object::_nil();
232 else if (myEditCurrentArgument == Group6F->LineEdit5)
233 myFace5 = GEOM::GEOM_Object::_nil();
234 else if (myEditCurrentArgument == Group6F->LineEdit6)
235 myFace6 = GEOM::GEOM_Object::_nil();
240 Standard_Boolean testResult = Standard_False;
241 GEOM::GEOM_Object_var aSelectedObject =
242 GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), testResult );
244 if (!testResult || CORBA::is_nil( aSelectedObject ))
247 if (myEditCurrentArgument == Group2F->LineEdit1 ||
248 myEditCurrentArgument == Group6F->LineEdit1)
249 myFace1 = aSelectedObject;
250 else if (myEditCurrentArgument == Group2F->LineEdit2 ||
251 myEditCurrentArgument == Group6F->LineEdit2)
252 myFace2 = aSelectedObject;
253 else if (myEditCurrentArgument == Group6F->LineEdit3)
254 myFace3 = aSelectedObject;
255 else if (myEditCurrentArgument == Group6F->LineEdit4)
256 myFace4 = aSelectedObject;
257 else if (myEditCurrentArgument == Group6F->LineEdit5)
258 myFace5 = aSelectedObject;
259 else if (myEditCurrentArgument == Group6F->LineEdit6)
260 myFace6 = aSelectedObject;
262 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
267 //=================================================================================
268 // function : SetEditCurrentArgument()
270 //=================================================================================
271 void BlocksGUI_BlockDlg::SetEditCurrentArgument()
273 QPushButton* aSender = (QPushButton*)sender();
275 if (aSender == Group2F->PushButton1) {
276 myEditCurrentArgument = Group2F->LineEdit1;
277 } else if (aSender == Group2F->PushButton2) {
278 myEditCurrentArgument = Group2F->LineEdit2;
280 } else if (aSender == Group6F->PushButton1) {
281 myEditCurrentArgument = Group6F->LineEdit1;
282 } else if (aSender == Group6F->PushButton2) {
283 myEditCurrentArgument = Group6F->LineEdit2;
284 } else if (aSender == Group6F->PushButton3) {
285 myEditCurrentArgument = Group6F->LineEdit3;
286 } else if (aSender == Group6F->PushButton4) {
287 myEditCurrentArgument = Group6F->LineEdit4;
288 } else if (aSender == Group6F->PushButton5) {
289 myEditCurrentArgument = Group6F->LineEdit5;
290 } else if (aSender == Group6F->PushButton6) {
291 myEditCurrentArgument = Group6F->LineEdit6;
294 globalSelection(GEOM_FACE);
296 myEditCurrentArgument->setFocus();
297 SelectionIntoArgument();
300 //=================================================================================
301 // function : ActivateThisDialog()
303 //=================================================================================
304 void BlocksGUI_BlockDlg::ActivateThisDialog()
306 GEOMBase_Skeleton::ActivateThisDialog();
307 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
309 globalSelection(GEOM_FACE);
311 SelectionIntoArgument();
314 //=================================================================================
315 // function : enterEvent()
317 //=================================================================================
318 void BlocksGUI_BlockDlg::enterEvent (QEvent* e)
320 if (!GroupConstructors->isEnabled())
321 ActivateThisDialog();
324 //=================================================================================
325 // function : DeactivateActiveDialog()
326 // purpose : public slot to deactivate if active
327 //=================================================================================
328 //void BlocksGUI_BlockDlg::DeactivateActiveDialog()
330 // GEOMBase_Skeleton::DeactivateActiveDialog();
333 //=================================================================================
334 // function : createOperation
336 //=================================================================================
337 GEOM::GEOM_IOperations_ptr BlocksGUI_BlockDlg::createOperation()
339 return getGeomEngine()->GetIBlocksOperations(getStudyId());
342 //=================================================================================
343 // function : isValid
345 //=================================================================================
346 bool BlocksGUI_BlockDlg::isValid (QString&)
348 switch (getConstructorId()) {
350 return !(myFace1->_is_nil() || myFace2->_is_nil());
352 return !(myFace1->_is_nil() || myFace2->_is_nil() ||
353 myFace3->_is_nil() || myFace4->_is_nil() ||
354 myFace5->_is_nil() || myFace6->_is_nil());
361 //=================================================================================
362 // function : execute
364 //=================================================================================
365 bool BlocksGUI_BlockDlg::execute (ObjectList& objects)
369 GEOM::GEOM_Object_var anObj;
371 switch (getConstructorId()) {
373 if (!CORBA::is_nil(myFace1) && !CORBA::is_nil(myFace2)) {
374 anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->
375 MakeHexa2Faces(myFace1, myFace2);
380 if (!CORBA::is_nil(myFace1) && !CORBA::is_nil(myFace2) &&
381 !CORBA::is_nil(myFace3) && !CORBA::is_nil(myFace4) &&
382 !CORBA::is_nil(myFace5) && !CORBA::is_nil(myFace6)) {
383 anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->
384 MakeHexa(myFace1, myFace2, myFace3, myFace4, myFace5, myFace6);
390 if (!anObj->_is_nil())
391 objects.push_back(anObj._retn());