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