Salome HOME
168d1543c224adef9d2f581fcd596191a0012946
[modules/geom.git] / src / RepairGUI / RepairGUI_InspectObjectDlg.cxx
1 // Copyright (C) 2014-2016  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.toLatin1(), "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 : GEOMBase_Helper       (parent),
241   QDialog               (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   myMinTolValLabel      (0),
251   myMaxTolValLabel      (0),
252   myTolEdit             (0),
253   myTreesLayout         (0),
254   myTransparency        (0.0),
255   myIsSelectAll         (false),
256   myMaxTol              (-1.),
257   myMinTol              (-1.)
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()->setClickable(true);
421   theTreeObjects->header()->setMovable(false);
422   theTreeObjects->header()->setResizeMode( 1, QHeaderView::ResizeToContents);
423   theTreeObjects->setSelectionMode(QAbstractItemView::ExtendedSelection);
424   theTreeObjects->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed);
425   // set custom item delegate
426   theTreeObjects->setItemDelegate(new Delegate(theTreeObjects));
427 }
428
429 //=================================================================================
430 // function : init()
431 // purpose  : initialize dialog data
432 //=================================================================================
433 void RepairGUI_InspectObjectDlg::init()
434 {
435   myTolFilterGrp->setChecked(false);
436   myComparisonCompo->addItem(">",  GEOMUtils::CC_GT);
437   myComparisonCompo->addItem(">=", GEOMUtils::CC_GE);
438   myComparisonCompo->addItem("<",  GEOMUtils::CC_LT);
439   myComparisonCompo->addItem("<=", GEOMUtils::CC_LE);
440
441   initSpinBox(myTolEdit, 0., 100., DEFAULT_TOLERANCE_VALUE, "len_tol_precision");
442   myTolEdit->setValue(DEFAULT_TOLERANCE_VALUE);
443
444   // Signals and slots connections
445   initTreeWidget(myTreeObjects);
446   initTreeWidget(myFilteredTreeObjects);
447   myCurrentTreeObjects = myTreeObjects;
448   myMaxTolResetBtn->setEnabled(false);
449   myMinTolResetBtn->setEnabled(false);
450
451   connect(myMinTolResetBtn,  SIGNAL(clicked()), this, SLOT(clickOnResetToMin()));
452   connect(myMaxTolResetBtn,  SIGNAL(clicked()), this, SLOT(clickOnResetToMax()));
453   connect(myShapeTypeBtnGrp, SIGNAL(buttonClicked(int)), this, SLOT(onInitFilteredData()));
454   connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
455   connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()),        this, SLOT(reject()));
456
457   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
458            this, SLOT( onViewSelectionChanged() ) );
459
460   connect( myGeomGUI->getApp()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
461            this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
462
463   // Connect signals and slots for filter group box elements.
464   connect(myTolFilterGrp, SIGNAL(toggled(bool)),
465           this, SLOT(onFilterToggled(bool)));
466   connect(myComparisonCompo, SIGNAL(currentIndexChanged(int)),
467           this, SLOT(onFilterData()));
468   connect(myTolEdit, SIGNAL(valueChanged(double)),
469           this, SLOT(onFilterData()));
470
471   if ( myViewWindow )
472     connect( myViewWindow->getViewManager(), SIGNAL( deleteView( SUIT_ViewWindow* ) ),
473              this, SLOT( onCloseView( SUIT_ViewWindow* ) ), Qt::UniqueConnection );
474
475   // Initialize the dialog with current selection.
476   onViewSelectionChanged();
477 }
478
479 //=================================================================================
480 // function : initSpinBox()
481 // purpose  : 
482 //=================================================================================
483 void RepairGUI_InspectObjectDlg::initSpinBox(SalomeApp_DoubleSpinBox* spinBox, 
484                                              double min,  double max, 
485                                              double step, const char* quantity)
486 {
487   // Obtain precision from preferences
488   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
489   int aPrecision = resMgr->integerValue( "Geometry", quantity, 6 );
490   
491   spinBox->setPrecision( aPrecision );
492   spinBox->setDecimals( qAbs( aPrecision ) ); // it's necessary to set decimals before the range setting,
493                                     // by default Qt rounds boundaries to 2 decimals at setRange
494   spinBox->setRange( min, max );
495   spinBox->setSingleStep( step );
496   
497   // Add a hint for the user saying how to tune precision
498   QString userPropName = QObject::tr( QString( "GEOM_PREF_%1" ).arg( quantity ).toLatin1().constData() );
499   spinBox->setProperty( "validity_tune_hint", 
500                         QVariant( QObject::tr( "GEOM_PRECISION_HINT" ).arg( userPropName ) ) );
501 }
502
503 //=================================================================================
504 // function : initTreeWidget()
505 // purpose  :
506 //=================================================================================
507 void RepairGUI_InspectObjectDlg::initTreeWidget(QTreeWidget *theTreeObjects)
508 {
509   connect(theTreeObjects, SIGNAL(itemClicked (QTreeWidgetItem *, int)),
510           this, SLOT(onItemClicked(QTreeWidgetItem *, int)));
511   connect(theTreeObjects, SIGNAL(itemChanged (QTreeWidgetItem *, int)),
512           this, SLOT(onItemChanged(QTreeWidgetItem *, int)));
513   connect(theTreeObjects, SIGNAL(itemExpanded (QTreeWidgetItem *)),
514           this, SLOT(onItemExpanded(QTreeWidgetItem *)));
515   connect(theTreeObjects, SIGNAL(itemSelectionChanged()),
516           this, SLOT(onItemSelectionChanged()));
517
518   connect(theTreeObjects->header(), SIGNAL(sectionClicked(int)),
519           this, SLOT(onHeaderClicked(int)));
520 }
521
522 //=================================================================================
523 // function : enterEvent()
524 // purpose  :
525 //=================================================================================
526 void RepairGUI_InspectObjectDlg::enterEvent (QEvent*)
527 {
528   if (!myTolFilterGrp->isEnabled())
529     ActivateThisDialog();
530 }
531
532 //=================================================================================
533 // function : checkVisibleIcon()
534 // purpose  : set visible or invisible icon in the header of tree
535 //=================================================================================
536 void RepairGUI_InspectObjectDlg::checkVisibleIcon()
537 {
538   bool isInvisible = false;
539   QTreeWidgetItemIterator it( myCurrentTreeObjects );
540   while ( *it ) {
541     TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>(*it);
542     if ( !anItem->isHidden() &&  !anItem->isVisible() ) {
543       isInvisible = true;
544       break;
545     }
546     ++it;
547   }
548
549   if ( isInvisible ) {
550     myCurrentTreeObjects->headerItem()->setIcon( 1, myInvisible );
551     myIsSelectAll = false;
552   }
553   else {
554     myCurrentTreeObjects->headerItem()->setIcon( 1, myVisible );
555     myIsSelectAll = true;
556   }
557 }
558
559 //=================================================================================
560 // function : addSubObjects()
561 // purpose  : add sub-objects to parent object in the tree
562 //=================================================================================
563 void RepairGUI_InspectObjectDlg::addSubObjects
564                     (TreeWidgetItem                   *theParentItem,
565                      const TopTools_IndexedMapOfShape &theIndices)
566 {
567   TreeWidgetItem* aMainItem = dynamic_cast<TreeWidgetItem*>( myTreeObjects->topLevelItem(0) );
568   TopoDS_Iterator it( theParentItem->getShape() );
569   for ( ; it.More(); it.Next() ) {
570     TopoDS_Shape aSubShape = it.Value();
571     int anIndex = theIndices.FindIndex(aSubShape);
572     QString anEntry = QString( "TEMP_" ) + aMainItem->getIO()->getEntry() + QString("_%1").arg( anIndex );
573     TreeWidgetItem* anItem = new TreeWidgetItem( theParentItem, QStringList(), aSubShape, anEntry);
574     anItem->setVisible( false, myInvisible );
575     addSubObjects(anItem, theIndices);
576   }
577 }
578
579 //=================================================================================
580 // function : onInitFilteredData()
581 // purpose  : add sub-objects to parent object in the filtered tree
582 //=================================================================================
583 void RepairGUI_InspectObjectDlg::onInitFilteredData()
584 {
585   TreeWidgetItem *aMainItem =
586           dynamic_cast<TreeWidgetItem*>(myFilteredTreeObjects->topLevelItem(0));
587
588   if (!aMainItem) {
589     return;
590   }
591
592   // Remove the children.
593   SALOME_ListIO           aListOfIO;
594   QTreeWidgetItemIterator it(aMainItem);
595
596   while (*it) {
597     TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>(*it);
598     if (aMainItem != anItem && (anItem->flags() & Qt::ItemIsSelectable) &&
599         anItem->isVisible() && !anItem->isHidden()) {
600       aListOfIO.Append(anItem->getIO());
601     }
602
603     ++it;
604   }
605
606   myFilteredTreeObjects->clearSelection();
607   myFilteredTreeObjects->headerItem()->setIcon(1, myInvisible);
608   getDisplayer()->Erase(aListOfIO);
609   getDisplayer()->UpdateViewer();
610
611   // Delete child items.
612   QList<QTreeWidgetItem *> aListItems = aMainItem->takeChildren();
613
614   foreach (QTreeWidgetItem *anItem, aListItems) {
615     delete anItem;
616   }
617
618   // Initialize the tree with a new list.
619   TopoDS_Shape      aShape     = aMainItem->getShape();
620   TopAbs_ShapeEnum  aShapeType = aShape.ShapeType();
621
622   myShapeTypeBtnGrp->button(TYPE_FACE)->setVisible(aShapeType < TYPE_FACE);
623   myShapeTypeBtnGrp->button(TYPE_EDGE)->setVisible(aShapeType < TYPE_EDGE);
624   myShapeTypeBtnGrp->button(TYPE_VERTEX)->setVisible(aShapeType < TYPE_VERTEX);
625
626   int anId = myShapeTypeBtnGrp->checkedId();
627
628   myMaxTol = -RealLast();
629   myMinTol =  RealLast();
630
631   if (anId != -1 && myShapeTypeBtnGrp->checkedButton()->isVisible()) {
632     // Get sub-shapes
633     TopTools_MapOfShape         aMapFence;
634     TopExp_Explorer             anExp(aShape, (TopAbs_ShapeEnum)anId);
635     TopTools_IndexedMapOfShape  anIndices;
636
637     TopExp::MapShapes(aShape, anIndices);
638
639     for (; anExp.More(); anExp.Next()) {
640       const TopoDS_Shape &aSubShape = anExp.Current();
641
642       if (aMapFence.Add(aSubShape)) {
643         // Compute tolerance
644         Standard_Real aTolerance = -1.;
645
646         switch (aSubShape.ShapeType()) {
647           case TYPE_FACE:
648             aTolerance = BRep_Tool::Tolerance(TopoDS::Face(aSubShape));
649             break;
650           case TYPE_EDGE:
651             aTolerance = BRep_Tool::Tolerance(TopoDS::Edge(aSubShape));
652             break;
653           case TYPE_VERTEX:
654             aTolerance = BRep_Tool::Tolerance(TopoDS::Vertex(aSubShape));
655             break;
656           default:
657             break;
658         }
659
660         if (aTolerance < 0.) {
661           continue;
662         }
663
664         if (aTolerance > myMaxTol) {
665           myMaxTol = aTolerance;
666         }
667
668         if (aTolerance < myMinTol) {
669           myMinTol = aTolerance;
670         }
671
672         int anIndex = anIndices.FindIndex(aSubShape);
673         QString anEntry = QString( "TEMP_" ) +
674                           aMainItem->getIO()->getEntry() +
675                           QString::number(anIndex);
676         TreeWidgetItem* anItem =
677             new TreeWidgetItem(aMainItem, QStringList(),
678                                aSubShape, anEntry, aTolerance);
679         anItem->setVisible( false, myInvisible );
680       }
681     }
682   }
683
684   // Compose names of sub-items if the main item is expanded.
685   if (aMainItem->isExpanded()) {
686     onItemExpanded(aMainItem);
687   }
688
689   myMaxTolResetBtn->setEnabled(myMaxTol >= myMinTol);
690   myMinTolResetBtn->setEnabled(myMaxTol >= myMinTol);
691
692   if (myMaxTol < myMinTol) {
693     myMinTol = DEFAULT_TOLERANCE_VALUE;
694     myMaxTol = DEFAULT_TOLERANCE_VALUE;
695     myMinTolValLabel->setText(QString::number(DEFAULT_TOLERANCE_VALUE));
696     myMaxTolValLabel->setText(QString::number(DEFAULT_TOLERANCE_VALUE));
697     myTolEdit->setValue(DEFAULT_TOLERANCE_VALUE);
698   } else {
699     myMinTolValLabel->setText(QString::number(myMinTol));
700     myMaxTolValLabel->setText(QString::number(myMaxTol));
701
702     if (GEOMUtils::CompareToleranceValues(myMinTol, myTolEdit->value()) == 1) {
703       clickOnResetToMin();
704     } else if (GEOMUtils::CompareToleranceValues
705                                          (myMaxTol, myTolEdit->value()) == -1) {
706       clickOnResetToMax();
707     } else {
708       onFilterData();
709     }
710   }
711 }
712
713 //=================================================================================
714 // function : onFilterData()
715 // purpose  : filter objects in the filtered tree
716 //=================================================================================
717 void RepairGUI_InspectObjectDlg::onFilterData()
718 {
719   TreeWidgetItem *aMainItem =
720           dynamic_cast<TreeWidgetItem*>(myFilteredTreeObjects->topLevelItem(0));
721
722   if (!aMainItem) {
723     return;
724   }
725
726   SALOME_ListIO           aListOfIOToHide;
727   QTreeWidgetItemIterator anIt(aMainItem);
728   const int               aCompValue =
729          myComparisonCompo->itemData(myComparisonCompo->currentIndex()).toInt();
730   const double            aTolValue  = myTolEdit->value();
731
732   while (*anIt) {
733     TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>(*anIt);
734
735     if (aMainItem != anItem) {
736       const bool isToFilter = !GEOMUtils::IsFitCondition
737         ((GEOMUtils::ComparisonCondition) aCompValue,
738          anItem->getTolerance(), aTolValue);
739
740       if (isToFilter && !anItem->isHidden()) {
741         if (anItem->isVisible()) {
742           aListOfIOToHide.Append(anItem->getIO());
743         }
744
745         anItem->setVisible(false, myInvisible);
746       }
747
748       anItem->setHidden(isToFilter);
749     }
750
751     ++anIt;
752   }
753
754   if (!aListOfIOToHide.IsEmpty()) {
755     getDisplayer()->Erase(aListOfIOToHide);
756     getDisplayer()->UpdateViewer();
757   }
758
759   checkVisibleIcon();
760 }
761
762 //=================================================================================
763 // function : displayItem()
764 // purpose  : display sub-object of inspected object according its tree item
765 //=================================================================================
766 void RepairGUI_InspectObjectDlg::displayItem( TreeWidgetItem* theItem )
767 {
768   GEOM_Displayer* aDisplayer = getDisplayer();
769   if ( theItem == myCurrentTreeObjects->topLevelItem(0) ) {
770     aDisplayer->UnsetColor();
771     aDisplayer->UnsetWidth();
772   }
773   else if ( aDisplayer->GetColor() != Quantity_NOC_VIOLET && aDisplayer->GetWidth() != 2.0 ) {
774     aDisplayer->SetColor( Quantity_NOC_VIOLET );
775     aDisplayer->SetWidth( 2.0 );
776   }
777
778   SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation( theItem->getShape(), theItem->getIO()->getEntry(),
779                                                             GEOM_Displayer::GetActiveView() );
780   if ( aPrs )
781     displayPreview( aPrs, true, false );
782 }
783
784 //=================================================================================
785 // function : setItemDisplayStatus()
786 // purpose  : set visible or invisible status for the same items in the tree
787 //=================================================================================
788 void RepairGUI_InspectObjectDlg::setItemDisplayStatus( TreeWidgetItem* theItem, bool theIsVisible )
789 {
790   QTreeWidgetItemIterator it( myCurrentTreeObjects );
791   while (*it) {
792     TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>(*it);
793     if ( anItem->getShape().IsSame( theItem->getShape() ) )
794       anItem->setVisible( theIsVisible, theIsVisible ? myVisible : myInvisible );
795     ++it;
796   }
797 }
798
799 //=================================================================================
800 // function : setMainObjectTransparency()
801 // purpose  : set transparency for the inspected object
802 //=================================================================================
803 void RepairGUI_InspectObjectDlg::setMainObjectTransparency( double theTransparency )
804 {
805   SUIT_ViewManager* aViewMan = myViewWindow->getViewManager();
806   SALOME_View* aView = dynamic_cast<SALOME_View*>( aViewMan->getViewModel() );
807   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myGeomGUI->getApp()->activeStudy() );
808
809   TreeWidgetItem* aMainItem = dynamic_cast<TreeWidgetItem*>( myCurrentTreeObjects->topLevelItem(0) );
810
811   if (!aMainItem) {
812     return;
813   }
814
815   aStudy->setObjectProperty( myViewWindow->getViewManager()->getGlobalId(),
816                              QString( aMainItem->getIO()->getEntry() ),
817                              GEOM::propertyName( GEOM::Transparency ), theTransparency );
818
819   if ( aView->isVisible( aMainItem->getIO() ) )
820     getDisplayer()->Redisplay( aMainItem->getIO(), true, aView );
821 }
822
823 //=================================================================================
824 // function : restoreParam()
825 // purpose  : restore initial parameters of the dialog and the viewer
826 //=================================================================================
827 void RepairGUI_InspectObjectDlg::restoreParam()
828 {
829   SUIT_ViewManager* aViewMan = myViewWindow->getViewManager();
830   SALOME_View* aView = dynamic_cast<SALOME_View*>( aViewMan->getViewModel() );
831   GEOM_Displayer* aDisplayer = getDisplayer();
832   // restore initial parameters for viewer
833   aDisplayer->UnsetColor();
834   aDisplayer->UnsetWidth();
835
836   // restore transparency of main object
837   setMainObjectTransparency( myTransparency );
838
839   // erase sub-shapes
840   TreeWidgetItem* aMainItem = dynamic_cast<TreeWidgetItem*>( myCurrentTreeObjects->topLevelItem(0) );
841   QTreeWidgetItemIterator it( myCurrentTreeObjects );
842   while (*it) {
843     if ( *it != aMainItem ) {
844       TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>(*it);
845       aDisplayer->Erase( anItem->getIO(), false, false, aView );
846       anItem->setVisible( false, myInvisible );
847     }
848     ++it;
849   }
850 }
851
852 //=================================================================================
853 // function : onEditMainShape()
854 // purpose  : called when selection button was clicked
855 //=================================================================================
856 void RepairGUI_InspectObjectDlg::onEditMainShape()
857 {
858   if ( myEditMainShape->text().isEmpty() || !myViewWindow )
859     return;
860
861   restoreParam();
862
863   // restore initial parameters for dialog box
864   myEditMainShape->setEnabled( true );
865   myEditMainShape->setText("");
866   myEditMainShape->setFocus();
867   myTreeObjects->clear();
868   myFilteredTreeObjects->clear();
869 }
870
871 //=================================================================================
872 // function : onItemClicked()
873 // purpose  : called when tree item was clicked
874 //=================================================================================
875 void RepairGUI_InspectObjectDlg::onItemClicked( QTreeWidgetItem* theItem, int theColumn )
876 {
877   if ( theColumn!= 1 || !( theItem->flags() & Qt::ItemIsSelectable ) || !myViewWindow )
878     return;
879
880   GEOM_Displayer* aDisplayer = getDisplayer();
881
882   TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>( theItem );
883
884   if ( anItem->isVisible() ) {
885     aDisplayer->Erase( anItem->getIO(), false, true );
886     setItemDisplayStatus( anItem, false );
887   }
888   else {
889     displayItem( anItem );
890     setItemDisplayStatus( anItem, true );
891   }
892   aDisplayer->UpdateViewer();
893   checkVisibleIcon();
894 }
895
896 //=================================================================================
897 // function : onItemChanged()
898 // purpose  : called when tree item was changed
899 //=================================================================================
900 void RepairGUI_InspectObjectDlg::onItemChanged( QTreeWidgetItem* theItem, int theColumn )
901 {
902   if ( theColumn!= 0 || !( theItem->flags() & Qt::ItemIsEditable ) )
903     return;
904
905   // rename the same items in the tree
906   QTreeWidgetItemIterator it( myCurrentTreeObjects );
907   while ( *it ) {
908     TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>(*it);
909     if ( anItem->getShape().IsSame( dynamic_cast<TreeWidgetItem*>( theItem )->getShape() ) )
910       anItem->setText( 0, theItem->text(0) );
911     ++it;
912   }
913 }
914
915 //=================================================================================
916 // function : onItemExpanded()
917 // purpose  : called when tree item was expanded
918 //=================================================================================
919 void RepairGUI_InspectObjectDlg::onItemExpanded( QTreeWidgetItem* theItem )
920 {
921   TreeWidgetItem* aMainItem = dynamic_cast<TreeWidgetItem*>( myCurrentTreeObjects->topLevelItem(0) );
922   GEOM::GEOM_Object_var aMainObject = GEOMBase::ConvertIOinGEOMObject( aMainItem->getIO() );
923
924   for ( int i = 0; i < theItem->childCount(); i++ ) {
925     TreeWidgetItem* aSubItem = dynamic_cast<TreeWidgetItem*>( theItem->child(i) );
926     int anIndex = GEOMBase::GetIndex( aSubItem->getShape(), aMainItem->getShape() );
927     if ( aSubItem->text(0).isEmpty() ) {
928       char* aName = aMainObject->GetSubShapeName( anIndex );
929       if ( !QString( aName ).isEmpty() )
930         aSubItem->setText( 0, QString( aName ) );
931       else
932         aSubItem->setText( 0, QString("%1_%2").arg( GEOMBase::TypeName( aSubItem->getShape().ShapeType(), true ) ).arg( anIndex ) );
933     }
934   }
935 }
936
937 //=================================================================================
938 // function : onItemSelectionChanged()
939 // purpose  : called when tree item was selected
940 //=================================================================================
941 void RepairGUI_InspectObjectDlg::onItemSelectionChanged()
942 {
943   if ( !myViewWindow )
944     return;
945
946   QList<QTreeWidgetItem*> listItem = myCurrentTreeObjects->selectedItems();
947   SALOME_ListIO aSelected;
948   for ( int i = 0; i < listItem.size(); i++ ) {
949     TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>( listItem.at(i) );
950     aSelected.Append( anItem->getIO() );
951   }
952   myGeomGUI->getApp()->selectionMgr()->setSelectedObjects( aSelected );
953 }
954
955 //=================================================================================
956 // function : onHeaderClicked()
957 // purpose  : called when header item of tree was clicked
958 //=================================================================================
959 void RepairGUI_InspectObjectDlg::onHeaderClicked( int theColumn )
960 {
961   if ( theColumn != 1 || !myViewWindow )
962     return;
963
964   GEOM_Displayer* aDisplayer = getDisplayer();
965
966   if ( myIsSelectAll ) {
967     myIsSelectAll = false;
968     myCurrentTreeObjects->headerItem()->setIcon( 1, myInvisible );
969     SALOME_ListIO aListOfIO;
970     QTreeWidgetItemIterator it( myCurrentTreeObjects );
971     while ( *it ) {
972       TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>(*it);
973       if ( !anItem->isHidden() && ( anItem->flags() & Qt::ItemIsSelectable ) &&
974           anItem->isVisible() ) {
975         aListOfIO.Append( anItem->getIO() );
976         anItem->setVisible( false, myInvisible );
977       }
978       ++it;
979     }
980     aDisplayer->Erase( aListOfIO );
981   }
982   else {
983     myIsSelectAll = true;
984     myCurrentTreeObjects->headerItem()->setIcon( 1, myVisible );
985     QTreeWidgetItemIterator it( myCurrentTreeObjects );
986     while ( *it ) {
987       TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>(*it);
988       if ( !anItem->isHidden() &&  ( anItem->flags() & Qt::ItemIsSelectable ) &&
989            !anItem->isVisible() ) {
990         displayItem( anItem );
991         anItem->setVisible( true, myVisible );
992       }
993       ++it;
994     }
995   }
996
997   aDisplayer->UpdateViewer();
998 }
999
1000 //=================================================================================
1001 // function : onViewSelectionChanged()
1002 // purpose  : called when selection of object browser was changed
1003 //=================================================================================
1004 void RepairGUI_InspectObjectDlg::onViewSelectionChanged()
1005 {
1006   if (!myEditMainShape->isEnabled())
1007     return;
1008
1009   //get shape from selection
1010   SALOME_ListIO selected;
1011   myGeomGUI->getApp()->selectionMgr()->selectedObjects(selected);
1012
1013   if ( selected.Extent() != 1 )
1014     return;
1015
1016   if ( !myViewWindow ) {
1017     SUIT_ViewManager* occVm = myGeomGUI->getApp()->getViewManager( OCCViewer_Viewer::Type(), true );
1018     myViewWindow = occVm->getActiveView();
1019     connect( occVm, SIGNAL( deleteView( SUIT_ViewWindow* ) ),
1020              this, SLOT( onCloseView( SUIT_ViewWindow* ) ), Qt::UniqueConnection );
1021   }
1022
1023   TopoDS_Shape aShape = GEOMBase::GetTopoFromSelection( selected );
1024   if ( aShape.IsNull() )
1025     return;
1026
1027   Handle(SALOME_InteractiveObject) anIO = selected.First();
1028   GEOM::GEOM_Object_var anObject = GEOMBase::ConvertIOinGEOMObject( anIO );
1029   QString aName = anObject->GetName();
1030   CORBA::String_var anEntry = anObject->GetStudyEntry();
1031
1032   myEditMainShape->setText( aName );
1033   myEditMainShape->setEnabled( false );
1034
1035   // remember initial transparency value
1036   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myGeomGUI->getApp()->activeStudy() );
1037   QVariant v = aStudy->getObjectProperty( myViewWindow->getViewManager()->getGlobalId(),
1038                                           QString( anEntry.in() ),
1039                                           GEOM::propertyName( GEOM::Transparency ), myTransparency );
1040   if ( v.canConvert( QVariant::Double ) )
1041     myTransparency = v.toDouble();
1042
1043   TreeWidgetItem* anItem         = new TreeWidgetItem
1044               (myTreeObjects, QStringList() << aName, aShape, anIO);
1045   TreeWidgetItem* anItemFiltered = new TreeWidgetItem
1046               (myFilteredTreeObjects, QStringList() << aName, aShape, anIO);
1047
1048   if ( getDisplayer()->IsDisplayed( anEntry.in() ) ) {
1049     anItem->setVisible( true, myVisible );
1050     anItemFiltered->setVisible( true, myVisible );
1051   } else {
1052     anItem->setVisible( false, myInvisible );
1053     anItemFiltered->setVisible( false, myInvisible );
1054   }
1055
1056   setMainObjectTransparency( 0.5 );
1057
1058   // add sub-objects in the tree
1059   TopTools_IndexedMapOfShape anIndices;
1060
1061   TopExp::MapShapes(aShape, anIndices);
1062   addSubObjects(anItem, anIndices);
1063   onInitFilteredData();
1064   updateViewer(false);
1065
1066   // check icon for tree header
1067   checkVisibleIcon();
1068 }
1069
1070 //=================================================================================
1071 // function : onWindowActivated()
1072 // purpose  : called when other window was activated
1073 //=================================================================================
1074 void RepairGUI_InspectObjectDlg::onWindowActivated( SUIT_ViewWindow* theViewWindow )
1075 {
1076   if ( myViewWindow )
1077     restoreParam();
1078
1079   connect( theViewWindow->getViewManager(), SIGNAL( deleteView( SUIT_ViewWindow* ) ),
1080            this, SLOT( onCloseView( SUIT_ViewWindow* ) ), Qt::UniqueConnection );
1081
1082   if ( theViewWindow->getViewManager()->getType() != OCCViewer_Viewer::Type() &&
1083        theViewWindow->getViewManager()->getType() != SVTK_Viewer::Type() ) {
1084     myViewWindow = 0;
1085     return;
1086   }
1087   myViewWindow = theViewWindow;
1088
1089   if ( myCurrentTreeObjects->topLevelItemCount() > 0 ) {
1090     setMainObjectTransparency( 0.5 );
1091     TreeWidgetItem* aMainItem = dynamic_cast<TreeWidgetItem*>( myCurrentTreeObjects->topLevelItem(0) );
1092     if ( getDisplayer()->IsDisplayed( aMainItem->getIO()->getEntry() ) )
1093       aMainItem->setVisible( true, myVisible );
1094     else
1095       aMainItem->setVisible( false, myInvisible );
1096   }
1097   checkVisibleIcon();
1098 }
1099
1100 //=================================================================================
1101 // function : onCloseView()
1102 // purpose  : called when last view was closed
1103 //=================================================================================
1104 void RepairGUI_InspectObjectDlg::onCloseView( SUIT_ViewWindow* )
1105 {
1106   if ( myGeomGUI->getApp()->desktop()->windows().size() == 0 ) {
1107     restoreParam();
1108     myViewWindow = 0;
1109   }
1110 }
1111
1112 //=================================================================================
1113 // function : clickOnShow()
1114 // purpose  : called when "Show selected" button was clicked
1115 //=================================================================================
1116 void RepairGUI_InspectObjectDlg::clickOnShow()
1117 {
1118   if ( !myViewWindow )
1119     return;
1120
1121   QList<QTreeWidgetItem*> listItem = myCurrentTreeObjects->selectedItems();
1122   for ( int i = 0; i < listItem.size(); i++ ) {
1123     TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>( listItem.at(i) );
1124     if ( !anItem->isVisible() ) {
1125       displayItem( anItem );
1126       setItemDisplayStatus( anItem, true );
1127     }
1128   }
1129   getDisplayer()->UpdateViewer();
1130   checkVisibleIcon();
1131 }
1132
1133 //=================================================================================
1134 // function : clickOnShowOnly()
1135 // purpose  : called when "Show only selected" button was clicked
1136 //=================================================================================
1137 void RepairGUI_InspectObjectDlg::clickOnShowOnly()
1138 {
1139   if ( !myViewWindow )
1140     return;
1141
1142   SALOME_ListIO aListOfIO;
1143   QTreeWidgetItemIterator it( myCurrentTreeObjects );
1144   while ( *it ) {
1145     TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>(*it);
1146     if ( !anItem->isHidden() && ( anItem->flags() & Qt::ItemIsSelectable ) &&
1147          anItem->isVisible() ) {
1148       aListOfIO.Append( anItem->getIO() );
1149       anItem->setVisible( false, myInvisible );
1150     }
1151     ++it;
1152   }
1153   getDisplayer()->Erase( aListOfIO );
1154
1155   clickOnShow();
1156 }
1157
1158 //=================================================================================
1159 // function : clickOnHide()
1160 // purpose  : called when "Hide selected" button was clicked
1161 //=================================================================================
1162 void RepairGUI_InspectObjectDlg::clickOnHide()
1163 {
1164   if ( !myViewWindow )
1165     return;
1166
1167   QList<QTreeWidgetItem*> listItem = myCurrentTreeObjects->selectedItems();
1168   for ( int i = 0; i < listItem.size(); i++ ) {
1169     TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>( listItem.at(i) );
1170     if ( anItem->isVisible() ) {
1171       getDisplayer()->Erase( anItem->getIO(), false, false );
1172       setItemDisplayStatus( anItem, false );
1173     }
1174   }
1175   getDisplayer()->UpdateViewer();
1176   checkVisibleIcon();
1177 }
1178
1179 //=================================================================================
1180 // function : clickOnPublish()
1181 // purpose  : called when "Publish selected" button was clicked
1182 //=================================================================================
1183 void RepairGUI_InspectObjectDlg::clickOnPublish()
1184 {
1185   _PTR(Study) studyDS = dynamic_cast<SalomeApp_Study*>( myGeomGUI->getApp()->activeStudy() )->studyDS();
1186
1187   // find main object
1188   TreeWidgetItem* aMainItem = dynamic_cast<TreeWidgetItem*>( myCurrentTreeObjects->topLevelItem(0) );
1189
1190   if (!aMainItem) {
1191     return;
1192   }
1193
1194   GEOM::GEOM_Object_var aMainObject = GEOMBase::ConvertIOinGEOMObject( aMainItem->getIO() );
1195
1196   // find unique indices of selected objects
1197   QList<QTreeWidgetItem*> selectedItems = myCurrentTreeObjects->selectedItems();
1198   QMap< int, QString > anIndices;
1199   GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
1200   anArray->length( selectedItems.size() );
1201   int j = 0;
1202   for ( int i = 0; i < selectedItems.size(); i++ ) {
1203     TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>( selectedItems.at(i) );
1204     int anIndex = GEOMBase::GetIndex( anItem->getShape(), aMainItem->getShape() );
1205     if ( anIndices.find( anIndex ) == anIndices.end() &&
1206         anItem != aMainItem ) {
1207       anIndices[ anIndex ] = anItem->text(0);
1208       anArray[j++] = anIndex;
1209     }
1210   }
1211   anArray->length(j);
1212
1213   // get selected sub-shapes
1214   GEOM::GEOM_IShapesOperations_var anOper = getGeomEngine()->GetIShapesOperations( getStudyId() );
1215   GEOM::ListOfGO_var aList = anOper->MakeSubShapes( aMainObject, anArray );
1216
1217   // publish sub-shapes
1218   for ( int i = 0; i < aList->length(); i++ )
1219     GeometryGUI::GetGeomGen()->AddInStudy( GeometryGUI::ClientStudyToStudy( studyDS ), aList[i],
1220                                            anIndices.values().at(i).toStdString().c_str(), aMainObject );
1221
1222   updateObjBrowser();
1223 }
1224
1225 //=================================================================================
1226 // function : clickOnHelp()
1227 // purpose  : called when Help button was clicked to open a help page
1228 //=================================================================================
1229 void RepairGUI_InspectObjectDlg::clickOnHelp()
1230 {
1231   myGeomGUI->getApp()->onHelpContextModule( "GEOM", "inspect_object_operation_page.html" );
1232 }
1233
1234 //=================================================================================
1235 // function : clickOnResetToMin()
1236 // purpose  : called when Reset button was clicked to reset tolerance filter to minimal value.
1237 //=================================================================================
1238 void RepairGUI_InspectObjectDlg::clickOnResetToMin()
1239 {
1240   if (myMinTol >= myTolEdit->minimum() && myMinTol <= myTolEdit->maximum()) {
1241     myTolEdit->setValue(myMinTol);
1242   }
1243 }
1244
1245 //=================================================================================
1246 // function : clickOnResetToMax()
1247 // purpose  : called when Reset button was clicked to reset tolerance filter to maximal value.
1248 //=================================================================================
1249 void RepairGUI_InspectObjectDlg::clickOnResetToMax()
1250 {
1251   if (myMaxTol >= myTolEdit->minimum() && myMaxTol <= myTolEdit->maximum()) {
1252     myTolEdit->setValue(myMaxTol);
1253   }
1254 }
1255
1256 //=================================================================================
1257 // function : clickOnShowAll()
1258 // purpose  : called when Help button was clicked to show all shapes
1259 //=================================================================================
1260 void RepairGUI_InspectObjectDlg::clickOnShowAll()
1261 {
1262   myIsSelectAll = false;
1263   onHeaderClicked(1);
1264 }
1265
1266 //=================================================================================
1267 // function : clickOnHideAll()
1268 // purpose  : called when Help button was clicked to hide all shapes
1269 //=================================================================================
1270 void RepairGUI_InspectObjectDlg::clickOnHideAll()
1271 {
1272   myIsSelectAll = true;
1273   onHeaderClicked(1);
1274 }
1275
1276 //=================================================================================
1277 // function : DeactivateActiveDialog()
1278 // purpose  :
1279 //=================================================================================
1280 void RepairGUI_InspectObjectDlg::DeactivateActiveDialog()
1281 {
1282   setEnabled(false);
1283   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
1284   myGeomGUI->SetActiveDialogBox(0);
1285   globalSelection();
1286   erasePreview();
1287 }
1288
1289 //=================================================================================
1290 // function : ActivateThisDialog()
1291 // purpose  :
1292 //=================================================================================
1293 void RepairGUI_InspectObjectDlg::ActivateThisDialog()
1294 {
1295   /* Emit a signal to deactivate the active dialog */
1296   myGeomGUI->EmitSignalDeactivateDialog();
1297   setEnabled(true);
1298   myGeomGUI->SetActiveDialogBox( (QDialog*)this );
1299
1300   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
1301           this, SLOT(onViewSelectionChanged()));
1302
1303   updateViewer(false);
1304 }
1305
1306 //=================================================================================
1307 // function : onFilterToggled()
1308 // purpose  :
1309 //=================================================================================
1310 void RepairGUI_InspectObjectDlg::onFilterToggled(bool isOn)
1311 {
1312   if (isOn) {
1313     myCurrentTreeObjects = myFilteredTreeObjects;
1314     myTreesLayout->setCurrentIndex(1);
1315   } else {
1316     myCurrentTreeObjects = myTreeObjects;
1317     myTreesLayout->setCurrentIndex(0);
1318   }
1319
1320   updateViewer(true);
1321 }
1322
1323 //=================================================================================
1324 // function : updateViewer()
1325 // purpose  :
1326 //=================================================================================
1327 void RepairGUI_InspectObjectDlg::updateViewer(const bool theIsHideOtherTree)
1328 {
1329   GEOM_Displayer *aDisplayer  = getDisplayer();
1330
1331   if (theIsHideOtherTree) {
1332     QTreeWidget    *aTreeToHide = myCurrentTreeObjects == myTreeObjects ?
1333                                           myFilteredTreeObjects: myTreeObjects;
1334
1335     // Hide the objects of disappeared tree, do not switch off flags.
1336     SALOME_ListIO           aListOfIO;
1337     QTreeWidgetItemIterator it(aTreeToHide);
1338
1339     while (*it) {
1340       TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>(*it);
1341       if ((anItem->flags() & Qt::ItemIsSelectable) &&
1342           anItem->isVisible() && !anItem->isHidden()) {
1343         aListOfIO.Append(anItem->getIO());
1344       }
1345
1346       ++it;
1347     }
1348
1349     aDisplayer->Erase(aListOfIO);
1350   }
1351
1352   // Show the objects that are marked as shown in the appeared tree.
1353   QTreeWidgetItemIterator it2(myCurrentTreeObjects);
1354
1355   while (*it2) {
1356     TreeWidgetItem* anItem = dynamic_cast<TreeWidgetItem*>(*it2);
1357     if ((anItem->flags() & Qt::ItemIsSelectable) &&
1358         anItem->isVisible() && !anItem->isHidden()) {
1359       displayItem(anItem);
1360     }
1361
1362     ++it2;
1363   }
1364
1365   aDisplayer->UpdateViewer();
1366 }