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