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