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