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_QuadFaceDlg.cxx
24 // Author : Julia DOROVSKIKH
28 #include "BlocksGUI_QuadFaceDlg.h"
29 #include "GEOMImpl_Types.hxx"
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "LightApp_SelectionMgr.h"
35 //using namespace std;
39 //=================================================================================
40 // class : BlocksGUI_QuadFaceDlg()
41 // purpose : Constructs a BlocksGUI_QuadFaceDlg which is a child of 'parent'.
42 //=================================================================================
43 BlocksGUI_QuadFaceDlg::BlocksGUI_QuadFaceDlg (QWidget* parent,
45 : GEOMBase_Skeleton(parent, "QuadFaceDlg", modal,
46 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
48 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_QUAD_FACE_4_VERT")));
49 QPixmap image2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_QUAD_FACE_2_EDGE")));
50 QPixmap image3 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_QUAD_FACE_4_EDGE")));
51 QPixmap imageS (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
53 setCaption(tr("GEOM_QUAD_FACE_TITLE"));
55 /***************************************************************/
56 GroupConstructors->setTitle(tr("GEOM_QUAD_FACE"));
58 RadioButton1->setPixmap(image1);
59 RadioButton2->setPixmap(image2);
60 RadioButton3->setPixmap(image3);
63 myGrp1 = new QGroupBox(1, Qt::Horizontal, tr("GEOM_ARGUMENTS"), this);
65 QGroupBox* aSelGrp1 = new QGroupBox(3, Qt::Horizontal, myGrp1);
66 aSelGrp1->setFrameStyle(QFrame::NoFrame);
67 aSelGrp1->setInsideMargin(0);
69 createSelWg(tr("VERTEX_1"), imageS, aSelGrp1, Vertex1);
70 createSelWg(tr("VERTEX_2"), imageS, aSelGrp1, Vertex2);
71 createSelWg(tr("VERTEX_3"), imageS, aSelGrp1, Vertex3);
72 createSelWg(tr("VERTEX_4"), imageS, aSelGrp1, Vertex4);
74 // Create second group
75 myGrp2 = new QGroupBox(1, Qt::Horizontal, tr("GEOM_ARGUMENTS"), this);
77 QGroupBox* aSelGrp2 = new QGroupBox(3, Qt::Horizontal, myGrp2);
78 aSelGrp2->setFrameStyle(QFrame::NoFrame);
79 aSelGrp2->setInsideMargin(0);
81 createSelWg(tr("EDGE_1"), imageS, aSelGrp2, Edge12);
82 createSelWg(tr("EDGE_2"), imageS, aSelGrp2, Edge22);
85 myGrp3 = new QGroupBox(1, Qt::Horizontal, tr("GEOM_ARGUMENTS"), this);
87 QGroupBox* aSelGrp3 = new QGroupBox(3, Qt::Horizontal, myGrp3);
88 aSelGrp3->setFrameStyle(QFrame::NoFrame);
89 aSelGrp3->setInsideMargin(0);
91 createSelWg(tr("EDGE_1"), imageS, aSelGrp3, Edge14);
92 createSelWg(tr("EDGE_2"), imageS, aSelGrp3, Edge24);
93 createSelWg(tr("EDGE_3"), imageS, aSelGrp3, Edge34);
94 createSelWg(tr("EDGE_4"), imageS, aSelGrp3, Edge44);
96 (new QLabel(myGrp3))->setSizePolicy(
97 QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
99 // Add groups to layout
100 Layout1->addWidget(myGrp1, 2, 0);
101 Layout1->addWidget(myGrp2, 2, 0);
102 Layout1->addWidget(myGrp3, 2, 0);
103 /***************************************************************/
108 //=================================================================================
109 // function : ~BlocksGUI_QuadFaceDlg()
110 // purpose : Destroys the object and frees any allocated resources
111 //=================================================================================
112 BlocksGUI_QuadFaceDlg::~BlocksGUI_QuadFaceDlg()
114 // no need to delete child widgets, Qt does it all for us
117 //=================================================================================
120 //=================================================================================
121 void BlocksGUI_QuadFaceDlg::Init()
123 // signals and slots connections
124 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
125 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
126 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
128 QMap<int, QPushButton*>::iterator anIterBtn;
129 for (anIterBtn = mySelBtn.begin(); anIterBtn != mySelBtn.end(); ++anIterBtn)
130 connect(anIterBtn.data(), SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
132 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
133 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
135 // init controls and fields
136 initName(tr("GEOM_QUAD_FACE"));
138 myConstructorId = -1;
139 ConstructorsClicked(0);
142 //=================================================================================
143 // function : ConstructorsClicked()
144 // purpose : Radio button management
145 //=================================================================================
146 void BlocksGUI_QuadFaceDlg::ConstructorsClicked (int constructorId)
148 if (myConstructorId == constructorId)
151 myConstructorId = constructorId;
153 switch (constructorId) {
158 myEditCurrentArgument = mySelName[Vertex1];
164 myEditCurrentArgument = mySelName[Edge12];
170 myEditCurrentArgument = mySelName[Edge14];
177 QMap<int, QLineEdit*>::iterator anIterLE;
178 for (anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE)
179 anIterLE.data()->setText("");
182 myShape1 = myShape2 = GEOM::GEOM_Object::_nil();
183 myShape3 = myShape4 = myShape1;
188 //=================================================================================
189 // function : ClickOnOk()
191 //=================================================================================
192 void BlocksGUI_QuadFaceDlg::ClickOnOk()
198 //=================================================================================
199 // function : ClickOnApply()
201 //=================================================================================
202 bool BlocksGUI_QuadFaceDlg::ClickOnApply()
211 //=================================================================================
212 // function : SelectionIntoArgument()
213 // purpose : Called when selection has changed
214 //=================================================================================
215 void BlocksGUI_QuadFaceDlg::SelectionIntoArgument()
218 myEditCurrentArgument->setText("");
220 // Get index of current selection focus
222 QMap<int, QLineEdit*>::iterator anIter;
223 for (anIter = mySelName.begin(); anIter != mySelName.end(); ++anIter) {
224 if (myEditCurrentArgument == anIter.data()) {
225 aCurrFocus = anIter.key();
230 GEOM::GEOM_Object_var anObj;
231 Standard_Boolean aResult = Standard_False;
232 if (IObjectCount() == 1) {
233 anObj = GEOMBase::ConvertIOinGEOMObject(firstIObject(), aResult);
235 if (anObj->_is_nil()) {
236 aResult = Standard_False;
238 mySelName[aCurrFocus]->setText(GEOMBase::GetName(anObj));
241 anObj = GEOM::GEOM_Object::_nil();
245 if (aCurrFocus == Vertex1 || aCurrFocus == Edge12 || aCurrFocus == Edge14) {
247 } else if (aCurrFocus == Vertex2 || aCurrFocus == Edge22 || aCurrFocus == Edge24) {
249 } else if (aCurrFocus == Vertex3 || aCurrFocus == Edge34) {
251 } else if (aCurrFocus == Vertex4 || aCurrFocus == Edge44) {
260 //=================================================================================
261 // function : SetEditCurrentArgument()
263 //=================================================================================
264 void BlocksGUI_QuadFaceDlg::SetEditCurrentArgument()
266 QPushButton* aSender = (QPushButton*)sender();
268 QMap<int, QPushButton*>::iterator anIter;
269 for (anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter) {
270 if (anIter.data() == aSender) {
271 mySelName[anIter.key()]->setFocus();
272 myEditCurrentArgument = mySelName[anIter.key()];
279 //=================================================================================
280 // function : ActivateThisDialog()
282 //=================================================================================
283 void BlocksGUI_QuadFaceDlg::ActivateThisDialog()
285 GEOMBase_Skeleton::ActivateThisDialog();
286 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
287 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
293 //=================================================================================
294 // function : enterEvent()
296 //=================================================================================
297 void BlocksGUI_QuadFaceDlg::enterEvent (QEvent* e)
299 if (!GroupConstructors->isEnabled())
300 this->ActivateThisDialog();
303 //=================================================================================
304 // function : DeactivateActiveDialog()
306 //=================================================================================
307 //void BlocksGUI_QuadFaceDlg::DeactivateActiveDialog()
309 // // disconnect selection
310 // GEOMBase_Skeleton::DeactivateActiveDialog();
313 //=================================================================================
314 // function : createSelWg()
316 //=================================================================================
317 void BlocksGUI_QuadFaceDlg::createSelWg (const QString& theLbl,
322 new QLabel(theLbl, theParent);
323 mySelBtn[theId] = new QPushButton(theParent);
324 mySelBtn[theId]->setPixmap(thePix);
325 mySelName[theId] = new QLineEdit(theParent);
326 mySelName[theId]->setReadOnly(true);
329 //=================================================================================
330 // function : activateSelection
331 // purpose : Activate selection in accordance with myEditCurrentArgument
332 //=================================================================================
333 void BlocksGUI_QuadFaceDlg::activateSelection()
335 if (myEditCurrentArgument == mySelName[Vertex1] ||
336 myEditCurrentArgument == mySelName[Vertex2] ||
337 myEditCurrentArgument == mySelName[Vertex3] ||
338 myEditCurrentArgument == mySelName[Vertex4]) {
340 globalSelection(GEOM_POINT);
343 globalSelection(GEOM_EDGE);
346 SelectionIntoArgument();
349 //=================================================================================
350 // function : createOperation
352 //=================================================================================
353 GEOM::GEOM_IOperations_ptr BlocksGUI_QuadFaceDlg::createOperation()
355 return getGeomEngine()->GetIBlocksOperations(getStudyId());
358 //=================================================================================
359 // function : isValid
360 // purpose : Verify validity of input data
361 //=================================================================================
362 bool BlocksGUI_QuadFaceDlg::isValid (QString&)
364 switch (getConstructorId()) {
366 return (!myShape1->_is_nil() && !myShape2->_is_nil() &&
367 !myShape3->_is_nil() && !myShape4->_is_nil());
369 return (!myShape1->_is_nil() && !myShape2->_is_nil());
371 return (!myShape1->_is_nil() && !myShape2->_is_nil() &&
372 !myShape3->_is_nil() && !myShape4->_is_nil());
379 //=================================================================================
380 // function : execute
382 //=================================================================================
383 bool BlocksGUI_QuadFaceDlg::execute (ObjectList& objects)
387 GEOM::GEOM_Object_var anObj;
389 switch (getConstructorId()) {
391 anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->MakeQuad4Vertices
392 (myShape1, myShape2, myShape3, myShape4);
396 anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->MakeQuad2Edges
397 (myShape1, myShape2);
401 anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->MakeQuad
402 (myShape1, myShape2, myShape3, myShape4);
409 if (!anObj->_is_nil())
410 objects.push_back(anObj._retn());