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"
36 #include <SUIT_Desktop.h>
37 #include <SUIT_Session.h>
38 #include <SUIT_ViewManager.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 <LightApp_DataOwner.h>
48 #include <SalomeApp_Tools.h>
50 #include "SALOME_Prs.h"
52 #include <OCCViewer_ViewModel.h>
53 #include <SVTK_ViewModel.h>
55 #include <TColStd_MapOfInteger.hxx>
56 #include <TCollection_AsciiString.hxx>
60 //================================================================
61 // Function : getActiveView
62 // Purpose : Get active view window, returns 0 if no open study frame
63 //================================================================
64 static SUIT_ViewWindow* getActiveView()
66 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
68 return SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
74 //================================================================
75 // Function : getGeomEngine
76 // Purpose : Static method
77 //================================================================
78 GEOM::GEOM_Gen_ptr GEOMBase_Helper::getGeomEngine()
80 return GeometryGUI::GetGeomGen();
83 //================================================================
84 // Function : GEOMBase_Helper
86 //================================================================
87 GEOMBase_Helper::GEOMBase_Helper( SUIT_Desktop* desktop )
88 : myDesktop( desktop ), myViewWindow( 0 ), myDisplayer( 0 ), myCommand( 0 ), isPreview( false )
92 //================================================================
93 // Function : ~GEOMBase_Helper
95 //================================================================
96 GEOMBase_Helper::~GEOMBase_Helper()
98 if ( !SUIT_Session::session()->activeApplication()->desktop() )
101 if ( myPreview.size() )
105 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
107 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
109 globalSelection(aGeomGUI->getLocalSelectionMode() , 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 ).toLatin1().constData() ) ), 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).toLatin1().constData())), 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 ).toLatin1().constData() ) ), 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,
249 const int displayMode,
254 if ( !isValid( msg ) )
256 erasePreview( update );
261 erasePreview( false );
264 SUIT_OverrideCursor wc;
266 if ( !execute( objects ) || !getOperation()->IsDone() ) {
270 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it )
272 displayPreview( *it, true, activate, false, lineWidth, displayMode, color );
273 if ( toRemoveFromEngine )
274 getGeomEngine()->RemoveObject( *it );
278 catch( const SALOME::SALOME_Exception& e ) {
279 SalomeApp_Tools::QtCatchCorbaException( e );
288 //================================================================
289 // Function : displayPreview
290 // Purpose : Method for displaying preview of resulting shape
291 //================================================================
292 void GEOMBase_Helper::displayPreview( GEOM::GEOM_Object_ptr object,
296 const double lineWidth,
297 const int displayMode,
300 // Set color for preview shape
301 getDisplayer()->SetColor( color == -1 ? Quantity_NOC_VIOLET : color );
303 // set width of displayed shape
304 getDisplayer()->SetWidth( lineWidth );
306 // set display mode of displayed shape
307 int aPrevDispMode = getDisplayer()->SetDisplayMode( displayMode );
309 // Disable activation of selection
310 getDisplayer()->SetToActivate( activate );
312 // Make a reference to GEOM_Object
313 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string( object );
314 getDisplayer()->SetName( objStr.in() );
317 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( object );
318 if ( aPrs == 0 || aPrs->IsNull() )
322 displayPreview( aPrs, append, update );
324 getDisplayer()->UnsetName();
325 getDisplayer()->UnsetColor();
326 getDisplayer()->SetDisplayMode( aPrevDispMode );
328 // Enable activation of displayed objects
329 getDisplayer()->SetToActivate( true );
332 //================================================================
333 // Function : displayPreview
334 // Purpose : Method for displaying arbitrary preview objects (not limited to shapes)
335 //================================================================
336 void GEOMBase_Helper::displayPreview( const SALOME_Prs* prs,
341 erasePreview( false );
343 // remember current view frame to make correct erase preview later
344 myViewWindow = getActiveView();
346 if ( myViewWindow == 0 )
350 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
351 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
352 aViewManager->getType() == SVTK_Viewer::Type() )
354 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
355 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
357 aView->Display( prs );
360 // Add prs to the preview list
361 myPreview.push_back( (SALOME_Prs*)prs );
365 getDisplayer()->UpdateViewer();
368 //================================================================
369 // Function : erasePreview
371 //================================================================
372 void GEOMBase_Helper::erasePreview( const bool update )
374 // check view frame where the preview was displayed
375 bool vfOK = checkViewWindow() && myViewWindow;
376 // Iterate through presentations and delete them
377 for ( PrsList::iterator anIter = myPreview.begin(); anIter != myPreview.end(); ++anIter ) {
380 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
381 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
382 aViewManager->getType() == SVTK_Viewer::Type() )
384 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
385 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
387 aView->Erase( *anIter, true );
399 //================================================================
400 // Function : localSelection
401 // Purpose : Activate selection of objects of a given type
402 // IMPORTANT : Works after localSelection( ... ) method call only
403 //================================================================
404 void GEOMBase_Helper::activate( const int theType )
406 if (!getStudy()) return;
407 _PTR(Study) aStudy = getStudy()->studyDS();
408 _PTR(SComponent) aGeom ( aStudy->FindComponent( "GEOM" ) );
413 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( aGeom ) );
414 for ( ; anIter->More(); anIter->Next() )
416 _PTR(SObject) aSO ( anIter->Value() );
419 _PTR(SObject) aRefSO;
420 if ( !aSO->ReferencedObject( aRefSO ) )
422 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow
423 (GeometryGUI::ClientSObjectToObject(aSO));
424 if ( !anObj->_is_nil() && anObj->GetType() == theType )
425 aList.Append( new SALOME_InteractiveObject( aSO->GetID().c_str(), "GEOM", aSO->GetName().c_str()) );
430 getDisplayer()->LocalSelection( aList, 0 );
433 //================================================================
434 // Function : localSelection
435 // Purpose : Activate selection of subshapes in accordance with mode
436 // theMode is from TopAbs_ShapeEnum
437 //================================================================
438 void GEOMBase_Helper::localSelection( const ObjectList& theObjs, const int theMode )
440 SALOME_ListIO aListOfIO;
442 ObjectList::const_iterator anIter = theObjs.begin();
443 for ( ; anIter != theObjs.end(); ++anIter )
445 GEOM::GEOM_Object_ptr anObj = *anIter;
446 if ( anObj->_is_nil() )
448 string aEntry = getEntry( anObj );
450 aListOfIO.Append( new SALOME_InteractiveObject(
451 aEntry.c_str(), "GEOM", strdup( GEOMBase::GetName( anObj ).toLatin1().constData() ) ) );
454 getDisplayer()->LocalSelection( aListOfIO, theMode );
457 //================================================================
458 // Function : localSelection
459 // Purpose : Activate selection of subshapes in accordance with mode
460 // theMode is from TopAbs_ShapeEnum
461 //================================================================
462 void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const int mode )
464 // If object is null local selection for all objects is activated
465 if ( obj->_is_nil() ) {
466 getDisplayer()->LocalSelection( Handle(SALOME_InteractiveObject)(), mode );
471 objList.push_back( obj );
472 localSelection( objList, mode );
476 //================================================================
477 // Function : globalSelection
478 // Purpose : Activate selection of subshapes. Set selection filters
479 // in accordance with mode. theMode is from GEOMImpl_Types
480 //================================================================
481 void GEOMBase_Helper::globalSelection( const int theMode, const bool update )
483 getDisplayer()->GlobalSelection( theMode, update );
486 //================================================================
487 // Function : globalSelection
488 // Purpose : Activate selection of subshapes. Set selection filters
489 // in accordance with mode. theMode is from GEOMImpl_Types
490 //================================================================
491 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
494 getDisplayer()->GlobalSelection( theModes, update );
497 //================================================================
498 // Function : addInStudy
499 // Purpose : Add object in study
500 //================================================================
501 void GEOMBase_Helper::addInStudy( GEOM::GEOM_Object_ptr theObj, const char* theName )
506 _PTR(Study) aStudy = getStudy()->studyDS();
507 if ( !aStudy || theObj->_is_nil() )
510 GEOM::GEOM_Object_ptr aFatherObj = getFather( theObj );
512 getGeomEngine()->AddInStudy(GeometryGUI::ClientStudyToStudy(aStudy),
513 theObj, theName, aFatherObj);
516 //================================================================
517 // Function : updateObjBrowser
518 // Purpose : Update object browser
519 //================================================================
520 void GEOMBase_Helper::updateObjBrowser() const
522 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
524 CAM_Module* module = app->module( "Geometry" );
525 SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
527 appMod->updateObjBrowser( true );
532 //================================================================
533 // Function : updateViewer
534 // Purpose : Update active 3D view
535 //================================================================
536 void GEOMBase_Helper::updateViewer()
538 getDisplayer()->UpdateViewer();
541 //================================================================
542 // Function : getStudyId
543 // Purpose : Get study Id
544 //================================================================
545 int GEOMBase_Helper::getStudyId() const
549 anId = getStudy()->id();
553 //================================================================
554 // Function : getStudy
555 // Purpose : Returns the active study. It is recommended to use
556 // this method instead of direct desktop->getActiveStudy() calls
557 //================================================================
558 SalomeApp_Study* GEOMBase_Helper::getStudy() const
560 SUIT_Desktop* aDesktop = getDesktop();
564 QList<SUIT_Application*> anAppList = SUIT_Session::session()->applications();
566 SUIT_Application* anApp = 0;
567 QListIterator<SUIT_Application*> it( anAppList );
568 while ( it.hasNext() )
571 if ( anApp && anApp->desktop() == aDesktop )
575 return dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
578 //================================================================
579 // Function : getEntry
581 //================================================================
582 char* GEOMBase_Helper::getEntry( GEOM::GEOM_Object_ptr object ) const
584 SalomeApp_Study* study = getStudy();
586 char * objIOR = GEOMBase::GetIORFromObject( object );
587 string IOR( objIOR );
590 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
592 return TCollection_AsciiString((char*)SO->GetID().c_str()).ToCString();
599 //================================================================
600 // Function : getDisplayer
602 //================================================================
603 GEOM_Displayer* GEOMBase_Helper::getDisplayer()
606 myDisplayer = new GEOM_Displayer( getStudy() );
610 //================================================================
611 // Function : clearShapeBuffer
613 //================================================================
614 void GEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
616 if ( CORBA::is_nil( theObj ) )
619 CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( theObj );
620 TCollection_AsciiString asciiIOR( (char *)IOR.in() );
621 GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
623 if ( !getStudy() || !getStudy()->studyDS() )
626 _PTR(Study) aStudy = getStudy()->studyDS();
627 _PTR(SObject) aSObj ( aStudy->FindObjectIOR( string( IOR ) ) );
631 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
632 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
633 _PTR(GenericAttribute) anAttr;
634 if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
635 _PTR(AttributeIOR) anIOR ( anAttr );
636 TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
637 GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
642 //================================================================
643 // Function : openCommand
645 //================================================================
646 bool GEOMBase_Helper::openCommand()
649 if ( !getStudy() || hasCommand() )
652 GEOM::GEOM_IOperations_var anOp = GEOM::GEOM_IOperations::_narrow( getOperation() );
653 if ( !anOp->_is_nil() ) {
654 myCommand = new GEOM_Operation( SUIT_Session::session()->activeApplication(), anOp.in() );
662 //================================================================
663 // Function : abortCommand
665 //================================================================
666 bool GEOMBase_Helper::abortCommand()
677 //================================================================
678 // Function : commitCommand
680 //================================================================
681 bool GEOMBase_Helper::commitCommand( const char* )
692 //================================================================
693 // Function : hasCommand
695 //================================================================
696 bool GEOMBase_Helper::hasCommand() const
698 return (bool)myCommand;
701 //================================================================
702 // Function : getOperation
704 //================================================================
705 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::getOperation()
707 if ( myOperation->_is_nil() )
708 myOperation = createOperation();
715 //================================================================
716 // Function : checkViewWindow
718 //================================================================
719 bool GEOMBase_Helper::checkViewWindow()
722 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
723 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
724 while ( it.hasNext() )
726 if ( myViewWindow == it.next() )
734 //================================================================
735 // Function : onAccept
736 // Purpose : This method should be called from dialog's slots onOk() and onApply()
737 // It perfroms user input validation, then it
738 // performs a proper operation and manages transactions, etc.
739 //================================================================
740 bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction )
742 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
743 if ( !appStudy ) return false;
744 _PTR(Study) aStudy = appStudy->studyDS();
746 bool aLocked = (_PTR(AttributeStudyProperties) (aStudy->GetProperties()))->IsLocked();
748 MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
749 SUIT_MessageBox::warning ( (QWidget*)SUIT_Session::session()->activeApplication()->desktop(),
750 QObject::tr("WRN_WARNING"),
751 QObject::tr("WRN_STUDY_LOCKED"),
752 QObject::tr("BUT_OK") );
757 if ( !isValid( msg ) ) {
762 erasePreview( false );
765 if ( ( !publish && !useTransaction ) || openCommand() ) {
766 SUIT_OverrideCursor wc;
767 SUIT_Session::session()->activeApplication()->putInfo( "" );
769 if ( !execute( objects ) || !getOperation()->IsDone() ) {
775 const int nbObjs = objects.size();
777 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
779 QString aName = getNewObjectName();
782 aName = getPrefix(*it);
784 // Try to find a unique name
785 aName = GEOMBase::GetDefaultName(aName);
787 // Don't check name uniqueness in case of numerous objects
788 aName = aName + "_" + QString::number(aNumber++);
791 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
792 if ( aName.isEmpty() )
793 aName = GEOMBase::GetDefaultName( getPrefix( *it ) );
795 addInStudy( *it, aName.toLatin1() );
797 display( *it, false );
800 // asv : fix of PAL6454. If publish==false, then the original shape
801 // was modified, and need to be re-cached in GEOM_Client before redisplay
802 clearShapeBuffer( *it );
803 // withChildren=true, updateView=false
804 redisplay( *it, true, false );
811 SUIT_Session::session()->activeApplication()->putInfo( QObject::tr("GEOM_PRP_DONE") );
818 catch( const SALOME::SALOME_Exception& e ) {
819 SalomeApp_Tools::QtCatchCorbaException( e );
829 //================================================================
830 // Function : showError
831 // Purpose : Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
832 //================================================================
833 void GEOMBase_Helper::showError()
836 if ( !getOperation()->_is_nil() )
837 msg = QObject::tr( getOperation()->GetErrorCode() );
840 msg = QObject::tr( "GEOM_PRP_ABORT" );
842 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
843 QObject::tr( "GEOM_ERROR_STATUS" ),
845 QObject::tr( "BUT_OK" ) );
848 //================================================================
849 // Function : showError
850 // Purpose : Shows a error message followed by <msg>
851 //================================================================
852 void GEOMBase_Helper::showError( const QString& msg )
854 QString str( QObject::tr( "GEOM_INCORRECT_INPUT" ) );
855 if ( !msg.isEmpty() )
857 SUIT_MessageBox::critical(SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ), str, QObject::tr( "BUT_OK" ) );
860 //////////////////////////////////////////////////////////////////
861 // Virtual methods to be redefined in dialogs
862 //////////////////////////////////////////////////////////////////
864 //================================================================
865 // Function : createOperation
866 // Purpose : Redefine this method to return proper IOperation reference
867 //================================================================
868 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::createOperation()
870 GEOM::GEOM_IOperations_var aNilOp;
871 return aNilOp._retn();
874 //================================================================
875 // Function : isValid
876 // Purpose : Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
877 //================================================================
878 bool GEOMBase_Helper::isValid( QString& )
883 //================================================================
884 // Function : execute
885 // Purpose : This method is called by onAccept().
886 // It should perform the required operation and put all new or modified objects into
887 // <objects> argument.Should return <false> if some error occurs during its execution.
888 //================================================================
889 bool GEOMBase_Helper::execute( ObjectList& objects )
894 //================================================================
895 // Function : getFather
896 // Purpose : This method is called by addInStudy(). It should return a father object
897 // for <theObj> or a nil reference if <theObj> should be published
898 // as a top-level object.
899 //================================================================
900 GEOM::GEOM_Object_ptr GEOMBase_Helper::getFather( GEOM::GEOM_Object_ptr theObj )
902 return GEOM::GEOM_Object::_nil();
905 //================================================================
906 // Function : getNewObjectName
907 // Purpose : Redefine this method to return proper name for a new object
908 //================================================================
909 const char* GEOMBase_Helper::getNewObjectName() const
914 //================================================================
915 // Function : getPrefix
916 // Purpose : Get prefix for name of created object
917 //================================================================
918 QString GEOMBase_Helper::getPrefix( GEOM::GEOM_Object_ptr theObj ) const
920 if ( !myPrefix.isEmpty() || theObj->_is_nil() )
923 //TopoDS_Shape aShape;
924 //if ( !GEOMBase::GetShape( theObj, aShape ) )
927 //long aType = aShape.ShapeType();
928 GEOM::shape_type aType = theObj->GetShapeType();
932 case GEOM::VERTEX : return QObject::tr( "GEOM_VERTEX" );
933 case GEOM::EDGE : return QObject::tr( "GEOM_EDGE" );
934 case GEOM::WIRE : return QObject::tr( "GEOM_WIRE" );
935 case GEOM::FACE : return QObject::tr( "GEOM_FACE" );
936 case GEOM::SHELL : return QObject::tr( "GEOM_SHELL" );
937 case GEOM::SOLID : return QObject::tr( "GEOM_SOLID" );
938 case GEOM::COMPSOLID: return QObject::tr( "GEOM_COMPOUNDSOLID" );
939 case GEOM::COMPOUND : return QObject::tr( "GEOM_COMPOUND" );
944 //================================================================
945 // Function : selectedIO
946 // Purpose : Return the list of selected SALOME_InteractiveObject's
947 //================================================================
948 const SALOME_ListIO& GEOMBase_Helper::selectedIO()
952 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
954 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
956 aSelMgr->selectedObjects( mySelected );
962 //================================================================
963 // Function : IObjectCount
964 // Purpose : Return the number of selected objects
965 //================================================================
966 int GEOMBase_Helper::IObjectCount()
968 return selectedIO().Extent();
971 //================================================================
972 // Function : firstIObject
973 // Purpose : Return the first selected object in the selected object list
974 //================================================================
975 Handle(SALOME_InteractiveObject) GEOMBase_Helper::firstIObject()
977 const SALOME_ListIO& aList = selectedIO();
978 return aList.Extent() > 0 ? aList.First() : Handle(SALOME_InteractiveObject)();
981 //================================================================
982 // Function : lastIObject
983 // Purpose : Return the last selected object in the selected object list
984 //================================================================
985 Handle(SALOME_InteractiveObject) GEOMBase_Helper::lastIObject()
987 const SALOME_ListIO& aList = selectedIO();
988 return aList.Extent() > 0 ? aList.Last() : Handle(SALOME_InteractiveObject)();
991 //================================================================
992 // Function : getDesktop
993 // Purpose : Returns myDesktop field. Initialized in constructor, usually as dynamic_cast<SUIT_Desktop*>(parentWidget())
994 //================================================================
995 SUIT_Desktop* GEOMBase_Helper::getDesktop() const
1000 //================================================================
1001 // Function : selectObjects
1002 // Purpose : Selects list of objects
1003 //================================================================
1004 bool GEOMBase_Helper::selectObjects( ObjectList& objects )
1006 SUIT_DataOwnerPtrList aList;
1007 ObjectList::iterator anIter;
1008 for ( anIter = objects.begin(); anIter != objects.end(); ++anIter )
1010 string entry = getEntry( *anIter );
1011 QString aEntry( entry.c_str() );
1012 LightApp_DataOwner* anOwher = new LightApp_DataOwner( aEntry );
1013 aList.append( anOwher );
1016 SUIT_Session* session = SUIT_Session::session();
1017 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1021 LightApp_SelectionMgr* aMgr = app->selectionMgr();
1025 aMgr->setSelected( aList, false );