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 <LightApp_DataOwner.h>
48 #include <SalomeApp_Tools.h>
49 #include <SalomeApp_DataModel.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() )
109 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
111 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
113 globalSelection(aGeomGUI->getLocalSelectionMode() , true );
120 //================================================================
121 // Function : display
123 //================================================================
124 void GEOMBase_Helper::display( const ObjectList& objList, const bool updateView )
126 ObjectList::const_iterator it;
127 for ( it = objList.begin(); it != objList.end(); it++ ) {
128 display( *it, false );
130 if ( !objList.empty() && updateView )
131 getDisplayer()->UpdateViewer();
134 //================================================================
135 // Function : display
136 // Purpose : Display object.
137 // Important : Object must be already in study
138 //================================================================
139 void GEOMBase_Helper::display( GEOM::GEOM_Object_ptr object, const bool updateView )
141 // Unset color of shape ( this color may be set during preview displaying )
142 // Default color will be used
143 getDisplayer()->UnsetColor();
144 getDisplayer()->UnsetWidth();
146 // Enable activisation of selection
147 getDisplayer()->SetToActivate( true );
150 getDisplayer()->Display( object, updateView );
153 //================================================================
156 //================================================================
157 void GEOMBase_Helper::erase( const ObjectList& objList, const bool updateView )
159 ObjectList::const_iterator it = objList.begin();
160 for ( ; it != objList.end(); it++ ) {
163 if ( !objList.empty() && updateView )
164 getDisplayer()->UpdateViewer();
167 //================================================================
170 //================================================================
171 void GEOMBase_Helper::erase( GEOM::GEOM_Object_ptr object, const bool updateView )
173 if ( !object->_is_nil() ) {
174 string entry = getEntry( object );
175 getDisplayer()->Erase( new SALOME_InteractiveObject(
176 entry.c_str(), "GEOM", strdup( GEOMBase::GetName( object ) ) ), true, updateView );
180 //================================================================
181 // Function : redisplay
183 //================================================================
184 void GEOMBase_Helper::redisplay( const ObjectList& objList,
185 const bool withChildren,
186 const bool updateView )
188 ObjectList::const_iterator it = objList.begin();
189 for ( ; it != objList.end(); it++ ) {
190 redisplay( *it, withChildren, false );
192 if ( !objList.empty() && updateView )
193 getDisplayer()->UpdateViewer();
196 //================================================================
197 // Function : redisplay
199 //================================================================
200 void GEOMBase_Helper::redisplay( GEOM::GEOM_Object_ptr object,
201 const bool withChildren,
202 const bool updateView )
204 if ( !object->_is_nil() ) {
205 // Unset color of shape ( this color may be set during preview displaying )
206 // Default color will be used
207 getDisplayer()->UnsetColor();
208 getDisplayer()->UnsetWidth();
210 // Enable activisation of selection
211 getDisplayer()->SetToActivate( true );
213 string entry = getEntry( object );
214 getDisplayer()->Redisplay(new SALOME_InteractiveObject
215 (entry.c_str(), "GEOM", strdup(GEOMBase::GetName(object))), false);
218 if ( withChildren ) {
219 SalomeApp_Study* aDoc = getStudy();
220 if ( aDoc && aDoc->studyDS() ) {
221 _PTR(Study) aStudy = aDoc->studyDS();
222 _PTR(SObject) aSObj (aStudy->FindObjectIOR(SalomeApp_Application::orb()->object_to_string(object)));
224 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
225 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
226 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow
227 (GeometryGUI::ClientSObjectToObject(anIt->Value()));
228 if ( !CORBA::is_nil( aChild ) ) {
229 if ( !aChild->_is_nil() ) {
230 string entry = getEntry( aChild );
231 getDisplayer()->Redisplay( new SALOME_InteractiveObject(
232 entry.c_str(), "GEOM", strdup( GEOMBase::GetName( aChild ) ) ), false );
241 getDisplayer()->UpdateViewer();
244 //================================================================
245 // Function : displayPreview
246 // Purpose : Method for displaying preview based on execute() results
247 //================================================================
248 void GEOMBase_Helper::displayPreview( const bool activate,
250 const bool toRemoveFromEngine,
251 const double lineWidth,
252 const int displayMode,
257 if ( !isValid( msg ) )
259 erasePreview( update );
264 erasePreview( false );
267 SUIT_OverrideCursor wc;
269 if ( !execute( objects ) || !getOperation()->IsDone() ) {
273 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it )
275 displayPreview( *it, true, activate, false, lineWidth, displayMode, color );
276 if ( toRemoveFromEngine )
277 getGeomEngine()->RemoveObject( *it );
281 catch( const SALOME::SALOME_Exception& e ) {
282 SalomeApp_Tools::QtCatchCorbaException( e );
291 //================================================================
292 // Function : displayPreview
293 // Purpose : Method for displaying preview of resulting shape
294 //================================================================
295 void GEOMBase_Helper::displayPreview( GEOM::GEOM_Object_ptr object,
299 const double lineWidth,
300 const int displayMode,
303 // Set color for preview shape
304 getDisplayer()->SetColor( color == -1 ? Quantity_NOC_VIOLET : color );
306 // set width of displayed shape
307 getDisplayer()->SetWidth( lineWidth );
309 // set display mode of displayed shape
310 int aPrevDispMode = getDisplayer()->SetDisplayMode( displayMode );
312 // Disable activation of selection
313 getDisplayer()->SetToActivate( activate );
315 // Make a reference to GEOM_Object
316 getDisplayer()->SetName( SalomeApp_Application::orb()->object_to_string( object ) );
319 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( object );
320 if ( aPrs == 0 || aPrs->IsNull() )
324 displayPreview( aPrs, append, update );
326 getDisplayer()->UnsetName();
327 getDisplayer()->UnsetColor();
328 getDisplayer()->SetDisplayMode( aPrevDispMode );
330 // Enable activation of displayed objects
331 getDisplayer()->SetToActivate( true );
334 //================================================================
335 // Function : displayPreview
336 // Purpose : Method for displaying arbitrary preview objects (not limited to shapes)
337 //================================================================
338 void GEOMBase_Helper::displayPreview( const SALOME_Prs* prs,
343 erasePreview( false );
345 // remember current view frame to make correct erase preview later
346 myViewWindow = getActiveView();
348 if ( myViewWindow == 0 )
352 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
353 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
354 aViewManager->getType() == SVTK_Viewer::Type() )
356 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
357 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
359 aView->Display( prs );
362 // Add prs to the preview list
363 myPreview.push_back( (SALOME_Prs*)prs );
367 getDisplayer()->UpdateViewer();
370 //================================================================
371 // Function : erasePreview
373 //================================================================
374 void GEOMBase_Helper::erasePreview( const bool update )
376 // check view frame where the preview was displayed
377 bool vfOK = checkViewWindow() && myViewWindow;
378 // Iterate through presentations and delete them
379 for ( PrsList::iterator anIter = myPreview.begin(); anIter != myPreview.end(); ++anIter ) {
382 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
383 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
384 aViewManager->getType() == SVTK_Viewer::Type() )
386 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
387 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
389 aView->Erase( *anIter, true );
401 //================================================================
402 // Function : localSelection
403 // Purpose : Activate selection of objects of a given type
404 // IMPORTANT : Works after localSelection( ... ) method call only
405 //================================================================
406 void GEOMBase_Helper::activate( const int theType )
408 if (!getStudy()) return;
409 _PTR(Study) aStudy = getStudy()->studyDS();
410 _PTR(SComponent) aGeom ( aStudy->FindComponent( "GEOM" ) );
415 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( aGeom ) );
416 for ( ; anIter->More(); anIter->Next() )
418 _PTR(SObject) aSO ( anIter->Value() );
421 _PTR(SObject) aRefSO;
422 if ( !aSO->ReferencedObject( aRefSO ) )
424 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow
425 (GeometryGUI::ClientSObjectToObject(aSO));
426 if ( !anObj->_is_nil() && anObj->GetType() == theType )
427 aList.Append( new SALOME_InteractiveObject( aSO->GetID().c_str(), "GEOM", aSO->GetName().c_str()) );
432 getDisplayer()->LocalSelection( aList, 0 );
435 //================================================================
436 // Function : localSelection
437 // Purpose : Activate selection of subshapes in accordance with mode
438 // theMode is from TopAbs_ShapeEnum
439 //================================================================
440 void GEOMBase_Helper::localSelection( const ObjectList& theObjs, const int theMode )
442 SALOME_ListIO aListOfIO;
444 ObjectList::const_iterator anIter = theObjs.begin();
445 for ( ; anIter != theObjs.end(); ++anIter )
447 GEOM::GEOM_Object_ptr anObj = *anIter;
448 if ( anObj->_is_nil() )
450 string aEntry = getEntry( anObj );
452 aListOfIO.Append( new SALOME_InteractiveObject(
453 aEntry.c_str(), "GEOM", strdup( GEOMBase::GetName( anObj ) ) ) );
456 getDisplayer()->LocalSelection( aListOfIO, theMode );
459 //================================================================
460 // Function : localSelection
461 // Purpose : Activate selection of subshapes in accordance with mode
462 // theMode is from TopAbs_ShapeEnum
463 //================================================================
464 void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const int mode )
466 // If object is null local selection for all objects is activated
467 if ( obj->_is_nil() ) {
468 getDisplayer()->LocalSelection( Handle(SALOME_InteractiveObject)(), mode );
473 objList.push_back( obj );
474 localSelection( objList, mode );
478 //================================================================
479 // Function : globalSelection
480 // Purpose : Activate selection of subshapes. Set selection filters
481 // in accordance with mode. theMode is from GEOMImpl_Types
482 //================================================================
483 void GEOMBase_Helper::globalSelection( const int theMode, const bool update )
485 getDisplayer()->GlobalSelection( theMode, update );
488 //================================================================
489 // Function : globalSelection
490 // Purpose : Activate selection of subshapes. Set selection filters
491 // in accordance with mode. theMode is from GEOMImpl_Types
492 //================================================================
493 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
496 getDisplayer()->GlobalSelection( theModes, update );
499 //================================================================
500 // Function : addInStudy
501 // Purpose : Add object in study
502 //================================================================
503 void GEOMBase_Helper::addInStudy( GEOM::GEOM_Object_ptr theObj, const char* theName )
508 _PTR(Study) aStudy = getStudy()->studyDS();
509 if ( !aStudy || theObj->_is_nil() )
512 GEOM::GEOM_Object_ptr aFatherObj = getFather( theObj );
514 getGeomEngine()->AddInStudy(GeometryGUI::ClientStudyToStudy(aStudy),
515 theObj, theName, aFatherObj);
518 //================================================================
519 // Function : updateObjBrowser
520 // Purpose : Update object browser
521 //================================================================
522 void GEOMBase_Helper::updateObjBrowser() const
524 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
526 CAM_Module* module = app->module( "Geometry" );
527 SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
529 appMod->updateObjBrowser( true );
534 //================================================================
535 // Function : updateViewer
536 // Purpose : Update active 3D view
537 //================================================================
538 void GEOMBase_Helper::updateViewer()
540 getDisplayer()->UpdateViewer();
543 //================================================================
544 // Function : getStudyId
545 // Purpose : Get study Id
546 //================================================================
547 int GEOMBase_Helper::getStudyId() const
551 anId = getStudy()->id();
555 //================================================================
556 // Function : getStudy
557 // Purpose : Returns the active study. It is recommended to use
558 // this method instead of direct desktop->getActiveStudy() calls
559 //================================================================
560 SalomeApp_Study* GEOMBase_Helper::getStudy() const
562 SUIT_Desktop* aDesktop = getDesktop();
566 QPtrList<SUIT_Application> anAppList = SUIT_Session::session()->applications();
568 SUIT_Application* anApp = 0;
569 for ( QPtrListIterator<SUIT_Application> it( anAppList ); it.current() ; ++it )
571 anApp = it.current();
572 if ( anApp->desktop() == aDesktop )
576 return dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
579 //================================================================
580 // Function : getEntry
582 //================================================================
583 char* GEOMBase_Helper::getEntry( GEOM::GEOM_Object_ptr object ) const
585 SalomeApp_Study* study = getStudy();
587 string IOR = GEOMBase::GetIORFromObject( object);
589 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
591 return TCollection_AsciiString((char*)SO->GetID().c_str()).ToCString();
598 //================================================================
599 // Function : getDisplayer
601 //================================================================
602 GEOM_Displayer* GEOMBase_Helper::getDisplayer()
605 myDisplayer = new GEOM_Displayer( getStudy() );
609 //================================================================
610 // Function : clearShapeBuffer
612 //================================================================
613 void GEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
615 if ( CORBA::is_nil( theObj ) )
618 string IOR = SalomeApp_Application::orb()->object_to_string( theObj );
619 TCollection_AsciiString asciiIOR( strdup( IOR.c_str() ) );
620 GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
622 if ( !getStudy() || !getStudy()->studyDS() )
625 _PTR(Study) aStudy = getStudy()->studyDS();
626 _PTR(SObject) aSObj ( aStudy->FindObjectIOR( IOR ) );
630 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
631 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
632 _PTR(GenericAttribute) anAttr;
633 if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
634 _PTR(AttributeIOR) anIOR ( anAttr );
635 TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
636 GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
641 //================================================================
642 // Function : openCommand
644 //================================================================
645 bool GEOMBase_Helper::openCommand()
648 if ( !getStudy() || hasCommand() )
651 GEOM::GEOM_IOperations_var anOp = GEOM::GEOM_IOperations::_narrow( getOperation() );
652 if ( !anOp->_is_nil() ) {
653 myCommand = new GEOM_Operation( SUIT_Session::session()->activeApplication(), anOp.in() );
661 //================================================================
662 // Function : abortCommand
664 //================================================================
665 bool GEOMBase_Helper::abortCommand()
676 //================================================================
677 // Function : commitCommand
679 //================================================================
680 bool GEOMBase_Helper::commitCommand( const char* )
691 //================================================================
692 // Function : hasCommand
694 //================================================================
695 bool GEOMBase_Helper::hasCommand() const
697 return (bool)myCommand;
700 //================================================================
701 // Function : getOperation
703 //================================================================
704 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::getOperation()
706 if ( myOperation->_is_nil() )
707 myOperation = createOperation();
714 //================================================================
715 // Function : checkViewWindow
717 //================================================================
718 bool GEOMBase_Helper::checkViewWindow()
721 QPtrList<SUIT_ViewWindow> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
722 for ( QPtrListIterator<SUIT_ViewWindow> it( aViewWindowsList ); it.current(); ++it )
724 if ( myViewWindow == it.current() )
732 //================================================================
733 // Function : onAccept
734 // Purpose : This method should be called from dialog's slots onOk() and onApply()
735 // It perfroms user input validation, then it
736 // performs a proper operation and manages transactions, etc.
737 //================================================================
738 bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction )
740 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
741 if ( !appStudy ) return false;
742 _PTR(Study) aStudy = appStudy->studyDS();
744 bool aLocked = (_PTR(AttributeStudyProperties) (aStudy->GetProperties()))->IsLocked();
746 MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
747 SUIT_MessageBox::warn1 ( (QWidget*)SUIT_Session::session()->activeApplication()->desktop(),
748 QObject::tr("WRN_WARNING"),
749 QObject::tr("WRN_STUDY_LOCKED"),
750 QObject::tr("BUT_OK") );
755 if ( !isValid( msg ) ) {
760 erasePreview( false );
763 if ( ( !publish && !useTransaction ) || openCommand() ) {
764 SUIT_OverrideCursor wc;
765 SUIT_Session::session()->activeApplication()->putInfo( "" );
767 if ( !execute( objects ) || !getOperation()->IsDone() ) {
773 const int nbObjs = objects.size();
775 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
777 QString aName = getNewObjectName();
780 aName = getPrefix(*it);
782 // Try to find a unique name
783 aName = GEOMBase::GetDefaultName(aName);
785 // Don't check name uniqueness in case of numerous objects
786 aName = aName + "_" + QString::number(aNumber++);
789 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
790 if ( aName.isEmpty() )
791 aName = GEOMBase::GetDefaultName( getPrefix( *it ) );
793 addInStudy( *it, aName.latin1() );
795 display( *it, false );
798 // asv : fix of PAL6454. If publish==false, then the original shape
799 // was modified, and need to be re-cached in GEOM_Client before redisplay
800 clearShapeBuffer( *it );
801 // withChildren=true, updateView=false
802 redisplay( *it, true, false );
809 SUIT_Session::session()->activeApplication()->putInfo( QObject::tr("GEOM_PRP_DONE") );
816 catch( const SALOME::SALOME_Exception& e ) {
817 SalomeApp_Tools::QtCatchCorbaException( e );
827 //================================================================
828 // Function : showError
829 // Purpose : Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
830 //================================================================
831 void GEOMBase_Helper::showError()
834 if ( !getOperation()->_is_nil() )
835 msg = QObject::tr( getOperation()->GetErrorCode() );
838 msg = QObject::tr( "GEOM_PRP_ABORT" );
840 SUIT_MessageBox::error1( SUIT_Session::session()->activeApplication()->desktop(),
841 QObject::tr( "GEOM_ERROR_STATUS" ),
843 QObject::tr( "BUT_OK" ) );
846 //================================================================
847 // Function : showError
848 // Purpose : Shows a error message followed by <msg>
849 //================================================================
850 void GEOMBase_Helper::showError( const QString& msg )
852 QString str( QObject::tr( "GEOM_INCORRECT_INPUT" ) );
853 if ( !msg.isEmpty() )
855 SUIT_MessageBox::error1(SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ), str, QObject::tr( "BUT_OK" ) );
858 //////////////////////////////////////////////////////////////////
859 // Virtual methods to be redefined in dialogs
860 //////////////////////////////////////////////////////////////////
862 //================================================================
863 // Function : createOperation
864 // Purpose : Redefine this method to return proper IOperation reference
865 //================================================================
866 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::createOperation()
868 GEOM::GEOM_IOperations_var aNilOp;
869 return aNilOp._retn();
872 //================================================================
873 // Function : isValid
874 // Purpose : Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
875 //================================================================
876 bool GEOMBase_Helper::isValid( QString& )
881 //================================================================
882 // Function : execute
883 // Purpose : This method is called by onAccept().
884 // It should perform the required operation and put all new or modified objects into
885 // <objects> argument.Should return <false> if some error occurs during its execution.
886 //================================================================
887 bool GEOMBase_Helper::execute( ObjectList& objects )
892 //================================================================
893 // Function : getFather
894 // Purpose : This method is called by addInStudy(). It should return a father object
895 // for <theObj> or a nil reference if <theObj> should be published
896 // as a top-level object.
897 //================================================================
898 GEOM::GEOM_Object_ptr GEOMBase_Helper::getFather( GEOM::GEOM_Object_ptr theObj )
900 return GEOM::GEOM_Object::_nil();
903 //================================================================
904 // Function : getNewObjectName
905 // Purpose : Redefine this method to return proper name for a new object
906 //================================================================
907 const char* GEOMBase_Helper::getNewObjectName() const
912 //================================================================
913 // Function : getPrefix
914 // Purpose : Get prefix for name of created object
915 //================================================================
916 QString GEOMBase_Helper::getPrefix( GEOM::GEOM_Object_ptr theObj ) const
918 if ( !myPrefix.isEmpty() || theObj->_is_nil() )
921 //TopoDS_Shape aShape;
922 //if ( !GEOMBase::GetShape( theObj, aShape ) )
925 //long aType = aShape.ShapeType();
926 GEOM::shape_type aType = theObj->GetShapeType();
930 case GEOM::VERTEX : return QObject::tr( "GEOM_VERTEX" );
931 case GEOM::EDGE : return QObject::tr( "GEOM_EDGE" );
932 case GEOM::WIRE : return QObject::tr( "GEOM_WIRE" );
933 case GEOM::FACE : return QObject::tr( "GEOM_FACE" );
934 case GEOM::SHELL : return QObject::tr( "GEOM_SHELL" );
935 case GEOM::SOLID : return QObject::tr( "GEOM_SOLID" );
936 case GEOM::COMPSOLID: return QObject::tr( "GEOM_COMPOUNDSOLID" );
937 case GEOM::COMPOUND : return QObject::tr( "GEOM_COMPOUND" );
942 //================================================================
943 // Function : selectedIO
944 // Purpose : Return the list of selected SALOME_InteractiveObject's
945 //================================================================
946 const SALOME_ListIO& GEOMBase_Helper::selectedIO()
950 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
952 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
954 aSelMgr->selectedObjects( mySelected );
960 //================================================================
961 // Function : IObjectCount
962 // Purpose : Return the number of selected objects
963 //================================================================
964 int GEOMBase_Helper::IObjectCount()
966 return selectedIO().Extent();
969 //================================================================
970 // Function : firstIObject
971 // Purpose : Return the first selected object in the selected object list
972 //================================================================
973 Handle(SALOME_InteractiveObject) GEOMBase_Helper::firstIObject()
975 const SALOME_ListIO& aList = selectedIO();
976 return aList.Extent() > 0 ? aList.First() : Handle(SALOME_InteractiveObject)();
979 //================================================================
980 // Function : lastIObject
981 // Purpose : Return the last selected object in the selected object list
982 //================================================================
983 Handle(SALOME_InteractiveObject) GEOMBase_Helper::lastIObject()
985 const SALOME_ListIO& aList = selectedIO();
986 return aList.Extent() > 0 ? aList.Last() : Handle(SALOME_InteractiveObject)();
989 //================================================================
990 // Function : getDesktop
991 // Purpose : Returns myDesktop field. Initialized in constructor, usually as dynamic_cast<SUIT_Desktop*>(parentWidget())
992 //================================================================
993 SUIT_Desktop* GEOMBase_Helper::getDesktop() const
998 //================================================================
999 // Function : selectObjects
1000 // Purpose : Selects list of objects
1001 //================================================================
1002 bool GEOMBase_Helper::selectObjects( ObjectList& objects )
1004 SUIT_DataOwnerPtrList aList;
1005 ObjectList::iterator anIter;
1006 for ( anIter = objects.begin(); anIter != objects.end(); ++anIter )
1008 string entry = getEntry( *anIter );
1009 QString aEntry( entry.c_str() );
1010 LightApp_DataOwner* anOwher = new LightApp_DataOwner( aEntry );
1011 aList.append( anOwher );
1014 SUIT_Session* session = SUIT_Session::session();
1015 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1019 LightApp_SelectionMgr* aMgr = app->selectionMgr();
1023 aMgr->setSelected( aList, false );