1 // Copyright (C) 2007-2010 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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : BlocksGUI_QuadFaceDlg.cxx
25 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S. (julia.dorovskikh@opencascade.com)
27 #include "BlocksGUI_QuadFaceDlg.h"
30 #include <GeometryGUI.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SalomeApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
43 #include <TColStd_IndexedMapOfInteger.hxx>
45 #include <GEOMImpl_Types.hxx>
47 //=================================================================================
48 // class : BlocksGUI_QuadFaceDlg()
49 // purpose : Constructs a BlocksGUI_QuadFaceDlg which is a child of 'parent'.
50 //=================================================================================
51 BlocksGUI_QuadFaceDlg::BlocksGUI_QuadFaceDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
52 : GEOMBase_Skeleton(theGeometryGUI, parent),
55 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
56 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_QUAD_FACE_4_VERT")));
57 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_QUAD_FACE_2_EDGE")));
58 QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_QUAD_FACE_4_EDGE")));
59 QPixmap imageS (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
61 setWindowTitle(tr("GEOM_QUAD_FACE_TITLE"));
63 /***************************************************************/
64 mainFrame()->GroupConstructors->setTitle(tr("GEOM_QUAD_FACE"));
66 mainFrame()->RadioButton1->setIcon(image1);
67 mainFrame()->RadioButton2->setIcon(image2);
68 mainFrame()->RadioButton3->setIcon(image3);
71 myGrp1 = new QGroupBox(tr("GEOM_ARGUMENTS"), centralWidget());
73 createSelWg(tr("VERTEX_1"), imageS, myGrp1, Vertex1);
74 createSelWg(tr("VERTEX_2"), imageS, myGrp1, Vertex2);
75 createSelWg(tr("VERTEX_3"), imageS, myGrp1, Vertex3);
76 createSelWg(tr("VERTEX_4"), imageS, myGrp1, Vertex4);
78 // Create second group
79 myGrp2 = new QGroupBox(tr("GEOM_ARGUMENTS"), centralWidget());
81 createSelWg(tr("EDGE_1"), imageS, myGrp2, Edge12);
82 createSelWg(tr("EDGE_2"), imageS, myGrp2, Edge22);
85 myGrp3 = new QGroupBox(tr("GEOM_ARGUMENTS"), centralWidget());
87 createSelWg(tr("EDGE_1"), imageS, myGrp3, Edge14);
88 createSelWg(tr("EDGE_2"), imageS, myGrp3, Edge24);
89 createSelWg(tr("EDGE_3"), imageS, myGrp3, Edge34);
90 createSelWg(tr("EDGE_4"), imageS, myGrp3, Edge44);
92 // Add groups to layout
93 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
94 layout->setMargin(0); layout->setSpacing(6);
95 layout->addWidget(myGrp1);
96 layout->addWidget(myGrp2);
97 layout->addWidget(myGrp3);
98 /***************************************************************/
100 setHelpFileName("build_by_blocks_page.html#quad_face_anchor");
105 //=================================================================================
106 // function : ~BlocksGUI_QuadFaceDlg()
107 // purpose : Destroys the object and frees any allocated resources
108 //=================================================================================
109 BlocksGUI_QuadFaceDlg::~BlocksGUI_QuadFaceDlg()
111 // no need to delete child widgets, Qt does it all for us
114 //=================================================================================
117 //=================================================================================
118 void BlocksGUI_QuadFaceDlg::Init()
120 // signals and slots connections
121 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
122 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
124 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
126 QMap<int, QPushButton*>::iterator anIterBtn;
127 for (anIterBtn = mySelBtn.begin(); anIterBtn != mySelBtn.end(); ++anIterBtn)
128 connect(anIterBtn.value(), SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
130 // init controls and fields
131 initName(tr("GEOM_QUAD_FACE"));
133 myConstructorId = -1;
134 ConstructorsClicked(0);
137 //=================================================================================
138 // function : ConstructorsClicked()
139 // purpose : Radio button management
140 //=================================================================================
141 void BlocksGUI_QuadFaceDlg::ConstructorsClicked (int constructorId)
143 if (myConstructorId == constructorId)
146 myConstructorId = constructorId;
155 QMap<int, QLineEdit*>::iterator anIterLE;
156 for (anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE)
157 anIterLE.value()->setText("");
159 switch (constructorId) {
164 mySelBtn[Vertex1]->click();
170 mySelBtn[Edge12]->click();
176 mySelBtn[Edge14]->click();
182 qApp->processEvents();
184 resize(minimumSizeHint());
186 // on dialog initialization we init the first field with a selected object (if any)
187 SelectionIntoArgument();
190 //=================================================================================
191 // function : ClickOnOk()
193 //=================================================================================
194 void BlocksGUI_QuadFaceDlg::ClickOnOk()
200 //=================================================================================
201 // function : ClickOnApply()
203 //=================================================================================
204 bool BlocksGUI_QuadFaceDlg::ClickOnApply()
213 //=================================================================================
214 // function : SelectionIntoArgument()
215 // purpose : Called when selection is changed or on dialog initialization or activation
216 //=================================================================================
217 void BlocksGUI_QuadFaceDlg::SelectionIntoArgument()
221 // Get index of current selection focus
223 QMap<int, QLineEdit*>::iterator anIter;
224 for (anIter = mySelName.begin(); anIter != mySelName.end(); ++anIter) {
225 if (myEditCurrentArgument == anIter.value()) {
226 aCurrFocus = anIter.key();
231 TopAbs_ShapeEnum aType = TopAbs_EDGE;
232 if (aCurrFocus == Vertex1 || aCurrFocus == Vertex2 ||
233 aCurrFocus == Vertex3 || aCurrFocus == Vertex4)
234 aType = TopAbs_VERTEX;
236 GEOM::GeomObjPtr aSelectedObject = getSelected( aType );
238 if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
239 QString aName = GEOMBase::GetName( aSelectedObject.get() );
240 myEditCurrentArgument->setText( aName );
241 switch (aCurrFocus) {
244 myShape1 = aSelectedObject;
245 if (!myShape2) mySelBtn[Vertex2]->click();
246 else if (!myShape3) mySelBtn[Vertex3]->click();
247 else if (!myShape4) mySelBtn[Vertex4]->click();
250 myShape2 = aSelectedObject;
251 if (!myShape3) mySelBtn[Vertex3]->click();
252 else if (!myShape4) mySelBtn[Vertex4]->click();
253 else if (!myShape1) mySelBtn[Vertex1]->click();
256 myShape3 = aSelectedObject;
257 if (!myShape4) mySelBtn[Vertex4]->click();
258 else if (!myShape1) mySelBtn[Vertex1]->click();
259 else if (!myShape2) mySelBtn[Vertex2]->click();
262 myShape4 = aSelectedObject;
263 if (!myShape1) mySelBtn[Vertex1]->click();
264 else if (!myShape2) mySelBtn[Vertex2]->click();
265 else if (!myShape3) mySelBtn[Vertex3]->click();
269 myShape1 = aSelectedObject;
270 if (!myShape2) mySelBtn[Edge22]->click();
273 myShape2 = aSelectedObject;
274 if (!myShape1) mySelBtn[Edge12]->click();
278 myShape1 = aSelectedObject;
279 if (!myShape2) mySelBtn[Edge24]->click();
280 else if (!myShape3) mySelBtn[Edge34]->click();
281 else if (!myShape4) mySelBtn[Edge44]->click();
284 myShape2 = aSelectedObject;
285 if (!myShape3) mySelBtn[Edge34]->click();
286 else if (!myShape4) mySelBtn[Edge44]->click();
287 else if (!myShape1) mySelBtn[Edge14]->click();
290 myShape3 = aSelectedObject;
291 if (!myShape4) mySelBtn[Edge44]->click();
292 else if (!myShape1) mySelBtn[Edge14]->click();
293 else if (!myShape2) mySelBtn[Edge24]->click();
296 myShape4 = aSelectedObject;
297 if (!myShape1) mySelBtn[Edge14]->click();
298 else if (!myShape2) mySelBtn[Edge24]->click();
299 else if (!myShape3) mySelBtn[Edge34]->click();
306 switch (aCurrFocus) {
328 myEditCurrentArgument->setText( "" );
331 displayPreview(true);
334 //=================================================================================
335 // function : SetEditCurrentArgument()
337 //=================================================================================
338 void BlocksGUI_QuadFaceDlg::SetEditCurrentArgument()
340 QPushButton* aSender = (QPushButton*)sender();
343 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
347 myGeomGUI->getApp()->selectionMgr()->clearSelected();
350 switch (myConstructorId) {
352 mySelBtn[Vertex1]->setDown(false);
353 mySelBtn[Vertex2]->setDown(false);
354 mySelBtn[Vertex3]->setDown(false);
355 mySelBtn[Vertex4]->setDown(false);
357 mySelName[Vertex1]->setEnabled(false);
358 mySelName[Vertex2]->setEnabled(false);
359 mySelName[Vertex3]->setEnabled(false);
360 mySelName[Vertex4]->setEnabled(false);
363 mySelBtn[Edge12]->setDown(false);
364 mySelBtn[Edge22]->setDown(false);
366 mySelName[Edge12]->setEnabled(false);
367 mySelName[Edge22]->setEnabled(false);
370 mySelBtn[Edge14]->setDown(false);
371 mySelBtn[Edge24]->setDown(false);
372 mySelBtn[Edge34]->setDown(false);
373 mySelBtn[Edge44]->setDown(false);
375 mySelName[Edge14]->setEnabled(false);
376 mySelName[Edge24]->setEnabled(false);
377 mySelName[Edge34]->setEnabled(false);
378 mySelName[Edge44]->setEnabled(false);
384 // set line edit as current argument
385 QMap<int, QPushButton*>::iterator anIter;
386 for (anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter) {
387 if (anIter.value() == aSender) {
388 myEditCurrentArgument = mySelName[anIter.key()];
394 myEditCurrentArgument->setEnabled(true);
395 myEditCurrentArgument->setFocus();
397 // enable push button
398 // after setFocus(), because it will be setDown(false) when loses focus
399 aSender->setDown(true);
404 //=================================================================================
405 // function : ActivateThisDialog()
407 //=================================================================================
408 void BlocksGUI_QuadFaceDlg::ActivateThisDialog()
410 GEOMBase_Skeleton::ActivateThisDialog();
414 displayPreview(true);
417 //=================================================================================
418 // function : enterEvent()
420 //=================================================================================
421 void BlocksGUI_QuadFaceDlg::enterEvent (QEvent*)
423 if (!mainFrame()->GroupConstructors->isEnabled())
424 ActivateThisDialog();
427 //=================================================================================
428 // function : createSelWg()
430 //=================================================================================
431 void BlocksGUI_QuadFaceDlg::createSelWg (const QString& theLbl,
436 QLabel* lab = new QLabel(theLbl, theParent);
437 mySelBtn[theId] = new QPushButton(theParent);
438 mySelBtn[theId]->setIcon(thePix);
439 mySelBtn[theId]->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
440 mySelName[theId] = new QLineEdit(theParent);
441 mySelName[theId]->setReadOnly(true);
443 if (!theParent->layout()) {
444 l = new QGridLayout(theParent);
445 l->setMargin(9); l->setSpacing(6);
448 l = qobject_cast<QGridLayout*>(theParent->layout());
450 int row = l->rowCount();
451 l->addWidget(lab, row, 0);
452 l->addWidget(mySelBtn[theId], row, 1);
453 l->addWidget(mySelName[theId], row, 2);
456 //=================================================================================
457 // function : activateSelection
458 // purpose : Activate selection in accordance with myEditCurrentArgument
459 //=================================================================================
460 void BlocksGUI_QuadFaceDlg::activateSelection()
462 globalSelection(); // close local contexts, if any
463 if (myEditCurrentArgument == mySelName[Vertex1] ||
464 myEditCurrentArgument == mySelName[Vertex2] ||
465 myEditCurrentArgument == mySelName[Vertex3] ||
466 myEditCurrentArgument == mySelName[Vertex4])
468 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX); //Select Vertices on All Shapes
472 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE); //Select Edges on All Shapes
474 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
475 this, SLOT(SelectionIntoArgument()));
478 //=================================================================================
479 // function : createOperation
481 //=================================================================================
482 GEOM::GEOM_IOperations_ptr BlocksGUI_QuadFaceDlg::createOperation()
484 return getGeomEngine()->GetIBlocksOperations(getStudyId());
487 //=================================================================================
488 // function : isValid
489 // purpose : Verify validity of input data
490 //=================================================================================
491 bool BlocksGUI_QuadFaceDlg::isValid (QString&)
494 switch (getConstructorId()) {
496 ok = myShape1 && myShape2 && myShape3 && myShape4;
499 ok = myShape1 && myShape2;
502 ok = myShape1 && myShape2 && myShape3 && myShape4;
510 //=================================================================================
511 // function : execute
513 //=================================================================================
514 bool BlocksGUI_QuadFaceDlg::execute (ObjectList& objects)
518 GEOM::GEOM_Object_var anObj;
520 GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow(getOperation());
522 switch (getConstructorId()) {
524 anObj = anOper->MakeQuad4Vertices(myShape1.get(), myShape2.get(), myShape3.get(), myShape4.get());
528 anObj = anOper->MakeQuad2Edges(myShape1.get(), myShape2.get());
532 anObj = anOper->MakeQuad(myShape1.get(), myShape2.get(), myShape3.get(), myShape4.get());
539 if (!anObj->_is_nil())
540 objects.push_back(anObj._retn());
545 //=================================================================================
546 // function : addSubshapeToStudy
547 // purpose : virtual method to add new SubObjects if local selection
548 //=================================================================================
549 void BlocksGUI_QuadFaceDlg::addSubshapesToStudy()
551 switch (getConstructorId()) {
553 GEOMBase::PublishSubObject( myShape1.get() );
554 GEOMBase::PublishSubObject( myShape2.get() );
555 GEOMBase::PublishSubObject( myShape3.get() );
556 GEOMBase::PublishSubObject( myShape4.get() );
559 GEOMBase::PublishSubObject( myShape1.get() );
560 GEOMBase::PublishSubObject( myShape2.get() );
563 GEOMBase::PublishSubObject( myShape1.get() );
564 GEOMBase::PublishSubObject( myShape2.get() );
565 GEOMBase::PublishSubObject( myShape3.get() );
566 GEOMBase::PublishSubObject( myShape4.get() );