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