]> SALOME platform Git repositories - modules/hexablock.git/blob - src/HEXABLOCKGUI/MyGEOMBase_Helper.cxx
Salome HOME
Merge from V6_main 13/12/2012
[modules/hexablock.git] / src / HEXABLOCKGUI / MyGEOMBase_Helper.cxx
1 // Copyright (C) 2009-2012  CEA/DEN, EDF R&D
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.
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 "MyGEOMBase_Helper.hxx"
21 #include "GEOMBase.h"
22 #include "GEOM_Operation.h"
23 #include "HEXABLOCKGUI.hxx"
24
25 #include <GeometryGUI.h>
26
27 #include <SUIT_Desktop.h>
28 #include <SUIT_Session.h>
29 #include <SUIT_ViewManager.h>
30 #include <SUIT_ViewModel.h>
31 #include <SUIT_MessageBox.h>
32 #include <SUIT_OverrideCursor.h>
33
34 #include <SalomeApp_Module.h>
35 #include <SalomeApp_Application.h>
36 #include <SalomeApp_Study.h>
37 #include <LightApp_SelectionMgr.h>
38 #include <LightApp_DataOwner.h>
39 #include <SalomeApp_Tools.h>
40 #include <SALOME_ListIteratorOfListIO.hxx>
41
42 #include <SALOME_Prs.h>
43
44 #include <OCCViewer_ViewModel.h>
45 #include <SOCC_ViewModel.h>
46 #include <SVTK_ViewModel.h>
47
48 #include <TColStd_MapOfInteger.hxx>
49 #include <TCollection_AsciiString.hxx>
50 #include <TColStd_IndexedMapOfInteger.hxx>
51 #include <AIS_ListIteratorOfListOfInteractive.hxx>
52
53 //To disable automatic genericobj management, the following line should be commented.
54 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
55 #define WITHGENERICOBJ
56
57 //================================================================
58 // Function : getActiveView
59 // Purpose  : Get active view window, returns 0 if no open study frame
60 //================================================================
61 static SUIT_ViewWindow* getActiveView()
62 {
63   SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
64   if ( activeStudy )
65     return SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
66
67   return 0;
68 }
69
70
71 //================================================================
72 // Function : getGeomEngine
73 // Purpose  : Static method
74 //================================================================
75 GEOM::GEOM_Gen_ptr MyGEOMBase_Helper::getGeomEngine()
76 {
77   return GeometryGUI::GetGeomGen();
78 }
79
80 //================================================================
81 // Function : MyGEOMBase_Helper
82 // Purpose  :
83 //================================================================
84 MyGEOMBase_Helper::MyGEOMBase_Helper( SUIT_Desktop* desktop )
85   : myDesktop( desktop ), myViewWindow( 0 ), myDisplayer( 0 ), myCommand( 0 ), isPreview( false ),
86     myIsApplyAndClose( false ), myIsOptimizedBrowsing( false )
87 {
88 }
89
90 //================================================================
91 // Function : ~MyGEOMBase_Helper
92 // Purpose  :
93 //================================================================
94 MyGEOMBase_Helper::~MyGEOMBase_Helper()
95 {
96   //rnv: Fix for the "IPAL21922 : WinTC5.1.4: incorrect quit salome"
97   if ( !SUIT_Session::session()->activeApplication() || !SUIT_Session::session()->activeApplication()->desktop() )
98     return;
99
100   if ( myPreview.size() )
101     erasePreview();
102   if ( hasCommand() )
103     abortCommand();
104 //   SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
105 //   if (app) {
106 //     GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
107 //     if(aGeomGUI)
108 //       globalSelection(aGeomGUI->getLocalSelectionMode() , true );
109 //   }
110
111   if (myDisplayer)
112     delete myDisplayer;
113   if ( !CORBA::is_nil( myOperation ) )
114     myOperation->UnRegister();
115 }
116
117 //================================================================
118 // Function : display
119 // Purpose  :
120 //================================================================
121 void MyGEOMBase_Helper::display( const ObjectList& objList, const bool updateView )
122 {
123   ObjectList::const_iterator it;
124   for ( it = objList.begin(); it != objList.end(); it++ ) {
125     display( *it, false );
126   }
127   if ( !objList.empty() && updateView )
128     getDisplayer()->UpdateViewer();
129 }
130
131 //================================================================
132 // Function  : display
133 // Purpose   : Display object.
134 // Important : Object must be already in study
135 //================================================================
136 void MyGEOMBase_Helper::display( GEOM::GEOM_Object_ptr object, const bool updateView )
137 {
138   // Unset color of shape ( this color may be set during preview displaying )
139   // Default color will be used
140   getDisplayer()->UnsetColor();
141   getDisplayer()->UnsetWidth();
142
143   // Enable activisation of selection
144   getDisplayer()->SetToActivate( true );
145
146   // Display object
147   getDisplayer()->Display( object, updateView );
148 }
149
150 //================================================================
151 // Function : erase
152 // Purpose  :
153 //================================================================
154 void MyGEOMBase_Helper::erase( const ObjectList& objList, const bool updateView )
155 {
156   ObjectList::const_iterator it = objList.begin();
157   for ( ; it != objList.end(); it++ ) {
158     erase( *it, false );
159   }
160   if ( !objList.empty() && updateView )
161     getDisplayer()->UpdateViewer();
162 }
163
164 //================================================================
165 // Function : erase
166 // Purpose  :
167 //================================================================
168 void MyGEOMBase_Helper::erase( GEOM::GEOM_Object_ptr object, const bool updateView )
169 {
170   if ( !object->_is_nil() ) {
171     QString entry = getEntry( object );
172     getDisplayer()->Erase( new SALOME_InteractiveObject(
173       entry.toLatin1().constData(),
174       "GEOM", strdup( GEOMBase::GetName( object ).toLatin1().constData() ) ), true, updateView );
175   }
176 }
177
178 //================================================================
179 // Function : redisplay
180 // Purpose  :
181 //================================================================
182 void MyGEOMBase_Helper::redisplay( const ObjectList& objList,
183                                  const bool withChildren,
184                                  const bool updateView )
185 {
186   ObjectList::const_iterator it = objList.begin();
187   for ( ; it != objList.end(); it++ ) {
188     redisplay( *it, withChildren, false );
189   }
190   if ( !objList.empty() && updateView )
191     getDisplayer()->UpdateViewer();
192 }
193
194 //================================================================
195 // Function : redisplay
196 // Purpose  :
197 //================================================================
198 void MyGEOMBase_Helper::redisplay( GEOM::GEOM_Object_ptr object,
199                                  const bool withChildren,
200                                  const bool updateView )
201 {
202   if ( !object->_is_nil() ) {
203     // Unset color of shape ( this color may be set during preview displaying )
204     // Default color will be used
205     getDisplayer()->UnsetColor();
206     getDisplayer()->UnsetWidth();
207
208     // Enable activisation of selection
209     getDisplayer()->SetToActivate( true );
210
211     QString entry = getEntry( object );
212     getDisplayer()->Redisplay(new SALOME_InteractiveObject
213                               (entry.toLatin1().constData(), "GEOM", strdup(GEOMBase::GetName(object).toLatin1().constData())), false);
214   }
215
216   if ( withChildren ) {
217     SalomeApp_Study* aDoc = getStudy();
218     if ( aDoc && aDoc->studyDS() ) {
219       _PTR(Study) aStudy = aDoc->studyDS();
220       CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string(object);
221       _PTR(SObject) aSObj (aStudy->FindObjectIOR(std::string(objStr.in())));
222       if ( aSObj  ) {
223         _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
224         for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
225           GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow
226             (GeometryGUI::ClientSObjectToObject(anIt->Value()));
227           if ( !CORBA::is_nil( aChild ) ) {
228             if ( !aChild->_is_nil() ) {
229               QString entry = getEntry( aChild );
230               getDisplayer()->Redisplay( new SALOME_InteractiveObject(
231                 entry.toLatin1().constData(), "GEOM", strdup( GEOMBase::GetName( aChild ).toLatin1().constData() ) ), false );
232             }
233           }
234         }
235       }
236     }
237   }
238
239   if ( updateView )
240     getDisplayer()->UpdateViewer();
241 }
242
243 //================================================================
244 // Function : displayPreview
245 // Purpose  : Method for displaying preview based on execute() results
246 //================================================================
247 void MyGEOMBase_Helper::displayPreview( const bool   display,
248                                       const bool   activate,
249                                       const bool   update,
250                                       const bool   toRemoveFromEngine,
251                                       const double lineWidth,
252                                       const int    displayMode,
253                                       const int    color )
254 {
255   if(!display) {
256     erasePreview( update );
257     return;
258   }
259
260   isPreview = true;
261   QString msg;
262   if ( !isValid( msg ) )
263   {
264     erasePreview( update );
265     isPreview = false;
266     return;
267   }
268
269   erasePreview( false );
270
271   try {
272     SUIT_OverrideCursor wc;
273     ObjectList objects;
274     if ( !execute( objects ) || !getOperation()->IsDone() ) {
275       wc.suspend();
276     }
277     else {
278       for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it )
279       {
280             GEOM::GEOM_Object_var obj=*it;
281         displayPreview( obj, true, activate, false, lineWidth, displayMode, color );
282         if ( toRemoveFromEngine )
283               obj->UnRegister();
284       }
285     }
286   }
287   catch( const SALOME::SALOME_Exception& e ) {
288     SalomeApp_Tools::QtCatchCorbaException( e );
289   }
290
291   isPreview = false;
292
293   if ( update )
294     updateViewer();
295 }
296
297 //================================================================
298 // Function : displayPreview
299 // Purpose  : Method for displaying preview of resulting shape
300 //================================================================
301 void MyGEOMBase_Helper::displayPreview( GEOM::GEOM_Object_ptr object,
302                                       const bool            append,
303                                       const bool            activate,
304                                       const bool            update,
305                                       const double          lineWidth,
306                                       const int             displayMode,
307                                       const int             color )
308 {
309   // Set color for preview shape
310   getDisplayer()->SetColor( color == -1 ? Quantity_NOC_VIOLET : color );
311
312   // set width of displayed shape
313   getDisplayer()->SetWidth( lineWidth );
314
315   // set display mode of displayed shape
316   int aPrevDispMode = getDisplayer()->SetDisplayMode( displayMode );
317
318   // Disable activation of selection
319   getDisplayer()->SetToActivate( activate );
320
321   // Make a reference to GEOM_Object
322   CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string( object );
323   getDisplayer()->SetName( objStr.in() );
324
325   // Build prs
326   SALOME_Prs* aPrs = getDisplayer()->BuildPrs( object );
327   if ( aPrs == 0 || aPrs->IsNull() )
328     return;
329
330   // Display prs
331   displayPreview( aPrs, append, update );
332
333   getDisplayer()->UnsetName();
334   getDisplayer()->UnsetColor();
335   getDisplayer()->SetDisplayMode( aPrevDispMode );
336
337   // Enable activation of displayed objects
338   getDisplayer()->SetToActivate( true );
339 }
340
341 //================================================================
342 // Function : displayPreview
343 // Purpose  : Method for displaying arbitrary preview objects (not limited to shapes)
344 //================================================================
345 void MyGEOMBase_Helper::displayPreview( const SALOME_Prs* prs,
346                                       const bool        append,
347                                       const bool        update )
348 {
349   if ( !append )
350     erasePreview( false );
351
352   // remember current view frame to make correct erase preview later
353   myViewWindow = getActiveView();
354
355   if ( myViewWindow == 0 )
356     return;
357
358   // Display prs
359   SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
360   if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
361        aViewManager->getType() == SVTK_Viewer::Type() )
362     {
363       SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
364       SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
365       if (aView)
366         aView->Display( prs );
367     }
368
369   // Add prs to the preview list
370   myPreview.push_back( (SALOME_Prs*)prs );
371
372   // Update viewer
373   if ( update )
374     getDisplayer()->UpdateViewer();
375 }
376
377 //================================================================
378 // Function : erasePreview
379 // Purpose  :
380 //================================================================
381 void MyGEOMBase_Helper::erasePreview( const bool update )
382 {
383   // check view frame where the preview was displayed
384   bool vfOK = checkViewWindow() && myViewWindow;
385   // Iterate through presentations and delete them
386   for ( PrsList::iterator anIter = myPreview.begin(); anIter != myPreview.end(); ++anIter ) {
387     if ( vfOK )
388       {
389          SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
390          if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
391               aViewManager->getType() == SVTK_Viewer::Type() )
392            {
393              SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
394              SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
395              if (aView)
396                aView->Erase( *anIter, true );
397            }
398       }
399     delete *anIter;
400   }
401   myPreview.clear();
402
403   // Update viewer
404   if ( update )
405     updateViewer();
406 }
407
408 //================================================================
409 // Function  : localSelection
410 // Purpose   : Activate selection of objects of a given type
411 // IMPORTANT : Works after localSelection( ... ) method call only
412 //================================================================
413 void MyGEOMBase_Helper::activate( const int theType )
414 {
415   if (!getStudy()) return;
416   _PTR(Study) aStudy = getStudy()->studyDS();
417   _PTR(SComponent) aGeom ( aStudy->FindComponent( "GEOM" ) );
418   if ( !aGeom )
419     return;
420
421   SALOME_ListIO aList;
422   _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( aGeom ) );
423   for ( ; anIter->More(); anIter->Next() )
424   {
425     _PTR(SObject) aSO ( anIter->Value() );
426     if ( aSO )
427     {
428       _PTR(SObject) aRefSO;
429       if ( !aSO->ReferencedObject( aRefSO ) )
430       {
431         GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow
432           (GeometryGUI::ClientSObjectToObject(aSO));
433         if ( !anObj->_is_nil() && anObj->GetType() == theType )
434           aList.Append( new SALOME_InteractiveObject( aSO->GetID().c_str(), "GEOM", aSO->GetName().c_str()) );
435       }
436     }
437   }
438
439   getDisplayer()->LocalSelection( aList, 0 );
440 }
441
442 //================================================================
443 // Function : localSelection
444 // Purpose  : Activate selection of subshapes in accordance with mode
445 //            theMode is from TopAbs_ShapeEnum
446 //================================================================
447 void MyGEOMBase_Helper::localSelection( const ObjectList& theObjs, const int theMode )
448 {
449   SALOME_ListIO aListOfIO;
450
451   ObjectList::const_iterator anIter = theObjs.begin();
452   for ( ; anIter != theObjs.end(); ++anIter )
453   {
454     GEOM::GEOM_Object_ptr anObj = *anIter;
455     if ( anObj->_is_nil() )
456       continue;
457     QString anEntry = getEntry( anObj );
458     if ( anEntry != "" )
459       aListOfIO.Append( new SALOME_InteractiveObject(
460         anEntry.toLatin1().constData(), "GEOM", strdup( GEOMBase::GetName( anObj ).toLatin1().constData() ) ) );
461   }
462
463   getDisplayer()->LocalSelection( aListOfIO, theMode );
464 }
465
466 //================================================================
467 // Function : localSelection
468 // Purpose  : Activate selection of subshapes in accordance with mode
469 //            theMode is from TopAbs_ShapeEnum
470 //================================================================
471 void MyGEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const int mode )
472 {
473   // If object is null local selection for all objects is activated
474   if ( obj->_is_nil() ) {
475     getDisplayer()->LocalSelection( Handle(SALOME_InteractiveObject)(), mode );
476     return;
477   }
478
479   ObjectList objList;
480   objList.push_back( obj );
481   localSelection( objList, mode );
482 }
483
484 //================================================================
485 // Beta version
486 // Function : localSelection
487 // Purpose  : Activate selection of subshapes in accordance with mode
488 //            theMode is from TopAbs_ShapeEnum
489 //================================================================
490 void MyGEOMBase_Helper::localSelection(SUIT_ViewWindow *view, const int theMode )
491 {
492     SUIT_Session* session = SUIT_Session::session();
493     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
494     if ( app == NULL || view == NULL ) return;
495
496     LightApp_SelectionMgr* sm = app->selectionMgr();
497
498     // remove all filters from selection
499     sm->clearFilters();
500
501     SALOME_View* vf = dynamic_cast<SALOME_View*>(view->getViewManager()->getViewModel());
502     if (vf == NULL) return;
503
504     SALOME_Prs* prs = vf->CreatePrs( NULL );
505     vf->LocalSelection( prs, theMode );
506     delete prs;  // delete presentation because displayer is its owner
507 }
508
509
510
511 //================================================================
512 // Beta version
513 // Function : globalSelection2
514 // Purpose  : Activate selection of subshapes. Set selection filters
515 //            in accordance with mode. theMode is from GEOMImpl_Types
516 // mode = GEOM_ALLOBJECTS
517 //================================================================
518 void MyGEOMBase_Helper::globalSelection(SUIT_ViewWindow *view, const bool update )
519 {
520     SUIT_Session* session = SUIT_Session::session();
521     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
522     if ( app == NULL || view == NULL ) return;
523
524     SALOME_View* vf = dynamic_cast<SALOME_View*>(view->getViewManager()->getViewModel());
525     if ( vf == NULL ) return;
526
527     // Close local context
528     vf->GlobalSelection( update );
529
530     // Set selection filters in accordance with current mode
531     LightApp_SelectionMgr* sm = app->selectionMgr();
532     if ( !sm )
533         return;
534
535
536     //@ aSel->ClearIndex();
537
538     sm->clearFilters();
539
540     // Remove filters from AIS_InteractiveContext
541     Handle(AIS_InteractiveContext) ic;
542     SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
543     if ( viewer )
544     {
545         ic = viewer->getAISContext();
546         if ( !ic.IsNull() )
547             ic->RemoveFilters();
548     }
549 }
550
551
552 //================================================================
553 // Function : globalSelection
554 // Purpose  : Activate selection of subshapes. Set selection filters
555 //            in accordance with mode. theMode is from GEOMImpl_Types
556 //================================================================
557 void MyGEOMBase_Helper::globalSelection( const int theMode, const bool update )
558 {
559   getDisplayer()->GlobalSelection( theMode, update );
560 }
561
562 //================================================================
563 // Function : globalSelection
564 // Purpose  : Activate selection of subshapes. Set selection filters
565 //            in accordance with mode. theMode is from GEOMImpl_Types
566 //================================================================
567 void MyGEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
568                                        const bool update )
569 {
570   getDisplayer()->GlobalSelection( theModes, update );
571 }
572
573 //================================================================
574 // Function : globalSelection
575 // Purpose  : Activate selection of subshapes. Set selection filters
576 //            in accordance with mode. theMode is from GEOMImpl_Types
577 //================================================================
578 void MyGEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
579                                        const QList<int>& subShapes,
580                                        const bool update )
581 {
582   getDisplayer()->GlobalSelection( theModes, update, &subShapes );
583 }
584
585 //================================================================
586 // Function : addInStudy
587 // Purpose  : Add object in study
588 //================================================================
589 QString MyGEOMBase_Helper::addInStudy( GEOM::GEOM_Object_ptr theObj, const char* theName )
590 {
591   if ( !hasCommand() )
592     return QString();
593
594   _PTR(Study) aStudy = getStudy()->studyDS();
595   if ( !aStudy || theObj->_is_nil() )
596     return QString();
597
598   SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy(aStudy);
599
600   GEOM::GEOM_Object_ptr aFatherObj = getFather( theObj );
601
602   SALOMEDS::SObject_var aSO =
603     getGeomEngine()->AddInStudy(aStudyDS, theObj, theName, aFatherObj);
604
605   QString anEntry;
606   if ( !aSO->_is_nil() )
607     anEntry = aSO->GetID();
608
609   // Each dialog is responsible for this method implementation,
610   // default implementation does nothing
611   restoreSubShapes(aStudyDS, aSO);
612   aSO->UnRegister();
613
614   return anEntry;
615 }
616
617 //================================================================
618 // Function : restoreSubShapes
619 // Purpose  : restore tree of argument's sub-shapes under the resulting shape
620 //================================================================
621 void MyGEOMBase_Helper::restoreSubShapes (SALOMEDS::Study_ptr   /*theStudy*/,
622                                         SALOMEDS::SObject_ptr /*theSObject*/)
623 {
624   // do nothing by default
625
626   // example of implementation in particular dialog:
627   // GEOM::ListOfGO anArgs;
628   // anArgs.length(0); // empty list means that all arguments should be restored
629   // getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
630   //                                     /*theFindMethod=*/GEOM::FSM_GetInPlace,
631   //                                     /*theInheritFirstArg=*/false);
632 }
633
634 //================================================================
635 // Function : updateObjBrowser
636 // Purpose  : Update object browser
637 //================================================================
638 void MyGEOMBase_Helper::updateObjBrowser() const
639 {
640   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
641   if (app) {
642     CAM_Module* module = app->module( "Geometry" );
643     SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
644     if ( appMod ) {
645       appMod->updateObjBrowser( true );
646     }
647   }
648 }
649
650 //================================================================
651 // Function : updateViewer
652 // Purpose  : Update active 3D view
653 //================================================================
654 void MyGEOMBase_Helper::updateViewer()
655 {
656   getDisplayer()->UpdateViewer();
657 }
658
659 //================================================================
660 // Function : getStudyId
661 // Purpose  : Get study Id
662 //================================================================
663 int MyGEOMBase_Helper::getStudyId() const
664 {
665   int anId = -1;
666   if ( getStudy() )
667     anId = getStudy()->id();
668   return anId;
669 }
670
671 //================================================================
672 // Function : getStudy
673 // Purpose  : Returns the active study. It is recommended to use
674 //            this method instead of direct desktop->getActiveStudy() calls
675 //================================================================
676 SalomeApp_Study* MyGEOMBase_Helper::getStudy() const
677 {
678   SUIT_Desktop* aDesktop = getDesktop();
679   if (!aDesktop)
680     return 0;
681
682   QList<SUIT_Application*> anAppList = SUIT_Session::session()->applications();
683
684   SUIT_Application* anApp = 0;
685   QListIterator<SUIT_Application*> it( anAppList );
686   while ( it.hasNext() )
687     {
688       anApp = it.next();
689       if ( anApp && anApp->desktop() == aDesktop )
690         break;
691     }
692
693   return dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
694 }
695
696 //================================================================
697 // Function : getEntry
698 // Purpose  :
699 //================================================================
700 QString MyGEOMBase_Helper::getEntry( GEOM::GEOM_Object_ptr object ) const
701 {
702   SalomeApp_Study* study = getStudy();
703   if ( study )  {
704     QString objIOR = GEOMBase::GetIORFromObject( object );
705     if ( objIOR != "" ) {
706       _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( objIOR.toLatin1().constData() ) );
707       if ( SO )
708         return QString::fromStdString(SO->GetID());
709     }
710   }
711   return "";
712 }
713
714 //================================================================
715 // Function : getDisplayer
716 // Purpose  :
717 //================================================================
718 GEOM_Displayer* MyGEOMBase_Helper::getDisplayer()
719 {
720   if ( !myDisplayer )
721     myDisplayer = new GEOM_Displayer( getStudy() );
722   return myDisplayer;
723 }
724
725 //================================================================
726 // Function : clearShapeBuffer
727 // Purpose  :
728 //================================================================
729 void MyGEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
730 {
731   if ( CORBA::is_nil( theObj ) )
732     return;
733
734   CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( theObj );
735   TCollection_AsciiString asciiIOR( (char *)IOR.in() );
736   GEOM_Client::get_client().RemoveShapeFromBuffer( asciiIOR );
737
738   if ( !getStudy() || !getStudy()->studyDS() )
739     return;
740
741   _PTR(Study) aStudy = getStudy()->studyDS();
742   _PTR(SObject) aSObj ( aStudy->FindObjectIOR( std::string( IOR ) ) );
743   if ( !aSObj )
744     return;
745
746   _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
747   for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
748     _PTR(GenericAttribute) anAttr;
749     if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
750       _PTR(AttributeIOR) anIOR ( anAttr );
751       TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
752       GEOM_Client::get_client().RemoveShapeFromBuffer( asciiIOR );
753     }
754   }
755 }
756
757 //================================================================
758 // Function : openCommand
759 // Purpose  :
760 //================================================================
761 bool MyGEOMBase_Helper::openCommand()
762 {
763   bool res = false;
764   if ( !getStudy() || hasCommand() )
765     return res;
766
767   GEOM::GEOM_IOperations_var anOp = GEOM::GEOM_IOperations::_narrow( getOperation() );
768   if ( !anOp->_is_nil() ) {
769     myCommand = new GEOM_Operation( SUIT_Session::session()->activeApplication(), anOp.in() );
770     myCommand->start();
771     res = true;
772   }
773
774   return res;
775 }
776
777 //================================================================
778 // Function : abortCommand
779 // Purpose  :
780 //================================================================
781 bool MyGEOMBase_Helper::abortCommand()
782 {
783   if ( !hasCommand() )
784     return false;
785
786   myCommand->abort();
787   delete myCommand; // I don't know where to delete this object here ?
788   myCommand = 0;
789
790   return true;
791 }
792
793 //================================================================
794 // Function : commitCommand
795 // Purpose  :
796 //================================================================
797 bool MyGEOMBase_Helper::commitCommand( const char* )
798 {
799   if ( !hasCommand() )
800     return false;
801
802   myCommand->commit();
803   delete myCommand; // I don't know where to delete this object here ?
804   myCommand = 0;
805
806   return true;
807 }
808
809 //================================================================
810 // Function : hasCommand
811 // Purpose  :
812 //================================================================
813 bool MyGEOMBase_Helper::hasCommand() const
814 {
815   return (bool)myCommand;
816 }
817
818 //================================================================
819 // Function : getOperation
820 // Purpose  :
821 //================================================================
822 GEOM::GEOM_IOperations_ptr MyGEOMBase_Helper::getOperation()
823 {
824   if ( myOperation->_is_nil() )
825     myOperation = createOperation();
826
827   return myOperation;
828 }
829
830
831
832 //================================================================
833 // Function : checkViewWindow
834 // Purpose  :
835 //================================================================
836 bool MyGEOMBase_Helper::checkViewWindow()
837 {
838   if ( myViewWindow ){
839     QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
840     QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
841     while ( it.hasNext() )
842       {
843         if ( myViewWindow == it.next() )
844           return true;
845       }
846   }
847   myViewWindow = 0;
848   return false;
849 }
850
851 //================================================================
852 // Function : onAccept
853 // Purpose  : This method should be called from dialog's slots onOk() and onApply()
854 //            It perfroms user input validation, then it
855 //            performs a proper operation and manages transactions, etc.
856 //================================================================
857 bool MyGEOMBase_Helper::onAccept( const bool publish, const bool useTransaction )
858 {
859   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
860   if ( !appStudy ) return false;
861   _PTR(Study) aStudy = appStudy->studyDS();
862
863   bool aLocked = (_PTR(AttributeStudyProperties) (aStudy->GetProperties()))->IsLocked();
864   if ( aLocked ) {
865     SUIT_MessageBox::warning ( (QWidget*)SUIT_Session::session()->activeApplication()->desktop(),
866                                QObject::tr("WRN_WARNING"),
867                                QObject::tr("WRN_STUDY_LOCKED"),
868                                QObject::tr("BUT_OK") );
869     return false;
870   }
871
872   QString msg;
873   if ( !isValid( msg ) ) {
874     showError( msg );
875     return false;
876   }
877
878   erasePreview( false );
879
880   bool result = false;
881
882   try {
883     if ( ( !publish && !useTransaction ) || openCommand() ) {
884       SUIT_OverrideCursor wc;
885       SUIT_Session::session()->activeApplication()->putInfo( "" );
886       ObjectList objects;
887       if ( !execute( objects ) || !getOperation()->IsDone() ) {
888         wc.suspend();
889         abortCommand();
890         showError();
891       }
892       else {
893         addSubshapesToStudy(); // add Subshapes if local selection
894         const int nbObjs = objects.size();
895         QStringList anEntryList;
896         int aNumber = 1;
897         for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
898           GEOM::GEOM_Object_var obj=*it;
899           if ( publish ) {
900             QString aName = getNewObjectName();
901             if ( nbObjs > 1 ) {
902               if (aName.isEmpty())
903                 aName = getPrefix(obj);
904               if (nbObjs <= 30) {
905                 // Try to find a unique name
906                 aName = GEOMBase::GetDefaultName(aName, extractPrefix());
907               } else {
908                 // Don't check name uniqueness in case of numerous objects
909                 aName = aName + "_" + QString::number(aNumber++);
910               }
911             } else {
912               // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
913               if ( aName.isEmpty() )
914                 aName = GEOMBase::GetDefaultName( getPrefix( obj ) );
915             }
916             anEntryList << addInStudy( obj, aName.toLatin1().constData() );
917             // updateView=false
918             display( obj, false );
919 #ifdef WITHGENERICOBJ
920             // obj has been published in study. Its refcount has been incremented.
921             // It is safe to decrement its refcount
922             // so that it will be destroyed when the entry in study will be removed
923             obj->UnRegister();
924 #endif
925           }
926           else {
927             // asv : fix of PAL6454. If publish==false, then the original shape
928             // was modified, and need to be re-cached in GEOM_Client before redisplay
929             clearShapeBuffer( obj );
930             // withChildren=true, updateView=false
931             redisplay( obj, true, false );
932           }
933         }
934
935         if ( nbObjs ) {
936           commitCommand();
937           updateObjBrowser();
938           if( SUIT_Application* anApp = SUIT_Session::session()->activeApplication() ) {
939             if( LightApp_Application* aLightApp = dynamic_cast<LightApp_Application*>( anApp ) )
940               aLightApp->browseObjects( anEntryList, isApplyAndClose(), isOptimizedBrowsing() );
941             anApp->putInfo( QObject::tr("GEOM_PRP_DONE") );
942           }
943           result = true;
944         }
945         else
946           abortCommand();
947       }
948     }
949   }
950   catch( const SALOME::SALOME_Exception& e ) {
951     SalomeApp_Tools::QtCatchCorbaException( e );
952     abortCommand();
953   }
954
955   updateViewer();
956
957   return result;
958 }
959
960
961 //================================================================
962 // Function : showError
963 // Purpose  : Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
964 //================================================================
965 void MyGEOMBase_Helper::showError()
966 {
967   QString msg;
968   if ( !getOperation()->_is_nil() )
969     msg = QObject::tr( getOperation()->GetErrorCode() );
970
971   if ( msg.isEmpty() )
972     msg = QObject::tr( "GEOM_PRP_ABORT" );
973
974   SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
975                              QObject::tr( "GEOM_ERROR_STATUS" ),
976                              msg,
977                              QObject::tr( "BUT_OK" ) );
978 }
979
980 //================================================================
981 // Function : showError
982 // Purpose  : Shows a error message followed by <msg>
983 //================================================================
984 void MyGEOMBase_Helper::showError( const QString& msg )
985 {
986   QString str( QObject::tr( "GEOM_INCORRECT_INPUT" ) );
987   if ( !msg.isEmpty() )
988     str += "\n" + msg;
989   SUIT_MessageBox::critical(SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ), str, QObject::tr( "BUT_OK" ) );
990 }
991
992 //////////////////////////////////////////////////////////////////
993 // Virtual methods to be redefined in dialogs
994 //////////////////////////////////////////////////////////////////
995
996 //================================================================
997 // Function : createOperation
998 // Purpose  : Redefine this method to return proper IOperation reference
999 //================================================================
1000 GEOM::GEOM_IOperations_ptr MyGEOMBase_Helper::createOperation()
1001 {
1002   GEOM::GEOM_IOperations_var aNilOp;
1003   return aNilOp._retn();
1004 }
1005
1006 //================================================================
1007 // Function : isValid
1008 // Purpose  : Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
1009 //================================================================
1010 bool MyGEOMBase_Helper::isValid( QString& )
1011 {
1012   return true;
1013 }
1014
1015 //================================================================
1016 // Function : execute
1017 // Purpose  : This method is called by onAccept().
1018 //            It should perform the required operation and put all new or modified objects into
1019 //            <objects> argument.Should return <false> if some error occurs during its execution.
1020 //================================================================
1021 bool MyGEOMBase_Helper::execute( ObjectList& objects )
1022 {
1023   return false;
1024 }
1025
1026 //================================================================
1027 // Function : getFather
1028 // Purpose  : This method is called by addInStudy(). It should return a father object
1029 //            for <theObj> or a nil reference if <theObj> should be published
1030 //            as a top-level object.
1031 //================================================================
1032 GEOM::GEOM_Object_ptr MyGEOMBase_Helper::getFather( GEOM::GEOM_Object_ptr theObj )
1033 {
1034   return GEOM::GEOM_Object::_nil();
1035 }
1036
1037 //================================================================
1038 // Function : getNewObjectName
1039 // Purpose  : Redefine this method to return proper name for a new object
1040 //================================================================
1041 QString MyGEOMBase_Helper::getNewObjectName() const
1042 {
1043   return QString::null;
1044 }
1045
1046 //================================================================
1047 // Function : extractPrefix
1048 // Purpose  : Redefine this method to return \c true if necessary
1049 //            to extract prefix when generating new name for the
1050 //            object(s) being created
1051 //================================================================
1052 bool MyGEOMBase_Helper::extractPrefix() const
1053 {
1054   return false;
1055 }
1056
1057 //================================================================
1058 // Function : getPrefix
1059 // Purpose  : Get prefix for name of created object
1060 //================================================================
1061 QString MyGEOMBase_Helper::getPrefix( GEOM::GEOM_Object_ptr theObj ) const
1062 {
1063   if ( !myPrefix.isEmpty() || theObj->_is_nil() )
1064     return myPrefix;
1065
1066   GEOM::shape_type aType = theObj->GetShapeType();
1067
1068   switch ( aType )
1069   {
1070     case GEOM::VERTEX   : return QObject::tr( "GEOM_VERTEX" );
1071     case GEOM::EDGE     : return QObject::tr( "GEOM_EDGE" );
1072     case GEOM::WIRE     : return QObject::tr( "GEOM_WIRE" );
1073     case GEOM::FACE     : return QObject::tr( "GEOM_FACE" );
1074     case GEOM::SHELL    : return QObject::tr( "GEOM_SHELL" );
1075     case GEOM::SOLID    : return QObject::tr( "GEOM_SOLID" );
1076     case GEOM::COMPSOLID: return QObject::tr( "GEOM_COMPOUNDSOLID" );
1077     case GEOM::COMPOUND : return QObject::tr( "GEOM_COMPOUND" );
1078     default : return "";
1079   }
1080 }
1081
1082 //================================================================
1083 // Function : getDesktop
1084 // Purpose  : Returns myDesktop field. Initialized in constructor,
1085 //            usually as dynamic_cast<SUIT_Desktop*>(parentWidget())
1086 //================================================================
1087 SUIT_Desktop* MyGEOMBase_Helper::getDesktop() const
1088 {
1089   return myDesktop;
1090 }
1091
1092 //================================================================
1093 // Function : selectObjects
1094 // Purpose  : Selects list of objects
1095 //================================================================
1096 bool MyGEOMBase_Helper::selectObjects( ObjectList& objects )
1097 {
1098   SUIT_DataOwnerPtrList aList;
1099   ObjectList::iterator anIter;
1100   for ( anIter = objects.begin(); anIter != objects.end(); ++anIter )
1101   {
1102     QString anEntry = getEntry( *anIter );
1103     LightApp_DataOwner* anOwher = new LightApp_DataOwner( anEntry );
1104     aList.append( anOwher );
1105   }
1106
1107   SUIT_Session* session = SUIT_Session::session();
1108   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1109   if ( !app )
1110     return false;
1111
1112   LightApp_SelectionMgr* aMgr = app->selectionMgr();
1113   if ( !aMgr )
1114     return false;
1115
1116   aMgr->setSelected( aList, false );
1117
1118   return true;
1119 }
1120
1121 //================================================================
1122 // Function : findObjectInFather
1123 // Purpose  : It should return an object if its founded in study or
1124 //            return Null object if the object is not founded
1125 //================================================================
1126 GEOM::GEOM_Object_ptr MyGEOMBase_Helper::findObjectInFather (GEOM::GEOM_Object_ptr theFather,
1127                                                            const QString& theName)
1128 {
1129   SalomeApp_Application* app =
1130     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1131   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1132   _PTR(Study) aDStudy = appStudy->studyDS();
1133   QString IOR = GEOMBase::GetIORFromObject( theFather );
1134   _PTR(SObject) SObj ( aDStudy->FindObjectIOR( IOR.toLatin1().constData() ) );
1135
1136   bool inStudy = false;
1137   GEOM::GEOM_Object_var aReturnObject;
1138   for (_PTR(ChildIterator) iit (aDStudy->NewChildIterator( SObj )); iit->More() && !inStudy; iit->Next()) {
1139     _PTR(SObject) child (iit->Value());
1140     QString aChildName = child->GetName().c_str();
1141     if (aChildName == theName) {
1142       inStudy = true;
1143       CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(iit->Value());
1144       aReturnObject = GEOM::GEOM_Object::_narrow( corbaObj );
1145     }
1146   }
1147   if (inStudy)
1148     return aReturnObject._retn();
1149
1150   return GEOM::GEOM_Object::_nil();
1151 }
1152
1153 //================================================================
1154 // Function : findObjectInFather
1155 // Purpose  : It should return an object if its founded in study or
1156 //            return Null object if the object is not founded
1157 //================================================================
1158 GEOM::GEOM_Object_ptr MyGEOMBase_Helper::findObjectInFather( GEOM::GEOM_Object_ptr theFather,
1159                                                            int theIndex )
1160 {
1161   GEOM::GEOM_Object_var object;
1162   bool found = false;
1163
1164   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
1165   if ( study ) {
1166     _PTR(Study) studyDS = study->studyDS();
1167     QString IOR = GEOMBase::GetIORFromObject( theFather );
1168     _PTR(SObject) sobject( studyDS->FindObjectIOR( IOR.toLatin1().constData() ) );
1169     if ( sobject ) {
1170       _PTR(ChildIterator) it( studyDS->NewChildIterator( sobject ) );
1171       for ( ; it->More() && !found; it->Next() ) {
1172         GEOM::GEOM_Object_var cobject = GEOM::GEOM_Object::_narrow( GeometryGUI::ClientSObjectToObject( it->Value() ) );
1173         if ( !CORBA::is_nil( cobject ) ) {
1174           GEOM::ListOfLong_var indices = cobject->GetSubShapeIndices();
1175           int length = indices->length();
1176           for ( int i = 0; i < length && !found; i++ ) {
1177             if ( indices[i] == theIndex ) {
1178               object = cobject;
1179               found = true;
1180             }
1181           }
1182         }
1183       }
1184     }
1185   }
1186
1187   return object._retn();
1188 }
1189
1190 //================================================================
1191 // Function : addSubshapesToStudy
1192 // Purpose  : Virtual method to add subshapes if needs
1193 //================================================================
1194 void MyGEOMBase_Helper::addSubshapesToStudy()
1195 {
1196   //Impemented in Dialogs, called from Accept method
1197 }
1198
1199 //================================================================
1200 // Function : getSelected
1201 // Purpose  : Get selected object by specified type
1202 //
1203 // Returns valid object if only one object of the specified type is selected
1204 // (no matter global or local selection is activated). If \a type is TopAbs_SHAPE,
1205 // geometrical object of any valid type is expected.
1206 //
1207 // \param type type of the object to be obtained from selection
1208 // \return selected geometrical object or nil object if selection is not satisfactory
1209 //================================================================
1210 GEOM::GeomObjPtr MyGEOMBase_Helper::getSelected( TopAbs_ShapeEnum type )
1211 {
1212   QList<TopAbs_ShapeEnum> types;
1213   types << type;
1214   return getSelected( types );
1215 }
1216
1217 //================================================================
1218 // Function : getSelected
1219 // Purpose  : Get selected object by specified types
1220 //
1221 // Returns valid object if only one object of the specified type is selected
1222 // (no matter global or local selection is activated). The list of allowed
1223 // shape types is passed via \a types. If \a types includes TopAbs_SHAPE,
1224 // geometrical object of any valid type is expected.
1225 //
1226 // \param types list of allowed shape types for the objects to be obtained from selection
1227 // \return selected geometrical object or nil object if selection is not satisfactory
1228 //================================================================
1229 GEOM::GeomObjPtr MyGEOMBase_Helper::getSelected( const QList<TopAbs_ShapeEnum>& types )
1230 {
1231   QList<GEOM::GeomObjPtr> selected = getSelected( types, 1 );
1232   return selected.count() > 0 ? selected[0] : GEOM::GeomObjPtr();
1233 }
1234
1235 //================================================================
1236 // Function : getSelected
1237 // Purpose  : Get selected object(s) by specified type
1238 //
1239 // Returns list of selected objects if selection satisfies specifies selection options.
1240 // (no matter global or local selection is activated). If \a type is TopAbs_SHAPE,
1241 // geometrical objects of any valid type are expected.
1242 //
1243 // The \a type parameter specifies allowed type of the object(s) being selected.
1244 // The \a count parameter specifies exact number of the objects to be retrieved from selection.
1245 // The \a strict parameter specifies policy being applied to the selection.
1246 // If \a count < 0, then any number of the selected objects is valid (including 0).
1247 // In this case, if \a strict is \c true (default), all selected objects should satisfy
1248 // the specified \a type.
1249 // If \a count > 0, only specified number of the objects is retrieved from the selection.
1250 // In this case, if \a strict is \c true (default), function returns empty list if total number of selected
1251 // objects does not correspond to the \a count parameter. Otherwise (if \a strict is \c false),
1252 // function returns valid list of objects if at least \a count objects satisfy specified \a type.
1253 //
1254 // \param type type of the object(s) to be obtained from selection
1255 // \param count number of items to be retrieved from selection
1256 // \param strict selection policy
1257 // \return list of selected geometrical objects or empty list if selection is not satisfactory
1258 //================================================================
1259 QList<GEOM::GeomObjPtr> MyGEOMBase_Helper::getSelected( TopAbs_ShapeEnum type, int count, bool strict )
1260 {
1261   QList<TopAbs_ShapeEnum> types;
1262   types << type;
1263   return getSelected( types, count, strict );
1264 }
1265
1266 static bool typeInList( TopAbs_ShapeEnum type, const QList<TopAbs_ShapeEnum>& types )
1267 {
1268   bool ok = false;
1269   for ( int i = 0; i < types.count() && !ok; i++ )
1270     ok = types[i] == TopAbs_SHAPE || types[i] == type;
1271   return ok;
1272 }
1273
1274 //================================================================
1275 // Function : getSelected
1276 // Purpose  : Get selected objects by specified types
1277 //
1278 // Returns list of selected objects if selection satisfies specifies selection options.
1279 // (no matter global or local selection is activated). If \a types includes TopAbs_SHAPE,
1280 // geometrical objects of any valid type are expected.
1281 //
1282 // The \a types parameter specifies allowed types of the object(s) being selected.
1283 // The \a count parameter specifies exact number of the objects to be retrieved from selection.
1284 // The \a strict parameter specifies policy being applied to the selection.
1285 // If \a count < 0, then any number of the selected objects is valid (including 0).
1286 // In this case, if \a strict is \c true (default), all selected objects should satisfy
1287 // the specified \a type.
1288 // If \a count > 0, only specified number of the objects is retrieved from the selection.
1289 // In this case, if \a strict is \c true (default), function returns empty list if total number of selected
1290 // objects does not correspond to the \a count parameter. Otherwise (if \a strict is \c false),
1291 // function returns valid list of objects if at least \a count objects satisfy specified \a type.
1292 //
1293 // \param types list of allowed shape types for the objects to be obtained from selection
1294 // \param count number of items to be retrieved from selection
1295 // \param strict selection policy
1296 // \return list of selected geometrical objects or empty list if selection is not satisfactory
1297 //================================================================
1298 QList<GEOM::GeomObjPtr> MyGEOMBase_Helper::getSelected( const QList<TopAbs_ShapeEnum>& types, int count, bool strict )
1299 {
1300     SUIT_Session* session = SUIT_Session::session();
1301     QList<GEOM::GeomObjPtr> result;
1302
1303     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1304     if ( app ) {
1305 //        LightApp_SelectionMgr* selMgr = app->selectionMgr();
1306 //        if ( selMgr ) {
1307         if ( HEXABLOCKGUI::selectionMgr() != NULL) {
1308             SALOME_ListIO selected;
1309
1310             //======================================
1311 //            SUIT_DataOwnerPtrList selectedDataOwner;
1312 //            AIS_ListOfInteractive listOfSelected;
1313 //
1314 //            if (HEXABLOCKGUI::currentOccSelector != NULL)
1315 //                HEXABLOCKGUI::currentOccSelector->viewer()->getSelectedObjects(listOfSelected);
1316 //
1317 //            AIS_ListIteratorOfListOfInteractive it (listOfSelected);
1318 //            while (it.More ())
1319 //            {
1320 //                //do something with the current item : it.Value ()
1321 //                selected.Append(it.Value());
1322 //                it.Next ();
1323 //            }
1324             //======================================
1325
1326 //            selMgr->selectedObjects( selected );
1327             HEXABLOCKGUI::selectionMgr()->selectedObjects( selected/*, "", false*/ );
1328             SALOME_ListIteratorOfListIO it( selected );
1329             bool stopped = false;
1330             for ( ; it.More() && !stopped; it.Next() ) {
1331                 Handle(SALOME_InteractiveObject) IO = it.Value();
1332                 GEOM::GeomObjPtr object = GEOMBase::ConvertIOinGEOMObject( IO );
1333                 if ( object ) {
1334                     TColStd_IndexedMapOfInteger subShapes;
1335                     HEXABLOCKGUI::selectionMgr()->GetIndexes( IO, subShapes );
1336                     int nbSubShapes = subShapes.Extent();
1337                     if ( nbSubShapes == 0 ) {
1338                         // global selection
1339                         if ( typeInList( (TopAbs_ShapeEnum)(object->GetShapeType()), types ) ) {
1340                             result << object;
1341                             if ( count > 0 ) {
1342                                 if ( strict && result.count() > count ) {
1343                                     result.clear();
1344                                     stopped = true;
1345                                 }
1346                                 else if ( !strict && result.count() == count )
1347                                     stopped = true;
1348                             }
1349                         }
1350                         else if ( strict ) {
1351                             result.clear();
1352                             stopped = true;
1353                         }
1354                     }
1355                     else {
1356                         // local selection
1357                         for ( int i = 1; i <= nbSubShapes && !stopped; i++ ) {
1358                             int idx = subShapes( i );
1359                             GEOM::GeomObjPtr subShape = findObjectInFather( object.get(), idx );
1360                             if ( !subShape ) {
1361                                 // sub-shape is not yet published in the study
1362                                 GEOM::ShapesOpPtr shapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
1363                                 subShape.take( shapesOp->GetSubShape( object.get(), idx ) ); // take ownership!
1364                             }
1365                             if ( typeInList( (TopAbs_ShapeEnum)(subShape->GetShapeType()), types ) ) {
1366                                 result << subShape;
1367                                 if ( count > 0 ) {
1368                                     if ( strict && result.count() > count ) {
1369                                         result.clear();
1370                                         stopped = true;
1371                                     }
1372                                     else if ( !strict && result.count() == count )
1373                                         stopped = true;
1374                                 }
1375                             }
1376                             else if ( strict ) {
1377                                 result.clear();
1378                                 stopped = true;
1379                             }
1380                         }
1381                     }
1382                 }
1383             }
1384         }
1385     }
1386     return result;
1387 }
1388
1389 //================================================================
1390 // Function : setIsApplyAndClose
1391 // Purpose  : Set value of the flag indicating that the dialog is
1392 //            accepted by Apply & Close button
1393 //================================================================
1394 void MyGEOMBase_Helper::setIsApplyAndClose( const bool theFlag )
1395 {
1396   myIsApplyAndClose = theFlag;
1397 }
1398
1399 //================================================================
1400 // Function : isApplyAndClose
1401 // Purpose  : Get value of the flag indicating that the dialog is
1402 //            accepted by Apply & Close button
1403 //================================================================
1404 bool MyGEOMBase_Helper::isApplyAndClose() const
1405 {
1406   return myIsApplyAndClose;
1407 }
1408
1409 //================================================================
1410 // Function : setIsOptimizedBrowsing
1411 // Purpose  : Set value of the flag switching to optimized
1412 //            browsing mode (to select the first published
1413 //            object only)
1414 //================================================================
1415 void MyGEOMBase_Helper::setIsOptimizedBrowsing( const bool theFlag )
1416 {
1417   myIsOptimizedBrowsing = theFlag;
1418 }
1419
1420 //================================================================
1421 // Function : isOptimizedBrowsing
1422 // Purpose  : Get value of the flag switching to optimized
1423 //            browsing mode (to select the first published
1424 //            object only)
1425 //================================================================
1426 bool MyGEOMBase_Helper::isOptimizedBrowsing() const
1427 {
1428   return myIsOptimizedBrowsing;
1429 }