Salome HOME
All modules must use SVTK package instead VTK
[modules/geom.git] / src / GEOMBase / GEOMBase_Helper.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2004  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.
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.org
21 //
22 //
23 //
24 //  File   : GEOMBase_Helper.cxx
25 //  Author : Sergey ANIKIN
26 //  Module : GEOM
27 //  $Header$
28
29 #include <SUIT_ViewModel.h>
30
31 #include "GEOMBase_Helper.h"
32 #include "GEOMBase.h"
33 #include "GEOM_Operation.h"
34 #include "GeometryGUI.h"
35 #include "GEOM_Displayer.h"
36 #include "GEOMImpl_Types.hxx"
37
38 #include <SUIT_Session.h>
39 #include <SUIT_ViewWindow.h>
40 #include <SUIT_MessageBox.h>
41 #include <SUIT_OverrideCursor.h>
42
43 #include <SalomeApp_Module.h>
44 #include <SalomeApp_Application.h>
45 #include <SalomeApp_Study.h>
46 #include <SalomeApp_SelectionMgr.h>
47 #include <SalomeApp_Tools.h>
48 #include <SalomeApp_DataModel.h>
49 #include <SalomeApp_Module.h>
50
51 #include <OCCViewer_ViewModel.h>
52 #include <SVTK_ViewModel.h>
53
54 #include <OB_Browser.h>
55
56 #include <TColStd_MapOfInteger.hxx>
57 #include <TCollection_AsciiString.hxx>
58
59 using namespace std;
60
61 #include <SALOMEDSClient.hxx>
62
63
64 //================================================================
65 // Function : getActiveView
66 // Purpose  : Get active view window, returns 0 if no open study frame
67 //================================================================
68 static SUIT_ViewWindow* 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   : myDesktop( desktop ), myViewWindow( 0 ), myDisplayer( 0 ), myCommand( 0 ), isPreview( false )
93 {
94 }
95
96 //================================================================
97 // Function : ~GEOMBase_Helper
98 // Purpose  :
99 //================================================================
100 GEOMBase_Helper::~GEOMBase_Helper()
101 {
102   if ( !SUIT_Session::session()->activeApplication()->desktop() )
103     return;
104
105   if ( myPreview.size() )
106     erasePreview();
107   if ( hasCommand() )
108     abortCommand();
109
110   globalSelection( GEOM_ALLOBJECTS, true );
111
112   delete myDisplayer;
113 }
114
115 //================================================================
116 // Function : display
117 // Purpose  :
118 //================================================================
119 void GEOMBase_Helper::display( const ObjectList& objList, const bool updateView )
120 {
121   ObjectList::const_iterator it;
122   for ( it = objList.begin(); it != objList.end(); it++ ) {
123     display( *it, false );
124   }
125   if ( !objList.empty() && updateView )
126     getDisplayer()->UpdateViewer();
127 }
128
129 //================================================================
130 // Function  : display
131 // Purpose   : Display object.
132 // Important : Object must be already in study
133 //================================================================
134 void GEOMBase_Helper::display( GEOM::GEOM_Object_ptr object, const bool updateView )
135 {
136   // Unset color of shape ( this color may be set during preview displaying )
137   // Default color will be used
138   getDisplayer()->UnsetColor();
139   getDisplayer()->UnsetWidth();
140
141   // Enable activisation of selection
142   getDisplayer()->SetToActivate( true );
143
144   // Display object
145   getDisplayer()->Display( object, updateView );
146 }
147
148 //================================================================
149 // Function : erase
150 // Purpose  :
151 //================================================================
152 void GEOMBase_Helper::erase( const ObjectList& objList, const bool updateView )
153 {
154   ObjectList::const_iterator it = objList.begin();
155   for ( ; it != objList.end(); it++ ) {
156     erase( *it, false );
157   }
158   if ( !objList.empty() && updateView )
159     getDisplayer()->UpdateViewer();
160 }
161
162 //================================================================
163 // Function : erase
164 // Purpose  :
165 //================================================================
166 void GEOMBase_Helper::erase( GEOM::GEOM_Object_ptr object, const bool updateView )
167 {
168   if ( !object->_is_nil() ) {
169     string entry = getEntry( object );
170     getDisplayer()->Erase( new SALOME_InteractiveObject(
171       entry.c_str(), "GEOM", strdup( GEOMBase::GetName( object ) ) ), true, updateView );
172   }
173 }
174
175 //================================================================
176 // Function : redisplay
177 // Purpose  :
178 //================================================================
179 void GEOMBase_Helper::redisplay( const ObjectList& objList,
180                                  const bool withChildren,
181                                  const bool updateView )
182 {
183   ObjectList::const_iterator it = objList.begin();
184   for ( ; it != objList.end(); it++ ) {
185     redisplay( *it, withChildren, false );
186   }
187   if ( !objList.empty() && updateView )
188     getDisplayer()->UpdateViewer();
189 }
190
191 //================================================================
192 // Function : redisplay
193 // Purpose  :
194 //================================================================
195 void GEOMBase_Helper::redisplay( GEOM::GEOM_Object_ptr object,
196                                  const bool withChildren,
197                                  const bool updateView )
198 {
199   if ( !object->_is_nil() ) {
200     // Unset color of shape ( this color may be set during preview displaying )
201     // Default color will be used
202     getDisplayer()->UnsetColor();
203     getDisplayer()->UnsetWidth();
204
205     // Enable activisation of selection
206     getDisplayer()->SetToActivate( true );
207
208     string entry = getEntry( object );
209     getDisplayer()->Redisplay(new SALOME_InteractiveObject
210                               (entry.c_str(), "GEOM", strdup(GEOMBase::GetName(object))), false);
211   }
212
213   if ( withChildren ) {
214     SalomeApp_Study* aDoc = getStudy();
215     if ( aDoc && aDoc->studyDS() ) {
216       _PTR(Study) aStudy = aDoc->studyDS();
217       _PTR(SObject) aSObj (aStudy->FindObjectIOR(SalomeApp_Application::orb()->object_to_string(object)));
218       if ( aSObj  ) {
219         _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
220         for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
221           GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow
222             (GeometryGUI::ClientSObjectToObject(anIt->Value()));
223           if ( !CORBA::is_nil( aChild ) ) {
224             if ( !aChild->_is_nil() ) {
225               string entry = getEntry( aChild );
226               getDisplayer()->Redisplay( new SALOME_InteractiveObject(
227                 entry.c_str(), "GEOM", strdup( GEOMBase::GetName( aChild ) ) ), false );
228             }
229           }
230         }
231       }
232     }
233   }
234
235   if ( updateView )
236     getDisplayer()->UpdateViewer();
237 }
238
239 //================================================================
240 // Function : displayPreview
241 // Purpose  : Method for displaying preview based on execute() results
242 //================================================================
243 void GEOMBase_Helper::displayPreview( const bool   activate,
244                                       const bool   update,
245                                       const bool   toRemoveFromEngine,
246                                       const double lineWidth )
247 {
248   isPreview = true;
249   QString msg;
250   if ( !isValid( msg ) )
251   {
252     erasePreview( update );
253     isPreview = false;
254     return;
255   }
256
257   erasePreview( false );
258
259   try {
260     SUIT_OverrideCursor wc;
261     ObjectList objects;
262     if ( !execute( objects ) || !getOperation()->IsDone() ) {
263       wc.suspend();
264     }
265     else {
266       for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it )
267       {
268         displayPreview( *it, true, activate, false, lineWidth );
269         if ( toRemoveFromEngine )
270           getGeomEngine()->RemoveObject( *it );
271       }
272     }
273   }
274   catch( const SALOME::SALOME_Exception& e ) {
275     SalomeApp_Tools::QtCatchCorbaException( e );
276   }
277
278   isPreview = false;
279
280   if ( update )
281     updateViewer();
282 }
283
284 //================================================================
285 // Function : displayPreview
286 // Purpose  : Method for displaying preview of resulting shape
287 //================================================================
288 void GEOMBase_Helper::displayPreview( GEOM::GEOM_Object_ptr object,
289                                       const bool            append,
290                                       const bool            activate,
291                                       const bool            update,
292                                       const double          lineWidth )
293 {
294   // Set color for preview shape
295   getDisplayer()->SetColor( Quantity_NOC_VIOLET );
296
297   // set width of displayed shape
298   getDisplayer()->SetWidth( lineWidth );
299
300   // Disable activation of selection
301   getDisplayer()->SetToActivate( activate );
302
303   // Make a reference to GEOM_Object
304   getDisplayer()->SetName( SalomeApp_Application::orb()->object_to_string( object ) );
305
306   // Build prs
307   SALOME_Prs* aPrs = getDisplayer()->BuildPrs( object );
308   if ( aPrs == 0 || aPrs->IsNull() )
309     return;
310
311   // Display prs
312   displayPreview( aPrs, append, update );
313
314   getDisplayer()->UnsetName();
315
316   // Enable activation of displayed objects
317   getDisplayer()->SetToActivate( true );
318 }
319
320 //================================================================
321 // Function : displayPreview
322 // Purpose  : Method for displaying arbitrary preview objects (not limited to shapes)
323 //================================================================
324 void GEOMBase_Helper::displayPreview( const SALOME_Prs* prs,
325                                       const bool        append,
326                                       const bool        update )
327 {
328   if ( !append )
329     erasePreview( false );
330
331   // remember current view frame to make correct erase preview later
332   myViewWindow = getActiveView();
333
334   if ( myViewWindow == 0 )
335     return;
336
337   // Display prs
338   SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
339   if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
340        aViewManager->getType() == SVTK_Viewer::Type() )
341     {
342       SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
343       SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
344       if (aView)
345         aView->Display( prs );
346     }
347
348   // Add prs to the preview list
349   myPreview.push_back( (SALOME_Prs*)prs );
350
351   // Update viewer
352   if ( update )
353     getDisplayer()->UpdateViewer();
354 }
355
356 //================================================================
357 // Function : erasePreview
358 // Purpose  :
359 //================================================================
360 void GEOMBase_Helper::erasePreview( const bool update )
361 {
362   // check view frame where the preview was displayed
363   bool vfOK = checkViewWindow() && myViewWindow;
364   // Iterate through presentations and delete them
365   for ( PrsList::iterator anIter = myPreview.begin(); anIter != myPreview.end(); ++anIter ) {
366     if ( vfOK )
367       {
368          SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
369          if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
370               aViewManager->getType() == SVTK_Viewer::Type() )
371            {
372              SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
373              SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
374              if (aView)
375                aView->Erase( *anIter, true );
376            }
377       }
378     delete *anIter;
379   }
380   myPreview.clear();
381
382   // Update viewer
383   if ( update )
384     updateViewer();
385 }
386
387 //================================================================
388 // Function  : localSelection
389 // Purpose   : Activate selection of objects of a given type
390 // IMPORTANT : Works after localSelection( ... ) method call only
391 //================================================================
392 void GEOMBase_Helper::activate( const int theType )
393 {
394   if (!getStudy()) return;
395   _PTR(Study) aStudy = getStudy()->studyDS();
396   _PTR(SComponent) aGeom ( aStudy->FindComponent( "GEOM" ) );
397   if ( !aGeom )
398     return;
399
400   SALOME_ListIO aList;
401   _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( aGeom ) );
402   for ( ; anIter->More(); anIter->Next() )
403   {
404     _PTR(SObject) aSO ( anIter->Value() );
405     if ( aSO )
406     {
407       _PTR(SObject) aRefSO;
408       if ( !aSO->ReferencedObject( aRefSO ) )
409       {
410         GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow
411           (GeometryGUI::ClientSObjectToObject(aSO));
412         if ( !anObj->_is_nil() && anObj->GetType() == theType )
413           aList.Append( new SALOME_InteractiveObject( aSO->GetID().c_str(), "GEOM", aSO->GetName().c_str()) );
414       }
415     }
416   }
417
418   getDisplayer()->LocalSelection( aList, 0 );
419 }
420
421 //================================================================
422 // Function : localSelection
423 // Purpose  : Activate selection of subshapes in accordance with mode
424 //            theMode is from TopAbs_ShapeEnum
425 //================================================================
426 void GEOMBase_Helper::localSelection( const ObjectList& theObjs, const int theMode )
427 {
428   SALOME_ListIO aListOfIO;
429
430   ObjectList::const_iterator anIter = theObjs.begin();
431   for ( ; anIter != theObjs.end(); ++anIter )
432   {
433     GEOM::GEOM_Object_ptr anObj = *anIter;
434     if ( anObj->_is_nil() )
435       continue;
436     string aEntry = getEntry( anObj );
437     if ( aEntry != "" )
438       aListOfIO.Append( new SALOME_InteractiveObject(
439         aEntry.c_str(), "GEOM", strdup( GEOMBase::GetName( anObj ) ) ) );
440   }
441
442   getDisplayer()->LocalSelection( aListOfIO, theMode );
443 }
444
445 //================================================================
446 // Function : localSelection
447 // Purpose  : Activate selection of subshapes in accordance with mode
448 //            theMode is from TopAbs_ShapeEnum
449 //================================================================
450 void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const int mode )
451 {
452   // If object is null local selection for all objects is activated
453   if ( obj->_is_nil() ) {
454     getDisplayer()->LocalSelection( Handle(SALOME_InteractiveObject)(), mode );
455     return;
456   }
457
458   ObjectList objList;
459   objList.push_back( obj );
460   localSelection( objList, mode );
461 }
462
463
464 //================================================================
465 // Function : globalSelection
466 // Purpose  : Activate selection of subshapes. Set selection filters
467 //            in accordance with mode. theMode is from GEOMImpl_Types
468 //================================================================
469 void GEOMBase_Helper::globalSelection( const int theMode, const bool update )
470 {
471   getDisplayer()->GlobalSelection( theMode, update );
472 }
473
474 //================================================================
475 // Function : globalSelection
476 // Purpose  : Activate selection of subshapes. Set selection filters
477 //            in accordance with mode. theMode is from GEOMImpl_Types
478 //================================================================
479 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
480                                        const bool update )
481 {
482   getDisplayer()->GlobalSelection( theModes, update );
483 }
484
485 //================================================================
486 // Function : addInStudy
487 // Purpose  : Add object in study
488 //================================================================
489 void GEOMBase_Helper::addInStudy( GEOM::GEOM_Object_ptr theObj, const char* theName )
490 {
491   if ( !hasCommand() )
492     return;
493
494   _PTR(Study) aStudy = getStudy()->studyDS();
495   if ( !aStudy || theObj->_is_nil() )
496     return;
497
498   GEOM::GEOM_Object_ptr aFatherObj = getFather( theObj );
499
500   getGeomEngine()->AddInStudy(GeometryGUI::ClientStudyToStudy(aStudy),
501                               theObj, theName, aFatherObj);
502 }
503
504 //================================================================
505 // Function : updateObjBrowser
506 // Purpose  : Update object browser
507 //================================================================
508 void GEOMBase_Helper::updateObjBrowser() const
509 {
510   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
511   if (app) {
512     CAM_Module* module = app->module( "Geometry" );
513     SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
514     if ( appMod ) {
515       appMod->updateObjBrowser( true );
516     }
517   }
518 }
519
520 //================================================================
521 // Function : updateViewer
522 // Purpose  : Update active 3D view
523 //================================================================
524 void GEOMBase_Helper::updateViewer()
525 {
526   getDisplayer()->UpdateViewer();
527 }
528
529 //================================================================
530 // Function : getStudyId
531 // Purpose  : Get study Id
532 //================================================================
533 int GEOMBase_Helper::getStudyId() const
534 {
535   int anId = -1;
536   if ( getStudy() )
537     anId = getStudy()->id();
538   return anId;
539 }
540
541 //================================================================
542 // Function : getStudy
543 // Purpose  : Returns the active study. It is recommended to use
544 //            this method instead of direct desktop->getActiveStudy() calls
545 //================================================================
546 SalomeApp_Study* GEOMBase_Helper::getStudy() const
547 {
548   SUIT_Desktop* aDesktop = getDesktop();
549   if (!aDesktop)
550     return 0;
551
552   QPtrList<SUIT_Application> anAppList = SUIT_Session::session()->applications();
553
554   SUIT_Application* anApp = 0;
555   for ( QPtrListIterator<SUIT_Application> it( anAppList ); it.current() ; ++it )
556     {
557       anApp = it.current();
558       if ( anApp->desktop() == aDesktop )
559         break;
560     }
561
562   return dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
563 }
564
565 //================================================================
566 // Function : getEntry
567 // Purpose  :
568 //================================================================
569 char* GEOMBase_Helper::getEntry( GEOM::GEOM_Object_ptr object ) const
570 {
571   SalomeApp_Study* study = getStudy();
572   if ( study )  {
573     string IOR = GEOMBase::GetIORFromObject( object);
574     if ( IOR != "" ) {
575       _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
576       if ( SO ) {
577         return TCollection_AsciiString((char*)SO->GetID().c_str()).ToCString();
578       }
579     }
580   }
581   return "";
582 }
583
584 //================================================================
585 // Function : getDisplayer
586 // Purpose  :
587 //================================================================
588 GEOM_Displayer* GEOMBase_Helper::getDisplayer()
589 {
590   if ( !myDisplayer )
591     myDisplayer = new GEOM_Displayer( getStudy() );
592   return myDisplayer;
593 }
594
595 //================================================================
596 // Function : clearShapeBuffer
597 // Purpose  :
598 //================================================================
599 void GEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
600 {
601   if ( CORBA::is_nil( theObj ) )
602     return;
603
604   string IOR = SalomeApp_Application::orb()->object_to_string( theObj );
605   TCollection_AsciiString asciiIOR( strdup( IOR.c_str() ) );
606   GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
607
608   if ( !getStudy() || !getStudy()->studyDS() )
609     return;
610
611   _PTR(Study) aStudy = getStudy()->studyDS();
612   _PTR(SObject) aSObj ( aStudy->FindObjectIOR( IOR ) );
613   if ( !aSObj )
614     return;
615
616   _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
617   for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
618     _PTR(GenericAttribute) anAttr;
619     if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
620       _PTR(AttributeIOR) anIOR ( anAttr );
621       TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
622       GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
623     }
624   }
625 }
626
627 //================================================================
628 // Function : openCommand
629 // Purpose  :
630 //================================================================
631 bool GEOMBase_Helper::openCommand()
632 {
633   bool res = false;
634   if ( !getStudy() || hasCommand() )
635     return res;
636
637   GEOM::GEOM_IOperations_var anOp = GEOM::GEOM_IOperations::_narrow( getOperation() );
638   if ( !anOp->_is_nil() ) {
639     myCommand = new GEOM_Operation( SUIT_Session::session()->activeApplication(), anOp.in() );
640     myCommand->start();
641     res = true;
642   }
643
644   return res;
645 }
646
647 //================================================================
648 // Function : abortCommand
649 // Purpose  :
650 //================================================================
651 bool GEOMBase_Helper::abortCommand()
652 {
653   if ( !hasCommand() )
654     return false;
655
656   myCommand->abort();
657   myCommand = 0;
658
659   return true;
660 }
661
662 //================================================================
663 // Function : commitCommand
664 // Purpose  :
665 //================================================================
666 bool GEOMBase_Helper::commitCommand( const char* )
667 {
668   if ( !hasCommand() )
669     return false;
670
671   myCommand->commit();
672   myCommand = 0;
673
674   return true;
675 }
676
677 //================================================================
678 // Function : hasCommand
679 // Purpose  :
680 //================================================================
681 bool GEOMBase_Helper::hasCommand() const
682 {
683   return (bool)myCommand;
684 }
685
686 //================================================================
687 // Function : getOperation
688 // Purpose  :
689 //================================================================
690 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::getOperation()
691 {
692   if ( myOperation->_is_nil() )
693     myOperation = createOperation();
694
695   return myOperation;
696 }
697
698
699
700 //================================================================
701 // Function : checkViewWindow
702 // Purpose  :
703 //================================================================
704 bool GEOMBase_Helper::checkViewWindow()
705 {
706   if ( myViewWindow ){
707     QPtrList<SUIT_ViewWindow> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
708     for ( QPtrListIterator<SUIT_ViewWindow> it( aViewWindowsList ); it.current(); ++it )
709       {
710         if ( myViewWindow == it.current() )
711           return true;
712       }
713   }
714   myViewWindow = 0;
715   return false;
716 }
717
718 //================================================================
719 // Function : onAccept
720 // Purpose  : This method should be called from dialog's slots onOk() and onApply()
721 //            It perfroms user input validation, then it
722 //            performs a proper operation and manages transactions, etc.
723 //================================================================
724 bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction )
725 {
726   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
727   if ( !appStudy ) return false;
728   _PTR(Study) aStudy = appStudy->studyDS();
729
730   bool aLocked = (_PTR(AttributeStudyProperties) (aStudy->GetProperties()))->IsLocked();
731   if ( aLocked ) {
732     MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
733     SUIT_MessageBox::warn1 ( (QWidget*)SUIT_Session::session()->activeApplication()->desktop(),
734                            QObject::tr("WRN_WARNING"),
735                            QObject::tr("WRN_STUDY_LOCKED"),
736                            QObject::tr("BUT_OK") );
737     return false;
738   }
739
740   QString msg;
741   if ( !isValid( msg ) ) {
742     showError( msg );
743     return false;
744   }
745
746   erasePreview( false );
747
748   try {
749     if ( ( !publish && !useTransaction ) || openCommand() ) {
750       SUIT_OverrideCursor wc;
751       SUIT_Session::session()->activeApplication()->putInfo( "" );
752       ObjectList objects;
753       if ( !execute( objects ) || !getOperation()->IsDone() ) {
754         wc.suspend();
755         abortCommand();
756         showError();
757       }
758       else {
759         const int nbObjs = objects.size();
760         bool withChildren = false;
761         for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
762           if ( publish ) {
763             QString aName("");
764             if ( nbObjs > 1 )
765               aName = strlen( getNewObjectName() ) ? GEOMBase::GetDefaultName( getNewObjectName() ) : GEOMBase::GetDefaultName( getPrefix( *it ) );
766             else {
767               aName = getNewObjectName();
768               // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
769               if ( aName.isEmpty() )
770                 aName = GEOMBase::GetDefaultName( getPrefix( *it ) );
771             }
772             addInStudy( *it, aName.latin1() );
773             withChildren = false;
774             display( *it, false );
775           }
776           else { // asv : fix of PAL6454. If publish==false, then the original shape was modified, and need to be re-cached in GEOM_Client
777                  // before redisplay
778             clearShapeBuffer( *it );
779             withChildren = true;
780             redisplay( *it, withChildren, false );
781           }
782         }
783
784         if ( nbObjs ) {
785           commitCommand();
786           updateObjBrowser();
787           SUIT_Session::session()->activeApplication()->putInfo( QObject::tr("GEOM_PRP_DONE") );
788         }
789         else
790           abortCommand();
791       }
792     }
793   }
794   catch( const SALOME::SALOME_Exception& e ) {
795     SalomeApp_Tools::QtCatchCorbaException( e );
796     abortCommand();
797   }
798
799   updateViewer();
800
801   return true;
802 }
803
804
805 //================================================================
806 // Function : showError
807 // Purpose  : Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
808 //================================================================
809 void GEOMBase_Helper::showError()
810 {
811   QString msg;
812   if ( !getOperation()->_is_nil() )
813     msg = QObject::tr( getOperation()->GetErrorCode() );
814
815   if ( msg.isEmpty() )
816     msg = QObject::tr( "GEOM_PRP_ABORT" );
817
818   SUIT_MessageBox::error1( SUIT_Session::session()->activeApplication()->desktop(),
819                            QObject::tr( "GEOM_ERROR_STATUS" ),
820                            msg,
821                            QObject::tr( "BUT_OK" ) );
822 }
823
824 //================================================================
825 // Function : showError
826 // Purpose  : Shows a error message followed by <msg>
827 //================================================================
828 void GEOMBase_Helper::showError( const QString& msg )
829 {
830   QString str( QObject::tr( "GEOM_INCORRECT_INPUT" ) );
831   if ( !msg.isEmpty() )
832     str += "\n" + msg;
833   SUIT_MessageBox::error1(SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ), str, QObject::tr( "BUT_OK" ) );
834 }
835
836 //////////////////////////////////////////////////////////////////
837 // Virtual methods to be redefined in dialogs
838 //////////////////////////////////////////////////////////////////
839
840 //================================================================
841 // Function : createOperation
842 // Purpose  : Redefine this method to return proper IOperation reference
843 //================================================================
844 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::createOperation()
845 {
846   GEOM::GEOM_IOperations_var aNilOp;
847   return aNilOp._retn();
848 }
849
850 //================================================================
851 // Function : isValid
852 // Purpose  : Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
853 //================================================================
854 bool GEOMBase_Helper::isValid( QString& )
855 {
856   return true;
857 }
858
859 //================================================================
860 // Function : execute
861 // Purpose  : This method is called by onAccept().
862 //            It should perform the required operation and put all new or modified objects into
863 //            <objects> argument.Should return <false> if some error occurs during its execution.
864 //================================================================
865 bool GEOMBase_Helper::execute( ObjectList& objects )
866 {
867   return false;
868 }
869
870 //================================================================
871 // Function : getFather
872 // Purpose  : This method is called by addInStudy(). It should return a father object
873 //            for <theObj> or a nil reference if <theObj> should be published
874 //            as a top-level object.
875 //================================================================
876 GEOM::GEOM_Object_ptr GEOMBase_Helper::getFather( GEOM::GEOM_Object_ptr theObj )
877 {
878   return GEOM::GEOM_Object::_nil();
879 }
880
881 //================================================================
882 // Function : getNewObjectName
883 // Purpose  : Redefine this method to return proper name for a new object
884 //================================================================
885 const char* GEOMBase_Helper::getNewObjectName() const
886 {
887   return "";
888 }
889
890 //================================================================
891 // Function : getPrefix
892 // Purpose  : Get prefix for name of created object
893 //================================================================
894 QString GEOMBase_Helper::getPrefix( GEOM::GEOM_Object_ptr theObj ) const
895 {
896   if ( !myPrefix.isEmpty() || theObj->_is_nil() )
897     return myPrefix;
898
899   TopoDS_Shape aShape;
900   if ( !GEOMBase::GetShape( theObj, aShape ) )
901     return "";
902
903   long aType = aShape.ShapeType();
904
905   switch ( aType )
906   {
907     case TopAbs_VERTEX   : return QObject::tr( "GEOM_VERTEX" );
908     case TopAbs_EDGE     : return QObject::tr( "GEOM_EDGE" );
909     case TopAbs_WIRE     : return QObject::tr( "GEOM_WIRE" );
910     case TopAbs_FACE     : return QObject::tr( "GEOM_FACE" );
911     case TopAbs_SHELL    : return QObject::tr( "GEOM_SHELL" );
912     case TopAbs_SOLID    : return QObject::tr( "GEOM_SOLID" );
913     case TopAbs_COMPSOLID: return QObject::tr( "GEOM_COMPOUNDSOLID" );
914     case TopAbs_COMPOUND : return QObject::tr( "GEOM_COMPOUND" );
915     default : return "";
916   }
917 }
918
919 //================================================================
920 // Function : selectedIO
921 // Purpose  : Return the list of selected SALOME_InteractiveObject's
922 //================================================================
923 const SALOME_ListIO& GEOMBase_Helper::selectedIO()
924 {
925   mySelected.Clear();
926
927   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
928   if ( app ) {
929     SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
930     if ( aSelMgr )
931       aSelMgr->selectedObjects( mySelected );
932   }
933
934   return mySelected;
935 }
936
937 //================================================================
938 // Function : IObjectCount
939 // Purpose  : Return the number of selected objects
940 //================================================================
941 int GEOMBase_Helper::IObjectCount()
942 {
943   return selectedIO().Extent();
944 }
945
946 //================================================================
947 // Function : firstIObject
948 // Purpose  :  Return the first selected object in the selected object list
949 //================================================================
950 Handle(SALOME_InteractiveObject) GEOMBase_Helper::firstIObject()
951 {
952   const SALOME_ListIO& aList = selectedIO();
953   return aList.Extent() > 0 ? aList.First() : Handle(SALOME_InteractiveObject)();
954 }
955
956 //================================================================
957 // Function : lastIObject
958 // Purpose  : Return the last selected object in the selected object list
959 //================================================================
960 Handle(SALOME_InteractiveObject) GEOMBase_Helper::lastIObject()
961 {
962   const SALOME_ListIO& aList = selectedIO();
963   return aList.Extent() > 0 ? aList.Last() : Handle(SALOME_InteractiveObject)();
964 }
965
966 //================================================================
967 // Function : getDesktop
968 // Purpose  : Returns myDesktop field.  Initialized in constructor, usually as dynamic_cast<SUIT_Desktop*>(parentWidget())
969 //================================================================
970 SUIT_Desktop* GEOMBase_Helper::getDesktop() const
971 {
972   return myDesktop;
973 }
974