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