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