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