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"
30 #include "QAD_Desktop.h"
32 #include "GEOMImpl_Types.hxx"
34 //using namespace std;
36 //=================================================================================
37 // class : BlocksGUI_QuadFaceDlg()
38 // purpose : Constructs a BlocksGUI_QuadFaceDlg which is a child of 'parent'.
39 //=================================================================================
40 BlocksGUI_QuadFaceDlg::BlocksGUI_QuadFaceDlg (QWidget* parent,
41 SALOME_Selection* Sel,
43 : GEOMBase_Skeleton(parent, "QuadFaceDlg", Sel, modal,
44 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
46 QPixmap image1 (QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_QUAD_FACE_4_VERT")));
47 QPixmap image2 (QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_QUAD_FACE_2_EDGE")));
48 QPixmap image3 (QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_QUAD_FACE_4_EDGE")));
49 QPixmap imageS (QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
51 setCaption(tr("GEOM_QUAD_FACE_TITLE"));
53 /***************************************************************/
54 GroupConstructors->setTitle(tr("GEOM_QUAD_FACE"));
56 RadioButton1->setPixmap(image1);
57 RadioButton2->setPixmap(image2);
58 RadioButton3->setPixmap(image3);
61 myGrp1 = new QGroupBox(1, Qt::Horizontal, tr("GEOM_ARGUMENTS"), this);
63 QGroupBox* aSelGrp1 = new QGroupBox(3, Qt::Horizontal, myGrp1);
64 aSelGrp1->setFrameStyle(QFrame::NoFrame);
65 aSelGrp1->setInsideMargin(0);
67 createSelWg(tr("VERTEX_1"), imageS, aSelGrp1, Vertex1);
68 createSelWg(tr("VERTEX_2"), imageS, aSelGrp1, Vertex2);
69 createSelWg(tr("VERTEX_3"), imageS, aSelGrp1, Vertex3);
70 createSelWg(tr("VERTEX_4"), imageS, aSelGrp1, Vertex4);
72 // Create second group
73 myGrp2 = new QGroupBox(1, Qt::Horizontal, tr("GEOM_ARGUMENTS"), this);
75 QGroupBox* aSelGrp2 = new QGroupBox(3, Qt::Horizontal, myGrp2);
76 aSelGrp2->setFrameStyle(QFrame::NoFrame);
77 aSelGrp2->setInsideMargin(0);
79 createSelWg(tr("EDGE_1"), imageS, aSelGrp2, Edge12);
80 createSelWg(tr("EDGE_2"), imageS, aSelGrp2, Edge22);
83 myGrp3 = new QGroupBox(1, Qt::Horizontal, tr("GEOM_ARGUMENTS"), this);
85 QGroupBox* aSelGrp3 = new QGroupBox(3, Qt::Horizontal, myGrp3);
86 aSelGrp3->setFrameStyle(QFrame::NoFrame);
87 aSelGrp3->setInsideMargin(0);
89 createSelWg(tr("EDGE_1"), imageS, aSelGrp3, Edge14);
90 createSelWg(tr("EDGE_2"), imageS, aSelGrp3, Edge24);
91 createSelWg(tr("EDGE_3"), imageS, aSelGrp3, Edge34);
92 createSelWg(tr("EDGE_4"), imageS, aSelGrp3, Edge44);
94 (new QLabel(myGrp3))->setSizePolicy(
95 QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
97 // Add groups to layout
98 Layout1->addWidget(myGrp1, 2, 0);
99 Layout1->addWidget(myGrp2, 2, 0);
100 Layout1->addWidget(myGrp3, 2, 0);
101 /***************************************************************/
106 //=================================================================================
107 // function : ~BlocksGUI_QuadFaceDlg()
108 // purpose : Destroys the object and frees any allocated resources
109 //=================================================================================
110 BlocksGUI_QuadFaceDlg::~BlocksGUI_QuadFaceDlg()
112 // no need to delete child widgets, Qt does it all for us
115 //=================================================================================
118 //=================================================================================
119 void BlocksGUI_QuadFaceDlg::Init()
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 QMap<int, QPushButton*>::iterator anIterBtn;
127 for (anIterBtn = mySelBtn.begin(); anIterBtn != mySelBtn.end(); ++anIterBtn)
128 connect(anIterBtn.data(), SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
130 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
132 // init controls and fields
133 initName(tr("GEOM_QUAD_FACE"));
135 myConstructorId = -1;
136 ConstructorsClicked(0);
139 //=================================================================================
140 // function : ConstructorsClicked()
141 // purpose : Radio button management
142 //=================================================================================
143 void BlocksGUI_QuadFaceDlg::ConstructorsClicked (int constructorId)
145 if (myConstructorId == constructorId)
148 myConstructorId = constructorId;
150 switch (constructorId) {
155 myEditCurrentArgument = mySelName[Vertex1];
161 myEditCurrentArgument = mySelName[Edge12];
167 myEditCurrentArgument = mySelName[Edge14];
174 QMap<int, QLineEdit*>::iterator anIterLE;
175 for (anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE)
176 anIterLE.data()->setText("");
179 myShape1 = myShape2 = GEOM::GEOM_Object::_nil();
180 myShape3 = myShape4 = myShape1;
185 //=================================================================================
186 // function : ClickOnOk()
188 //=================================================================================
189 void BlocksGUI_QuadFaceDlg::ClickOnOk()
195 //=================================================================================
196 // function : ClickOnApply()
198 //=================================================================================
199 bool BlocksGUI_QuadFaceDlg::ClickOnApply()
208 //=================================================================================
209 // function : SelectionIntoArgument()
210 // purpose : Called when selection has changed
211 //=================================================================================
212 void BlocksGUI_QuadFaceDlg::SelectionIntoArgument()
215 myEditCurrentArgument->setText("");
217 // Get index of current selection focus
219 QMap<int, QLineEdit*>::iterator anIter;
220 for (anIter = mySelName.begin(); anIter != mySelName.end(); ++anIter) {
221 if (myEditCurrentArgument == anIter.data()) {
222 aCurrFocus = anIter.key();
227 GEOM::GEOM_Object_var anObj;
228 Standard_Boolean aResult = Standard_False;
229 if (mySelection->IObjectCount() == 1) {
230 anObj = GEOMBase::ConvertIOinGEOMObject(mySelection->firstIObject(), aResult);
232 if (anObj->_is_nil()) {
233 aResult = Standard_False;
235 mySelName[aCurrFocus]->setText(GEOMBase::GetName(anObj));
238 anObj = GEOM::GEOM_Object::_nil();
242 if (aCurrFocus == Vertex1 || aCurrFocus == Edge12 || aCurrFocus == Edge14) {
244 } else if (aCurrFocus == Vertex2 || aCurrFocus == Edge22 || aCurrFocus == Edge24) {
246 } else if (aCurrFocus == Vertex3 || aCurrFocus == Edge34) {
248 } else if (aCurrFocus == Vertex4 || aCurrFocus == Edge44) {
257 //=================================================================================
258 // function : SetEditCurrentArgument()
260 //=================================================================================
261 void BlocksGUI_QuadFaceDlg::SetEditCurrentArgument()
263 QPushButton* aSender = (QPushButton*)sender();
265 QMap<int, QPushButton*>::iterator anIter;
266 for (anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter) {
267 if (anIter.data() == aSender) {
268 mySelName[anIter.key()]->setFocus();
269 myEditCurrentArgument = mySelName[anIter.key()];
276 //=================================================================================
277 // function : ActivateThisDialog()
279 //=================================================================================
280 void BlocksGUI_QuadFaceDlg::ActivateThisDialog()
282 GEOMBase_Skeleton::ActivateThisDialog();
283 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
289 //=================================================================================
290 // function : enterEvent()
292 //=================================================================================
293 void BlocksGUI_QuadFaceDlg::enterEvent (QEvent* e)
295 if (!GroupConstructors->isEnabled())
296 this->ActivateThisDialog();
299 //=================================================================================
300 // function : DeactivateActiveDialog()
302 //=================================================================================
303 //void BlocksGUI_QuadFaceDlg::DeactivateActiveDialog()
305 // // disconnect selection
306 // GEOMBase_Skeleton::DeactivateActiveDialog();
309 //=================================================================================
310 // function : createSelWg()
312 //=================================================================================
313 void BlocksGUI_QuadFaceDlg::createSelWg (const QString& theLbl,
318 new QLabel(theLbl, theParent);
319 mySelBtn[theId] = new QPushButton(theParent);
320 mySelBtn[theId]->setPixmap(thePix);
321 mySelName[theId] = new QLineEdit(theParent);
322 mySelName[theId]->setReadOnly(true);
325 //=================================================================================
326 // function : activateSelection
327 // purpose : Activate selection in accordance with myEditCurrentArgument
328 //=================================================================================
329 void BlocksGUI_QuadFaceDlg::activateSelection()
331 if (myEditCurrentArgument == mySelName[Vertex1] ||
332 myEditCurrentArgument == mySelName[Vertex2] ||
333 myEditCurrentArgument == mySelName[Vertex3] ||
334 myEditCurrentArgument == mySelName[Vertex4]) {
336 globalSelection(GEOM_POINT);
339 globalSelection(GEOM_EDGE);
342 SelectionIntoArgument();
345 //=================================================================================
346 // function : createOperation
348 //=================================================================================
349 GEOM::GEOM_IOperations_ptr BlocksGUI_QuadFaceDlg::createOperation()
351 return getGeomEngine()->GetIBlocksOperations(getStudyId());
354 //=================================================================================
355 // function : isValid
356 // purpose : Verify validity of input data
357 //=================================================================================
358 bool BlocksGUI_QuadFaceDlg::isValid (QString&)
360 switch (getConstructorId()) {
362 return (!myShape1->_is_nil() && !myShape2->_is_nil() &&
363 !myShape3->_is_nil() && !myShape4->_is_nil());
365 return (!myShape1->_is_nil() && !myShape2->_is_nil());
367 return (!myShape1->_is_nil() && !myShape2->_is_nil() &&
368 !myShape3->_is_nil() && !myShape4->_is_nil());
375 //=================================================================================
376 // function : execute
378 //=================================================================================
379 bool BlocksGUI_QuadFaceDlg::execute (ObjectList& objects)
383 GEOM::GEOM_Object_var anObj;
385 switch (getConstructorId()) {
387 anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->MakeQuad4Vertices
388 (myShape1, myShape2, myShape3, myShape4);
392 anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->MakeQuad2Edges
393 (myShape1, myShape2);
397 anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->MakeQuad
398 (myShape1, myShape2, myShape3, myShape4);
405 if (!anObj->_is_nil())
406 objects.push_back(anObj._retn());