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