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