1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2004 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : GEOMBase_Helper.cxx
25 // Author : Sergey ANIKIN
29 #include <SUIT_ViewModel.h>
31 #include "GEOMBase_Helper.h"
33 #include "GEOM_Operation.h"
34 #include "GeometryGUI.h"
35 #include "GEOM_Displayer.h"
36 #include "GEOMImpl_Types.hxx"
38 #include <SUIT_Session.h>
39 #include <SUIT_ViewWindow.h>
40 #include <SUIT_MessageBox.h>
41 #include <SUIT_OverrideCursor.h>
43 #include <SalomeApp_Module.h>
44 #include <SalomeApp_Application.h>
45 #include <SalomeApp_Study.h>
46 #include <LightApp_SelectionMgr.h>
47 #include <SalomeApp_Tools.h>
48 #include <SalomeApp_DataModel.h>
49 #include <SalomeApp_Module.h>
51 #include <OCCViewer_ViewModel.h>
52 #include <SVTK_ViewModel.h>
54 #include <OB_Browser.h>
56 #include <TColStd_MapOfInteger.hxx>
57 #include <TCollection_AsciiString.hxx>
61 #include <SALOMEDSClient.hxx>
64 //================================================================
65 // Function : getActiveView
66 // Purpose : Get active view window, returns 0 if no open study frame
67 //================================================================
68 static SUIT_ViewWindow* getActiveView()
70 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
72 return SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
78 //================================================================
79 // Function : getGeomEngine
80 // Purpose : Static method
81 //================================================================
82 GEOM::GEOM_Gen_ptr GEOMBase_Helper::getGeomEngine()
84 return GeometryGUI::GetGeomGen();
87 //================================================================
88 // Function : GEOMBase_Helper
90 //================================================================
91 GEOMBase_Helper::GEOMBase_Helper( SUIT_Desktop* desktop )
92 : myDesktop( desktop ), myViewWindow( 0 ), myDisplayer( 0 ), myCommand( 0 ), isPreview( false )
96 //================================================================
97 // Function : ~GEOMBase_Helper
99 //================================================================
100 GEOMBase_Helper::~GEOMBase_Helper()
102 if ( !SUIT_Session::session()->activeApplication()->desktop() )
105 if ( myPreview.size() )
110 globalSelection( GEOM_ALLOBJECTS, true );
116 //================================================================
117 // Function : display
119 //================================================================
120 void GEOMBase_Helper::display( const ObjectList& objList, const bool updateView )
122 ObjectList::const_iterator it;
123 for ( it = objList.begin(); it != objList.end(); it++ ) {
124 display( *it, false );
126 if ( !objList.empty() && updateView )
127 getDisplayer()->UpdateViewer();
130 //================================================================
131 // Function : display
132 // Purpose : Display object.
133 // Important : Object must be already in study
134 //================================================================
135 void GEOMBase_Helper::display( GEOM::GEOM_Object_ptr object, const bool updateView )
137 // Unset color of shape ( this color may be set during preview displaying )
138 // Default color will be used
139 getDisplayer()->UnsetColor();
140 getDisplayer()->UnsetWidth();
142 // Enable activisation of selection
143 getDisplayer()->SetToActivate( true );
146 getDisplayer()->Display( object, updateView );
149 //================================================================
152 //================================================================
153 void GEOMBase_Helper::erase( const ObjectList& objList, const bool updateView )
155 ObjectList::const_iterator it = objList.begin();
156 for ( ; it != objList.end(); it++ ) {
159 if ( !objList.empty() && updateView )
160 getDisplayer()->UpdateViewer();
163 //================================================================
166 //================================================================
167 void GEOMBase_Helper::erase( GEOM::GEOM_Object_ptr object, const bool updateView )
169 if ( !object->_is_nil() ) {
170 string entry = getEntry( object );
171 getDisplayer()->Erase( new SALOME_InteractiveObject(
172 entry.c_str(), "GEOM", strdup( GEOMBase::GetName( object ) ) ), true, updateView );
176 //================================================================
177 // Function : redisplay
179 //================================================================
180 void GEOMBase_Helper::redisplay( const ObjectList& objList,
181 const bool withChildren,
182 const bool updateView )
184 ObjectList::const_iterator it = objList.begin();
185 for ( ; it != objList.end(); it++ ) {
186 redisplay( *it, withChildren, false );
188 if ( !objList.empty() && updateView )
189 getDisplayer()->UpdateViewer();
192 //================================================================
193 // Function : redisplay
195 //================================================================
196 void GEOMBase_Helper::redisplay( GEOM::GEOM_Object_ptr object,
197 const bool withChildren,
198 const bool updateView )
200 if ( !object->_is_nil() ) {
201 // Unset color of shape ( this color may be set during preview displaying )
202 // Default color will be used
203 getDisplayer()->UnsetColor();
204 getDisplayer()->UnsetWidth();
206 // Enable activisation of selection
207 getDisplayer()->SetToActivate( true );
209 string entry = getEntry( object );
210 getDisplayer()->Redisplay(new SALOME_InteractiveObject
211 (entry.c_str(), "GEOM", strdup(GEOMBase::GetName(object))), false);
214 if ( withChildren ) {
215 SalomeApp_Study* aDoc = getStudy();
216 if ( aDoc && aDoc->studyDS() ) {
217 _PTR(Study) aStudy = aDoc->studyDS();
218 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string(object);
219 _PTR(SObject) aSObj (aStudy->FindObjectIOR(string(objStr.in())));
221 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
222 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
223 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow
224 (GeometryGUI::ClientSObjectToObject(anIt->Value()));
225 if ( !CORBA::is_nil( aChild ) ) {
226 if ( !aChild->_is_nil() ) {
227 string entry = getEntry( aChild );
228 getDisplayer()->Redisplay( new SALOME_InteractiveObject(
229 entry.c_str(), "GEOM", strdup( GEOMBase::GetName( aChild ) ) ), false );
238 getDisplayer()->UpdateViewer();
241 //================================================================
242 // Function : displayPreview
243 // Purpose : Method for displaying preview based on execute() results
244 //================================================================
245 void GEOMBase_Helper::displayPreview( const bool activate,
247 const bool toRemoveFromEngine,
248 const double lineWidth )
252 if ( !isValid( msg ) )
254 erasePreview( update );
259 erasePreview( false );
262 SUIT_OverrideCursor wc;
264 if ( !execute( objects ) || !getOperation()->IsDone() ) {
268 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it )
270 displayPreview( *it, true, activate, false, lineWidth );
271 if ( toRemoveFromEngine )
272 getGeomEngine()->RemoveObject( *it );
276 catch( const SALOME::SALOME_Exception& e ) {
277 SalomeApp_Tools::QtCatchCorbaException( e );
286 //================================================================
287 // Function : displayPreview
288 // Purpose : Method for displaying preview of resulting shape
289 //================================================================
290 void GEOMBase_Helper::displayPreview( GEOM::GEOM_Object_ptr object,
294 const double lineWidth )
296 // Set color for preview shape
297 getDisplayer()->SetColor( Quantity_NOC_VIOLET );
299 // set width of displayed shape
300 getDisplayer()->SetWidth( lineWidth );
302 // Disable activation of selection
303 getDisplayer()->SetToActivate( activate );
305 // Make a reference to GEOM_Object
306 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string( object );
307 getDisplayer()->SetName( objStr.in() );
310 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( object );
311 if ( aPrs == 0 || aPrs->IsNull() )
315 displayPreview( aPrs, append, update );
317 getDisplayer()->UnsetName();
319 // Enable activation of displayed objects
320 getDisplayer()->SetToActivate( true );
323 //================================================================
324 // Function : displayPreview
325 // Purpose : Method for displaying arbitrary preview objects (not limited to shapes)
326 //================================================================
327 void GEOMBase_Helper::displayPreview( const SALOME_Prs* prs,
332 erasePreview( false );
334 // remember current view frame to make correct erase preview later
335 myViewWindow = getActiveView();
337 if ( myViewWindow == 0 )
341 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
342 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
343 aViewManager->getType() == SVTK_Viewer::Type() )
345 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
346 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
348 aView->Display( prs );
351 // Add prs to the preview list
352 myPreview.push_back( (SALOME_Prs*)prs );
356 getDisplayer()->UpdateViewer();
359 //================================================================
360 // Function : erasePreview
362 //================================================================
363 void GEOMBase_Helper::erasePreview( const bool update )
365 // check view frame where the preview was displayed
366 bool vfOK = checkViewWindow() && myViewWindow;
367 // Iterate through presentations and delete them
368 for ( PrsList::iterator anIter = myPreview.begin(); anIter != myPreview.end(); ++anIter ) {
371 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
372 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
373 aViewManager->getType() == SVTK_Viewer::Type() )
375 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
376 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
378 aView->Erase( *anIter, true );
390 //================================================================
391 // Function : localSelection
392 // Purpose : Activate selection of objects of a given type
393 // IMPORTANT : Works after localSelection( ... ) method call only
394 //================================================================
395 void GEOMBase_Helper::activate( const int theType )
397 if (!getStudy()) return;
398 _PTR(Study) aStudy = getStudy()->studyDS();
399 _PTR(SComponent) aGeom ( aStudy->FindComponent( "GEOM" ) );
404 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( aGeom ) );
405 for ( ; anIter->More(); anIter->Next() )
407 _PTR(SObject) aSO ( anIter->Value() );
410 _PTR(SObject) aRefSO;
411 if ( !aSO->ReferencedObject( aRefSO ) )
413 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow
414 (GeometryGUI::ClientSObjectToObject(aSO));
415 if ( !anObj->_is_nil() && anObj->GetType() == theType )
416 aList.Append( new SALOME_InteractiveObject( aSO->GetID().c_str(), "GEOM", aSO->GetName().c_str()) );
421 getDisplayer()->LocalSelection( aList, 0 );
424 //================================================================
425 // Function : localSelection
426 // Purpose : Activate selection of subshapes in accordance with mode
427 // theMode is from TopAbs_ShapeEnum
428 //================================================================
429 void GEOMBase_Helper::localSelection( const ObjectList& theObjs, const int theMode )
431 SALOME_ListIO aListOfIO;
433 ObjectList::const_iterator anIter = theObjs.begin();
434 for ( ; anIter != theObjs.end(); ++anIter )
436 GEOM::GEOM_Object_ptr anObj = *anIter;
437 if ( anObj->_is_nil() )
439 string aEntry = getEntry( anObj );
441 aListOfIO.Append( new SALOME_InteractiveObject(
442 aEntry.c_str(), "GEOM", strdup( GEOMBase::GetName( anObj ) ) ) );
445 getDisplayer()->LocalSelection( aListOfIO, theMode );
448 //================================================================
449 // Function : localSelection
450 // Purpose : Activate selection of subshapes in accordance with mode
451 // theMode is from TopAbs_ShapeEnum
452 //================================================================
453 void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const int mode )
455 // If object is null local selection for all objects is activated
456 if ( obj->_is_nil() ) {
457 getDisplayer()->LocalSelection( Handle(SALOME_InteractiveObject)(), mode );
462 objList.push_back( obj );
463 localSelection( objList, mode );
467 //================================================================
468 // Function : globalSelection
469 // Purpose : Activate selection of subshapes. Set selection filters
470 // in accordance with mode. theMode is from GEOMImpl_Types
471 //================================================================
472 void GEOMBase_Helper::globalSelection( const int theMode, const bool update )
474 getDisplayer()->GlobalSelection( theMode, update );
477 //================================================================
478 // Function : globalSelection
479 // Purpose : Activate selection of subshapes. Set selection filters
480 // in accordance with mode. theMode is from GEOMImpl_Types
481 //================================================================
482 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
485 getDisplayer()->GlobalSelection( theModes, update );
488 //================================================================
489 // Function : addInStudy
490 // Purpose : Add object in study
491 //================================================================
492 void GEOMBase_Helper::addInStudy( GEOM::GEOM_Object_ptr theObj, const char* theName )
497 _PTR(Study) aStudy = getStudy()->studyDS();
498 if ( !aStudy || theObj->_is_nil() )
501 GEOM::GEOM_Object_ptr aFatherObj = getFather( theObj );
503 getGeomEngine()->AddInStudy(GeometryGUI::ClientStudyToStudy(aStudy),
504 theObj, theName, aFatherObj);
507 //================================================================
508 // Function : updateObjBrowser
509 // Purpose : Update object browser
510 //================================================================
511 void GEOMBase_Helper::updateObjBrowser() const
513 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
515 CAM_Module* module = app->module( "Geometry" );
516 SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
518 appMod->updateObjBrowser( true );
523 //================================================================
524 // Function : updateViewer
525 // Purpose : Update active 3D view
526 //================================================================
527 void GEOMBase_Helper::updateViewer()
529 getDisplayer()->UpdateViewer();
532 //================================================================
533 // Function : getStudyId
534 // Purpose : Get study Id
535 //================================================================
536 int GEOMBase_Helper::getStudyId() const
540 anId = getStudy()->id();
544 //================================================================
545 // Function : getStudy
546 // Purpose : Returns the active study. It is recommended to use
547 // this method instead of direct desktop->getActiveStudy() calls
548 //================================================================
549 SalomeApp_Study* GEOMBase_Helper::getStudy() const
551 SUIT_Desktop* aDesktop = getDesktop();
555 QPtrList<SUIT_Application> anAppList = SUIT_Session::session()->applications();
557 SUIT_Application* anApp = 0;
558 for ( QPtrListIterator<SUIT_Application> it( anAppList ); it.current() ; ++it )
560 anApp = it.current();
561 if ( anApp->desktop() == aDesktop )
565 return dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
568 //================================================================
569 // Function : getEntry
571 //================================================================
572 char* GEOMBase_Helper::getEntry( GEOM::GEOM_Object_ptr object ) const
574 SalomeApp_Study* study = getStudy();
576 char * objIOR = GEOMBase::GetIORFromObject( object );
577 string IOR( objIOR );
580 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
582 return TCollection_AsciiString((char*)SO->GetID().c_str()).ToCString();
589 //================================================================
590 // Function : getDisplayer
592 //================================================================
593 GEOM_Displayer* GEOMBase_Helper::getDisplayer()
596 myDisplayer = new GEOM_Displayer( getStudy() );
600 //================================================================
601 // Function : clearShapeBuffer
603 //================================================================
604 void GEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
606 if ( CORBA::is_nil( theObj ) )
609 CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( theObj );
610 TCollection_AsciiString asciiIOR( (char *)IOR.in() );
611 GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
613 if ( !getStudy() || !getStudy()->studyDS() )
616 _PTR(Study) aStudy = getStudy()->studyDS();
617 _PTR(SObject) aSObj ( aStudy->FindObjectIOR( string( IOR ) ) );
621 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
622 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
623 _PTR(GenericAttribute) anAttr;
624 if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
625 _PTR(AttributeIOR) anIOR ( anAttr );
626 TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
627 GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
632 //================================================================
633 // Function : openCommand
635 //================================================================
636 bool GEOMBase_Helper::openCommand()
639 if ( !getStudy() || hasCommand() )
642 GEOM::GEOM_IOperations_var anOp = GEOM::GEOM_IOperations::_narrow( getOperation() );
643 if ( !anOp->_is_nil() ) {
644 myCommand = new GEOM_Operation( SUIT_Session::session()->activeApplication(), anOp.in() );
652 //================================================================
653 // Function : abortCommand
655 //================================================================
656 bool GEOMBase_Helper::abortCommand()
667 //================================================================
668 // Function : commitCommand
670 //================================================================
671 bool GEOMBase_Helper::commitCommand( const char* )
682 //================================================================
683 // Function : hasCommand
685 //================================================================
686 bool GEOMBase_Helper::hasCommand() const
688 return (bool)myCommand;
691 //================================================================
692 // Function : getOperation
694 //================================================================
695 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::getOperation()
697 if ( myOperation->_is_nil() )
698 myOperation = createOperation();
705 //================================================================
706 // Function : checkViewWindow
708 //================================================================
709 bool GEOMBase_Helper::checkViewWindow()
712 QPtrList<SUIT_ViewWindow> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
713 for ( QPtrListIterator<SUIT_ViewWindow> it( aViewWindowsList ); it.current(); ++it )
715 if ( myViewWindow == it.current() )
723 //================================================================
724 // Function : onAccept
725 // Purpose : This method should be called from dialog's slots onOk() and onApply()
726 // It perfroms user input validation, then it
727 // performs a proper operation and manages transactions, etc.
728 //================================================================
729 bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction )
731 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
732 if ( !appStudy ) return false;
733 _PTR(Study) aStudy = appStudy->studyDS();
735 bool aLocked = (_PTR(AttributeStudyProperties) (aStudy->GetProperties()))->IsLocked();
737 MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
738 SUIT_MessageBox::warn1 ( (QWidget*)SUIT_Session::session()->activeApplication()->desktop(),
739 QObject::tr("WRN_WARNING"),
740 QObject::tr("WRN_STUDY_LOCKED"),
741 QObject::tr("BUT_OK") );
746 if ( !isValid( msg ) ) {
751 erasePreview( false );
754 if ( ( !publish && !useTransaction ) || openCommand() ) {
755 SUIT_OverrideCursor wc;
756 SUIT_Session::session()->activeApplication()->putInfo( "" );
758 if ( !execute( objects ) || !getOperation()->IsDone() ) {
764 const int nbObjs = objects.size();
765 bool withChildren = false;
767 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
769 QString aName = getNewObjectName();
772 aName = getPrefix(*it);
774 // Try to find a unique name
775 aName = GEOMBase::GetDefaultName(aName);
777 // Don't check name uniqueness in case of numerous objects
778 aName = aName + "_" + QString::number(aNumber++);
781 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
782 if ( aName.isEmpty() )
783 aName = GEOMBase::GetDefaultName( getPrefix( *it ) );
785 addInStudy( *it, aName.latin1() );
786 withChildren = false;
787 display( *it, false );
789 else { // asv : fix of PAL6454. If publish==false, then the original shape was modified, and need to be re-cached in GEOM_Client
791 clearShapeBuffer( *it );
793 redisplay( *it, withChildren, false );
800 SUIT_Session::session()->activeApplication()->putInfo( QObject::tr("GEOM_PRP_DONE") );
807 catch( const SALOME::SALOME_Exception& e ) {
808 SalomeApp_Tools::QtCatchCorbaException( e );
818 //================================================================
819 // Function : showError
820 // Purpose : Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
821 //================================================================
822 void GEOMBase_Helper::showError()
825 if ( !getOperation()->_is_nil() )
826 msg = QObject::tr( getOperation()->GetErrorCode() );
829 msg = QObject::tr( "GEOM_PRP_ABORT" );
831 SUIT_MessageBox::error1( SUIT_Session::session()->activeApplication()->desktop(),
832 QObject::tr( "GEOM_ERROR_STATUS" ),
834 QObject::tr( "BUT_OK" ) );
837 //================================================================
838 // Function : showError
839 // Purpose : Shows a error message followed by <msg>
840 //================================================================
841 void GEOMBase_Helper::showError( const QString& msg )
843 QString str( QObject::tr( "GEOM_INCORRECT_INPUT" ) );
844 if ( !msg.isEmpty() )
846 SUIT_MessageBox::error1(SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ), str, QObject::tr( "BUT_OK" ) );
849 //////////////////////////////////////////////////////////////////
850 // Virtual methods to be redefined in dialogs
851 //////////////////////////////////////////////////////////////////
853 //================================================================
854 // Function : createOperation
855 // Purpose : Redefine this method to return proper IOperation reference
856 //================================================================
857 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::createOperation()
859 GEOM::GEOM_IOperations_var aNilOp;
860 return aNilOp._retn();
863 //================================================================
864 // Function : isValid
865 // Purpose : Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
866 //================================================================
867 bool GEOMBase_Helper::isValid( QString& )
872 //================================================================
873 // Function : execute
874 // Purpose : This method is called by onAccept().
875 // It should perform the required operation and put all new or modified objects into
876 // <objects> argument.Should return <false> if some error occurs during its execution.
877 //================================================================
878 bool GEOMBase_Helper::execute( ObjectList& objects )
883 //================================================================
884 // Function : getFather
885 // Purpose : This method is called by addInStudy(). It should return a father object
886 // for <theObj> or a nil reference if <theObj> should be published
887 // as a top-level object.
888 //================================================================
889 GEOM::GEOM_Object_ptr GEOMBase_Helper::getFather( GEOM::GEOM_Object_ptr theObj )
891 return GEOM::GEOM_Object::_nil();
894 //================================================================
895 // Function : getNewObjectName
896 // Purpose : Redefine this method to return proper name for a new object
897 //================================================================
898 const char* GEOMBase_Helper::getNewObjectName() const
903 //================================================================
904 // Function : getPrefix
905 // Purpose : Get prefix for name of created object
906 //================================================================
907 QString GEOMBase_Helper::getPrefix( GEOM::GEOM_Object_ptr theObj ) const
909 if ( !myPrefix.isEmpty() || theObj->_is_nil() )
913 if ( !GEOMBase::GetShape( theObj, aShape ) )
916 long aType = aShape.ShapeType();
920 case TopAbs_VERTEX : return QObject::tr( "GEOM_VERTEX" );
921 case TopAbs_EDGE : return QObject::tr( "GEOM_EDGE" );
922 case TopAbs_WIRE : return QObject::tr( "GEOM_WIRE" );
923 case TopAbs_FACE : return QObject::tr( "GEOM_FACE" );
924 case TopAbs_SHELL : return QObject::tr( "GEOM_SHELL" );
925 case TopAbs_SOLID : return QObject::tr( "GEOM_SOLID" );
926 case TopAbs_COMPSOLID: return QObject::tr( "GEOM_COMPOUNDSOLID" );
927 case TopAbs_COMPOUND : return QObject::tr( "GEOM_COMPOUND" );
932 //================================================================
933 // Function : selectedIO
934 // Purpose : Return the list of selected SALOME_InteractiveObject's
935 //================================================================
936 const SALOME_ListIO& GEOMBase_Helper::selectedIO()
940 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
942 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
944 aSelMgr->selectedObjects( mySelected );
950 //================================================================
951 // Function : IObjectCount
952 // Purpose : Return the number of selected objects
953 //================================================================
954 int GEOMBase_Helper::IObjectCount()
956 return selectedIO().Extent();
959 //================================================================
960 // Function : firstIObject
961 // Purpose : Return the first selected object in the selected object list
962 //================================================================
963 Handle(SALOME_InteractiveObject) GEOMBase_Helper::firstIObject()
965 const SALOME_ListIO& aList = selectedIO();
966 return aList.Extent() > 0 ? aList.First() : Handle(SALOME_InteractiveObject)();
969 //================================================================
970 // Function : lastIObject
971 // Purpose : Return the last selected object in the selected object list
972 //================================================================
973 Handle(SALOME_InteractiveObject) GEOMBase_Helper::lastIObject()
975 const SALOME_ListIO& aList = selectedIO();
976 return aList.Extent() > 0 ? aList.Last() : Handle(SALOME_InteractiveObject)();
979 //================================================================
980 // Function : getDesktop
981 // Purpose : Returns myDesktop field. Initialized in constructor, usually as dynamic_cast<SUIT_Desktop*>(parentWidget())
982 //================================================================
983 SUIT_Desktop* GEOMBase_Helper::getDesktop() const