Salome HOME
dc1be6191e3e456de915379d2a21e188d034a201
[modules/geom.git] / src / BuildGUI / BuildGUI_FaceDlg.cxx
1 // Copyright (C) 2007-2023  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   myTreeConstraints->header()->setSectionsMovable( false );
160   myTreeConstraints->header()->setSectionResizeMode( QHeaderView::ResizeToContents );
161   myTreeConstraints->setMinimumHeight( 140 );
162
163   QHBoxLayout* l = new QHBoxLayout( myGroupWireConstraints->Box );
164   l->setMargin( 0 ); l->setSpacing( 6 );
165   l->addWidget( aLabel);
166   l->addWidget( myTreeConstraints );
167
168   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
169   layout->setMargin( 0 ); layout->setSpacing( 6 );
170   layout->addWidget( myGroupWire );
171   layout->addWidget( myGroupSurf );
172   layout->addWidget( myGroupWireConstraints );
173   /***************************************************************/
174
175   setHelpFileName("create_face_page.html");
176
177   /* Initialisations */
178   Init();
179 }
180
181
182 //=================================================================================
183 // function : ~BuildGUI_FaceDlg()
184 // purpose  : Destroys the object and frees any allocated resources
185 //=================================================================================
186 BuildGUI_FaceDlg::~BuildGUI_FaceDlg()
187 {
188   // no need to delete child widgets, Qt does it all for us
189 }
190
191
192 //=================================================================================
193 // function : Init()
194 // purpose  :
195 //=================================================================================
196 void BuildGUI_FaceDlg::Init()
197 {
198   /* init variables */
199   myEditCurrentArgument = myGroupWire->LineEdit1;
200   myGroupWire->LineEdit1->setReadOnly( true );
201   myGroupSurf->LineEdit1->setReadOnly( true );
202   myGroupSurf->LineEdit2->setReadOnly( true );
203   myGroupWireConstraints->LineEdit1->setReadOnly( true );
204
205   myGroupWire->CheckButton1->setChecked( true );
206   myWires.clear();
207   myFace.nullify();
208   myWire.nullify();
209   myCurrentItem = 0;
210
211   /* signals and slots connections */
212   connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
213   connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()),        this, SLOT(ClickOnCancel()));
214
215   connect(this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
216
217   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
218   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
219   connect( myGroupWire->LineEdit1,   SIGNAL( returnPressed()), this, SLOT( LineEditReturnPressed() ) );
220   connect( myGroupWire->PushButton1, SIGNAL( clicked() ),      this, SLOT( SetEditCurrentArgument() ) );
221   connect( myGroupSurf->LineEdit1,   SIGNAL( returnPressed()), this, SLOT( LineEditReturnPressed() ) );
222   connect( myGroupSurf->PushButton1, SIGNAL( clicked() ),      this, SLOT( SetEditCurrentArgument() ) );
223   connect( myGroupSurf->LineEdit2,   SIGNAL( returnPressed()), this, SLOT( LineEditReturnPressed() ) );
224   connect( myGroupSurf->PushButton2, SIGNAL( clicked() ),      this, SLOT( SetEditCurrentArgument() ) );
225   connect( myGroupWireConstraints->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
226   connect( myGroupWireConstraints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
227   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
228            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
229
230   connect( myTreeConstraints, SIGNAL( itemClicked( QTreeWidgetItem*, int) ), this, SLOT( onItemClicked( QTreeWidgetItem*, int ) ) );
231
232   initName( tr( "GEOM_FACE" ) );
233
234   ConstructorsClicked(0);
235 }
236
237 //=================================================================================
238 // function : ConstructorsClicked()
239 // purpose  : Radio button management
240 //=================================================================================
241 void BuildGUI_FaceDlg::ConstructorsClicked(int constructorId)
242 {
243   switch (constructorId) {
244   case 0:
245     {
246       TColStd_MapOfInteger aMap;
247
248       aMap.Add(GEOM_EDGE);
249       aMap.Add(GEOM_WIRE);
250       aMap.Add(GEOM_FACE);
251       aMap.Add(GEOM_SHELL);
252       aMap.Add(GEOM_SOLID);
253       aMap.Add(GEOM_COMPOUND);
254       globalSelection(aMap);
255
256       myEditCurrentArgument = myGroupWire->LineEdit1;
257       myGroupWire->LineEdit1->setText("");
258       myGroupWire->show();
259       myGroupSurf->hide();
260       myGroupWireConstraints->hide();
261       break;
262     }
263   case 1:
264     {
265       globalSelection(GEOM_FACE); // For the first element.
266       localSelection( TopAbs_FACE );
267
268       myEditCurrentArgument = myGroupSurf->LineEdit1;
269       myGroupSurf->LineEdit1->setText("");
270       myGroupSurf->PushButton1->setDown(true);
271       myGroupSurf->PushButton2->setDown(false);
272       myGroupWire->hide();
273       myGroupSurf->show();
274       myGroupWireConstraints->hide();
275       break;
276     }
277   case 2:
278     {
279       globalSelection();
280       localSelection( TopAbs_WIRE );
281     
282       myTreeConstraints->clear();
283       myCurrentItem = 0;
284       myEditCurrentArgument = myGroupWireConstraints->LineEdit1;
285       myGroupWireConstraints->LineEdit1->setText("");
286       myGroupWireConstraints->LineEdit1->setEnabled(true);
287       myGroupWire->hide();
288       myGroupSurf->hide();
289       myGroupWireConstraints->show();
290       break;
291     }
292   }
293
294   myWires.clear();
295   myFace.nullify();
296   myWire.nullify();
297   qApp->processEvents();
298   updateGeometry();
299   resize(minimumSizeHint());
300   SelectionIntoArgument();
301 }
302
303 //=================================================================================
304 // function : updateConstraintsTree
305 // purpose  :
306 //=================================================================================
307 void BuildGUI_FaceDlg::updateConstraintsTree()
308 {
309   if ( myEditCurrentArgument != myGroupWireConstraints->LineEdit1 || myWire.isNull() )
310     return;
311
312   myTreeConstraints->clear();
313
314   GEOM::GEOM_IShapesOperations_ptr anOper = GEOM::GEOM_IShapesOperations::_narrow(getOperation());
315   GEOM::ListOfGO_var aList = anOper->ExtractSubShapes( myWire.get(), TopAbs_EDGE, false );
316   if ( !aList->length() )
317     return;
318
319   for ( int i = 0, n = aList->length(); i < n; i++ ) {
320     /*TreeWidgetItem* item =*/
321     new TreeWidgetItem( myTreeConstraints, GEOM::GeomObjPtr( aList[i] ) );
322   }
323
324   myEditCurrentArgument->setEnabled(false);
325   globalSelection();
326   localSelection( TopAbs_FACE );
327   
328   myTreeConstraints->resizeColumnToContents(0);
329   QTreeWidgetItem* firstItem = myTreeConstraints->topLevelItem(0);
330   firstItem->setSelected( true );
331   onItemClicked( firstItem, 0 );
332 }
333
334 //=================================================================================
335 // function : findEmptyTreeItem()
336 // purpose  :
337 //=================================================================================
338 void BuildGUI_FaceDlg::findEmptyTreeItem()
339 {
340   if ( isTreeFull() )
341     return;
342
343   QTreeWidgetItem* nextItem = 0;
344   QTreeWidgetItem* item;
345   for ( item = myTreeConstraints->itemBelow( myCurrentItem );
346         item && !nextItem;
347         item = myTreeConstraints->itemBelow( item ) ) {
348     if ( (dynamic_cast<TreeWidgetItem*>(item))->getFace().isNull() )
349       nextItem = item;
350   }
351   for ( item = myTreeConstraints->topLevelItem(0);
352         item && item != myCurrentItem && !nextItem;
353         item = myTreeConstraints->itemBelow( item ) ) {
354     if ( (dynamic_cast<TreeWidgetItem*>(item))->getFace().isNull() )
355       nextItem = item;
356   }
357
358   if ( nextItem && nextItem != myCurrentItem ) {
359     myCurrentItem->setSelected( false );
360     nextItem->setSelected( true );
361     onItemClicked( nextItem, 0 );
362   }
363 }
364
365 //=================================================================================
366 // function : isTreeFull()
367 // purpose  :
368 //=================================================================================
369 bool BuildGUI_FaceDlg::isTreeFull()
370 {
371   bool ok = true;
372   QTreeWidgetItem* item;
373   for ( item = myTreeConstraints->topLevelItem(0);
374         item && ok;
375         item = myTreeConstraints->itemBelow( item ) ) {
376     ok = !(dynamic_cast<TreeWidgetItem*>(item))->getFace().isNull();
377   }
378   return ok;
379 }
380
381 //=================================================================================
382 // function : ClickOnOk()
383 // purpose  :
384 //=================================================================================
385 void BuildGUI_FaceDlg::ClickOnOk()
386 {
387   setIsApplyAndClose( true );
388   if ( ClickOnApply() )
389     ClickOnCancel();
390 }
391
392
393 //=================================================================================
394 // function : ClickOnApply()
395 // purpose  :
396 //=================================================================================
397 bool BuildGUI_FaceDlg::ClickOnApply()
398 {
399   if ( !onAccept() )
400     return false;
401
402   initName();
403
404   myEditCurrentArgument->setText("");
405   ConstructorsClicked( getConstructorId() );
406   return true;
407 }
408
409
410 //=================================================================================
411 // function : SelectionIntoArgument()
412 // purpose  : Called when selection as changed or other case
413 //=================================================================================
414 void BuildGUI_FaceDlg::SelectionIntoArgument()
415 {
416   erasePreview();
417   if ( myEditCurrentArgument == myGroupWire->LineEdit1 ) {
418     myEditCurrentArgument->setText( "" );
419
420     QList<TopAbs_ShapeEnum> types;
421     types << TopAbs_EDGE  << TopAbs_WIRE  << TopAbs_FACE
422           << TopAbs_SHELL << TopAbs_SOLID << TopAbs_COMPOUND;
423     myWires = getSelected( types, -1 );
424
425     if ( !myWires.isEmpty() ) {
426       QString aName = myWires.count() > 1 ? QString( "%1_objects").arg( myWires.count() ) : GEOMBase::GetName( myWires[0].get() );
427       myEditCurrentArgument->setText( aName );
428     }
429   }
430   else if (myEditCurrentArgument == myGroupSurf->LineEdit1 ||
431            myEditCurrentArgument == myGroupSurf->LineEdit2) {
432     const bool isEditFace = myEditCurrentArgument == myGroupSurf->LineEdit1;
433     const TopAbs_ShapeEnum aType = isEditFace ? TopAbs_FACE : TopAbs_WIRE;
434     GEOM::GeomObjPtr aSelectedObject = getSelected(aType);
435     GEOM::GeomObjPtr &anObj = isEditFace ? myFace : myWire;
436
437     if (aSelectedObject) {
438       myEditCurrentArgument->setText(GEOMBase::GetName(aSelectedObject.get()));
439       anObj = aSelectedObject;
440     } else {
441       myEditCurrentArgument->setText("");
442       anObj.nullify();
443     }
444
445     if (isEditFace) {
446       if (myFace && !myWire) {
447         myGroupSurf->PushButton2->click();
448       }
449     } else {
450       if (!myFace && myWire) {
451         myGroupSurf->PushButton1->click();
452       }
453     }
454   }
455   else if ( myEditCurrentArgument == myGroupWireConstraints->LineEdit1 ) {
456     if ( myCurrentItem ) {
457       GEOM::GeomObjPtr aSelectedObject = getSelected( TopAbs_FACE );
458       TopoDS_Shape aFaceShape;
459       GEOM::GEOM_IShapesOperations_ptr anOper = GEOM::GEOM_IShapesOperations::_narrow(getOperation());
460       if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aFaceShape ) && !aFaceShape.IsNull()
461           && anOper->IsSubShapeBelongsTo( myCurrentItem->getEdge().get(), 0, aSelectedObject.get(), 0 ) ) {
462         myCurrentItem->setFace( aSelectedObject );
463         findEmptyTreeItem();
464       }
465       else {
466         myCurrentItem->setFace( 0 );
467         displayPreview( myCurrentItem->getEdge().get(), true, false, true, 5, -1, Quantity_NOC_RED );
468       }
469     }
470     else {
471       myWire.nullify();
472       myEditCurrentArgument->setText( "" );
473       GEOM::GeomObjPtr aSelectedObject = getSelected( TopAbs_WIRE );
474       TopoDS_Shape aWireShape;
475       if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aWireShape ) && !aWireShape.IsNull() ) {
476         QString aName = GEOMBase::GetName( aSelectedObject.get() );
477         myEditCurrentArgument->setText( aName );
478         myWire = aSelectedObject;
479         updateConstraintsTree();
480       }
481       else {
482         myTreeConstraints->clear();
483         erasePreview( true );
484       }
485     }
486   }
487   displayPreview( true, false, true, true, -1, -1, -1, true );
488 }
489
490
491 //=================================================================================
492 // function : SetEditCurrentArgument()
493 // purpose  :
494 //=================================================================================
495 void BuildGUI_FaceDlg::SetEditCurrentArgument()
496 {
497   QPushButton* send = (QPushButton*)sender();
498   if ( send == myGroupWire->PushButton1 ) {
499     TColStd_MapOfInteger aMap;
500   
501     aMap.Add(GEOM_EDGE);
502     aMap.Add(GEOM_WIRE);
503     aMap.Add(GEOM_FACE);
504     aMap.Add(GEOM_SHELL);
505     aMap.Add(GEOM_SOLID);
506     aMap.Add(GEOM_COMPOUND);
507     globalSelection(aMap);
508     myEditCurrentArgument = myGroupWire->LineEdit1;
509   }
510   else if (send == myGroupSurf->PushButton1) {
511     globalSelection(GEOM_FACE);
512     localSelection( TopAbs_FACE );
513     myEditCurrentArgument = myGroupSurf->LineEdit1;
514     myGroupSurf->PushButton2->setDown(false);
515     myGroupSurf->LineEdit2->setEnabled(false);
516   }
517   else if (send == myGroupSurf->PushButton2) {
518     globalSelection(GEOM_WIRE);
519     localSelection( TopAbs_WIRE );
520     myEditCurrentArgument = myGroupSurf->LineEdit2;
521     myGroupSurf->PushButton1->setDown(false);
522     myGroupSurf->LineEdit1->setEnabled(false);
523   }
524   else if (send == myGroupWireConstraints->PushButton1) {
525     globalSelection();
526     localSelection( TopAbs_WIRE );
527     myEditCurrentArgument = myGroupWireConstraints->LineEdit1;
528     myCurrentItem = 0;
529   }
530
531   // enable line edit
532   myEditCurrentArgument->setEnabled(true);
533   myEditCurrentArgument->setFocus();
534   SelectionIntoArgument();
535 }
536
537
538 //=================================================================================
539 // function : ActivateThisDialog()
540 // purpose  :
541 //=================================================================================
542 void BuildGUI_FaceDlg::ActivateThisDialog()
543 {
544   GEOMBase_Skeleton::ActivateThisDialog();
545   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
546            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
547   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
548            this, SLOT(SelectionIntoArgument()));
549
550   ConstructorsClicked(getConstructorId());
551 }
552
553 //=================================================================================
554 // function : onItemClicked()
555 // purpose  : called when tree item was clicked
556 //=================================================================================
557 void BuildGUI_FaceDlg::onItemClicked( QTreeWidgetItem* theItem, int /*theColumn*/ )
558 {
559   if ( !theItem || !( theItem->flags() & Qt::ItemIsSelectable ) )
560     return;
561
562   myCurrentItem = dynamic_cast<TreeWidgetItem*>( theItem );
563   displayPreview( true );
564   displayPreview( myCurrentItem->getEdge().get(), true, false, true, 5, -1, Quantity_NOC_RED );
565 }
566
567 //=================================================================================
568 // function : enterEvent()
569 // purpose  :
570 //=================================================================================
571 void BuildGUI_FaceDlg::enterEvent( QEvent* )
572 {
573   if ( !mainFrame()->GroupConstructors->isEnabled() )
574     ActivateThisDialog(); 
575 }
576
577 //=================================================================================
578 // function : createOperation
579 // purpose  :
580 //=================================================================================
581 GEOM::GEOM_IOperations_ptr BuildGUI_FaceDlg::createOperation()
582 {
583   return getGeomEngine()->GetIShapesOperations();
584 }
585
586 //=================================================================================
587 // function : isValid
588 // purpose  :
589 //=================================================================================
590 bool BuildGUI_FaceDlg::isValid( QString& )
591 {
592   bool ok = false;
593
594   switch (getConstructorId()) {
595   case 0:
596     ok = !myWires.isEmpty();
597     break;
598   case 1:
599     ok = myFace && myWire;
600     break;
601   case 2:
602     ok = myWire;
603     break;
604   default:
605     break;
606   }
607
608   return ok;
609 }
610
611 //=================================================================================
612 // function : execute
613 // purpose  :
614 //=================================================================================
615 bool BuildGUI_FaceDlg::execute( ObjectList& objects )
616 {
617   bool res = false;
618   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
619   GEOM::GEOM_Object_var anObj;
620
621   switch (getConstructorId()) {
622   case 0:
623     {
624       GEOM::ListOfGO_var objlist = new GEOM::ListOfGO();
625       
626       objlist->length( myWires.count() );
627
628       for ( int i = 0; i < myWires.count(); i++ ) {
629         objlist[i] = myWires[i].copy();
630       }
631
632       anObj = anOper->MakeFaceWires( objlist.in(), myGroupWire->CheckButton1->isChecked() );
633       res = true;
634     }
635     break;
636   case 1:
637     anObj = anOper->MakeFaceFromSurface(myFace.get(), myWire.get());
638     res = true;
639     break;
640   case 2:
641     {
642       int numberOfItems = myTreeConstraints->topLevelItemCount();
643       GEOM::ListOfGO_var constraints = new GEOM::ListOfGO();
644       constraints->length( 2 * numberOfItems );
645       int j = 0;
646       for ( int i = 0; i < numberOfItems; i++ ) {
647         TreeWidgetItem* item = dynamic_cast<TreeWidgetItem*>( myTreeConstraints->topLevelItem(i) );
648         constraints[j++] = item->getEdge().copy();
649         if ( item->getFace() )
650           constraints[j++] = item->getFace().copy();
651       }
652       constraints->length(j);
653       anObj = anOper->MakeFaceWithConstraints( constraints.in() );
654       res = true;
655     }
656     break;
657   default:
658     break;
659   }
660
661   if (!anObj->_is_nil()) {
662     if ( !anOper->IsDone() && QString(anOper->GetErrorCode()) == "MAKE_FACE_TOLERANCE_TOO_BIG") {
663       if ( !IsPreview() ) {
664         SUIT_OverrideCursor wc;
665         wc.suspend();
666         QString msgw = QObject::tr(anOper->GetErrorCode());
667         SUIT_MessageBox::warning(this, tr("WRN_WARNING"), msgw, tr("BUT_OK"));
668       }
669       anOper->SetErrorCode("PAL_NO_ERROR");
670     }
671     else if ( anObj->GetShapeType() == GEOM::COMPOUND ) {
672       if ( !IsPreview() ) {
673         SUIT_MessageBox::warning(this,
674                                  QObject::tr("GEOM_WRN_WARNING"),
675                                  QObject::tr("GEOM_WRN_FACES_NOT_FACE"));
676       }
677     }
678     objects.push_back(anObj._retn());
679   }
680
681   return res;
682 }
683
684 //=================================================================================
685 // function : addSubshapeToStudy
686 // purpose  : virtual method to add new SubObjects if local selection
687 //=================================================================================
688 void BuildGUI_FaceDlg::addSubshapesToStudy()
689 {
690   switch (getConstructorId()) {
691   case 0:
692     break;
693   case 1:
694     GEOMBase::PublishSubObject( myFace.get() );
695     GEOMBase::PublishSubObject( myWire.get() );
696     break;
697   case 2:
698     for( int i = 0; i < myTreeConstraints->topLevelItemCount(); i++ ) {
699       TreeWidgetItem* item = dynamic_cast<TreeWidgetItem*>( myTreeConstraints->topLevelItem(i) );
700       if ( item->getFace().get() )
701         GEOMBase::PublishSubObject( item->getFace().get() );
702       GEOMBase::PublishSubObject( myWire.get() );
703     }
704     break;
705   default:
706     break;
707   }
708 }
709
710 //=================================================================================
711 // function : getSourceObjects
712 // purpose  : virtual method to get source objects
713 //=================================================================================
714 QList<GEOM::GeomObjPtr> BuildGUI_FaceDlg::getSourceObjects()
715 {
716   QList<GEOM::GeomObjPtr> res(myWires);
717   res << myFace << myWire;
718   return res;
719 }