]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMToolsGUI/GEOMToolsGUI_ReduceStudyDlg.cxx
Salome HOME
Implementation of 'Unpublish' and 'Remove' options functionality.
[modules/geom.git] / src / GEOMToolsGUI / GEOMToolsGUI_ReduceStudyDlg.cxx
1 // Copyright (C) 2014  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 #include "GEOMToolsGUI_ReduceStudyDlg.h"
21
22 #include <QVBoxLayout>
23 #include <QHBoxLayout>
24 #include <QGroupBox>
25 #include <QGridLayout>
26 #include <QHeaderView>
27 #include <QPushButton>
28 #include <QRadioButton>
29
30
31 // GUI includes
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SUIT_DataOwner.h>
35 #include <SalomeApp_Application.h>
36 #include <SalomeApp_Study.h>
37 #include <OCCViewer_ViewManager.h>
38 #include <LightApp_DataOwner.h>
39 #include <GEOMToolsGUI.h>
40
41 // GEOM includes
42 #include <SALOMEconfig.h>
43 #include CORBA_CLIENT_HEADER(GEOM_Gen)
44 #include <GEOMBase_Helper.h>
45
46 #include <LightApp_SelectionMgr.h>
47 #include <SALOME_ListIteratorOfListIO.hxx>
48
49 // GEOM includes
50 #include <GEOMBase.h>
51
52 #include <iostream>
53
54 GEOMToolsGUI_ReduceStudyDlg::GEOMToolsGUI_ReduceStudyDlg( QWidget* parent )
55 :QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
56 myDisplayer(NULL)
57 {
58   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
59   myVisible = QIcon( resMgr->loadPixmap( "SUIT", tr( "ICON_DATAOBJ_VISIBLE" ) ) );
60   myInvisible = QIcon( resMgr->loadPixmap( "SUIT", tr( "ICON_DATAOBJ_INVISIBLE" ) ) );
61
62   myApp = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
63   if ( !myApp ) return;
64   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
65   myStudy = GeometryGUI::ClientStudyToStudy( study->studyDS() );
66   myDisplayer = GEOM_Displayer( study );
67
68   setWindowTitle( tr( "GEOM_REDUCE_STUDY_TITLE" ) );
69   setAttribute(Qt::WA_DeleteOnClose);
70
71   QGridLayout* topLayout = new QGridLayout( this );
72   topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
73
74   /**********************   Objects to be kept    **********************/
75   QGroupBox* groupKeptObjects = new QGroupBox( tr( "GEOM_REDUCE_STUDY_KEPT_OBJECTS" ) );
76   QGridLayout* layoutKeptObjects = new QGridLayout( groupKeptObjects );
77   createTreeWidget( myTreeKeptObjects = new QTreeWidget() );
78   layoutKeptObjects->addWidget( myTreeKeptObjects );
79
80   /**********************  Objects to be removed  **********************/
81   QGroupBox* groupRemoveObjects = new QGroupBox( tr( "GEOM_REDUCE_STUDY_REMOVE_OBJECTS" ) );
82   QGridLayout* layoutRemoveObjects = new QGridLayout( groupRemoveObjects );
83   createTreeWidget( myTreeRemoveObjects = new QTreeWidget() );
84   layoutRemoveObjects->addWidget( myTreeRemoveObjects );
85
86   /**********************         Options         **********************/
87   QGroupBox* groupOptions = new QGroupBox( tr( "GEOM_REDUCE_STUDY_OPTIONS" ) );
88   QVBoxLayout* layoutOptions = new QVBoxLayout( groupOptions );
89
90   // Intermidiate objects
91   QGroupBox* groupIntermediates = createButtonGroup( myGroupIntermediates = new QButtonGroup() );
92   groupIntermediates->setTitle( tr( "GEOM_REDUCE_STUDY_INTERMEDIATES" ) );
93
94   // Sub-objects
95   QGroupBox* groupSubObjects = createButtonGroup( myGroupSubObjects = new QButtonGroup() );
96   groupSubObjects->setTitle( tr( "GEOM_REDUCE_STUDY_SUB_OBJECTS" ) );
97
98   // Others
99   myCBRemoveEmptyFolder = new QCheckBox( tr( "GEOM_REDUCE_STUDY_REMOVE_EMPTY_FOLDER" ) );
100   myCBRemoveEmptyFolder->setChecked( true );
101   myCBSoftRemoval = new QCheckBox( tr( "GEOM_REDUCE_STUDY_SOFT_REMOVAL" ) );
102
103   layoutOptions->addWidget( groupIntermediates );
104   layoutOptions->addWidget( groupSubObjects );
105   layoutOptions->addWidget( myCBRemoveEmptyFolder );
106   layoutOptions->addWidget( myCBSoftRemoval );
107
108   /**********************         Buttons         **********************/
109   QGroupBox* groupButtons = new QGroupBox();
110   QHBoxLayout* layoutButtons = new QHBoxLayout( groupButtons );
111
112   QPushButton* buttonOk = new QPushButton( tr( "GEOM_BUT_OK" ) );
113   QPushButton* buttonCancel = new QPushButton( tr( "GEOM_BUT_CANCEL" ) );
114   QPushButton* buttonHelp = new QPushButton( tr( "GEOM_BUT_HELP" ) );
115
116   layoutButtons->addWidget( buttonOk );
117   layoutButtons->addStretch();
118   layoutButtons->addWidget( buttonCancel );
119   layoutButtons->addWidget( buttonHelp );
120
121   topLayout->addWidget( groupKeptObjects, 0, 0 );
122   topLayout->addWidget( groupRemoveObjects, 0, 1 );
123   topLayout->addWidget( groupOptions, 1, 0, 1, 2 );
124   topLayout->addWidget( groupButtons, 2, 0, 1, 2 );
125
126   // Signals and slots connections
127
128   connect( myTreeKeptObjects, SIGNAL( itemClicked( QTreeWidgetItem*, int) ), this, SLOT( onItemClicked( QTreeWidgetItem*, int ) ) );
129   connect( myTreeRemoveObjects, SIGNAL( itemClicked( QTreeWidgetItem*, int) ), this, SLOT( onItemClicked( QTreeWidgetItem*, int ) ) );
130   connect( myTreeKeptObjects->header(), SIGNAL( sectionClicked ( int ) ), this, SLOT( onHeaderClicked( int ) ) );
131   connect( myTreeRemoveObjects->header(), SIGNAL( sectionClicked ( int ) ), this, SLOT( onHeaderClicked( int ) ) );
132
133   connect( myGroupIntermediates, SIGNAL( buttonClicked( int ) ), this, SLOT( update() ) );
134   connect( myGroupSubObjects, SIGNAL( buttonClicked( int ) ), this, SLOT( update() ) );
135
136   connect( buttonOk, SIGNAL( clicked() ), this, SLOT( clickOnOk() ) );
137   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
138   connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( clickOnHelp() ) );
139
140   connect( myApp->selectionMgr(), SIGNAL( currentSelectionChanged() ),
141            this, SLOT( selectionChanged() ) );
142
143   init( getSelectedObjects() );
144 }
145
146 GEOMToolsGUI_ReduceStudyDlg::~GEOMToolsGUI_ReduceStudyDlg()
147 {
148   // no need to delete child widgets, Qt does it all for us
149 }
150
151 void GEOMToolsGUI_ReduceStudyDlg::init( const std::set<std::string>& theObjectEntries )
152 {
153   myMainEntries.clear();
154
155   myKeptObjects.clear();
156   myListParents.clear();
157   myListSubObjects.clear();
158   myRemovedObjects.clear();
159
160   myMainEntries = theObjectEntries;
161
162   GEOM::string_array_var keptObjects = new GEOM::string_array();
163   int It = 0;
164   keptObjects->length( theObjectEntries.size() );
165   std::set<std::string>::iterator iter;
166   for( iter=theObjectEntries.begin(); iter!=theObjectEntries.end(); ++iter, It++ )
167     keptObjects[ It ] = (*iter).c_str();
168
169   GEOM::string_array_var parentsObjects = new GEOM::string_array();
170   GEOM::string_array_var subObjects = new GEOM::string_array();
171   GEOM::string_array_var otherObjects = new GEOM::string_array();
172
173   GeometryGUI::GetGeomGen()->GetEntriesToCleanStudy( myStudy, keptObjects, parentsObjects,
174                                                              subObjects, otherObjects );
175
176   for ( int i = 0; i < keptObjects->length(); i++ )
177     myKeptObjects.insert( keptObjects[i].in() );
178   for( int i = 0; i< otherObjects->length(); i++ )
179     myRemovedObjects.insert( otherObjects[i].in() );
180   for( int i = 0; i< parentsObjects->length(); i++ )
181     myListParents.insert( parentsObjects[i].in() );
182   for( int i = 0; i< subObjects->length(); i++ )
183     myListSubObjects.insert( subObjects[i].in() );
184
185   update();
186
187   checkVisibleIcon( myTreeKeptObjects );
188   checkVisibleIcon( myTreeRemoveObjects );
189 }
190
191 std::set<std::string> GEOMToolsGUI_ReduceStudyDlg::getSelectedObjects() const
192 {
193   std::set<std::string> objects;
194
195   SALOME_ListIO selected;
196   myApp->selectionMgr()->selectedObjects( selected );
197
198   for( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
199     Handle( SALOME_InteractiveObject ) io = It.Value();
200     if( !io->hasEntry() )
201       continue;
202     GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_nil();
203     geomObject = GEOMBase::ConvertIOinGEOMObject( io );
204     if( geomObject->_is_nil() )
205       continue;
206     QString entry = geomObject->GetEntry();
207     objects.insert( entry.toStdString().c_str() );
208   }
209   return objects;
210 }
211
212 void GEOMToolsGUI_ReduceStudyDlg::createTreeWidget( QTreeWidget* theTreeWidget )
213 {
214   theTreeWidget->setColumnCount( 2 );
215   QStringList columnNames;
216   columnNames.append(tr( "GEOM_REDUCE_STUDY_NAME" ));
217   columnNames.append("");
218   theTreeWidget->setHeaderLabels( columnNames );
219   QTreeWidgetItem * headerItem = new QTreeWidgetItem( columnNames );
220   theTreeWidget->setHeaderItem ( headerItem );
221   theTreeWidget->header()->moveSection( 1, 0 );
222   theTreeWidget->header()->setClickable( true );
223   theTreeWidget->header()->setMovable( false );
224   theTreeWidget->header()->setResizeMode( 1, QHeaderView::ResizeToContents );
225   theTreeWidget->setSelectionMode( QAbstractItemView::ExtendedSelection );
226 }
227
228 QGroupBox* GEOMToolsGUI_ReduceStudyDlg::createButtonGroup( QButtonGroup* theButtonGroup )
229 {
230   QGroupBox* groupObjects = new QGroupBox();
231   QHBoxLayout* layoutObjects = new QHBoxLayout( groupObjects );
232
233   QRadioButton* buttonKeep = new QRadioButton( tr( "GEOM_REDUCE_STUDY_KEEP") );
234   theButtonGroup->addButton( buttonKeep, 0 );
235   QRadioButton* buttonUnpublish = new QRadioButton( tr( "GEOM_REDUCE_STUDY_UNPUBLISH") );
236   theButtonGroup->addButton( buttonUnpublish, 1 );
237   QRadioButton* buttonRemove = new QRadioButton( tr( "GEOM_REDUCE_STUDY_REMOVE") );
238   theButtonGroup->addButton( buttonRemove, 2 );
239
240   theButtonGroup->button( 0 )->setChecked( true );
241   theButtonGroup->setExclusive( true );
242
243   layoutObjects->addWidget( buttonKeep );
244   layoutObjects->addWidget( buttonUnpublish );
245   layoutObjects->addWidget( buttonRemove );
246
247   return groupObjects;
248 }
249
250 void GEOMToolsGUI_ReduceStudyDlg::addObjectsToTree( QTreeWidget* theWidget, std::set<std::string>& theObjects )
251 {
252   std::set<std::string>::iterator it;
253   for( it = theObjects.begin(); it != theObjects.end(); ++it ) {
254     std::string objectEntry = *it;
255     GEOM::GEOM_BaseObject_var GeomBaseObject = GeometryGUI::GetGeomGen()->GetObject( myStudy->StudyId(), objectEntry.c_str() );
256     GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
257     QString studyEntry = GeomBaseObject->GetStudyEntry();
258     if( GeomObject->_is_nil() || studyEntry.isEmpty() )
259       continue;
260     addSubObject( theWidget, theObjects, GeomObject );
261   }
262 }
263
264 GEOMToolsGUI_TreeWidgetItem* GEOMToolsGUI_ReduceStudyDlg::addSubObject( QTreeWidget* theWidget,
265                                                                         std::set<std::string>& theObjects,
266                                                                         GEOM::GEOM_Object_var theObject )
267 {
268   GEOMToolsGUI_TreeWidgetItem* item;
269   if( !theObject->IsMainShape() ) {
270     GEOMToolsGUI_TreeWidgetItem* parentItem = addSubObject( theWidget, theObjects, theObject->GetMainShape() );
271     item = findObjectInTree( theWidget, theObject );
272     if( !item )
273       item = new GEOMToolsGUI_TreeWidgetItem( parentItem, QStringList() << theObject->GetName(), theObject->GetStudyEntry() );
274   }
275   else {
276     item = findObjectInTree( theWidget, theObject );
277     if( !item )
278       item = new GEOMToolsGUI_TreeWidgetItem( theWidget, QStringList() << theObject->GetName(), theObject->GetStudyEntry() );
279   }
280
281   bool isDisplayed = false;
282   if( theObjects.find( theObject->GetEntry() ) != theObjects.end() ) {
283     isDisplayed = myDisplayer.IsDisplayed( theObject->GetStudyEntry() );
284     if ( isDisplayed )
285       item->setVisible( true, myVisible );
286     else
287       item->setVisible( false, myInvisible );
288
289     if( myMainEntries.find( theObject->GetEntry() ) != myMainEntries.end() ) {
290       QFont Textfont = item->font(0);
291       Textfont.setBold( true );
292       item->setFont( 0, Textfont );
293     }
294   }
295   else {
296     item->setFlags( item->flags() & ~Qt::ItemIsSelectable );
297     item->setTextColor( 0, QColor( 150, 150, 150 ) );
298   }
299   return item;
300 }
301
302 GEOMToolsGUI_TreeWidgetItem* GEOMToolsGUI_ReduceStudyDlg::findObjectInTree( QTreeWidget* theWidget, GEOM::GEOM_Object_var theObject )
303 {
304   QTreeWidgetItemIterator it( theWidget );
305   while(*it) {
306     GEOMToolsGUI_TreeWidgetItem* item = dynamic_cast<GEOMToolsGUI_TreeWidgetItem*>(*it);
307     if( QString( item->getStudyEntry() ) == QString( theObject->GetStudyEntry() ) )
308       return item;
309     ++it;
310   }
311   return NULL;
312 }
313
314 void GEOMToolsGUI_ReduceStudyDlg::checkVisibleIcon( QTreeWidget* theWidget )
315 {
316   bool isInvisible = false;
317   QTreeWidgetItemIterator it( theWidget );
318   while(*it) {
319     GEOMToolsGUI_TreeWidgetItem* item = dynamic_cast<GEOMToolsGUI_TreeWidgetItem*>(*it);
320     const char* entry = item->getStudyEntry();
321     if( item->flags() & Qt::ItemIsSelectable )
322       if( !item->isVisible() )
323         isInvisible = true;
324     ++it;
325   }
326
327   if( isInvisible ) {
328     theWidget->headerItem()->setIcon( 1, myInvisible );
329     myMapTreeSelectAll[ theWidget ] = false;
330   }
331   else {
332     theWidget->headerItem()->setIcon( 1, myVisible );
333     myMapTreeSelectAll[ theWidget ] = true;
334   }
335 }
336
337 void GEOMToolsGUI_ReduceStudyDlg::unpublishObjects( std::set<std::string>& theObjects )
338 {
339   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
340   _PTR(Study) aStudy = appStudy->studyDS();
341   _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
342   std::string objectEntry, studyEntry;
343   std::set<std::string>::iterator it;
344   for( it = theObjects.begin(); it != theObjects.end(); ++it ) {
345     objectEntry = *it;
346     GEOM::GEOM_BaseObject_var GeomBaseObject = GeometryGUI::GetGeomGen()->GetObject( aStudy->StudyId(), objectEntry.c_str() );
347     studyEntry = GeomBaseObject->GetStudyEntry();
348     if ( studyEntry == "" )
349       continue;
350     _PTR(SObject) obj ( aStudy->FindObjectID( studyEntry.c_str() ) );
351     _PTR(GenericAttribute) anAttr;
352     if ( obj ) {
353       _PTR(AttributeDrawable) aDrw = aStudyBuilder->FindOrCreateAttribute( obj, "AttributeDrawable" );
354       aDrw->SetDrawable( false );
355       myDisplayer.EraseWithChildren( new SALOME_InteractiveObject( studyEntry.c_str(), "GEOM", "TEMP_IO" ) );
356     } // if ( obj )
357   } // iterator
358
359   myApp->updateObjectBrowser( false );
360   myApp->updateActions();
361 }
362
363 void GEOMToolsGUI_ReduceStudyDlg::removeObjects( std::set<std::string>& theObjects )
364 {
365   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
366   _PTR(Study) aStudy = appStudy->studyDS();
367   _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
368   _PTR(UseCaseBuilder) aUseCaseBuilder = aStudy->GetUseCaseBuilder();
369   std::string objectEntry, studyEntry;
370   std::set<std::string>::iterator it;
371   for( it = theObjects.begin(); it != theObjects.end(); ++it ) {
372     objectEntry = *it;
373     GEOM::GEOM_BaseObject_var GeomBaseObject = GeometryGUI::GetGeomGen()->GetObject( aStudy->StudyId(), objectEntry.c_str() );
374     studyEntry = GeomBaseObject->GetStudyEntry();
375     if ( studyEntry == "" )
376       continue;
377     _PTR(SObject) obj ( aStudy->FindObjectID( studyEntry.c_str() ) );
378     if ( obj ) {
379       //Remove visual properties of the object
380       appStudy->removeObjectFromAll(obj->GetID().c_str());
381       // remove objects from study
382       aStudyBuilder->RemoveObjectWithChildren( obj );
383       // remove object from use case tree
384       aUseCaseBuilder->Remove( obj );
385       myDisplayer.EraseWithChildren( new SALOME_InteractiveObject( studyEntry.c_str(), "GEOM", "TEMP_IO" ) );
386     } // if ( obj )
387   } // iterator
388
389   myApp->updateObjectBrowser( false );
390   myApp->updateActions();
391 }
392
393 //=================================================================================
394 // function : onItemClicked()
395 // purpose  : Called then treeItem clicked
396 //=================================================================================
397 void GEOMToolsGUI_ReduceStudyDlg::onItemClicked( QTreeWidgetItem* theItem, int theColumn )
398 {
399   if( theColumn != 1 || !( theItem->flags() & Qt::ItemIsSelectable ) )
400     return;
401
402   GEOMToolsGUI_TreeWidgetItem* item = dynamic_cast<GEOMToolsGUI_TreeWidgetItem*>( theItem );
403
404   const char* entry = item->getStudyEntry();
405   Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry, "GEOM", "TEMP_IO" );
406   if( myDisplayer.IsDisplayed( entry ) ) {
407     item->setVisible( false, myInvisible );
408     myDisplayer.Erase( io );
409   }
410   else {
411     item->setVisible( true, myVisible );
412     myDisplayer.Display( io );
413   }
414   myDisplayer.UpdateViewer();
415   checkVisibleIcon( item->treeWidget() );
416 }
417
418 void GEOMToolsGUI_ReduceStudyDlg::onHeaderClicked( int theColumn )
419 {
420   if( theColumn != 1 )
421     return;
422
423   QTreeWidget* treeWidget = dynamic_cast<QTreeWidget*>(sender()->parent());
424   if( myMapTreeSelectAll[ treeWidget ] ) {
425     myMapTreeSelectAll[ treeWidget ] = false;
426     treeWidget->headerItem()->setIcon( 1, myInvisible );
427     QTreeWidgetItemIterator it( treeWidget );
428     while(*it) {
429       GEOMToolsGUI_TreeWidgetItem* item = dynamic_cast<GEOMToolsGUI_TreeWidgetItem*>(*it);
430       if( ( item->flags() & Qt::ItemIsSelectable ) && item->isVisible() ) {
431         const char* entry = item->getStudyEntry();
432         item->setVisible( false, myInvisible );
433         myDisplayer.Erase( new SALOME_InteractiveObject( entry, "GEOM", "TEMP_IO" ) );
434       }
435       ++it;
436     }
437   }
438   else {
439     myMapTreeSelectAll[ treeWidget ] = true;
440     treeWidget->headerItem()->setIcon( 1, myVisible );
441     QTreeWidgetItemIterator it( treeWidget );
442     while(*it) {
443       GEOMToolsGUI_TreeWidgetItem* item = dynamic_cast<GEOMToolsGUI_TreeWidgetItem*>(*it);
444       if( ( item->flags() & Qt::ItemIsSelectable ) && !item->isVisible() ) {
445         const char* entry = item->getStudyEntry();
446         item->setVisible( true, myVisible );
447         myDisplayer.Display( new SALOME_InteractiveObject( entry, "GEOM", "TEMP_IO" ) );
448       }
449       ++it;
450     }
451   }
452   myDisplayer.UpdateViewer();
453 }
454
455 void GEOMToolsGUI_ReduceStudyDlg::selectionChanged()
456 {
457   init( getSelectedObjects() );
458 }
459
460 void GEOMToolsGUI_ReduceStudyDlg::update()
461 {
462   myTreeKeptObjects->clear();
463   myTreeRemoveObjects->clear();
464
465   std::set<std::string> keptObjects( myKeptObjects );
466   std::set<std::string> removeObjects( myRemovedObjects );
467
468   // Intermediate objects
469   if( myGroupIntermediates->checkedId() == 2 ) { // remove
470     std::set<std::string>::iterator iter;
471     for( iter=myListParents.begin(); iter!=myListParents.end(); ++iter)
472       removeObjects.insert( *iter );
473   }
474   else { // keep or unpublish
475     std::set<std::string>::iterator iter;
476     for( iter=myListParents.begin(); iter!=myListParents.end(); ++iter)
477       keptObjects.insert( *iter );
478   }
479
480   // Sub-objects
481   if( myGroupSubObjects->checkedId() == 2 ) {
482     std::set<std::string>::iterator iter;
483     for( iter=myListSubObjects.begin(); iter!=myListSubObjects.end(); ++iter)
484       removeObjects.insert( *iter );
485   }
486   else {
487     std::set<std::string>::iterator iter;
488     for( iter=myListSubObjects.begin(); iter!=myListSubObjects.end(); ++iter)
489       keptObjects.insert( *iter );
490   }
491
492   addObjectsToTree( myTreeKeptObjects, keptObjects );
493   addObjectsToTree( myTreeRemoveObjects, removeObjects );
494
495   myTreeKeptObjects->collapseAll();
496   myTreeRemoveObjects->collapseAll();
497
498 }
499
500 void GEOMToolsGUI_ReduceStudyDlg::clickOnOk()
501 {
502   std::set<std::string> objectsToBeRemoved = myRemovedObjects;
503   std::set<std::string> objectsToBeUnpublished;
504
505   std::set<std::string>::iterator iter;
506   if( myGroupIntermediates->checkedId() == 1 ) { // unpublish
507     for( iter = myListParents.begin(); iter != myListParents.end(); ++iter )
508     objectsToBeUnpublished.insert( *iter );
509   }
510   if( myGroupIntermediates->checkedId() == 2 ) { // remove
511     for( iter = myListParents.begin(); iter != myListParents.end(); ++iter )
512       objectsToBeRemoved.insert( *iter );
513   }
514
515   if( myGroupSubObjects->checkedId() == 1 ) { // unpublish
516     for( iter = myListSubObjects.begin(); iter != myListSubObjects.end(); ++iter )
517       objectsToBeUnpublished.insert( *iter );
518   }
519   else if( myGroupSubObjects->checkedId() == 2 ) { // remove
520     for( iter = myListSubObjects.begin(); iter != myListSubObjects.end(); ++iter )
521       objectsToBeRemoved.insert( *iter );
522   }
523
524   if( myCBSoftRemoval->isChecked() ) {
525     for( iter = objectsToBeRemoved.begin(); iter != objectsToBeRemoved.end(); ++iter )
526       objectsToBeUnpublished.insert( *iter );
527     unpublishObjects( objectsToBeUnpublished );
528   }
529   else {
530     unpublishObjects( objectsToBeUnpublished );
531     removeObjects( objectsToBeRemoved );
532   }
533
534   accept();
535
536
537 //  std::cout<< "\n\n REMOVE:" << std::endl;
538 //  std::set<std::string>::iterator it;
539 //  for( it = objectsToBeRemoved.begin(); it != objectsToBeRemoved.end(); ++it )
540 //    std::cout <<"  " << (*it) << std::endl;
541 //
542 //  SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
543 //  if ( !app ) return;
544 //  SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
545 //  // get currently opened views
546 //  QList<SALOME_View*> views;
547 //  SALOME_View* view;
548 //  ViewManagerList vmans = app->viewManagers();
549 //  SUIT_ViewManager* vman;
550 //  foreach ( vman, vmans ) {
551 //    SUIT_ViewModel* vmod = vman->getViewModel();
552 //    view = dynamic_cast<SALOME_View*> ( vmod ); // must work for OCC and VTK views
553 //    if ( view )
554 //      views.append( view );
555 //  }
556 //  _PTR(Study) aStudy = study->studyDS();
557
558
559 //  _PTR(StudyBuilder) aStudyBuilder (aStudy->NewBuilder());
560 //  _PTR(UseCaseBuilder) aUseCaseBuilder = aStudy->GetUseCaseBuilder();
561 //
562 //  for( it = ObjectsToBeRemove.begin(); it != ObjectsToBeRemove.end(); ++it ) {
563 //    std::string objectEntry = *it;
564 //    GEOM::GEOM_BaseObject_var GeomBaseObject = GeometryGUI::GetGeomGen()->GetObject( myStudyId, objectEntry.c_str() );
565 //    GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
566 //    _PTR(SObject) obj = aStudy->FindObjectID( objectEntry.c_str() );
567 //
568 //    //Remove visual properties of the object
569 //    study->removeObjectFromAll(objectEntry.c_str());
570 //
571 //    // remove object from study
572 //    aStudyBuilder->RemoveObjectWithChildren( obj );
573 ////    // remove object from use case tree
574 ////    aUseCaseBuilder->Remove( obj );
575 //
576 //    // Erase graphical object
577 //    QListIterator<SALOME_View*> it( views );
578 //    while ( it.hasNext() )
579 //      if ( SALOME_View* view = it.next() )
580 //        myDisplayer.Erase( GeomObject, true, true, view);
581 //
582 //    GeometryGUI::GetGeomGen()->RemoveObject( GeomBaseObject );
583 //  }
584 //
585 //  myDisplayer.UpdateViewer();
586 //  GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
587 //  aGeomGUI->updateObjBrowser();
588 //  app->updateActions(); //SRN: To update a Save button in the toolbar
589
590
591 //  _PTR(StudyBuilder) B = aStudy->NewBuilder();
592 //  for( it = ObjectsToBeUnpublish.begin(); it != ObjectsToBeUnpublish.end(); ++it ) {
593 //    std::string objectEntry = *it;
594 //    _PTR(SObject) obj ( aStudy->FindObjectID( objectEntry ) );
595 //    _PTR(GenericAttribute) anAttr;
596 //    if ( obj ) {
597 //      _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
598 //      aDrw->SetDrawable( false );
599 //      myDisplayer.EraseWithChildren( new SALOME_InteractiveObject( objectEntry.c_str(), "GEOM", "TEMP_IO" ) );
600 //    } // if ( obj )
601 //  } // iterator
602 //
603 //  app->updateObjectBrowser( false );
604 //  app->updateActions();
605 //
606
607 //  LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
608 //  SALOME_ListIO aSelList;
609 //
610 //  for( it = ObjectsToBeUnpublish.begin(); it != ObjectsToBeUnpublish.end(); ++it ) {
611 //    std::string objectEntry = *it;
612 //    GEOM::GEOM_BaseObject_var GeomBaseObject = GeometryGUI::GetGeomGen()->GetObject( myStudyId, objectEntry.c_str() );
613 //    GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
614 //    QString studyEntry = GeomBaseObject->GetStudyEntry();
615 //    Handle(SALOME_InteractiveObject) tmpIO =
616 //      new SALOME_InteractiveObject( studyEntry.toStdString().c_str(), "GEOM", "TEMP_IO");
617 //    aSelList.Append(tmpIO);
618 //
619 //  }
620 //  aSelMgr->clearSelected();
621 //  aSelMgr->setSelectedObjects(aSelList);
622 //  GEOMToolsGUI::OnUnpublishObject();
623
624
625
626 //  if( myCBRemoveEmptyFolder->isChecked() ) {
627 //
628 //        SALOME_ListIO selected;
629 //        SalomeApp_Application* app =
630 //          dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
631 //        if ( !app )
632 //          return;
633 //
634 //        LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
635 //        SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
636 //        if ( !aSelMgr || !appStudy )
637 //          return;
638 //
639 //        // get selection
640 //        aSelMgr->selectedObjects( selected, "ObjectBrowser", false );
641 //        if ( selected.IsEmpty() )
642 //          return;
643 //
644 //        _PTR(Study) aStudy = appStudy->studyDS();
645 //        _PTR(UseCaseBuilder) aUseCaseBuilder = aStudy->GetUseCaseBuilder();
646 //
647 //          // ... and then delete all folders
648 //          for ( it = toBeDelFolders.begin(); it != toBeDelFolders.end(); ++it ) {
649 //            _PTR(SObject) obj ( aStudy->FindObjectID( it.key().toLatin1().data() ) );
650 //            // remove object from GEOM engine
651 //            removeObjectWithChildren( obj, aStudy, views, disp );
652 //            // remove objects from study
653 //            aStudyBuilder->RemoveObjectWithChildren( obj );
654 //            // remove object from use case tree
655 //            aUseCaseBuilder->Remove( obj );
656 //          }
657 //  }
658 }
659
660 ////=======================================================================
661 //// function : getGeomChildrenAndFolders
662 //// purpose  : Get direct (1-level) GEOM objects under each folder, sub-folder, etc. and these folders itself
663 ////=======================================================================
664 //static void getGeomChildrenAndFolders( _PTR(SObject) theSO,
665 //                                       QMap<QString,QString>& geomObjList,
666 //                                       QMap<QString,QString>& folderList ) {
667 //  if ( !theSO ) return;
668 //  _PTR(Study) aStudy = theSO->GetStudy();
669 //  if ( !aStudy ) return;
670 //  _PTR(UseCaseBuilder) aUseCaseBuilder = aStudy->GetUseCaseBuilder();
671 //
672 //  bool isFolder = false;
673 //  _PTR(GenericAttribute) anAttr;
674 //  if ( theSO->FindAttribute(anAttr, "AttributeLocalID") ) {
675 //    _PTR(AttributeLocalID) aLocalID( anAttr );
676 //    isFolder = aLocalID->Value() == 999;
677 //  }
678 //  QString anEntry = theSO->GetID().c_str();
679 //  QString aName = theSO->GetName().c_str();
680 //  if ( isFolder ) {
681 //    folderList.insert( anEntry, aName );
682 //    _PTR(UseCaseIterator) ucit ( aUseCaseBuilder->GetUseCaseIterator( theSO ) );
683 //    for ( ucit->Init( false ); ucit->More(); ucit->Next() ) {
684 //      getGeomChildrenAndFolders( ucit->Value(), geomObjList, folderList );
685 //    }
686 //  } else {
687 //    geomObjList.insert( anEntry, aName );
688 //  }
689 //}
690
691 void GEOMToolsGUI_ReduceStudyDlg::clickOnHelp()
692 {
693
694 }
695
696
697 GEOMToolsGUI_TreeWidgetItem::GEOMToolsGUI_TreeWidgetItem( QTreeWidget* view, const QStringList &strings,
698                                                           char* studyEntry, int type )
699 :QTreeWidgetItem( view, strings, type ),
700  myStudyEntry( studyEntry ),
701  myVisible( false )
702 {
703 }
704
705 GEOMToolsGUI_TreeWidgetItem::GEOMToolsGUI_TreeWidgetItem( QTreeWidgetItem* parent, const QStringList &strings,
706                                                           char* studyEntry, int type )
707 :QTreeWidgetItem( parent, strings, type ),
708  myStudyEntry( studyEntry ),
709  myVisible( false )
710 {
711 }
712
713 GEOMToolsGUI_TreeWidgetItem::~GEOMToolsGUI_TreeWidgetItem()
714 {
715 }
716
717 bool GEOMToolsGUI_TreeWidgetItem::isVisible()
718 {
719   return myVisible;
720 }
721
722 void GEOMToolsGUI_TreeWidgetItem::setVisible( bool theIsVisible, QIcon& theIcon )
723 {
724   myVisible = theIsVisible;
725   setIcon( 1, theIcon );
726 }
727
728 char* GEOMToolsGUI_TreeWidgetItem::getStudyEntry() const
729 {
730   return myStudyEntry;
731 }