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