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