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