Salome HOME
64b650fece6592d0d851042fcee0ebd7849b9e11
[modules/geom.git] / src / RepairGUI / RepairGUI_InspectObjectDlg.cxx
1 // Copyright (C) 2014-2020  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // internal includes
21 #include "RepairGUI_InspectObjectDlg.h"
22
23 // GEOM includes
24 #include <GEOMBase.h>
25 #include <GEOM_Constants.h>
26 #include <GeometryGUI.h>
27 #include <GEOMUtils.hxx>
28
29 // GUI includes
30 #include <SUIT_Session.h>
31 #include <SUIT_ResourceMgr.h>
32 #include <SUIT_Desktop.h>
33 #include <SUIT_ViewManager.h>
34 #include <SUIT_ViewWindow.h>
35
36 #include <LightApp_SelectionMgr.h>
37
38 #include <SalomeApp_Application.h>
39 #include <SalomeApp_DoubleSpinBox.h>
40 #include <SalomeApp_Study.h>
41
42 #include <OCCViewer_ViewModel.h>
43 #include <SVTK_ViewModel.h>
44
45 // OCCT includes
46 #include <BRep_Tool.hxx>
47 #include <TopExp.hxx>
48 #include <TopExp_Explorer.hxx>
49 #include <TopoDS.hxx>
50 #include <TopoDS_Iterator.hxx>
51 #include <TopTools_IndexedMapOfShape.hxx>
52 #include <TopTools_MapOfShape.hxx>
53
54 // Qt includes
55 #include <QButtonGroup>
56 #include <QComboBox>
57 #include <QGridLayout>
58 #include <QGroupBox>
59 #include <QPushButton>
60 #include <QHeaderView>
61 #include <QItemDelegate>
62 #include <QLineEdit>
63 #include <QRadioButton>
64 #include <QStackedLayout>
65 #include <QTreeWidgetItem>
66
67 // Shape type definitions (values are equal to corresponding types of TopAbs_ShapeEnum).
68 #define TYPE_FACE   4
69 #define TYPE_EDGE   6
70 #define TYPE_VERTEX 7
71
72 // Comparison type definitions
73 #define COMPARE_GT 0
74 #define COMPARE_GE 1
75 #define COMPARE_LT 2
76 #define COMPARE_LE 3
77
78 // Default tolerance values
79 #define DEFAULT_TOLERANCE_VALUE         1.e-07
80
81 //=================================================================================
82 // class    : RepairGUI_InspectObjectDlg::TreeWidgetItem
83 // purpose  : class for "Inspect Object" tree item creation
84 //=================================================================================
85 class RepairGUI_InspectObjectDlg::TreeWidgetItem : public QTreeWidgetItem
86 {
87 public:
88   TreeWidgetItem(QTreeWidget*,
89                  const QStringList&,
90                  const TopoDS_Shape&,
91                  const Handle(SALOME_InteractiveObject)&,
92                  double = DEFAULT_TOLERANCE_VALUE,
93                  int = Type);
94
95   TreeWidgetItem(QTreeWidgetItem*,
96                  const QStringList&,
97                  const TopoDS_Shape&,
98                  const QString&,
99                  double = DEFAULT_TOLERANCE_VALUE,
100                  int = Type);
101
102   ~TreeWidgetItem();
103
104   bool                             isVisible();
105   void                             setVisible( bool, QIcon& );
106
107   TopoDS_Shape                     getShape() const;
108   Handle(SALOME_InteractiveObject) getIO() const;
109
110   double                           getTolerance() const;
111   void                             setTolerance(double theTolerance);
112
113 private:
114   bool                             myIsVisible;
115   TopoDS_Shape                     myShape;
116   Handle(SALOME_InteractiveObject) myIO;
117   double                           myTolerance;
118
119 };
120
121 RepairGUI_InspectObjectDlg::TreeWidgetItem::TreeWidgetItem
122                      (QTreeWidget                            *view,
123                       const QStringList                      &strings,
124                       const TopoDS_Shape                     &shape,
125                       const Handle(SALOME_InteractiveObject) &io,
126                       double                                  theTolerance,
127                       int                                     type)
128 : QTreeWidgetItem( view, strings, type ),
129   myIsVisible( false ),
130   myShape( shape ),
131   myIO( io ),
132   myTolerance (theTolerance)
133 {
134 }
135
136 RepairGUI_InspectObjectDlg::TreeWidgetItem::TreeWidgetItem
137                      (QTreeWidgetItem    *parent,
138                       const QStringList  &strings,
139                       const TopoDS_Shape &shape,
140                       const QString      &entry,
141                       double              theTolerance,
142                       int                 type)
143 : QTreeWidgetItem( parent, strings, type ),
144   myIsVisible( false ),
145   myShape( shape ),
146   myTolerance (theTolerance)
147 {
148   myIO = new SALOME_InteractiveObject( entry.toUtf8(), "GEOM", "TEMP_IO" );
149   setFlags( flags() | Qt::ItemIsEditable );
150 }
151
152 RepairGUI_InspectObjectDlg::TreeWidgetItem::~TreeWidgetItem()
153 {
154 }
155
156 bool RepairGUI_InspectObjectDlg::TreeWidgetItem::isVisible()
157 {
158   return myIsVisible;
159 }
160
161 void RepairGUI_InspectObjectDlg::TreeWidgetItem::setVisible( bool isVisible, QIcon& icon )
162 {
163   myIsVisible = isVisible;
164   setIcon( 1, icon );
165 }
166
167 TopoDS_Shape RepairGUI_InspectObjectDlg::TreeWidgetItem::getShape() const
168 {
169   return myShape;
170 }
171
172 Handle(SALOME_InteractiveObject) RepairGUI_InspectObjectDlg::TreeWidgetItem::getIO() const
173 {
174   return myIO;
175 }
176
177 double RepairGUI_InspectObjectDlg::TreeWidgetItem::getTolerance() const
178 {
179   return myTolerance;
180 }
181
182 void RepairGUI_InspectObjectDlg::TreeWidgetItem::setTolerance(double theTolerance)
183 {
184   myTolerance = theTolerance;
185 }
186
187 //=================================================================================
188 // class    : RepairGUI_InspectObjectDlg::Delegate
189 // purpose  : class for "Inspect Object" tree item editing
190 //=================================================================================
191 class RepairGUI_InspectObjectDlg::Delegate : public QItemDelegate
192 {
193 public:
194   Delegate( QObject* = 0 );
195   ~Delegate();
196
197   void   setEditorData( QWidget*, const QModelIndex& ) const;
198   void   setModelData( QWidget*, QAbstractItemModel*, const QModelIndex& ) const;
199   QWidget* createEditor( QWidget*, const QStyleOptionViewItem&, const QModelIndex& ) const;
200 };
201
202 RepairGUI_InspectObjectDlg::Delegate::Delegate( QObject* parent )
203 : QItemDelegate( parent )
204 {
205 }
206
207 RepairGUI_InspectObjectDlg::Delegate::~Delegate()
208 {
209 }
210
211 void RepairGUI_InspectObjectDlg::Delegate::setEditorData( QWidget* editor,
212                                                           const QModelIndex& index ) const
213 {
214   QItemDelegate::setEditorData( editor, index );
215   editor->setProperty( "___name___", editor->property( "text" ) );
216 }
217
218 void RepairGUI_InspectObjectDlg::Delegate::setModelData( QWidget* editor,
219                                                          QAbstractItemModel* model,
220                                                          const QModelIndex& index ) const
221 {
222   QString aNewName = editor->property( "text" ).toString();
223   if ( aNewName.trimmed().isEmpty() )
224     editor->setProperty( "text", editor->property( "___name___" ) );
225   QItemDelegate::setModelData( editor, model, index );
226 }
227
228 QWidget* RepairGUI_InspectObjectDlg::Delegate::createEditor( QWidget* parent,
229                                                              const QStyleOptionViewItem& option,
230                                                              const QModelIndex& index ) const
231 {
232   return index.column() == 1 ? 0 : QItemDelegate::createEditor( parent, option, index );
233 }
234
235 //=================================================================================
236 // class    : RepairGUI_InspectObjectDlg()
237 // purpose  : Constructs a RepairGUI_InspectObjectDlg which is a child of 'parent'.
238 //=================================================================================
239 RepairGUI_InspectObjectDlg::RepairGUI_InspectObjectDlg(GeometryGUI *theGeomGUI, SUIT_Desktop* parent )
240 : QDialog               (parent),
241   GEOMBase_Helper       (parent),
242   myGeomGUI             (theGeomGUI),
243   myTreeObjects         (0),
244   myFilteredTreeObjects (0),
245   myCurrentTreeObjects  (0),
246   myEditMainShape       (0),
247   myTolFilterGrp        (0),
248   myShapeTypeBtnGrp     (0),
249   myComparisonCompo     (0),
250   myTolEdit             (0),
251   myMinTolValLabel      (0),
252   myMaxTolValLabel      (0),
253   myTreesLayout         (0),
254   myMaxTol              (-1.),
255   myMinTol              (-1.),
256   myIsSelectAll         (false),
257   myTransparency        (0.0)
258 {
259   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
260   QIcon iconSelect( resMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
261   myVisible = QIcon( resMgr->loadPixmap( "SUIT", tr( "ICON_DATAOBJ_VISIBLE" ) ) );
262   myInvisible = QIcon( resMgr->loadPixmap( "SUIT", tr( "ICON_DATAOBJ_INVISIBLE" ) ) );
263
264   QPixmap anImageVtx(resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_VERTEX")));
265   QPixmap anImageEdge(resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_EDGE")));
266   QPixmap anImageFace(resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_FACE")));
267
268   setWindowTitle( tr( "GEOM_INSPECT_OBJECT_TITLE" ) );
269   setAttribute( Qt::WA_DeleteOnClose );
270
271   myViewWindow = myGeomGUI->getApp()->desktop()->activeWindow();
272
273   QGridLayout* topLayout = new QGridLayout( this );
274   topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
275
276   /**********************   Inspected Object    **********************/
277
278   QHBoxLayout* mainShapeLayout = new QHBoxLayout(this);
279
280   QLabel* label = new QLabel( tr( "GEOM_INSPECT_OBJECT_MAIN_SHAPE" ), this );
281   QPushButton* selBtn = new QPushButton(this);
282   selBtn->setIcon( iconSelect );
283   myEditMainShape = new QLineEdit(this);
284   myEditMainShape->setReadOnly(true);
285
286   mainShapeLayout->addWidget( label );
287   mainShapeLayout->addWidget( selBtn );
288   mainShapeLayout->addWidget( myEditMainShape );
289
290   /**********************   Tolerance filter    **********************/
291
292   myTolFilterGrp    = new QGroupBox (tr("GEOM_INSPECT_TOLERANCE_FILTER"), this);
293   myShapeTypeBtnGrp = new QButtonGroup(myTolFilterGrp);
294
295   // Filter on shape type
296   QRadioButton *aVtx   = new QRadioButton(tr("GEOM_VERTEX"), myTolFilterGrp);
297   QRadioButton *anEdge = new QRadioButton(tr("GEOM_EDGE"),   myTolFilterGrp);
298   QRadioButton *aFace  = new QRadioButton(tr("GEOM_FACE"),   myTolFilterGrp);
299
300   aVtx->setIcon(anImageVtx);
301   anEdge->setIcon(anImageEdge);
302   aFace->setIcon(anImageFace);
303   myShapeTypeBtnGrp->addButton(aVtx,   TYPE_VERTEX);
304   myShapeTypeBtnGrp->addButton(anEdge, TYPE_EDGE);
305   myShapeTypeBtnGrp->addButton(aFace,  TYPE_FACE);
306
307   // Filter on sub-shape tolerance
308   QLabel      *aTolLabel     = new QLabel(tr("GEOM_TOLERANCE"), myTolFilterGrp);
309   QLabel      *aMinTolLabel  = new QLabel(tr("GEOM_MIN"), myTolFilterGrp);
310   QLabel      *aMaxTolLabel  = new QLabel(tr("GEOM_MAX"), myTolFilterGrp);
311   QGridLayout *aFilterLayout = new QGridLayout(myTolFilterGrp);
312
313   myMinTolValLabel  = new QLabel(myTolFilterGrp);
314   myMaxTolValLabel  = new QLabel(myTolFilterGrp);
315   myMinTolResetBtn  = new QPushButton(tr("GEOM_INSPECT_RESET_MIN"), myTolFilterGrp);
316   myMaxTolResetBtn  = new QPushButton(tr("GEOM_INSPECT_RESET_MAX"), myTolFilterGrp);
317   myComparisonCompo = new QComboBox(myTolFilterGrp);
318   myTolEdit         = new SalomeApp_DoubleSpinBox(myTolFilterGrp);
319   myTolEdit->setMinimumWidth(120);
320   aFilterLayout->addWidget(aVtx,   0, 0);
321   aFilterLayout->addWidget(anEdge, 0, 1);
322   aFilterLayout->addWidget(aFace,  0, 2);
323   aFilterLayout->addWidget(aMaxTolLabel,      1, 0, Qt::AlignRight);
324   aFilterLayout->addWidget(aTolLabel,         2, 0);
325   aFilterLayout->addWidget(aMinTolLabel,      3, 0, Qt::AlignRight);
326   aFilterLayout->addWidget(myMaxTolValLabel,  1, 1);
327   aFilterLayout->addWidget(myComparisonCompo, 2, 1);
328   aFilterLayout->addWidget(myMinTolValLabel,  3, 1);
329   aFilterLayout->addWidget(myMaxTolResetBtn,  1, 2);
330   aFilterLayout->addWidget(myTolEdit,         2, 2);
331   aFilterLayout->addWidget(myMinTolResetBtn,  3, 2);
332   aFilterLayout->setRowMinimumHeight(0, 30);
333
334   myTolFilterGrp->setCheckable(true);
335
336   /**********************   Sub-objects trees   **********************/
337   createTreeWidget(myTreeObjects);
338   createTreeWidget(myFilteredTreeObjects);
339
340   myTreesLayout = new QStackedLayout(this);
341   myTreesLayout->addWidget(myTreeObjects);
342   myTreesLayout->addWidget(myFilteredTreeObjects);
343
344   /**********************        Buttons        **********************/
345
346   QVBoxLayout* buttonsLayout1 = new QVBoxLayout(this);
347
348   QPushButton* buttonShow = new QPushButton( tr( "GEOM_INSPECT_OBJECT_SHOW" ), this );
349   QPushButton* buttonShowOnly = new QPushButton( tr( "GEOM_INSPECT_OBJECT_SHOW_ONLY" ), this );
350   QPushButton* buttonHide = new QPushButton( tr( "GEOM_INSPECT_OBJECT_HIDE" ), this );
351   QPushButton* buttonPublish = new QPushButton( tr( "GEOM_INSPECT_OBJECT_PUBLISH" ), this );
352   QPushButton* aShowAllBtn = new QPushButton(tr("SHOW_ALL_BTN"), this);
353   QPushButton* aHideAllBtn = new QPushButton(tr("HIDE_ALL_BTN"), this);
354
355
356   buttonsLayout1->addWidget( buttonShow );
357   buttonsLayout1->addWidget( buttonShowOnly );
358   buttonsLayout1->addWidget( buttonHide );
359   buttonsLayout1->addWidget( aShowAllBtn );
360   buttonsLayout1->addWidget( aHideAllBtn );
361   buttonsLayout1->addWidget( buttonPublish );
362   buttonsLayout1->addStretch();
363
364   QHBoxLayout* buttonsLayout2 = new QHBoxLayout(this);
365
366   QPushButton* buttonClose = new QPushButton( tr( "GEOM_BUT_CLOSE" ), this );
367   QPushButton* buttonHelp = new QPushButton( tr( "GEOM_BUT_HELP" ), this );
368
369   buttonsLayout2->addWidget( buttonClose );
370   buttonsLayout2->addStretch();
371   buttonsLayout2->addWidget( buttonHelp );
372
373   topLayout->addLayout( mainShapeLayout, 0, 0 );
374   topLayout->addWidget( myTolFilterGrp, 1, 0);
375   topLayout->addLayout( myTreesLayout, 2, 0 );
376   topLayout->addLayout( buttonsLayout1, 0, 1, 3, 1 );
377   topLayout->addLayout( buttonsLayout2, 3, 0, 1, 2 );
378
379   connect( selBtn, SIGNAL( clicked() ), this, SLOT( onEditMainShape() ) );
380
381   connect( buttonShow,     SIGNAL( clicked() ), this, SLOT( clickOnShow() ) );
382   connect( buttonShowOnly, SIGNAL( clicked() ), this, SLOT( clickOnShowOnly() ) );
383   connect( buttonHide,     SIGNAL( clicked() ), this, SLOT( clickOnHide() ) );
384   connect( buttonPublish,  SIGNAL( clicked() ), this, SLOT( clickOnPublish() ) );
385   connect( buttonClose,    SIGNAL( clicked() ), this, SLOT( reject() ) );
386   connect( buttonHelp,     SIGNAL( clicked() ), this, SLOT( clickOnHelp() ) );
387   connect( aShowAllBtn,   SIGNAL( clicked() ), this, SLOT( clickOnShowAll() ) );
388   connect( aHideAllBtn,   SIGNAL( clicked() ), this, SLOT( clickOnHideAll() ) );
389
390   init();
391 }
392
393 RepairGUI_InspectObjectDlg::~RepairGUI_InspectObjectDlg()
394 {
395   if ( myViewWindow )
396     onEditMainShape();
397   // restore initial parameters for viewer
398   getDisplayer()->UnsetColor();
399   getDisplayer()->UnsetWidth();
400   // no need to delete child widgets, Qt does it all for us
401 }
402
403 //=================================================================================
404 // function : createTreeWidget()
405 // purpose  :
406 //=================================================================================
407 void RepairGUI_InspectObjectDlg::createTreeWidget(QTreeWidget *&theTreeObjects)
408 {
409   theTreeObjects = new QTreeWidget(this);
410   theTreeObjects->setColumnCount(2);
411   QStringList columnNames;
412   columnNames.append(tr("GEOM_INSPECT_OBJECT_NAME"));
413   columnNames.append("");
414   theTreeObjects->setHeaderLabels(columnNames);
415   QTreeWidgetItem* headerItem = new QTreeWidgetItem(columnNames);
416
417   headerItem->setIcon(1, myInvisible);
418   theTreeObjects->setHeaderItem(headerItem);
419   theTreeObjects->header()->moveSection(1, 0);
420   theTreeObjects->header()->setSectionsClickable(true);
421   theTreeObjects->header()->setSectionsMovable(false);
422   theTreeObjects->header()->setSectionResizeMode( 1, QHeaderView::ResizeToContents);
423
424   theTreeObjects->setSelectionMode(QAbstractItemView::ExtendedSelection);
425   theTreeObjects->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed);
426   // set custom item delegate
427   theTreeObjects->setItemDelegate(new Delegate(theTreeObjects));
428 }
429
430 //=================================================================================
431 // function : init()
432 // purpose  : initialize dialog data
433 //=================================================================================
434 void RepairGUI_InspectObjectDlg::init()
435 {
436   myTolFilterGrp->setChecked(false);
437   myComparisonCompo->addItem(">",  GEOMUtils::CC_GT);
438   myComparisonCompo->addItem(">=", GEOMUtils::CC_GE);
439   myComparisonCompo->addItem("<",  GEOMUtils::CC_LT);
440   myComparisonCompo->addItem("<=", GEOMUtils::CC_LE);
441
442   initSpinBox(myTolEdit, 0., 100., DEFAULT_TOLERANCE_VALUE, "len_tol_precision");
443   myTolEdit->setValue(DEFAULT_TOLERANCE_VALUE);
444
445   // Signals and slots connections
446   initTreeWidget(myTreeObjects);
447   initTreeWidget(myFilteredTreeObjects);
448   myCurrentTreeObjects = myTreeObjects;
449   myMaxTolResetBtn->setEnabled(false);
450   myMinTolResetBtn->setEnabled(false);
451
452   connect(myMinTolResetBtn,  SIGNAL(clicked()), this, SLOT(clickOnResetToMin()));
453   connect(myMaxTolResetBtn,  SIGNAL(clicked()), this, SLOT(clickOnResetToMax()));
454   connect(myShapeTypeBtnGrp, SIGNAL(buttonClicked(int)), this, SLOT(onInitFilteredData()));
455   connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
456   connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()),        this, SLOT(reject()));
457
458   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
459            this, SLOT( onViewSelectionChanged() ) );
460
461   connect( myGeomGUI->getApp()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
462            this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
463
464   // Connect signals and slots for filter group box elements.
465   connect(myTolFilterGrp, SIGNAL(toggled(bool)),
466           this, SLOT(onFilterToggled(bool)));
467   connect(myComparisonCompo, SIGNAL(currentIndexChanged(int)),
468           this, SLOT(onFilterData()));
469   connect(myTolEdit, SIGNAL(valueChanged(double)),
470           this, SLOT(onFilterData()));
471
472   if ( myViewWindow )
473     connect( myViewWindow->getViewManager(), SIGNAL( deleteView( SUIT_ViewWindow* ) ),
474              this, SLOT( onCloseView( SUIT_ViewWindow* ) ), Qt::UniqueConnection );
475
476   // Initialize the dialog with current selection.
477   onViewSelectionChanged();
478 }
479
480 //=================================================================================
481 // function : initSpinBox()
482 // purpose  : 
483 //=================================================================================
484 void RepairGUI_InspectObjectDlg::initSpinBox(SalomeApp_DoubleSpinBox* spinBox, 
485                                              double min,  double max, 
486                                              double step, const char* quantity)
487 {
488   // Obtain precision from preferences
489   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
490   int aPrecision = resMgr->integerValue( "Geometry", quantity, 6 );
491   
492   spinBox->setPrecision( aPrecision );
493   spinBox->setDecimals( qAbs( aPrecision ) ); // it's necessary to set decimals before the range setting,
494                                     // by default Qt rounds boundaries to 2 decimals at setRange
495   spinBox->setRange( min, max );
496   spinBox->setSingleStep( step );
497   
498   // Add a hint for the user saying how to tune precision
499   QString userPropName = QObject::tr( QString( "GEOM_PREF_%1" ).arg( quantity ).toLatin1().constData() );
500   spinBox->setProperty( "validity_tune_hint", 
501                         QVariant( QObject::tr( "GEOM_PRECISION_HINT" ).arg( userPropName ) ) );
502 }
503
504 //=================================================================================
505 // function : initTreeWidget()
506 // purpose  :
507 //=================================================================================
508 void RepairGUI_InspectObjectDlg::initTreeWidget(QTreeWidget *theTreeObjects)
509 {
510   connect(theTreeObjects, SIGNAL(itemClicked (QTreeWidgetItem *, int)),
511           this, SLOT(onItemClicked(QTreeWidgetItem *, int)));
512   connect(theTreeObjects, SIGNAL(itemChanged (QTreeWidgetItem *, int)),
513           this, SLOT(onItemChanged(QTreeWidgetItem *, int)));
514   connect(theTreeObjects, SIGNAL(itemExpanded (QTreeWidgetItem *)),
515           this, SLOT(onItemExpanded(QTreeWidgetItem *)));
516   connect(theTreeObjects, SIGNAL(itemSelectionChanged()),
517           this, SLOT(onItemSelectionChanged()));
518
519   connect(theTreeObjects->header(), SIGNAL(sectionClicked(int)),
520           this, SLOT(onHeaderClicked(int)));
521 }
522
523 //=================================================================================
524 // function : enterEvent()
525 // purpose  :
526 //=================================================================================
527 void RepairGUI_InspectObjectDlg::enterEvent (QEvent*)
528 {
529   if (!myTolFilterGrp->isEnabled())
530     ActivateThisDialog();
531 }
532
533 //=================================================================================
534 // function : checkVisibleIcon()
535 // purpose  : set visible or invisible icon in the header of tree
536 //=================================================================================
537 void RepairGUI_InspectObjectDlg::checkVisibleIcon()
538 {
539   bool isInvisible = false;
540   QTreeWidgetItemIterator it( myCurrentTreeObjects );
541   while ( *it ) {
542     TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>(*it);
543     if ( !anItem->isHidden() &&  !anItem->isVisible() ) {
544       isInvisible = true;
545       break;
546     }
547     ++it;
548   }
549
550   if ( isInvisible ) {
551     myCurrentTreeObjects->headerItem()->setIcon( 1, myInvisible );
552     myIsSelectAll = false;
553   }
554   else {
555     myCurrentTreeObjects->headerItem()->setIcon( 1, myVisible );
556     myIsSelectAll = true;
557   }
558 }
559
560 //=================================================================================
561 // function : addSubObjects()
562 // purpose  : add sub-objects to parent object in the tree
563 //=================================================================================
564 void RepairGUI_InspectObjectDlg::addSubObjects
565                     (TreeWidgetItem                   *theParentItem,
566                      const TopTools_IndexedMapOfShape &theIndices)
567 {
568   TreeWidgetItem* aMainItem = dynamic_cast<TreeWidgetItem*>( myTreeObjects->topLevelItem(0) );
569   TopoDS_Iterator it( theParentItem->getShape() );
570   for ( ; it.More(); it.Next() ) {
571     TopoDS_Shape aSubShape = it.Value();
572     int anIndex = theIndices.FindIndex(aSubShape);
573     QString anEntry = QString( "TEMP_" ) + aMainItem->getIO()->getEntry() + QString("_%1").arg( anIndex );
574     TreeWidgetItem* anItem = new TreeWidgetItem( theParentItem, QStringList(), aSubShape, anEntry);
575     anItem->setVisible( false, myInvisible );
576     addSubObjects(anItem, theIndices);
577   }
578 }
579
580 //=================================================================================
581 // function : onInitFilteredData()
582 // purpose  : add sub-objects to parent object in the filtered tree
583 //=================================================================================
584 void RepairGUI_InspectObjectDlg::onInitFilteredData()
585 {
586   TreeWidgetItem *aMainItem =
587           dynamic_cast<TreeWidgetItem*>(myFilteredTreeObjects->topLevelItem(0));
588
589   if (!aMainItem) {
590     return;
591   }
592
593   // Remove the children.
594   SALOME_ListIO           aListOfIO;
595   QTreeWidgetItemIterator it(aMainItem);
596
597   while (*it) {
598     TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>(*it);
599     if (aMainItem != anItem && (anItem->flags() & Qt::ItemIsSelectable) &&
600         anItem->isVisible() && !anItem->isHidden()) {
601       aListOfIO.Append(anItem->getIO());
602     }
603
604     ++it;
605   }
606
607   myFilteredTreeObjects->clearSelection();
608   myFilteredTreeObjects->headerItem()->setIcon(1, myInvisible);
609   getDisplayer()->Erase(aListOfIO);
610   getDisplayer()->UpdateViewer();
611
612   // Delete child items.
613   QList<QTreeWidgetItem *> aListItems = aMainItem->takeChildren();
614
615   foreach (QTreeWidgetItem *anItem, aListItems) {
616     delete anItem;
617   }
618
619   // Initialize the tree with a new list.
620   TopoDS_Shape      aShape     = aMainItem->getShape();
621   TopAbs_ShapeEnum  aShapeType = aShape.ShapeType();
622
623   myShapeTypeBtnGrp->button(TYPE_FACE)->setVisible(aShapeType < TYPE_FACE);
624   myShapeTypeBtnGrp->button(TYPE_EDGE)->setVisible(aShapeType < TYPE_EDGE);
625   myShapeTypeBtnGrp->button(TYPE_VERTEX)->setVisible(aShapeType < TYPE_VERTEX);
626
627   int anId = myShapeTypeBtnGrp->checkedId();
628
629   myMaxTol = -RealLast();
630   myMinTol =  RealLast();
631
632   if (anId != -1 && myShapeTypeBtnGrp->checkedButton()->isVisible()) {
633     // Get sub-shapes
634     TopTools_MapOfShape         aMapFence;
635     TopExp_Explorer             anExp(aShape, (TopAbs_ShapeEnum)anId);
636     TopTools_IndexedMapOfShape  anIndices;
637
638     TopExp::MapShapes(aShape, anIndices);
639
640     for (; anExp.More(); anExp.Next()) {
641       const TopoDS_Shape &aSubShape = anExp.Current();
642
643       if (aMapFence.Add(aSubShape)) {
644         // Compute tolerance
645         Standard_Real aTolerance = -1.;
646
647         switch (aSubShape.ShapeType()) {
648           case TYPE_FACE:
649             aTolerance = BRep_Tool::Tolerance(TopoDS::Face(aSubShape));
650             break;
651           case TYPE_EDGE:
652             aTolerance = BRep_Tool::Tolerance(TopoDS::Edge(aSubShape));
653             break;
654           case TYPE_VERTEX:
655             aTolerance = BRep_Tool::Tolerance(TopoDS::Vertex(aSubShape));
656             break;
657           default:
658             break;
659         }
660
661         if (aTolerance < 0.) {
662           continue;
663         }
664
665         if (aTolerance > myMaxTol) {
666           myMaxTol = aTolerance;
667         }
668
669         if (aTolerance < myMinTol) {
670           myMinTol = aTolerance;
671         }
672
673         int anIndex = anIndices.FindIndex(aSubShape);
674         QString anEntry = QString( "TEMP_" ) +
675                           aMainItem->getIO()->getEntry() +
676                           QString::number(anIndex);
677         TreeWidgetItem* anItem =
678             new TreeWidgetItem(aMainItem, QStringList(),
679                                aSubShape, anEntry, aTolerance);
680         anItem->setVisible( false, myInvisible );
681       }
682     }
683   }
684
685   // Compose names of sub-items if the main item is expanded.
686   if (aMainItem->isExpanded()) {
687     onItemExpanded(aMainItem);
688   }
689
690   myMaxTolResetBtn->setEnabled(myMaxTol >= myMinTol);
691   myMinTolResetBtn->setEnabled(myMaxTol >= myMinTol);
692
693   if (myMaxTol < myMinTol) {
694     myMinTol = DEFAULT_TOLERANCE_VALUE;
695     myMaxTol = DEFAULT_TOLERANCE_VALUE;
696     myMinTolValLabel->setText(QString::number(DEFAULT_TOLERANCE_VALUE));
697     myMaxTolValLabel->setText(QString::number(DEFAULT_TOLERANCE_VALUE));
698     myTolEdit->setValue(DEFAULT_TOLERANCE_VALUE);
699   } else {
700     myMinTolValLabel->setText(QString::number(myMinTol));
701     myMaxTolValLabel->setText(QString::number(myMaxTol));
702
703     if (GEOMUtils::CompareToleranceValues(myMinTol, myTolEdit->value()) == 1) {
704       clickOnResetToMin();
705     } else if (GEOMUtils::CompareToleranceValues
706                                          (myMaxTol, myTolEdit->value()) == -1) {
707       clickOnResetToMax();
708     } else {
709       onFilterData();
710     }
711   }
712 }
713
714 //=================================================================================
715 // function : onFilterData()
716 // purpose  : filter objects in the filtered tree
717 //=================================================================================
718 void RepairGUI_InspectObjectDlg::onFilterData()
719 {
720   TreeWidgetItem *aMainItem =
721           dynamic_cast<TreeWidgetItem*>(myFilteredTreeObjects->topLevelItem(0));
722
723   if (!aMainItem) {
724     return;
725   }
726
727   SALOME_ListIO           aListOfIOToHide;
728   QTreeWidgetItemIterator anIt(aMainItem);
729   const int               aCompValue =
730          myComparisonCompo->itemData(myComparisonCompo->currentIndex()).toInt();
731   const double            aTolValue  = myTolEdit->value();
732
733   while (*anIt) {
734     TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>(*anIt);
735
736     if (aMainItem != anItem) {
737       const bool isToFilter = !GEOMUtils::IsFitCondition
738         ((GEOMUtils::ComparisonCondition) aCompValue,
739          anItem->getTolerance(), aTolValue);
740
741       if (isToFilter && !anItem->isHidden()) {
742         if (anItem->isVisible()) {
743           aListOfIOToHide.Append(anItem->getIO());
744         }
745
746         anItem->setVisible(false, myInvisible);
747       }
748
749       anItem->setHidden(isToFilter);
750     }
751
752     ++anIt;
753   }
754
755   if (!aListOfIOToHide.IsEmpty()) {
756     getDisplayer()->Erase(aListOfIOToHide);
757     getDisplayer()->UpdateViewer();
758   }
759
760   checkVisibleIcon();
761 }
762
763 //=================================================================================
764 // function : displayItem()
765 // purpose  : display sub-object of inspected object according its tree item
766 //=================================================================================
767 void RepairGUI_InspectObjectDlg::displayItem( TreeWidgetItem* theItem )
768 {
769   GEOM_Displayer* aDisplayer = getDisplayer();
770   if ( theItem == myCurrentTreeObjects->topLevelItem(0) ) {
771     aDisplayer->UnsetColor();
772     aDisplayer->UnsetWidth();
773   }
774   else if ( aDisplayer->GetColor() != Quantity_NOC_VIOLET && aDisplayer->GetWidth() != 2.0 ) {
775     aDisplayer->SetColor( Quantity_NOC_VIOLET );
776     aDisplayer->SetWidth( 2.0 );
777   }
778
779   SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation( theItem->getShape(), theItem->getIO()->getEntry(),
780                                                             GEOM_Displayer::GetActiveView() );
781   if ( aPrs )
782     displayPreview( aPrs, true, false );
783 }
784
785 //=================================================================================
786 // function : setItemDisplayStatus()
787 // purpose  : set visible or invisible status for the same items in the tree
788 //=================================================================================
789 void RepairGUI_InspectObjectDlg::setItemDisplayStatus( TreeWidgetItem* theItem, bool theIsVisible )
790 {
791   QTreeWidgetItemIterator it( myCurrentTreeObjects );
792   while (*it) {
793     TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>(*it);
794     if ( anItem->getShape().IsSame( theItem->getShape() ) )
795       anItem->setVisible( theIsVisible, theIsVisible ? myVisible : myInvisible );
796     ++it;
797   }
798 }
799
800 //=================================================================================
801 // function : setMainObjectTransparency()
802 // purpose  : set transparency for the inspected object
803 //=================================================================================
804 void RepairGUI_InspectObjectDlg::setMainObjectTransparency( double theTransparency )
805 {
806   SUIT_ViewManager* aViewMan = myViewWindow->getViewManager();
807   SALOME_View* aView = dynamic_cast<SALOME_View*>( aViewMan->getViewModel() );
808   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myGeomGUI->getApp()->activeStudy() );
809
810   TreeWidgetItem* aMainItem = dynamic_cast<TreeWidgetItem*>( myCurrentTreeObjects->topLevelItem(0) );
811
812   if (!aMainItem) {
813     return;
814   }
815
816   aStudy->setObjectProperty( myViewWindow->getViewManager()->getGlobalId(),
817                              QString( aMainItem->getIO()->getEntry() ),
818                              GEOM::propertyName( GEOM::Transparency ), theTransparency );
819
820   if ( aView->isVisible( aMainItem->getIO() ) )
821     getDisplayer()->Redisplay( aMainItem->getIO(), true, aView );
822 }
823
824 //=================================================================================
825 // function : restoreParam()
826 // purpose  : restore initial parameters of the dialog and the viewer
827 //=================================================================================
828 void RepairGUI_InspectObjectDlg::restoreParam()
829 {
830   SUIT_ViewManager* aViewMan = myViewWindow->getViewManager();
831   SALOME_View* aView = dynamic_cast<SALOME_View*>( aViewMan->getViewModel() );
832   GEOM_Displayer* aDisplayer = getDisplayer();
833   // restore initial parameters for viewer
834   aDisplayer->UnsetColor();
835   aDisplayer->UnsetWidth();
836
837   // restore transparency of main object
838   setMainObjectTransparency( myTransparency );
839
840   // erase sub-shapes
841   TreeWidgetItem* aMainItem = dynamic_cast<TreeWidgetItem*>( myCurrentTreeObjects->topLevelItem(0) );
842   QTreeWidgetItemIterator it( myCurrentTreeObjects );
843   while (*it) {
844     if ( *it != aMainItem ) {
845       TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>(*it);
846       aDisplayer->Erase( anItem->getIO(), false, false, aView );
847       anItem->setVisible( false, myInvisible );
848     }
849     ++it;
850   }
851 }
852
853 //=================================================================================
854 // function : onEditMainShape()
855 // purpose  : called when selection button was clicked
856 //=================================================================================
857 void RepairGUI_InspectObjectDlg::onEditMainShape()
858 {
859   if ( myEditMainShape->text().isEmpty() || !myViewWindow )
860     return;
861
862   restoreParam();
863
864   // restore initial parameters for dialog box
865   myEditMainShape->setEnabled( true );
866   myEditMainShape->setText("");
867   myEditMainShape->setFocus();
868   myTreeObjects->clear();
869   myFilteredTreeObjects->clear();
870 }
871
872 //=================================================================================
873 // function : onItemClicked()
874 // purpose  : called when tree item was clicked
875 //=================================================================================
876 void RepairGUI_InspectObjectDlg::onItemClicked( QTreeWidgetItem* theItem, int theColumn )
877 {
878   if ( theColumn!= 1 || !( theItem->flags() & Qt::ItemIsSelectable ) || !myViewWindow )
879     return;
880
881   GEOM_Displayer* aDisplayer = getDisplayer();
882
883   TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>( theItem );
884
885   if ( anItem->isVisible() ) {
886     aDisplayer->Erase( anItem->getIO(), false, true );
887     setItemDisplayStatus( anItem, false );
888   }
889   else {
890     displayItem( anItem );
891     setItemDisplayStatus( anItem, true );
892   }
893   aDisplayer->UpdateViewer();
894   checkVisibleIcon();
895 }
896
897 //=================================================================================
898 // function : onItemChanged()
899 // purpose  : called when tree item was changed
900 //=================================================================================
901 void RepairGUI_InspectObjectDlg::onItemChanged( QTreeWidgetItem* theItem, int theColumn )
902 {
903   if ( theColumn!= 0 || !( theItem->flags() & Qt::ItemIsEditable ) )
904     return;
905
906   // rename the same items in the tree
907   QTreeWidgetItemIterator it( myCurrentTreeObjects );
908   while ( *it ) {
909     TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>(*it);
910     if ( anItem->getShape().IsSame( dynamic_cast<TreeWidgetItem*>( theItem )->getShape() ) )
911       anItem->setText( 0, theItem->text(0) );
912     ++it;
913   }
914 }
915
916 //=================================================================================
917 // function : onItemExpanded()
918 // purpose  : called when tree item was expanded
919 //=================================================================================
920 void RepairGUI_InspectObjectDlg::onItemExpanded( QTreeWidgetItem* theItem )
921 {
922   TreeWidgetItem* aMainItem = dynamic_cast<TreeWidgetItem*>( myCurrentTreeObjects->topLevelItem(0) );
923   GEOM::GEOM_Object_var aMainObject = GEOMBase::ConvertIOinGEOMObject( aMainItem->getIO() );
924
925   for ( int i = 0; i < theItem->childCount(); i++ ) {
926     TreeWidgetItem* aSubItem = dynamic_cast<TreeWidgetItem*>( theItem->child(i) );
927     int anIndex = GEOMBase::GetIndex( aSubItem->getShape(), aMainItem->getShape() );
928     if ( aSubItem->text(0).isEmpty() ) {
929       char* aName = aMainObject->GetSubShapeName( anIndex );
930       if ( !QString( aName ).isEmpty() )
931         aSubItem->setText( 0, QString( aName ) );
932       else
933         aSubItem->setText( 0, QString("%1_%2").arg( GEOMBase::TypeName( aSubItem->getShape().ShapeType(), true ) ).arg( anIndex ) );
934     }
935   }
936 }
937
938 //=================================================================================
939 // function : onItemSelectionChanged()
940 // purpose  : called when tree item was selected
941 //=================================================================================
942 void RepairGUI_InspectObjectDlg::onItemSelectionChanged()
943 {
944   if ( !myViewWindow )
945     return;
946
947   QList<QTreeWidgetItem*> listItem = myCurrentTreeObjects->selectedItems();
948   SALOME_ListIO aSelected;
949   for ( int i = 0; i < listItem.size(); i++ ) {
950     TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>( listItem.at(i) );
951     aSelected.Append( anItem->getIO() );
952   }
953   myGeomGUI->getApp()->selectionMgr()->setSelectedObjects( aSelected );
954 }
955
956 //=================================================================================
957 // function : onHeaderClicked()
958 // purpose  : called when header item of tree was clicked
959 //=================================================================================
960 void RepairGUI_InspectObjectDlg::onHeaderClicked( int theColumn )
961 {
962   if ( theColumn != 1 || !myViewWindow )
963     return;
964
965   GEOM_Displayer* aDisplayer = getDisplayer();
966
967   if ( myIsSelectAll ) {
968     myIsSelectAll = false;
969     myCurrentTreeObjects->headerItem()->setIcon( 1, myInvisible );
970     SALOME_ListIO aListOfIO;
971     QTreeWidgetItemIterator it( myCurrentTreeObjects );
972     while ( *it ) {
973       TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>(*it);
974       if ( !anItem->isHidden() && ( anItem->flags() & Qt::ItemIsSelectable ) &&
975           anItem->isVisible() ) {
976         aListOfIO.Append( anItem->getIO() );
977         anItem->setVisible( false, myInvisible );
978       }
979       ++it;
980     }
981     aDisplayer->Erase( aListOfIO );
982   }
983   else {
984     myIsSelectAll = true;
985     myCurrentTreeObjects->headerItem()->setIcon( 1, myVisible );
986     QTreeWidgetItemIterator it( myCurrentTreeObjects );
987     while ( *it ) {
988       TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>(*it);
989       if ( !anItem->isHidden() &&  ( anItem->flags() & Qt::ItemIsSelectable ) &&
990            !anItem->isVisible() ) {
991         displayItem( anItem );
992         anItem->setVisible( true, myVisible );
993       }
994       ++it;
995     }
996   }
997
998   aDisplayer->UpdateViewer();
999 }
1000
1001 //=================================================================================
1002 // function : onViewSelectionChanged()
1003 // purpose  : called when selection of object browser was changed
1004 //=================================================================================
1005 void RepairGUI_InspectObjectDlg::onViewSelectionChanged()
1006 {
1007   if (!myEditMainShape->isEnabled())
1008     return;
1009
1010   //get shape from selection
1011   SALOME_ListIO selected;
1012   myGeomGUI->getApp()->selectionMgr()->selectedObjects(selected);
1013
1014   if ( selected.Extent() != 1 )
1015     return;
1016
1017   if ( !myViewWindow ) {
1018     SUIT_ViewManager* occVm = myGeomGUI->getApp()->getViewManager( OCCViewer_Viewer::Type(), true );
1019     myViewWindow = occVm->getActiveView();
1020     connect( occVm, SIGNAL( deleteView( SUIT_ViewWindow* ) ),
1021              this, SLOT( onCloseView( SUIT_ViewWindow* ) ), Qt::UniqueConnection );
1022   }
1023
1024   TopoDS_Shape aShape = GEOMBase::GetTopoFromSelection( selected );
1025   if ( aShape.IsNull() )
1026     return;
1027
1028   Handle(SALOME_InteractiveObject) anIO = selected.First();
1029   GEOM::GEOM_Object_var anObject = GEOMBase::ConvertIOinGEOMObject( anIO );
1030   QString aName = anObject->GetName();
1031   CORBA::String_var anEntry = anObject->GetStudyEntry();
1032
1033   myEditMainShape->setText( aName );
1034   myEditMainShape->setEnabled( false );
1035
1036   // remember initial transparency value
1037   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myGeomGUI->getApp()->activeStudy() );
1038   QVariant v = aStudy->getObjectProperty( myViewWindow->getViewManager()->getGlobalId(),
1039                                           QString( anEntry.in() ),
1040                                           GEOM::propertyName( GEOM::Transparency ), myTransparency );
1041   if ( v.canConvert( QVariant::Double ) )
1042     myTransparency = v.toDouble();
1043
1044   TreeWidgetItem* anItem         = new TreeWidgetItem
1045               (myTreeObjects, QStringList() << aName, aShape, anIO);
1046   TreeWidgetItem* anItemFiltered = new TreeWidgetItem
1047               (myFilteredTreeObjects, QStringList() << aName, aShape, anIO);
1048
1049   if ( getDisplayer()->IsDisplayed( anEntry.in() ) ) {
1050     anItem->setVisible( true, myVisible );
1051     anItemFiltered->setVisible( true, myVisible );
1052   } else {
1053     anItem->setVisible( false, myInvisible );
1054     anItemFiltered->setVisible( false, myInvisible );
1055   }
1056
1057   setMainObjectTransparency( 0.5 );
1058
1059   // add sub-objects in the tree
1060   TopTools_IndexedMapOfShape anIndices;
1061
1062   TopExp::MapShapes(aShape, anIndices);
1063   addSubObjects(anItem, anIndices);
1064   onInitFilteredData();
1065   updateViewer(false);
1066
1067   // check icon for tree header
1068   checkVisibleIcon();
1069 }
1070
1071 //=================================================================================
1072 // function : onWindowActivated()
1073 // purpose  : called when other window was activated
1074 //=================================================================================
1075 void RepairGUI_InspectObjectDlg::onWindowActivated( SUIT_ViewWindow* theViewWindow )
1076 {
1077   if ( myViewWindow )
1078     restoreParam();
1079
1080   connect( theViewWindow->getViewManager(), SIGNAL( deleteView( SUIT_ViewWindow* ) ),
1081            this, SLOT( onCloseView( SUIT_ViewWindow* ) ), Qt::UniqueConnection );
1082
1083   if ( theViewWindow->getViewManager()->getType() != OCCViewer_Viewer::Type() &&
1084        theViewWindow->getViewManager()->getType() != SVTK_Viewer::Type() ) {
1085     myViewWindow = 0;
1086     return;
1087   }
1088   myViewWindow = theViewWindow;
1089
1090   if ( myCurrentTreeObjects->topLevelItemCount() > 0 ) {
1091     setMainObjectTransparency( 0.5 );
1092     TreeWidgetItem* aMainItem = dynamic_cast<TreeWidgetItem*>( myCurrentTreeObjects->topLevelItem(0) );
1093     if ( getDisplayer()->IsDisplayed( aMainItem->getIO()->getEntry() ) )
1094       aMainItem->setVisible( true, myVisible );
1095     else
1096       aMainItem->setVisible( false, myInvisible );
1097   }
1098   checkVisibleIcon();
1099 }
1100
1101 //=================================================================================
1102 // function : onCloseView()
1103 // purpose  : called when last view was closed
1104 //=================================================================================
1105 void RepairGUI_InspectObjectDlg::onCloseView( SUIT_ViewWindow* )
1106 {
1107   if ( myGeomGUI->getApp()->desktop()->windows().size() == 0 ) {
1108     restoreParam();
1109     myViewWindow = 0;
1110   }
1111 }
1112
1113 //=================================================================================
1114 // function : clickOnShow()
1115 // purpose  : called when "Show selected" button was clicked
1116 //=================================================================================
1117 void RepairGUI_InspectObjectDlg::clickOnShow()
1118 {
1119   if ( !myViewWindow )
1120     return;
1121
1122   QList<QTreeWidgetItem*> listItem = myCurrentTreeObjects->selectedItems();
1123   for ( int i = 0; i < listItem.size(); i++ ) {
1124     TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>( listItem.at(i) );
1125     if ( !anItem->isVisible() ) {
1126       displayItem( anItem );
1127       setItemDisplayStatus( anItem, true );
1128     }
1129   }
1130   getDisplayer()->UpdateViewer();
1131   checkVisibleIcon();
1132 }
1133
1134 //=================================================================================
1135 // function : clickOnShowOnly()
1136 // purpose  : called when "Show only selected" button was clicked
1137 //=================================================================================
1138 void RepairGUI_InspectObjectDlg::clickOnShowOnly()
1139 {
1140   if ( !myViewWindow )
1141     return;
1142
1143   SALOME_ListIO aListOfIO;
1144   QTreeWidgetItemIterator it( myCurrentTreeObjects );
1145   while ( *it ) {
1146     TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>(*it);
1147     if ( !anItem->isHidden() && ( anItem->flags() & Qt::ItemIsSelectable ) &&
1148          anItem->isVisible() ) {
1149       aListOfIO.Append( anItem->getIO() );
1150       anItem->setVisible( false, myInvisible );
1151     }
1152     ++it;
1153   }
1154   getDisplayer()->Erase( aListOfIO );
1155
1156   clickOnShow();
1157 }
1158
1159 //=================================================================================
1160 // function : clickOnHide()
1161 // purpose  : called when "Hide selected" button was clicked
1162 //=================================================================================
1163 void RepairGUI_InspectObjectDlg::clickOnHide()
1164 {
1165   if ( !myViewWindow )
1166     return;
1167
1168   QList<QTreeWidgetItem*> listItem = myCurrentTreeObjects->selectedItems();
1169   for ( int i = 0; i < listItem.size(); i++ ) {
1170     TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>( listItem.at(i) );
1171     if ( anItem->isVisible() ) {
1172       getDisplayer()->Erase( anItem->getIO(), false, false );
1173       setItemDisplayStatus( anItem, false );
1174     }
1175   }
1176   getDisplayer()->UpdateViewer();
1177   checkVisibleIcon();
1178 }
1179
1180 //=================================================================================
1181 // function : clickOnPublish()
1182 // purpose  : called when "Publish selected" button was clicked
1183 //=================================================================================
1184 void RepairGUI_InspectObjectDlg::clickOnPublish()
1185 {
1186   // find main object
1187   TreeWidgetItem* aMainItem = dynamic_cast<TreeWidgetItem*>( myCurrentTreeObjects->topLevelItem(0) );
1188
1189   if (!aMainItem) {
1190     return;
1191   }
1192
1193   GEOM::GEOM_Object_var aMainObject = GEOMBase::ConvertIOinGEOMObject( aMainItem->getIO() );
1194
1195   // find unique indices of selected objects
1196   QList<QTreeWidgetItem*> selectedItems = myCurrentTreeObjects->selectedItems();
1197   QMap< int, QString > anIndices;
1198   GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
1199   anArray->length( selectedItems.size() );
1200   int j = 0;
1201   for ( int i = 0; i < selectedItems.size(); i++ ) {
1202     TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>( selectedItems.at(i) );
1203     int anIndex = GEOMBase::GetIndex( anItem->getShape(), aMainItem->getShape() );
1204     if ( anIndices.find( anIndex ) == anIndices.end() &&
1205         anItem != aMainItem ) {
1206       anIndices[ anIndex ] = anItem->text(0);
1207       anArray[j++] = anIndex;
1208     }
1209   }
1210   anArray->length(j);
1211
1212   // get selected sub-shapes
1213   GEOM::GEOM_IShapesOperations_var anOper = getGeomEngine()->GetIShapesOperations();
1214   GEOM::ListOfGO_var aList = anOper->MakeSubShapes( aMainObject, anArray );
1215
1216   // publish sub-shapes
1217   for ( int i = 0; i < (int)aList->length(); i++ )
1218     GeometryGUI::GetGeomGen()->AddInStudy( aList[i],
1219                                            anIndices.values().at(i).toStdString().c_str(), aMainObject );
1220
1221   updateObjBrowser();
1222 }
1223
1224 //=================================================================================
1225 // function : clickOnHelp()
1226 // purpose  : called when Help button was clicked to open a help page
1227 //=================================================================================
1228 void RepairGUI_InspectObjectDlg::clickOnHelp()
1229 {
1230   myGeomGUI->getApp()->onHelpContextModule( "GEOM", "inspect_object_operation_page.html" );
1231 }
1232
1233 //=================================================================================
1234 // function : clickOnResetToMin()
1235 // purpose  : called when Reset button was clicked to reset tolerance filter to minimal value.
1236 //=================================================================================
1237 void RepairGUI_InspectObjectDlg::clickOnResetToMin()
1238 {
1239   if (myMinTol >= myTolEdit->minimum() && myMinTol <= myTolEdit->maximum()) {
1240     myTolEdit->setValue(myMinTol);
1241   }
1242 }
1243
1244 //=================================================================================
1245 // function : clickOnResetToMax()
1246 // purpose  : called when Reset button was clicked to reset tolerance filter to maximal value.
1247 //=================================================================================
1248 void RepairGUI_InspectObjectDlg::clickOnResetToMax()
1249 {
1250   if (myMaxTol >= myTolEdit->minimum() && myMaxTol <= myTolEdit->maximum()) {
1251     myTolEdit->setValue(myMaxTol);
1252   }
1253 }
1254
1255 //=================================================================================
1256 // function : clickOnShowAll()
1257 // purpose  : called when Help button was clicked to show all shapes
1258 //=================================================================================
1259 void RepairGUI_InspectObjectDlg::clickOnShowAll()
1260 {
1261   myIsSelectAll = false;
1262   onHeaderClicked(1);
1263 }
1264
1265 //=================================================================================
1266 // function : clickOnHideAll()
1267 // purpose  : called when Help button was clicked to hide all shapes
1268 //=================================================================================
1269 void RepairGUI_InspectObjectDlg::clickOnHideAll()
1270 {
1271   myIsSelectAll = true;
1272   onHeaderClicked(1);
1273 }
1274
1275 //=================================================================================
1276 // function : DeactivateActiveDialog()
1277 // purpose  :
1278 //=================================================================================
1279 void RepairGUI_InspectObjectDlg::DeactivateActiveDialog()
1280 {
1281   setEnabled(false);
1282   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
1283   myGeomGUI->SetActiveDialogBox(0);
1284   globalSelection();
1285   erasePreview();
1286 }
1287
1288 //=================================================================================
1289 // function : ActivateThisDialog()
1290 // purpose  :
1291 //=================================================================================
1292 void RepairGUI_InspectObjectDlg::ActivateThisDialog()
1293 {
1294   /* Emit a signal to deactivate the active dialog */
1295   myGeomGUI->EmitSignalDeactivateDialog();
1296   setEnabled(true);
1297   myGeomGUI->SetActiveDialogBox( (QDialog*)this );
1298
1299   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
1300           this, SLOT(onViewSelectionChanged()));
1301
1302   updateViewer(false);
1303 }
1304
1305 //=================================================================================
1306 // function : onFilterToggled()
1307 // purpose  :
1308 //=================================================================================
1309 void RepairGUI_InspectObjectDlg::onFilterToggled(bool isOn)
1310 {
1311   if (isOn) {
1312     myCurrentTreeObjects = myFilteredTreeObjects;
1313     myTreesLayout->setCurrentIndex(1);
1314   } else {
1315     myCurrentTreeObjects = myTreeObjects;
1316     myTreesLayout->setCurrentIndex(0);
1317   }
1318
1319   updateViewer(true);
1320 }
1321
1322 //=================================================================================
1323 // function : updateViewer()
1324 // purpose  :
1325 //=================================================================================
1326 void RepairGUI_InspectObjectDlg::updateViewer(const bool theIsHideOtherTree)
1327 {
1328   GEOM_Displayer *aDisplayer  = getDisplayer();
1329
1330   if (theIsHideOtherTree) {
1331     QTreeWidget    *aTreeToHide = myCurrentTreeObjects == myTreeObjects ?
1332                                           myFilteredTreeObjects: myTreeObjects;
1333
1334     // Hide the objects of disappeared tree, do not switch off flags.
1335     SALOME_ListIO           aListOfIO;
1336     QTreeWidgetItemIterator it(aTreeToHide);
1337
1338     while (*it) {
1339       TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>(*it);
1340       if ((anItem->flags() & Qt::ItemIsSelectable) &&
1341           anItem->isVisible() && !anItem->isHidden()) {
1342         aListOfIO.Append(anItem->getIO());
1343       }
1344
1345       ++it;
1346     }
1347
1348     aDisplayer->Erase(aListOfIO);
1349   }
1350
1351   // Show the objects that are marked as shown in the appeared tree.
1352   QTreeWidgetItemIterator it2(myCurrentTreeObjects);
1353
1354   while (*it2) {
1355     TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>(*it2);
1356     if ((anItem->flags() & Qt::ItemIsSelectable) &&
1357         anItem->isVisible() && !anItem->isHidden()) {
1358       displayItem(anItem);
1359     }
1360
1361     ++it2;
1362   }
1363
1364   aDisplayer->UpdateViewer();
1365 }