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