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>
50 #include <OCCViewer_ViewModel.h>
51 #include <SVTK_ViewModel.h>
53 #include <OB_Browser.h>
55 #include <TColStd_MapOfInteger.hxx>
56 #include <TCollection_AsciiString.hxx>
60 #include <SALOMEDSClient.hxx>
63 //================================================================
64 // Function : getActiveView
65 // Purpose : Get active view window, returns 0 if no open study frame
66 //================================================================
67 static SUIT_ViewWindow* getActiveView()
69 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
71 return SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
77 //================================================================
78 // Function : getGeomEngine
79 // Purpose : Static method
80 //================================================================
81 GEOM::GEOM_Gen_ptr GEOMBase_Helper::getGeomEngine()
83 return GeometryGUI::GetGeomGen();
86 //================================================================
87 // Function : GEOMBase_Helper
89 //================================================================
90 GEOMBase_Helper::GEOMBase_Helper( SUIT_Desktop* desktop )
91 : myDesktop( desktop ), myViewWindow( 0 ), myDisplayer( 0 ), myCommand( 0 ), isPreview( false )
95 //================================================================
96 // Function : ~GEOMBase_Helper
98 //================================================================
99 GEOMBase_Helper::~GEOMBase_Helper()
101 if ( !SUIT_Session::session()->activeApplication()->desktop() )
104 if ( myPreview.size() )
108 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
110 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
112 globalSelection(aGeomGUI->getLocalSelectionMode() , true );
119 //================================================================
120 // Function : display
122 //================================================================
123 void GEOMBase_Helper::display( const ObjectList& objList, const bool updateView )
125 ObjectList::const_iterator it;
126 for ( it = objList.begin(); it != objList.end(); it++ ) {
127 display( *it, false );
129 if ( !objList.empty() && updateView )
130 getDisplayer()->UpdateViewer();
133 //================================================================
134 // Function : display
135 // Purpose : Display object.
136 // Important : Object must be already in study
137 //================================================================
138 void GEOMBase_Helper::display( GEOM::GEOM_Object_ptr object, const bool updateView )
140 // Unset color of shape ( this color may be set during preview displaying )
141 // Default color will be used
142 getDisplayer()->UnsetColor();
143 getDisplayer()->UnsetWidth();
145 // Enable activisation of selection
146 getDisplayer()->SetToActivate( true );
149 getDisplayer()->Display( object, updateView );
152 //================================================================
155 //================================================================
156 void GEOMBase_Helper::erase( const ObjectList& objList, const bool updateView )
158 ObjectList::const_iterator it = objList.begin();
159 for ( ; it != objList.end(); it++ ) {
162 if ( !objList.empty() && updateView )
163 getDisplayer()->UpdateViewer();
166 //================================================================
169 //================================================================
170 void GEOMBase_Helper::erase( GEOM::GEOM_Object_ptr object, const bool updateView )
172 if ( !object->_is_nil() ) {
173 string entry = getEntry( object );
174 getDisplayer()->Erase( new SALOME_InteractiveObject(
175 entry.c_str(), "GEOM", strdup( GEOMBase::GetName( object ) ) ), true, updateView );
179 //================================================================
180 // Function : redisplay
182 //================================================================
183 void GEOMBase_Helper::redisplay( const ObjectList& objList,
184 const bool withChildren,
185 const bool updateView )
187 ObjectList::const_iterator it = objList.begin();
188 for ( ; it != objList.end(); it++ ) {
189 redisplay( *it, withChildren, false );
191 if ( !objList.empty() && updateView )
192 getDisplayer()->UpdateViewer();
195 //================================================================
196 // Function : redisplay
198 //================================================================
199 void GEOMBase_Helper::redisplay( GEOM::GEOM_Object_ptr object,
200 const bool withChildren,
201 const bool updateView )
203 if ( !object->_is_nil() ) {
204 // Unset color of shape ( this color may be set during preview displaying )
205 // Default color will be used
206 getDisplayer()->UnsetColor();
207 getDisplayer()->UnsetWidth();
209 // Enable activisation of selection
210 getDisplayer()->SetToActivate( true );
212 string entry = getEntry( object );
213 getDisplayer()->Redisplay(new SALOME_InteractiveObject
214 (entry.c_str(), "GEOM", strdup(GEOMBase::GetName(object))), false);
217 if ( withChildren ) {
218 SalomeApp_Study* aDoc = getStudy();
219 if ( aDoc && aDoc->studyDS() ) {
220 _PTR(Study) aStudy = aDoc->studyDS();
221 _PTR(SObject) aSObj (aStudy->FindObjectIOR(SalomeApp_Application::orb()->object_to_string(object)));
223 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
224 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
225 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow
226 (GeometryGUI::ClientSObjectToObject(anIt->Value()));
227 if ( !CORBA::is_nil( aChild ) ) {
228 if ( !aChild->_is_nil() ) {
229 string entry = getEntry( aChild );
230 getDisplayer()->Redisplay( new SALOME_InteractiveObject(
231 entry.c_str(), "GEOM", strdup( GEOMBase::GetName( aChild ) ) ), false );
240 getDisplayer()->UpdateViewer();
243 //================================================================
244 // Function : displayPreview
245 // Purpose : Method for displaying preview based on execute() results
246 //================================================================
247 void GEOMBase_Helper::displayPreview( const bool activate,
249 const bool toRemoveFromEngine,
250 const double lineWidth )
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 );
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 )
298 // Set color for preview shape
299 getDisplayer()->SetColor( Quantity_NOC_VIOLET );
301 // set width of displayed shape
302 getDisplayer()->SetWidth( lineWidth );
304 // Disable activation of selection
305 getDisplayer()->SetToActivate( activate );
307 // Make a reference to GEOM_Object
308 getDisplayer()->SetName( SalomeApp_Application::orb()->object_to_string( object ) );
311 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( object );
312 if ( aPrs == 0 || aPrs->IsNull() )
316 displayPreview( aPrs, append, update );
318 getDisplayer()->UnsetName();
320 // Enable activation of displayed objects
321 getDisplayer()->SetToActivate( true );
324 //================================================================
325 // Function : displayPreview
326 // Purpose : Method for displaying arbitrary preview objects (not limited to shapes)
327 //================================================================
328 void GEOMBase_Helper::displayPreview( const SALOME_Prs* prs,
333 erasePreview( false );
335 // remember current view frame to make correct erase preview later
336 myViewWindow = getActiveView();
338 if ( myViewWindow == 0 )
342 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
343 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
344 aViewManager->getType() == SVTK_Viewer::Type() )
346 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
347 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
349 aView->Display( prs );
352 // Add prs to the preview list
353 myPreview.push_back( (SALOME_Prs*)prs );
357 getDisplayer()->UpdateViewer();
360 //================================================================
361 // Function : erasePreview
363 //================================================================
364 void GEOMBase_Helper::erasePreview( const bool update )
366 // check view frame where the preview was displayed
367 bool vfOK = checkViewWindow() && myViewWindow;
368 // Iterate through presentations and delete them
369 for ( PrsList::iterator anIter = myPreview.begin(); anIter != myPreview.end(); ++anIter ) {
372 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
373 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
374 aViewManager->getType() == SVTK_Viewer::Type() )
376 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
377 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
379 aView->Erase( *anIter, true );
391 //================================================================
392 // Function : localSelection
393 // Purpose : Activate selection of objects of a given type
394 // IMPORTANT : Works after localSelection( ... ) method call only
395 //================================================================
396 void GEOMBase_Helper::activate( const int theType )
398 if (!getStudy()) return;
399 _PTR(Study) aStudy = getStudy()->studyDS();
400 _PTR(SComponent) aGeom ( aStudy->FindComponent( "GEOM" ) );
405 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( aGeom ) );
406 for ( ; anIter->More(); anIter->Next() )
408 _PTR(SObject) aSO ( anIter->Value() );
411 _PTR(SObject) aRefSO;
412 if ( !aSO->ReferencedObject( aRefSO ) )
414 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow
415 (GeometryGUI::ClientSObjectToObject(aSO));
416 if ( !anObj->_is_nil() && anObj->GetType() == theType )
417 aList.Append( new SALOME_InteractiveObject( aSO->GetID().c_str(), "GEOM", aSO->GetName().c_str()) );
422 getDisplayer()->LocalSelection( aList, 0 );
425 //================================================================
426 // Function : localSelection
427 // Purpose : Activate selection of subshapes in accordance with mode
428 // theMode is from TopAbs_ShapeEnum
429 //================================================================
430 void GEOMBase_Helper::localSelection( const ObjectList& theObjs, const int theMode )
432 SALOME_ListIO aListOfIO;
434 ObjectList::const_iterator anIter = theObjs.begin();
435 for ( ; anIter != theObjs.end(); ++anIter )
437 GEOM::GEOM_Object_ptr anObj = *anIter;
438 if ( anObj->_is_nil() )
440 string aEntry = getEntry( anObj );
442 aListOfIO.Append( new SALOME_InteractiveObject(
443 aEntry.c_str(), "GEOM", strdup( GEOMBase::GetName( anObj ) ) ) );
446 getDisplayer()->LocalSelection( aListOfIO, theMode );
449 //================================================================
450 // Function : localSelection
451 // Purpose : Activate selection of subshapes in accordance with mode
452 // theMode is from TopAbs_ShapeEnum
453 //================================================================
454 void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const int mode )
456 // If object is null local selection for all objects is activated
457 if ( obj->_is_nil() ) {
458 getDisplayer()->LocalSelection( Handle(SALOME_InteractiveObject)(), mode );
463 objList.push_back( obj );
464 localSelection( objList, mode );
468 //================================================================
469 // Function : globalSelection
470 // Purpose : Activate selection of subshapes. Set selection filters
471 // in accordance with mode. theMode is from GEOMImpl_Types
472 //================================================================
473 void GEOMBase_Helper::globalSelection( const int theMode, const bool update )
475 getDisplayer()->GlobalSelection( theMode, update );
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 TColStd_MapOfInteger& theModes,
486 getDisplayer()->GlobalSelection( theModes, update );
489 //================================================================
490 // Function : addInStudy
491 // Purpose : Add object in study
492 //================================================================
493 void GEOMBase_Helper::addInStudy( GEOM::GEOM_Object_ptr theObj, const char* theName )
498 _PTR(Study) aStudy = getStudy()->studyDS();
499 if ( !aStudy || theObj->_is_nil() )
502 GEOM::GEOM_Object_ptr aFatherObj = getFather( theObj );
504 getGeomEngine()->AddInStudy(GeometryGUI::ClientStudyToStudy(aStudy),
505 theObj, theName, aFatherObj);
508 //================================================================
509 // Function : updateObjBrowser
510 // Purpose : Update object browser
511 //================================================================
512 void GEOMBase_Helper::updateObjBrowser() const
514 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
516 CAM_Module* module = app->module( "Geometry" );
517 SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
519 appMod->updateObjBrowser( true );
524 //================================================================
525 // Function : updateViewer
526 // Purpose : Update active 3D view
527 //================================================================
528 void GEOMBase_Helper::updateViewer()
530 getDisplayer()->UpdateViewer();
533 //================================================================
534 // Function : getStudyId
535 // Purpose : Get study Id
536 //================================================================
537 int GEOMBase_Helper::getStudyId() const
541 anId = getStudy()->id();
545 //================================================================
546 // Function : getStudy
547 // Purpose : Returns the active study. It is recommended to use
548 // this method instead of direct desktop->getActiveStudy() calls
549 //================================================================
550 SalomeApp_Study* GEOMBase_Helper::getStudy() const
552 SUIT_Desktop* aDesktop = getDesktop();
556 QPtrList<SUIT_Application> anAppList = SUIT_Session::session()->applications();
558 SUIT_Application* anApp = 0;
559 for ( QPtrListIterator<SUIT_Application> it( anAppList ); it.current() ; ++it )
561 anApp = it.current();
562 if ( anApp->desktop() == aDesktop )
566 return dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
569 //================================================================
570 // Function : getEntry
572 //================================================================
573 char* GEOMBase_Helper::getEntry( GEOM::GEOM_Object_ptr object ) const
575 SalomeApp_Study* study = getStudy();
577 string IOR = GEOMBase::GetIORFromObject( object);
579 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
581 return TCollection_AsciiString((char*)SO->GetID().c_str()).ToCString();
588 //================================================================
589 // Function : getDisplayer
591 //================================================================
592 GEOM_Displayer* GEOMBase_Helper::getDisplayer()
595 myDisplayer = new GEOM_Displayer( getStudy() );
599 //================================================================
600 // Function : clearShapeBuffer
602 //================================================================
603 void GEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
605 if ( CORBA::is_nil( theObj ) )
608 string IOR = SalomeApp_Application::orb()->object_to_string( theObj );
609 TCollection_AsciiString asciiIOR( strdup( IOR.c_str() ) );
610 GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
612 if ( !getStudy() || !getStudy()->studyDS() )
615 _PTR(Study) aStudy = getStudy()->studyDS();
616 _PTR(SObject) aSObj ( aStudy->FindObjectIOR( IOR ) );
620 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
621 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
622 _PTR(GenericAttribute) anAttr;
623 if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
624 _PTR(AttributeIOR) anIOR ( anAttr );
625 TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
626 GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
631 //================================================================
632 // Function : openCommand
634 //================================================================
635 bool GEOMBase_Helper::openCommand()
638 if ( !getStudy() || hasCommand() )
641 GEOM::GEOM_IOperations_var anOp = GEOM::GEOM_IOperations::_narrow( getOperation() );
642 if ( !anOp->_is_nil() ) {
643 myCommand = new GEOM_Operation( SUIT_Session::session()->activeApplication(), anOp.in() );
651 //================================================================
652 // Function : abortCommand
654 //================================================================
655 bool GEOMBase_Helper::abortCommand()
666 //================================================================
667 // Function : commitCommand
669 //================================================================
670 bool GEOMBase_Helper::commitCommand( const char* )
681 //================================================================
682 // Function : hasCommand
684 //================================================================
685 bool GEOMBase_Helper::hasCommand() const
687 return (bool)myCommand;
690 //================================================================
691 // Function : getOperation
693 //================================================================
694 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::getOperation()
696 if ( myOperation->_is_nil() )
697 myOperation = createOperation();
704 //================================================================
705 // Function : checkViewWindow
707 //================================================================
708 bool GEOMBase_Helper::checkViewWindow()
711 QPtrList<SUIT_ViewWindow> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
712 for ( QPtrListIterator<SUIT_ViewWindow> it( aViewWindowsList ); it.current(); ++it )
714 if ( myViewWindow == it.current() )
722 //================================================================
723 // Function : onAccept
724 // Purpose : This method should be called from dialog's slots onOk() and onApply()
725 // It perfroms user input validation, then it
726 // performs a proper operation and manages transactions, etc.
727 //================================================================
728 bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction )
730 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
731 if ( !appStudy ) return false;
732 _PTR(Study) aStudy = appStudy->studyDS();
734 bool aLocked = (_PTR(AttributeStudyProperties) (aStudy->GetProperties()))->IsLocked();
736 MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
737 SUIT_MessageBox::warn1 ( (QWidget*)SUIT_Session::session()->activeApplication()->desktop(),
738 QObject::tr("WRN_WARNING"),
739 QObject::tr("WRN_STUDY_LOCKED"),
740 QObject::tr("BUT_OK") );
745 if ( !isValid( msg ) ) {
750 erasePreview( false );
753 if ( ( !publish && !useTransaction ) || openCommand() ) {
754 SUIT_OverrideCursor wc;
755 SUIT_Session::session()->activeApplication()->putInfo( "" );
757 if ( !execute( objects ) || !getOperation()->IsDone() ) {
763 const int nbObjs = objects.size();
765 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
767 QString aName = getNewObjectName();
770 aName = getPrefix(*it);
772 // Try to find a unique name
773 aName = GEOMBase::GetDefaultName(aName);
775 // Don't check name uniqueness in case of numerous objects
776 aName = aName + "_" + QString::number(aNumber++);
779 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
780 if ( aName.isEmpty() )
781 aName = GEOMBase::GetDefaultName( getPrefix( *it ) );
783 addInStudy( *it, aName.latin1() );
785 display( *it, false );
788 // asv : fix of PAL6454. If publish==false, then the original shape
789 // was modified, and need to be re-cached in GEOM_Client before redisplay
790 clearShapeBuffer( *it );
791 // withChildren=true, updateView=false
792 redisplay( *it, true, false );
799 SUIT_Session::session()->activeApplication()->putInfo( QObject::tr("GEOM_PRP_DONE") );
806 catch( const SALOME::SALOME_Exception& e ) {
807 SalomeApp_Tools::QtCatchCorbaException( e );
817 //================================================================
818 // Function : showError
819 // Purpose : Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
820 //================================================================
821 void GEOMBase_Helper::showError()
824 if ( !getOperation()->_is_nil() )
825 msg = QObject::tr( getOperation()->GetErrorCode() );
828 msg = QObject::tr( "GEOM_PRP_ABORT" );
830 SUIT_MessageBox::error1( SUIT_Session::session()->activeApplication()->desktop(),
831 QObject::tr( "GEOM_ERROR_STATUS" ),
833 QObject::tr( "BUT_OK" ) );
836 //================================================================
837 // Function : showError
838 // Purpose : Shows a error message followed by <msg>
839 //================================================================
840 void GEOMBase_Helper::showError( const QString& msg )
842 QString str( QObject::tr( "GEOM_INCORRECT_INPUT" ) );
843 if ( !msg.isEmpty() )
845 SUIT_MessageBox::error1(SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ), str, QObject::tr( "BUT_OK" ) );
848 //////////////////////////////////////////////////////////////////
849 // Virtual methods to be redefined in dialogs
850 //////////////////////////////////////////////////////////////////
852 //================================================================
853 // Function : createOperation
854 // Purpose : Redefine this method to return proper IOperation reference
855 //================================================================
856 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::createOperation()
858 GEOM::GEOM_IOperations_var aNilOp;
859 return aNilOp._retn();
862 //================================================================
863 // Function : isValid
864 // Purpose : Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
865 //================================================================
866 bool GEOMBase_Helper::isValid( QString& )
871 //================================================================
872 // Function : execute
873 // Purpose : This method is called by onAccept().
874 // It should perform the required operation and put all new or modified objects into
875 // <objects> argument.Should return <false> if some error occurs during its execution.
876 //================================================================
877 bool GEOMBase_Helper::execute( ObjectList& objects )
882 //================================================================
883 // Function : getFather
884 // Purpose : This method is called by addInStudy(). It should return a father object
885 // for <theObj> or a nil reference if <theObj> should be published
886 // as a top-level object.
887 //================================================================
888 GEOM::GEOM_Object_ptr GEOMBase_Helper::getFather( GEOM::GEOM_Object_ptr theObj )
890 return GEOM::GEOM_Object::_nil();
893 //================================================================
894 // Function : getNewObjectName
895 // Purpose : Redefine this method to return proper name for a new object
896 //================================================================
897 const char* GEOMBase_Helper::getNewObjectName() const
902 //================================================================
903 // Function : getPrefix
904 // Purpose : Get prefix for name of created object
905 //================================================================
906 QString GEOMBase_Helper::getPrefix( GEOM::GEOM_Object_ptr theObj ) const
908 if ( !myPrefix.isEmpty() || theObj->_is_nil() )
911 //TopoDS_Shape aShape;
912 //if ( !GEOMBase::GetShape( theObj, aShape ) )
915 //long aType = aShape.ShapeType();
916 GEOM::shape_type aType = theObj->GetShapeType();
920 case GEOM::VERTEX : return QObject::tr( "GEOM_VERTEX" );
921 case GEOM::EDGE : return QObject::tr( "GEOM_EDGE" );
922 case GEOM::WIRE : return QObject::tr( "GEOM_WIRE" );
923 case GEOM::FACE : return QObject::tr( "GEOM_FACE" );
924 case GEOM::SHELL : return QObject::tr( "GEOM_SHELL" );
925 case GEOM::SOLID : return QObject::tr( "GEOM_SOLID" );
926 case GEOM::COMPSOLID: return QObject::tr( "GEOM_COMPOUNDSOLID" );
927 case GEOM::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