Salome HOME
IPAL54049: Operations on multiple study objects are very long
[modules/geom.git] / src / BuildGUI / BuildGUI_FaceDlg.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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, or (at your option) any later version.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : BuildGUI_FaceDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26
27 #include "BuildGUI_FaceDlg.h"
28
29 #include <GEOMImpl_Types.hxx>
30 #include <TColStd_MapOfInteger.hxx>
31
32 #include <DlgRef.h>
33 #include <GeometryGUI.h>
34 #include <GEOMBase.h>
35
36 #include <SalomeApp_Application.h>
37 #include <LightApp_SelectionMgr.h>
38
39 #include <SUIT_ResourceMgr.h>
40 #include <SUIT_Session.h>
41 #include <SUIT_MessageBox.h>
42 #include <SUIT_OverrideCursor.h>
43
44 #include <QTreeWidget>
45
46 //=================================================================================
47 // class    : BuildGUI_TreeWidgetItem
48 // purpose  : class for constraint(Edge-Face) creation
49 //=================================================================================
50 class BuildGUI_FaceDlg::TreeWidgetItem : public QTreeWidgetItem
51 {
52 public:
53   TreeWidgetItem( QTreeWidget*, const GEOM::GeomObjPtr, int = Type );
54   TreeWidgetItem( QTreeWidgetItem*, const GEOM::GeomObjPtr, int = Type );
55   ~TreeWidgetItem();
56   void             setFace( const GEOM::GeomObjPtr );
57   GEOM::GeomObjPtr getFace() const;
58   GEOM::GeomObjPtr getEdge() const;
59 private:
60   GEOM::GeomObjPtr myEdge;
61   GEOM::GeomObjPtr myFace;
62 };
63
64 BuildGUI_FaceDlg::TreeWidgetItem::TreeWidgetItem( QTreeWidget* view, const GEOM::GeomObjPtr edge, int type )
65 :QTreeWidgetItem( view, QStringList()<<GEOMBase::GetName( edge.get() ), type ),
66   myEdge( edge ),
67   myFace( 0 )
68 {
69 }
70
71 BuildGUI_FaceDlg::TreeWidgetItem::TreeWidgetItem( QTreeWidgetItem* parent, const GEOM::GeomObjPtr edge, int type )
72 :QTreeWidgetItem( parent, QStringList()<<GEOMBase::GetName( edge.get() ), type ),
73   myEdge( edge ),
74   myFace( 0 )
75 {
76 }
77
78 BuildGUI_FaceDlg::TreeWidgetItem::~TreeWidgetItem()
79 {
80 }
81
82 void BuildGUI_FaceDlg::TreeWidgetItem::setFace( const GEOM::GeomObjPtr face )
83 {
84   QString aName = GEOMBase::GetName( face.get() );
85   setText( 1, aName );
86   treeWidget()->resizeColumnToContents(1);
87   myFace = face;
88 }
89
90 GEOM::GeomObjPtr BuildGUI_FaceDlg::TreeWidgetItem::getFace() const
91 {
92   return myFace;
93 }
94
95 GEOM::GeomObjPtr BuildGUI_FaceDlg::TreeWidgetItem::getEdge() const
96 {
97   return myEdge;
98 }
99
100 //=================================================================================
101 // class    : BuildGUI_FaceDlg()
102 // purpose  : Constructs a BuildGUI_FaceDlg which is a child of 'parent', with the 
103 //            name 'name' and widget flags set to 'f'.
104 //            The dialog will by default be modeless, unless you set 'modal' to
105 //            TRUE to construct a modal dialog.
106 //=================================================================================
107 BuildGUI_FaceDlg::BuildGUI_FaceDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
108   : GEOMBase_Skeleton( theGeometryGUI, parent ),
109     myGroupWire(0),
110     myGroupSurf(0),
111     myGroupWireConstraints(0)
112 {
113   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
114   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BUILD_FACE" ) ) );
115   QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BUILD_FACE_SURFACE" ) ) );
116   QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BUILD_FACE_CONSTRAINTS" ) ) );
117
118   setWindowTitle( tr( "GEOM_FACE_TITLE" ) );
119
120   /***************************************************************/
121   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_FACE" ) );
122   mainFrame()->RadioButton1->setIcon( image1 );
123   mainFrame()->RadioButton2->setIcon( image2 );
124   mainFrame()->RadioButton3->setIcon( image3 );
125
126   // Face creation from wires and/or edges
127
128   myGroupWire = new DlgRef_1Sel1Check( centralWidget() );
129
130   myGroupWire->GroupBox1->setTitle( tr( "GEOM_FACE_FFW" ) );
131   myGroupWire->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
132   myGroupWire->CheckButton1->setText( tr( "GEOM_FACE_OPT" ) );
133   myGroupWire->PushButton1->setIcon( image0 );
134
135   // Face creation from surface
136
137   myGroupSurf = new DlgRef_2Sel(centralWidget());
138
139   myGroupSurf->GroupBox1->setTitle(tr("GEOM_FACE_FROM_SURFACE" ) );
140   myGroupSurf->TextLabel1->setText(tr("GEOM_FACE"));
141   myGroupSurf->TextLabel2->setText(tr("GEOM_WIRE"));
142   myGroupSurf->PushButton1->setIcon(image0);
143   myGroupSurf->PushButton2->setIcon(image0);
144   
145   // Face creation from wire and constraints
146
147   myGroupWireConstraints = new DlgRef_1SelExt( centralWidget() );
148   myGroupWireConstraints->GroupBox1->setTitle( tr( "GEOM_FACE_FFWC" ) );
149   myGroupWireConstraints->TextLabel1->setText( tr( "GEOM_WIRE" ) );
150   myGroupWireConstraints->PushButton1->setIcon( image0 );
151
152   QLabel* aLabel = new QLabel( tr( "GEOM_CONSTRAINTS" ) );
153   myTreeConstraints = new QTreeWidget( myGroupWireConstraints->Box );
154   myTreeConstraints->setColumnCount(2);
155   QStringList columnNames;
156   columnNames.append( tr( "GEOM_EDGE" ));
157   columnNames.append( tr( "GEOM_FACE_CONSTRAINT" ) );
158   myTreeConstraints->setHeaderLabels( columnNames );
159 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
160   myTreeConstraints->header()->setMovable( false );
161   myTreeConstraints->header()->setResizeMode( QHeaderView::ResizeToContents );
162 #else
163   myTreeConstraints->header()->setSectionsMovable( false );
164   myTreeConstraints->header()->setSectionResizeMode( QHeaderView::ResizeToContents );
165 #endif
166   myTreeConstraints->setMinimumHeight( 140 );
167
168   QHBoxLayout* l = new QHBoxLayout( myGroupWireConstraints->Box );
169   l->setMargin( 0 ); l->setSpacing( 6 );
170   l->addWidget( aLabel);
171   l->addWidget( myTreeConstraints );
172
173   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
174   layout->setMargin( 0 ); layout->setSpacing( 6 );
175   layout->addWidget( myGroupWire );
176   layout->addWidget( myGroupSurf );
177   layout->addWidget( myGroupWireConstraints );
178   /***************************************************************/
179
180   setHelpFileName("create_face_page.html");
181
182   /* Initialisations */
183   Init();
184 }
185
186
187 //=================================================================================
188 // function : ~BuildGUI_FaceDlg()
189 // purpose  : Destroys the object and frees any allocated resources
190 //=================================================================================
191 BuildGUI_FaceDlg::~BuildGUI_FaceDlg()
192 {
193   // no need to delete child widgets, Qt does it all for us
194 }
195
196
197 //=================================================================================
198 // function : Init()
199 // purpose  :
200 //=================================================================================
201 void BuildGUI_FaceDlg::Init()
202 {
203   /* init variables */
204   myEditCurrentArgument = myGroupWire->LineEdit1;
205   myGroupWire->LineEdit1->setReadOnly( true );
206   myGroupSurf->LineEdit1->setReadOnly( true );
207   myGroupSurf->LineEdit2->setReadOnly( true );
208   myGroupWireConstraints->LineEdit1->setReadOnly( true );
209
210   myGroupWire->CheckButton1->setChecked( true );
211   myWires.clear();
212   myFace.nullify();
213   myWire.nullify();
214   myCurrentItem = 0;
215
216   /* signals and slots connections */
217   connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
218   connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()),        this, SLOT(ClickOnCancel()));
219
220   connect(this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
221
222   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
223   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
224   connect( myGroupWire->LineEdit1,   SIGNAL( returnPressed()), this, SLOT( LineEditReturnPressed() ) );
225   connect( myGroupWire->PushButton1, SIGNAL( clicked() ),      this, SLOT( SetEditCurrentArgument() ) );
226   connect( myGroupSurf->LineEdit1,   SIGNAL( returnPressed()), this, SLOT( LineEditReturnPressed() ) );
227   connect( myGroupSurf->PushButton1, SIGNAL( clicked() ),      this, SLOT( SetEditCurrentArgument() ) );
228   connect( myGroupSurf->LineEdit2,   SIGNAL( returnPressed()), this, SLOT( LineEditReturnPressed() ) );
229   connect( myGroupSurf->PushButton2, SIGNAL( clicked() ),      this, SLOT( SetEditCurrentArgument() ) );
230   connect( myGroupWireConstraints->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
231   connect( myGroupWireConstraints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
232   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
233            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
234
235   connect( myTreeConstraints, SIGNAL( itemClicked( QTreeWidgetItem*, int) ), this, SLOT( onItemClicked( QTreeWidgetItem*, int ) ) );
236
237   initName( tr( "GEOM_FACE" ) );
238
239   ConstructorsClicked(0);
240 }
241
242 //=================================================================================
243 // function : ConstructorsClicked()
244 // purpose  : Radio button management
245 //=================================================================================
246 void BuildGUI_FaceDlg::ConstructorsClicked(int constructorId)
247 {
248   switch (constructorId) {
249   case 0:
250     {
251       TColStd_MapOfInteger aMap;
252
253       aMap.Add(GEOM_EDGE);
254       aMap.Add(GEOM_WIRE);
255       aMap.Add(GEOM_FACE);
256       aMap.Add(GEOM_SHELL);
257       aMap.Add(GEOM_SOLID);
258       aMap.Add(GEOM_COMPOUND);
259       globalSelection(aMap);
260
261       myEditCurrentArgument = myGroupWire->LineEdit1;
262       myGroupWire->LineEdit1->setText("");
263       myGroupWire->show();
264       myGroupSurf->hide();
265       myGroupWireConstraints->hide();
266       break;
267     }
268   case 1:
269     {
270       globalSelection(GEOM_FACE); // For the first element.
271       localSelection( TopAbs_FACE );
272
273       myEditCurrentArgument = myGroupSurf->LineEdit1;
274       myGroupSurf->LineEdit1->setText("");
275       myGroupSurf->PushButton1->setDown(true);
276       myGroupSurf->PushButton2->setDown(false);
277       myGroupWire->hide();
278       myGroupSurf->show();
279       myGroupWireConstraints->hide();
280       break;
281     }
282   case 2:
283     {
284       globalSelection();
285       localSelection( TopAbs_WIRE );
286     
287       myTreeConstraints->clear();
288       myCurrentItem = 0;
289       myEditCurrentArgument = myGroupWireConstraints->LineEdit1;
290       myGroupWireConstraints->LineEdit1->setText("");
291       myGroupWireConstraints->LineEdit1->setEnabled(true);
292       myGroupWire->hide();
293       myGroupSurf->hide();
294       myGroupWireConstraints->show();
295       break;
296     }
297   }
298
299   myWires.clear();
300   myFace.nullify();
301   myWire.nullify();
302   qApp->processEvents();
303   updateGeometry();
304   resize(minimumSizeHint());
305   SelectionIntoArgument();
306 }
307
308 //=================================================================================
309 // function : updateConstraintsTree
310 // purpose  :
311 //=================================================================================
312 void BuildGUI_FaceDlg::updateConstraintsTree()
313 {
314   if ( myEditCurrentArgument != myGroupWireConstraints->LineEdit1 || myWire.isNull() )
315     return;
316
317   myTreeConstraints->clear();
318
319   GEOM::GEOM_IShapesOperations_ptr anOper = GEOM::GEOM_IShapesOperations::_narrow(getOperation());
320   GEOM::ListOfGO_var aList = anOper->ExtractSubShapes( myWire.get(), TopAbs_EDGE, false );
321   if ( !aList->length() )
322     return;
323
324   for ( int i = 0, n = aList->length(); i < n; i++ ) {
325     /*TreeWidgetItem* item =*/
326     new TreeWidgetItem( myTreeConstraints, GEOM::GeomObjPtr( aList[i] ) );
327   }
328
329   myEditCurrentArgument->setEnabled(false);
330   globalSelection();
331   localSelection( TopAbs_FACE );
332   
333   myTreeConstraints->resizeColumnToContents(0);
334   QTreeWidgetItem* firstItem = myTreeConstraints->topLevelItem(0);
335   firstItem->setSelected( true );
336   onItemClicked( firstItem, 0 );
337 }
338
339 //=================================================================================
340 // function : findEmptyTreeItem()
341 // purpose  :
342 //=================================================================================
343 void BuildGUI_FaceDlg::findEmptyTreeItem()
344 {
345   if ( isTreeFull() )
346     return;
347
348   QTreeWidgetItem* nextItem = 0;
349   QTreeWidgetItem* item;
350   for ( item = myTreeConstraints->itemBelow( myCurrentItem );
351         item && !nextItem;
352         item = myTreeConstraints->itemBelow( item ) ) {
353     if ( (dynamic_cast<TreeWidgetItem*>(item))->getFace().isNull() )
354       nextItem = item;
355   }
356   for ( item = myTreeConstraints->topLevelItem(0);
357         item && item != myCurrentItem && !nextItem;
358         item = myTreeConstraints->itemBelow( item ) ) {
359     if ( (dynamic_cast<TreeWidgetItem*>(item))->getFace().isNull() )
360       nextItem = item;
361   }
362
363   if ( nextItem && nextItem != myCurrentItem ) {
364     myCurrentItem->setSelected( false );
365     nextItem->setSelected( true );
366     onItemClicked( nextItem, 0 );
367   }
368 }
369
370 //=================================================================================
371 // function : isTreeFull()
372 // purpose  :
373 //=================================================================================
374 bool BuildGUI_FaceDlg::isTreeFull()
375 {
376   bool ok = true;
377   QTreeWidgetItem* item;
378   for ( item = myTreeConstraints->topLevelItem(0);
379         item && ok;
380         item = myTreeConstraints->itemBelow( item ) ) {
381     ok = !(dynamic_cast<TreeWidgetItem*>(item))->getFace().isNull();
382   }
383   return ok;
384 }
385
386 //=================================================================================
387 // function : ClickOnOk()
388 // purpose  :
389 //=================================================================================
390 void BuildGUI_FaceDlg::ClickOnOk()
391 {
392   setIsApplyAndClose( true );
393   if ( ClickOnApply() )
394     ClickOnCancel();
395 }
396
397
398 //=================================================================================
399 // function : ClickOnApply()
400 // purpose  :
401 //=================================================================================
402 bool BuildGUI_FaceDlg::ClickOnApply()
403 {
404   if ( !onAccept() )
405     return false;
406
407   initName();
408
409   myEditCurrentArgument->setText("");
410   ConstructorsClicked( getConstructorId() );
411   return true;
412 }
413
414
415 //=================================================================================
416 // function : SelectionIntoArgument()
417 // purpose  : Called when selection as changed or other case
418 //=================================================================================
419 void BuildGUI_FaceDlg::SelectionIntoArgument()
420 {
421   erasePreview();
422   if ( myEditCurrentArgument == myGroupWire->LineEdit1 ) {
423     myEditCurrentArgument->setText( "" );
424
425     QList<TopAbs_ShapeEnum> types;
426     types << TopAbs_EDGE  << TopAbs_WIRE  << TopAbs_FACE
427           << TopAbs_SHELL << TopAbs_SOLID << TopAbs_COMPOUND;
428     myWires = getSelected( types, -1 );
429
430     if ( !myWires.isEmpty() ) {
431       QString aName = myWires.count() > 1 ? QString( "%1_objects").arg( myWires.count() ) : GEOMBase::GetName( myWires[0].get() );
432       myEditCurrentArgument->setText( aName );
433     }
434   }
435   else if (myEditCurrentArgument == myGroupSurf->LineEdit1 ||
436            myEditCurrentArgument == myGroupSurf->LineEdit2) {
437     const bool isEditFace = myEditCurrentArgument == myGroupSurf->LineEdit1;
438     const TopAbs_ShapeEnum aType = isEditFace ? TopAbs_FACE : TopAbs_WIRE;
439     GEOM::GeomObjPtr aSelectedObject = getSelected(aType);
440     GEOM::GeomObjPtr &anObj = isEditFace ? myFace : myWire;
441
442     if (aSelectedObject) {
443       myEditCurrentArgument->setText(GEOMBase::GetName(aSelectedObject.get()));
444       anObj = aSelectedObject;
445     } else {
446       myEditCurrentArgument->setText("");
447       anObj.nullify();
448     }
449
450     if (isEditFace) {
451       if (myFace && !myWire) {
452         myGroupSurf->PushButton2->click();
453       }
454     } else {
455       if (!myFace && myWire) {
456         myGroupSurf->PushButton1->click();
457       }
458     }
459   }
460   else if ( myEditCurrentArgument == myGroupWireConstraints->LineEdit1 ) {
461     if ( myCurrentItem ) {
462       GEOM::GeomObjPtr aSelectedObject = getSelected( TopAbs_FACE );
463       TopoDS_Shape aFaceShape;
464       GEOM::GEOM_IShapesOperations_ptr anOper = GEOM::GEOM_IShapesOperations::_narrow(getOperation());
465       if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aFaceShape ) && !aFaceShape.IsNull()
466           && anOper->IsSubShapeBelongsTo( myCurrentItem->getEdge().get(), 0, aSelectedObject.get(), 0 ) ) {
467         myCurrentItem->setFace( aSelectedObject );
468         findEmptyTreeItem();
469       }
470       else {
471         myCurrentItem->setFace( 0 );
472         displayPreview( myCurrentItem->getEdge().get(), true, false, true, 5, -1, Quantity_NOC_RED );
473       }
474     }
475     else {
476       myWire.nullify();
477       myEditCurrentArgument->setText( "" );
478       GEOM::GeomObjPtr aSelectedObject = getSelected( TopAbs_WIRE );
479       TopoDS_Shape aWireShape;
480       if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aWireShape ) && !aWireShape.IsNull() ) {
481         QString aName = GEOMBase::GetName( aSelectedObject.get() );
482         myEditCurrentArgument->setText( aName );
483         myWire = aSelectedObject;
484         updateConstraintsTree();
485       }
486       else {
487         myTreeConstraints->clear();
488         erasePreview( true );
489       }
490     }
491   }
492   displayPreview( true, false, true, true, -1, -1, -1, true );
493 }
494
495
496 //=================================================================================
497 // function : SetEditCurrentArgument()
498 // purpose  :
499 //=================================================================================
500 void BuildGUI_FaceDlg::SetEditCurrentArgument()
501 {
502   QPushButton* send = (QPushButton*)sender();
503   if ( send == myGroupWire->PushButton1 ) {
504     TColStd_MapOfInteger aMap;
505   
506     aMap.Add(GEOM_EDGE);
507     aMap.Add(GEOM_WIRE);
508     aMap.Add(GEOM_FACE);
509     aMap.Add(GEOM_SHELL);
510     aMap.Add(GEOM_SOLID);
511     aMap.Add(GEOM_COMPOUND);
512     globalSelection(aMap);
513     myEditCurrentArgument = myGroupWire->LineEdit1;
514   }
515   else if (send == myGroupSurf->PushButton1) {
516     globalSelection(GEOM_FACE);
517     localSelection( TopAbs_FACE );
518     myEditCurrentArgument = myGroupSurf->LineEdit1;
519     myGroupSurf->PushButton2->setDown(false);
520     myGroupSurf->LineEdit2->setEnabled(false);
521   }
522   else if (send == myGroupSurf->PushButton2) {
523     globalSelection(GEOM_WIRE);
524     localSelection( TopAbs_WIRE );
525     myEditCurrentArgument = myGroupSurf->LineEdit2;
526     myGroupSurf->PushButton1->setDown(false);
527     myGroupSurf->LineEdit1->setEnabled(false);
528   }
529   else if (send == myGroupWireConstraints->PushButton1) {
530     globalSelection();
531     localSelection( TopAbs_WIRE );
532     myEditCurrentArgument = myGroupWireConstraints->LineEdit1;
533     myCurrentItem = 0;
534   }
535
536   // enable line edit
537   myEditCurrentArgument->setEnabled(true);
538   myEditCurrentArgument->setFocus();
539   SelectionIntoArgument();
540 }
541
542
543 //=================================================================================
544 // function : ActivateThisDialog()
545 // purpose  :
546 //=================================================================================
547 void BuildGUI_FaceDlg::ActivateThisDialog()
548 {
549   GEOMBase_Skeleton::ActivateThisDialog();
550   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
551            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
552   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
553            this, SLOT(SelectionIntoArgument()));
554
555   ConstructorsClicked(getConstructorId());
556 }
557
558 //=================================================================================
559 // function : onItemClicked()
560 // purpose  : called when tree item was clicked
561 //=================================================================================
562 void BuildGUI_FaceDlg::onItemClicked( QTreeWidgetItem* theItem, int theColumn )
563 {
564   if ( !theItem || !( theItem->flags() & Qt::ItemIsSelectable ) )
565     return;
566
567   myCurrentItem = dynamic_cast<TreeWidgetItem*>( theItem );
568   displayPreview( true );
569   displayPreview( myCurrentItem->getEdge().get(), true, false, true, 5, -1, Quantity_NOC_RED );
570 }
571
572 //=================================================================================
573 // function : enterEvent()
574 // purpose  :
575 //=================================================================================
576 void BuildGUI_FaceDlg::enterEvent( QEvent* )
577 {
578   if ( !mainFrame()->GroupConstructors->isEnabled() )
579     ActivateThisDialog(); 
580 }
581
582 //=================================================================================
583 // function : createOperation
584 // purpose  :
585 //=================================================================================
586 GEOM::GEOM_IOperations_ptr BuildGUI_FaceDlg::createOperation()
587 {
588   return getGeomEngine()->GetIShapesOperations( getStudyId() );
589 }
590
591 //=================================================================================
592 // function : isValid
593 // purpose  :
594 //=================================================================================
595 bool BuildGUI_FaceDlg::isValid( QString& )
596 {
597   bool ok = false;
598
599   switch (getConstructorId()) {
600   case 0:
601     ok = !myWires.isEmpty();
602     break;
603   case 1:
604     ok = myFace && myWire;
605     break;
606   case 2:
607     ok = myWire;
608     break;
609   default:
610     break;
611   }
612
613   return ok;
614 }
615
616 //=================================================================================
617 // function : execute
618 // purpose  :
619 //=================================================================================
620 bool BuildGUI_FaceDlg::execute( ObjectList& objects )
621 {
622   bool res = false;
623   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
624   GEOM::GEOM_Object_var anObj;
625
626   switch (getConstructorId()) {
627   case 0:
628     {
629       GEOM::ListOfGO_var objlist = new GEOM::ListOfGO();
630       
631       objlist->length( myWires.count() );
632
633       for ( int i = 0; i < myWires.count(); i++ ) {
634         objlist[i] = myWires[i].copy();
635       }
636
637       anObj = anOper->MakeFaceWires( objlist.in(), myGroupWire->CheckButton1->isChecked() );
638       res = true;
639     }
640     break;
641   case 1:
642     anObj = anOper->MakeFaceFromSurface(myFace.get(), myWire.get());
643     res = true;
644     break;
645   case 2:
646     {
647       int numberOfItems = myTreeConstraints->topLevelItemCount();
648       GEOM::ListOfGO_var constraints = new GEOM::ListOfGO();
649       constraints->length( 2 * numberOfItems );
650       int j = 0;
651       for ( int i = 0; i < numberOfItems; i++ ) {
652         TreeWidgetItem* item = dynamic_cast<TreeWidgetItem*>( myTreeConstraints->topLevelItem(i) );
653         constraints[j++] = item->getEdge().copy();
654         if ( item->getFace() )
655           constraints[j++] = item->getFace().copy();
656       }
657       constraints->length(j);
658       anObj = anOper->MakeFaceWithConstraints( constraints.in() );
659       res = true;
660     }
661     break;
662   default:
663     break;
664   }
665
666   if (!anObj->_is_nil()) {
667     if ( !anOper->IsDone() && QString(anOper->GetErrorCode()) == "MAKE_FACE_TOLERANCE_TOO_BIG") {
668       if ( !IsPreview() ) {
669         SUIT_OverrideCursor wc;
670         wc.suspend();
671         QString msgw = QObject::tr(anOper->GetErrorCode());
672         SUIT_MessageBox::warning(this, tr("WRN_WARNING"), msgw, tr("BUT_OK"));
673       }
674       anOper->SetErrorCode("PAL_NO_ERROR");
675     }
676     else if ( anObj->GetShapeType() == GEOM::COMPOUND ) {
677       if ( !IsPreview() ) {
678         SUIT_MessageBox::warning(this,
679                                  QObject::tr("GEOM_WRN_WARNING"),
680                                  QObject::tr("GEOM_WRN_FACES_NOT_FACE"));
681       }
682     }
683     objects.push_back(anObj._retn());
684   }
685
686   return res;
687 }
688
689 //=================================================================================
690 // function : addSubshapeToStudy
691 // purpose  : virtual method to add new SubObjects if local selection
692 //=================================================================================
693 void BuildGUI_FaceDlg::addSubshapesToStudy()
694 {
695   switch (getConstructorId()) {
696   case 0:
697     break;
698   case 1:
699     break;
700   case 2:
701     for( int i = 0; i < myTreeConstraints->topLevelItemCount(); i++ ) {
702       TreeWidgetItem* item = dynamic_cast<TreeWidgetItem*>( myTreeConstraints->topLevelItem(i) );
703       if ( item->getFace().get() )
704         GEOMBase::PublishSubObject( item->getFace().get() );
705       GEOMBase::PublishSubObject( myWire.get() );
706     }
707     break;
708   default:
709     break;
710   }
711 }
712
713 //=================================================================================
714 // function : getSourceObjects
715 // purpose  : virtual method to get source objects
716 //=================================================================================
717 QList<GEOM::GeomObjPtr> BuildGUI_FaceDlg::getSourceObjects()
718 {
719   QList<GEOM::GeomObjPtr> res(myWires);
720   res << myFace << myWire;
721   return res;
722 }