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
22 // File : GEOMBase_Helper.cxx
23 // Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
26 #include "GEOMBase_Helper.h"
28 #include "GEOM_Operation.h"
30 #include <GeometryGUI.h>
32 #include <SUIT_Desktop.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ViewManager.h>
35 #include <SUIT_ViewWindow.h>
36 #include <SUIT_ViewModel.h>
37 #include <SUIT_MessageBox.h>
38 #include <SUIT_OverrideCursor.h>
40 #include <SalomeApp_Module.h>
41 #include <SalomeApp_Application.h>
42 #include <SalomeApp_Study.h>
43 #include <LightApp_SelectionMgr.h>
44 #include <LightApp_DataOwner.h>
45 #include <SalomeApp_Tools.h>
47 #include <SALOME_Prs.h>
49 #include <OCCViewer_ViewModel.h>
50 #include <SVTK_ViewModel.h>
52 #include <TColStd_MapOfInteger.hxx>
53 #include <TCollection_AsciiString.hxx>
57 //================================================================
58 // Function : getActiveView
59 // Purpose : Get active view window, returns 0 if no open study frame
60 //================================================================
61 static SUIT_ViewWindow* getActiveView()
63 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
65 return SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
71 //================================================================
72 // Function : getGeomEngine
73 // Purpose : Static method
74 //================================================================
75 GEOM::GEOM_Gen_ptr GEOMBase_Helper::getGeomEngine()
77 return GeometryGUI::GetGeomGen();
80 //================================================================
81 // Function : GEOMBase_Helper
83 //================================================================
84 GEOMBase_Helper::GEOMBase_Helper( SUIT_Desktop* desktop )
85 : myDesktop( desktop ), myViewWindow( 0 ), myDisplayer( 0 ), myCommand( 0 ), isPreview( false )
89 //================================================================
90 // Function : ~GEOMBase_Helper
92 //================================================================
93 GEOMBase_Helper::~GEOMBase_Helper()
95 if ( !SUIT_Session::session()->activeApplication()->desktop() )
98 if ( myPreview.size() )
102 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
104 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
106 globalSelection(aGeomGUI->getLocalSelectionMode() , true );
113 //================================================================
114 // Function : display
116 //================================================================
117 void GEOMBase_Helper::display( const ObjectList& objList, const bool updateView )
119 ObjectList::const_iterator it;
120 for ( it = objList.begin(); it != objList.end(); it++ ) {
121 display( *it, false );
123 if ( !objList.empty() && updateView )
124 getDisplayer()->UpdateViewer();
127 //================================================================
128 // Function : display
129 // Purpose : Display object.
130 // Important : Object must be already in study
131 //================================================================
132 void GEOMBase_Helper::display( GEOM::GEOM_Object_ptr object, const bool updateView )
134 // Unset color of shape ( this color may be set during preview displaying )
135 // Default color will be used
136 getDisplayer()->UnsetColor();
137 getDisplayer()->UnsetWidth();
139 // Enable activisation of selection
140 getDisplayer()->SetToActivate( true );
143 getDisplayer()->Display( object, updateView );
146 //================================================================
149 //================================================================
150 void GEOMBase_Helper::erase( const ObjectList& objList, const bool updateView )
152 ObjectList::const_iterator it = objList.begin();
153 for ( ; it != objList.end(); it++ ) {
156 if ( !objList.empty() && updateView )
157 getDisplayer()->UpdateViewer();
160 //================================================================
163 //================================================================
164 void GEOMBase_Helper::erase( GEOM::GEOM_Object_ptr object, const bool updateView )
166 if ( !object->_is_nil() ) {
167 string entry = getEntry( object );
168 getDisplayer()->Erase( new SALOME_InteractiveObject(
169 entry.c_str(), "GEOM", strdup( GEOMBase::GetName( object ).toLatin1().constData() ) ), true, updateView );
173 //================================================================
174 // Function : redisplay
176 //================================================================
177 void GEOMBase_Helper::redisplay( const ObjectList& objList,
178 const bool withChildren,
179 const bool updateView )
181 ObjectList::const_iterator it = objList.begin();
182 for ( ; it != objList.end(); it++ ) {
183 redisplay( *it, withChildren, false );
185 if ( !objList.empty() && updateView )
186 getDisplayer()->UpdateViewer();
189 //================================================================
190 // Function : redisplay
192 //================================================================
193 void GEOMBase_Helper::redisplay( GEOM::GEOM_Object_ptr object,
194 const bool withChildren,
195 const bool updateView )
197 if ( !object->_is_nil() ) {
198 // Unset color of shape ( this color may be set during preview displaying )
199 // Default color will be used
200 getDisplayer()->UnsetColor();
201 getDisplayer()->UnsetWidth();
203 // Enable activisation of selection
204 getDisplayer()->SetToActivate( true );
206 string entry = getEntry( object );
207 getDisplayer()->Redisplay(new SALOME_InteractiveObject
208 (entry.c_str(), "GEOM", strdup(GEOMBase::GetName(object).toLatin1().constData())), false);
211 if ( withChildren ) {
212 SalomeApp_Study* aDoc = getStudy();
213 if ( aDoc && aDoc->studyDS() ) {
214 _PTR(Study) aStudy = aDoc->studyDS();
215 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string(object);
216 _PTR(SObject) aSObj (aStudy->FindObjectIOR(string(objStr.in())));
218 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
219 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
220 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow
221 (GeometryGUI::ClientSObjectToObject(anIt->Value()));
222 if ( !CORBA::is_nil( aChild ) ) {
223 if ( !aChild->_is_nil() ) {
224 string entry = getEntry( aChild );
225 getDisplayer()->Redisplay( new SALOME_InteractiveObject(
226 entry.c_str(), "GEOM", strdup( GEOMBase::GetName( aChild ).toLatin1().constData() ) ), false );
235 getDisplayer()->UpdateViewer();
238 //================================================================
239 // Function : displayPreview
240 // Purpose : Method for displaying preview based on execute() results
241 //================================================================
242 void GEOMBase_Helper::displayPreview( const bool activate,
244 const bool toRemoveFromEngine,
245 const double lineWidth,
246 const int displayMode,
251 if ( !isValid( msg ) )
253 erasePreview( update );
258 erasePreview( false );
261 SUIT_OverrideCursor wc;
263 if ( !execute( objects ) || !getOperation()->IsDone() ) {
267 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it )
269 displayPreview( *it, true, activate, false, lineWidth, displayMode, color );
270 if ( toRemoveFromEngine )
271 getGeomEngine()->RemoveObject( *it );
275 catch( const SALOME::SALOME_Exception& e ) {
276 SalomeApp_Tools::QtCatchCorbaException( e );
285 //================================================================
286 // Function : displayPreview
287 // Purpose : Method for displaying preview of resulting shape
288 //================================================================
289 void GEOMBase_Helper::displayPreview( GEOM::GEOM_Object_ptr object,
293 const double lineWidth,
294 const int displayMode,
297 // Set color for preview shape
298 getDisplayer()->SetColor( color == -1 ? Quantity_NOC_VIOLET : color );
300 // set width of displayed shape
301 getDisplayer()->SetWidth( lineWidth );
303 // set display mode of displayed shape
304 int aPrevDispMode = getDisplayer()->SetDisplayMode( displayMode );
306 // Disable activation of selection
307 getDisplayer()->SetToActivate( activate );
309 // Make a reference to GEOM_Object
310 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string( object );
311 getDisplayer()->SetName( objStr.in() );
314 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( object );
315 if ( aPrs == 0 || aPrs->IsNull() )
319 displayPreview( aPrs, append, update );
321 getDisplayer()->UnsetName();
322 getDisplayer()->UnsetColor();
323 getDisplayer()->SetDisplayMode( aPrevDispMode );
325 // Enable activation of displayed objects
326 getDisplayer()->SetToActivate( true );
329 //================================================================
330 // Function : displayPreview
331 // Purpose : Method for displaying arbitrary preview objects (not limited to shapes)
332 //================================================================
333 void GEOMBase_Helper::displayPreview( const SALOME_Prs* prs,
338 erasePreview( false );
340 // remember current view frame to make correct erase preview later
341 myViewWindow = getActiveView();
343 if ( myViewWindow == 0 )
347 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
348 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
349 aViewManager->getType() == SVTK_Viewer::Type() )
351 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
352 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
354 aView->Display( prs );
357 // Add prs to the preview list
358 myPreview.push_back( (SALOME_Prs*)prs );
362 getDisplayer()->UpdateViewer();
365 //================================================================
366 // Function : erasePreview
368 //================================================================
369 void GEOMBase_Helper::erasePreview( const bool update )
371 // check view frame where the preview was displayed
372 bool vfOK = checkViewWindow() && myViewWindow;
373 // Iterate through presentations and delete them
374 for ( PrsList::iterator anIter = myPreview.begin(); anIter != myPreview.end(); ++anIter ) {
377 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
378 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
379 aViewManager->getType() == SVTK_Viewer::Type() )
381 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
382 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
384 aView->Erase( *anIter, true );
396 //================================================================
397 // Function : localSelection
398 // Purpose : Activate selection of objects of a given type
399 // IMPORTANT : Works after localSelection( ... ) method call only
400 //================================================================
401 void GEOMBase_Helper::activate( const int theType )
403 if (!getStudy()) return;
404 _PTR(Study) aStudy = getStudy()->studyDS();
405 _PTR(SComponent) aGeom ( aStudy->FindComponent( "GEOM" ) );
410 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( aGeom ) );
411 for ( ; anIter->More(); anIter->Next() )
413 _PTR(SObject) aSO ( anIter->Value() );
416 _PTR(SObject) aRefSO;
417 if ( !aSO->ReferencedObject( aRefSO ) )
419 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow
420 (GeometryGUI::ClientSObjectToObject(aSO));
421 if ( !anObj->_is_nil() && anObj->GetType() == theType )
422 aList.Append( new SALOME_InteractiveObject( aSO->GetID().c_str(), "GEOM", aSO->GetName().c_str()) );
427 getDisplayer()->LocalSelection( aList, 0 );
430 //================================================================
431 // Function : localSelection
432 // Purpose : Activate selection of subshapes in accordance with mode
433 // theMode is from TopAbs_ShapeEnum
434 //================================================================
435 void GEOMBase_Helper::localSelection( const ObjectList& theObjs, const int theMode )
437 SALOME_ListIO aListOfIO;
439 ObjectList::const_iterator anIter = theObjs.begin();
440 for ( ; anIter != theObjs.end(); ++anIter )
442 GEOM::GEOM_Object_ptr anObj = *anIter;
443 if ( anObj->_is_nil() )
445 string aEntry = getEntry( anObj );
447 aListOfIO.Append( new SALOME_InteractiveObject(
448 aEntry.c_str(), "GEOM", strdup( GEOMBase::GetName( anObj ).toLatin1().constData() ) ) );
451 getDisplayer()->LocalSelection( aListOfIO, theMode );
454 //================================================================
455 // Function : localSelection
456 // Purpose : Activate selection of subshapes in accordance with mode
457 // theMode is from TopAbs_ShapeEnum
458 //================================================================
459 void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const int mode )
461 // If object is null local selection for all objects is activated
462 if ( obj->_is_nil() ) {
463 getDisplayer()->LocalSelection( Handle(SALOME_InteractiveObject)(), mode );
468 objList.push_back( obj );
469 localSelection( objList, mode );
473 //================================================================
474 // Function : globalSelection
475 // Purpose : Activate selection of subshapes. Set selection filters
476 // in accordance with mode. theMode is from GEOMImpl_Types
477 //================================================================
478 void GEOMBase_Helper::globalSelection( const int theMode, const bool update )
480 getDisplayer()->GlobalSelection( theMode, update );
483 //================================================================
484 // Function : globalSelection
485 // Purpose : Activate selection of subshapes. Set selection filters
486 // in accordance with mode. theMode is from GEOMImpl_Types
487 //================================================================
488 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
491 getDisplayer()->GlobalSelection( theModes, update );
494 //================================================================
495 // Function : addInStudy
496 // Purpose : Add object in study
497 //================================================================
498 void GEOMBase_Helper::addInStudy( GEOM::GEOM_Object_ptr theObj, const char* theName )
503 _PTR(Study) aStudy = getStudy()->studyDS();
504 if ( !aStudy || theObj->_is_nil() )
507 GEOM::GEOM_Object_ptr aFatherObj = getFather( theObj );
509 getGeomEngine()->AddInStudy(GeometryGUI::ClientStudyToStudy(aStudy),
510 theObj, theName, aFatherObj);
513 //================================================================
514 // Function : updateObjBrowser
515 // Purpose : Update object browser
516 //================================================================
517 void GEOMBase_Helper::updateObjBrowser() const
519 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
521 CAM_Module* module = app->module( "Geometry" );
522 SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
524 appMod->updateObjBrowser( true );
529 //================================================================
530 // Function : updateViewer
531 // Purpose : Update active 3D view
532 //================================================================
533 void GEOMBase_Helper::updateViewer()
535 getDisplayer()->UpdateViewer();
538 //================================================================
539 // Function : getStudyId
540 // Purpose : Get study Id
541 //================================================================
542 int GEOMBase_Helper::getStudyId() const
546 anId = getStudy()->id();
550 //================================================================
551 // Function : getStudy
552 // Purpose : Returns the active study. It is recommended to use
553 // this method instead of direct desktop->getActiveStudy() calls
554 //================================================================
555 SalomeApp_Study* GEOMBase_Helper::getStudy() const
557 SUIT_Desktop* aDesktop = getDesktop();
561 QList<SUIT_Application*> anAppList = SUIT_Session::session()->applications();
563 SUIT_Application* anApp = 0;
564 QListIterator<SUIT_Application*> it( anAppList );
565 while ( it.hasNext() )
568 if ( anApp && anApp->desktop() == aDesktop )
572 return dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
575 //================================================================
576 // Function : getEntry
578 //================================================================
579 char* GEOMBase_Helper::getEntry( GEOM::GEOM_Object_ptr object ) const
581 SalomeApp_Study* study = getStudy();
583 char * objIOR = GEOMBase::GetIORFromObject( object );
584 string IOR( objIOR );
587 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
589 return TCollection_AsciiString((char*)SO->GetID().c_str()).ToCString();
596 //================================================================
597 // Function : getDisplayer
599 //================================================================
600 GEOM_Displayer* GEOMBase_Helper::getDisplayer()
603 myDisplayer = new GEOM_Displayer( getStudy() );
607 //================================================================
608 // Function : clearShapeBuffer
610 //================================================================
611 void GEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
613 if ( CORBA::is_nil( theObj ) )
616 CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( theObj );
617 TCollection_AsciiString asciiIOR( (char *)IOR.in() );
618 GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
620 if ( !getStudy() || !getStudy()->studyDS() )
623 _PTR(Study) aStudy = getStudy()->studyDS();
624 _PTR(SObject) aSObj ( aStudy->FindObjectIOR( string( IOR ) ) );
628 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
629 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
630 _PTR(GenericAttribute) anAttr;
631 if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
632 _PTR(AttributeIOR) anIOR ( anAttr );
633 TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
634 GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
639 //================================================================
640 // Function : openCommand
642 //================================================================
643 bool GEOMBase_Helper::openCommand()
646 if ( !getStudy() || hasCommand() )
649 GEOM::GEOM_IOperations_var anOp = GEOM::GEOM_IOperations::_narrow( getOperation() );
650 if ( !anOp->_is_nil() ) {
651 myCommand = new GEOM_Operation( SUIT_Session::session()->activeApplication(), anOp.in() );
659 //================================================================
660 // Function : abortCommand
662 //================================================================
663 bool GEOMBase_Helper::abortCommand()
674 //================================================================
675 // Function : commitCommand
677 //================================================================
678 bool GEOMBase_Helper::commitCommand( const char* )
689 //================================================================
690 // Function : hasCommand
692 //================================================================
693 bool GEOMBase_Helper::hasCommand() const
695 return (bool)myCommand;
698 //================================================================
699 // Function : getOperation
701 //================================================================
702 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::getOperation()
704 if ( myOperation->_is_nil() )
705 myOperation = createOperation();
712 //================================================================
713 // Function : checkViewWindow
715 //================================================================
716 bool GEOMBase_Helper::checkViewWindow()
719 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
720 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
721 while ( it.hasNext() )
723 if ( myViewWindow == it.next() )
731 //================================================================
732 // Function : onAccept
733 // Purpose : This method should be called from dialog's slots onOk() and onApply()
734 // It perfroms user input validation, then it
735 // performs a proper operation and manages transactions, etc.
736 //================================================================
737 bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction )
739 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
740 if ( !appStudy ) return false;
741 _PTR(Study) aStudy = appStudy->studyDS();
743 bool aLocked = (_PTR(AttributeStudyProperties) (aStudy->GetProperties()))->IsLocked();
745 MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
746 SUIT_MessageBox::warning ( (QWidget*)SUIT_Session::session()->activeApplication()->desktop(),
747 QObject::tr("WRN_WARNING"),
748 QObject::tr("WRN_STUDY_LOCKED"),
749 QObject::tr("BUT_OK") );
754 if ( !isValid( msg ) ) {
759 erasePreview( false );
762 if ( ( !publish && !useTransaction ) || openCommand() ) {
763 SUIT_OverrideCursor wc;
764 SUIT_Session::session()->activeApplication()->putInfo( "" );
766 if ( !execute( objects ) || !getOperation()->IsDone() ) {
772 const int nbObjs = objects.size();
774 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
776 QString aName = getNewObjectName();
779 aName = getPrefix(*it);
781 // Try to find a unique name
782 aName = GEOMBase::GetDefaultName(aName);
784 // Don't check name uniqueness in case of numerous objects
785 aName = aName + "_" + QString::number(aNumber++);
788 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
789 if ( aName.isEmpty() )
790 aName = GEOMBase::GetDefaultName( getPrefix( *it ) );
792 addInStudy( *it, aName.toLatin1().constData() );
794 display( *it, false );
797 // asv : fix of PAL6454. If publish==false, then the original shape
798 // was modified, and need to be re-cached in GEOM_Client before redisplay
799 clearShapeBuffer( *it );
800 // withChildren=true, updateView=false
801 redisplay( *it, true, false );
808 SUIT_Session::session()->activeApplication()->putInfo( QObject::tr("GEOM_PRP_DONE") );
815 catch( const SALOME::SALOME_Exception& e ) {
816 SalomeApp_Tools::QtCatchCorbaException( e );
826 //================================================================
827 // Function : showError
828 // Purpose : Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
829 //================================================================
830 void GEOMBase_Helper::showError()
833 if ( !getOperation()->_is_nil() )
834 msg = QObject::tr( getOperation()->GetErrorCode() );
837 msg = QObject::tr( "GEOM_PRP_ABORT" );
839 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
840 QObject::tr( "GEOM_ERROR_STATUS" ),
842 QObject::tr( "BUT_OK" ) );
845 //================================================================
846 // Function : showError
847 // Purpose : Shows a error message followed by <msg>
848 //================================================================
849 void GEOMBase_Helper::showError( const QString& msg )
851 QString str( QObject::tr( "GEOM_INCORRECT_INPUT" ) );
852 if ( !msg.isEmpty() )
854 SUIT_MessageBox::critical(SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ), str, QObject::tr( "BUT_OK" ) );
857 //////////////////////////////////////////////////////////////////
858 // Virtual methods to be redefined in dialogs
859 //////////////////////////////////////////////////////////////////
861 //================================================================
862 // Function : createOperation
863 // Purpose : Redefine this method to return proper IOperation reference
864 //================================================================
865 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::createOperation()
867 GEOM::GEOM_IOperations_var aNilOp;
868 return aNilOp._retn();
871 //================================================================
872 // Function : isValid
873 // Purpose : Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
874 //================================================================
875 bool GEOMBase_Helper::isValid( QString& )
880 //================================================================
881 // Function : execute
882 // Purpose : This method is called by onAccept().
883 // It should perform the required operation and put all new or modified objects into
884 // <objects> argument.Should return <false> if some error occurs during its execution.
885 //================================================================
886 bool GEOMBase_Helper::execute( ObjectList& objects )
891 //================================================================
892 // Function : getFather
893 // Purpose : This method is called by addInStudy(). It should return a father object
894 // for <theObj> or a nil reference if <theObj> should be published
895 // as a top-level object.
896 //================================================================
897 GEOM::GEOM_Object_ptr GEOMBase_Helper::getFather( GEOM::GEOM_Object_ptr theObj )
899 return GEOM::GEOM_Object::_nil();
902 //================================================================
903 // Function : getNewObjectName
904 // Purpose : Redefine this method to return proper name for a new object
905 //================================================================
906 const char* GEOMBase_Helper::getNewObjectName() const
911 //================================================================
912 // Function : getPrefix
913 // Purpose : Get prefix for name of created object
914 //================================================================
915 QString GEOMBase_Helper::getPrefix( GEOM::GEOM_Object_ptr theObj ) const
917 if ( !myPrefix.isEmpty() || theObj->_is_nil() )
920 //TopoDS_Shape aShape;
921 //if ( !GEOMBase::GetShape( theObj, aShape ) )
924 //long aType = aShape.ShapeType();
925 GEOM::shape_type aType = theObj->GetShapeType();
929 case GEOM::VERTEX : return QObject::tr( "GEOM_VERTEX" );
930 case GEOM::EDGE : return QObject::tr( "GEOM_EDGE" );
931 case GEOM::WIRE : return QObject::tr( "GEOM_WIRE" );
932 case GEOM::FACE : return QObject::tr( "GEOM_FACE" );
933 case GEOM::SHELL : return QObject::tr( "GEOM_SHELL" );
934 case GEOM::SOLID : return QObject::tr( "GEOM_SOLID" );
935 case GEOM::COMPSOLID: return QObject::tr( "GEOM_COMPOUNDSOLID" );
936 case GEOM::COMPOUND : return QObject::tr( "GEOM_COMPOUND" );
941 //================================================================
942 // Function : selectedIO
943 // Purpose : Return the list of selected SALOME_InteractiveObject's
944 //================================================================
945 const SALOME_ListIO& GEOMBase_Helper::selectedIO()
949 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
951 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
953 aSelMgr->selectedObjects( mySelected );
959 //================================================================
960 // Function : IObjectCount
961 // Purpose : Return the number of selected objects
962 //================================================================
963 int GEOMBase_Helper::IObjectCount()
965 return selectedIO().Extent();
968 //================================================================
969 // Function : firstIObject
970 // Purpose : Return the first selected object in the selected object list
971 //================================================================
972 Handle(SALOME_InteractiveObject) GEOMBase_Helper::firstIObject()
974 const SALOME_ListIO& aList = selectedIO();
975 return aList.Extent() > 0 ? aList.First() : Handle(SALOME_InteractiveObject)();
978 //================================================================
979 // Function : lastIObject
980 // Purpose : Return the last selected object in the selected object list
981 //================================================================
982 Handle(SALOME_InteractiveObject) GEOMBase_Helper::lastIObject()
984 const SALOME_ListIO& aList = selectedIO();
985 return aList.Extent() > 0 ? aList.Last() : Handle(SALOME_InteractiveObject)();
988 //================================================================
989 // Function : getDesktop
990 // Purpose : Returns myDesktop field. Initialized in constructor, usually as dynamic_cast<SUIT_Desktop*>(parentWidget())
991 //================================================================
992 SUIT_Desktop* GEOMBase_Helper::getDesktop() const
997 //================================================================
998 // Function : selectObjects
999 // Purpose : Selects list of objects
1000 //================================================================
1001 bool GEOMBase_Helper::selectObjects( ObjectList& objects )
1003 SUIT_DataOwnerPtrList aList;
1004 ObjectList::iterator anIter;
1005 for ( anIter = objects.begin(); anIter != objects.end(); ++anIter )
1007 string entry = getEntry( *anIter );
1008 QString aEntry( entry.c_str() );
1009 LightApp_DataOwner* anOwher = new LightApp_DataOwner( aEntry );
1010 aList.append( anOwher );
1013 SUIT_Session* session = SUIT_Session::session();
1014 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1018 LightApp_SelectionMgr* aMgr = app->selectionMgr();
1022 aMgr->setSelected( aList, false );