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