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 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string(object);
223 _PTR(SObject) aSObj (aStudy->FindObjectIOR(string(objStr.in())));
225 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
226 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
227 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow
228 (GeometryGUI::ClientSObjectToObject(anIt->Value()));
229 if ( !CORBA::is_nil( aChild ) ) {
230 if ( !aChild->_is_nil() ) {
231 string entry = getEntry( aChild );
232 getDisplayer()->Redisplay( new SALOME_InteractiveObject(
233 entry.c_str(), "GEOM", strdup( GEOMBase::GetName( aChild ) ) ), false );
242 getDisplayer()->UpdateViewer();
245 //================================================================
246 // Function : displayPreview
247 // Purpose : Method for displaying preview based on execute() results
248 //================================================================
249 void GEOMBase_Helper::displayPreview( const bool activate,
251 const bool toRemoveFromEngine,
252 const double lineWidth,
253 const int displayMode,
258 if ( !isValid( msg ) )
260 erasePreview( update );
265 erasePreview( false );
268 SUIT_OverrideCursor wc;
270 if ( !execute( objects ) || !getOperation()->IsDone() ) {
274 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it )
276 displayPreview( *it, true, activate, false, lineWidth, displayMode, color );
277 if ( toRemoveFromEngine )
278 getGeomEngine()->RemoveObject( *it );
282 catch( const SALOME::SALOME_Exception& e ) {
283 SalomeApp_Tools::QtCatchCorbaException( e );
292 //================================================================
293 // Function : displayPreview
294 // Purpose : Method for displaying preview of resulting shape
295 //================================================================
296 void GEOMBase_Helper::displayPreview( GEOM::GEOM_Object_ptr object,
300 const double lineWidth,
301 const int displayMode,
304 // Set color for preview shape
305 getDisplayer()->SetColor( color == -1 ? Quantity_NOC_VIOLET : color );
307 // set width of displayed shape
308 getDisplayer()->SetWidth( lineWidth );
310 // set display mode of displayed shape
311 int aPrevDispMode = getDisplayer()->SetDisplayMode( displayMode );
313 // Disable activation of selection
314 getDisplayer()->SetToActivate( activate );
316 // Make a reference to GEOM_Object
317 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string( object );
318 getDisplayer()->SetName( objStr.in() );
321 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( object );
322 if ( aPrs == 0 || aPrs->IsNull() )
326 displayPreview( aPrs, append, update );
328 getDisplayer()->UnsetName();
329 getDisplayer()->UnsetColor();
330 getDisplayer()->SetDisplayMode( aPrevDispMode );
332 // Enable activation of displayed objects
333 getDisplayer()->SetToActivate( true );
336 //================================================================
337 // Function : displayPreview
338 // Purpose : Method for displaying arbitrary preview objects (not limited to shapes)
339 //================================================================
340 void GEOMBase_Helper::displayPreview( const SALOME_Prs* prs,
345 erasePreview( false );
347 // remember current view frame to make correct erase preview later
348 myViewWindow = getActiveView();
350 if ( myViewWindow == 0 )
354 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
355 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
356 aViewManager->getType() == SVTK_Viewer::Type() )
358 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
359 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
361 aView->Display( prs );
364 // Add prs to the preview list
365 myPreview.push_back( (SALOME_Prs*)prs );
369 getDisplayer()->UpdateViewer();
372 //================================================================
373 // Function : erasePreview
375 //================================================================
376 void GEOMBase_Helper::erasePreview( const bool update )
378 // check view frame where the preview was displayed
379 bool vfOK = checkViewWindow() && myViewWindow;
380 // Iterate through presentations and delete them
381 for ( PrsList::iterator anIter = myPreview.begin(); anIter != myPreview.end(); ++anIter ) {
384 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
385 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
386 aViewManager->getType() == SVTK_Viewer::Type() )
388 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
389 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
391 aView->Erase( *anIter, true );
403 //================================================================
404 // Function : localSelection
405 // Purpose : Activate selection of objects of a given type
406 // IMPORTANT : Works after localSelection( ... ) method call only
407 //================================================================
408 void GEOMBase_Helper::activate( const int theType )
410 if (!getStudy()) return;
411 _PTR(Study) aStudy = getStudy()->studyDS();
412 _PTR(SComponent) aGeom ( aStudy->FindComponent( "GEOM" ) );
417 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( aGeom ) );
418 for ( ; anIter->More(); anIter->Next() )
420 _PTR(SObject) aSO ( anIter->Value() );
423 _PTR(SObject) aRefSO;
424 if ( !aSO->ReferencedObject( aRefSO ) )
426 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow
427 (GeometryGUI::ClientSObjectToObject(aSO));
428 if ( !anObj->_is_nil() && anObj->GetType() == theType )
429 aList.Append( new SALOME_InteractiveObject( aSO->GetID().c_str(), "GEOM", aSO->GetName().c_str()) );
434 getDisplayer()->LocalSelection( aList, 0 );
437 //================================================================
438 // Function : localSelection
439 // Purpose : Activate selection of subshapes in accordance with mode
440 // theMode is from TopAbs_ShapeEnum
441 //================================================================
442 void GEOMBase_Helper::localSelection( const ObjectList& theObjs, const int theMode )
444 SALOME_ListIO aListOfIO;
446 ObjectList::const_iterator anIter = theObjs.begin();
447 for ( ; anIter != theObjs.end(); ++anIter )
449 GEOM::GEOM_Object_ptr anObj = *anIter;
450 if ( anObj->_is_nil() )
452 string aEntry = getEntry( anObj );
454 aListOfIO.Append( new SALOME_InteractiveObject(
455 aEntry.c_str(), "GEOM", strdup( GEOMBase::GetName( anObj ) ) ) );
458 getDisplayer()->LocalSelection( aListOfIO, theMode );
461 //================================================================
462 // Function : localSelection
463 // Purpose : Activate selection of subshapes in accordance with mode
464 // theMode is from TopAbs_ShapeEnum
465 //================================================================
466 void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const int mode )
468 // If object is null local selection for all objects is activated
469 if ( obj->_is_nil() ) {
470 getDisplayer()->LocalSelection( Handle(SALOME_InteractiveObject)(), mode );
475 objList.push_back( obj );
476 localSelection( objList, mode );
480 //================================================================
481 // Function : globalSelection
482 // Purpose : Activate selection of subshapes. Set selection filters
483 // in accordance with mode. theMode is from GEOMImpl_Types
484 //================================================================
485 void GEOMBase_Helper::globalSelection( const int theMode, const bool update )
487 getDisplayer()->GlobalSelection( theMode, update );
490 //================================================================
491 // Function : globalSelection
492 // Purpose : Activate selection of subshapes. Set selection filters
493 // in accordance with mode. theMode is from GEOMImpl_Types
494 //================================================================
495 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
498 getDisplayer()->GlobalSelection( theModes, update );
501 //================================================================
502 // Function : addInStudy
503 // Purpose : Add object in study
504 //================================================================
505 void GEOMBase_Helper::addInStudy( GEOM::GEOM_Object_ptr theObj, const char* theName )
510 _PTR(Study) aStudy = getStudy()->studyDS();
511 if ( !aStudy || theObj->_is_nil() )
514 GEOM::GEOM_Object_ptr aFatherObj = getFather( theObj );
516 getGeomEngine()->AddInStudy(GeometryGUI::ClientStudyToStudy(aStudy),
517 theObj, theName, aFatherObj);
520 //================================================================
521 // Function : updateObjBrowser
522 // Purpose : Update object browser
523 //================================================================
524 void GEOMBase_Helper::updateObjBrowser() const
526 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
528 CAM_Module* module = app->module( "Geometry" );
529 SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
531 appMod->updateObjBrowser( true );
536 //================================================================
537 // Function : updateViewer
538 // Purpose : Update active 3D view
539 //================================================================
540 void GEOMBase_Helper::updateViewer()
542 getDisplayer()->UpdateViewer();
545 //================================================================
546 // Function : getStudyId
547 // Purpose : Get study Id
548 //================================================================
549 int GEOMBase_Helper::getStudyId() const
553 anId = getStudy()->id();
557 //================================================================
558 // Function : getStudy
559 // Purpose : Returns the active study. It is recommended to use
560 // this method instead of direct desktop->getActiveStudy() calls
561 //================================================================
562 SalomeApp_Study* GEOMBase_Helper::getStudy() const
564 SUIT_Desktop* aDesktop = getDesktop();
568 QPtrList<SUIT_Application> anAppList = SUIT_Session::session()->applications();
570 SUIT_Application* anApp = 0;
571 for ( QPtrListIterator<SUIT_Application> it( anAppList ); it.current() ; ++it )
573 anApp = it.current();
574 if ( anApp->desktop() == aDesktop )
578 return dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
581 //================================================================
582 // Function : getEntry
584 //================================================================
585 char* GEOMBase_Helper::getEntry( GEOM::GEOM_Object_ptr object ) const
587 SalomeApp_Study* study = getStudy();
589 char * objIOR = GEOMBase::GetIORFromObject( object );
590 string IOR( objIOR );
593 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
595 return TCollection_AsciiString((char*)SO->GetID().c_str()).ToCString();
602 //================================================================
603 // Function : getDisplayer
605 //================================================================
606 GEOM_Displayer* GEOMBase_Helper::getDisplayer()
609 myDisplayer = new GEOM_Displayer( getStudy() );
613 //================================================================
614 // Function : clearShapeBuffer
616 //================================================================
617 void GEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
619 if ( CORBA::is_nil( theObj ) )
622 CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( theObj );
623 TCollection_AsciiString asciiIOR( (char *)IOR.in() );
624 GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
626 if ( !getStudy() || !getStudy()->studyDS() )
629 _PTR(Study) aStudy = getStudy()->studyDS();
630 _PTR(SObject) aSObj ( aStudy->FindObjectIOR( string( IOR ) ) );
634 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
635 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
636 _PTR(GenericAttribute) anAttr;
637 if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
638 _PTR(AttributeIOR) anIOR ( anAttr );
639 TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
640 GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
645 //================================================================
646 // Function : openCommand
648 //================================================================
649 bool GEOMBase_Helper::openCommand()
652 if ( !getStudy() || hasCommand() )
655 GEOM::GEOM_IOperations_var anOp = GEOM::GEOM_IOperations::_narrow( getOperation() );
656 if ( !anOp->_is_nil() ) {
657 myCommand = new GEOM_Operation( SUIT_Session::session()->activeApplication(), anOp.in() );
665 //================================================================
666 // Function : abortCommand
668 //================================================================
669 bool GEOMBase_Helper::abortCommand()
680 //================================================================
681 // Function : commitCommand
683 //================================================================
684 bool GEOMBase_Helper::commitCommand( const char* )
695 //================================================================
696 // Function : hasCommand
698 //================================================================
699 bool GEOMBase_Helper::hasCommand() const
701 return (bool)myCommand;
704 //================================================================
705 // Function : getOperation
707 //================================================================
708 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::getOperation()
710 if ( myOperation->_is_nil() )
711 myOperation = createOperation();
718 //================================================================
719 // Function : checkViewWindow
721 //================================================================
722 bool GEOMBase_Helper::checkViewWindow()
725 QPtrList<SUIT_ViewWindow> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
726 for ( QPtrListIterator<SUIT_ViewWindow> it( aViewWindowsList ); it.current(); ++it )
728 if ( myViewWindow == it.current() )
736 //================================================================
737 // Function : onAccept
738 // Purpose : This method should be called from dialog's slots onOk() and onApply()
739 // It perfroms user input validation, then it
740 // performs a proper operation and manages transactions, etc.
741 //================================================================
742 bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction )
744 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
745 if ( !appStudy ) return false;
746 _PTR(Study) aStudy = appStudy->studyDS();
748 bool aLocked = (_PTR(AttributeStudyProperties) (aStudy->GetProperties()))->IsLocked();
750 MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
751 SUIT_MessageBox::warn1 ( (QWidget*)SUIT_Session::session()->activeApplication()->desktop(),
752 QObject::tr("WRN_WARNING"),
753 QObject::tr("WRN_STUDY_LOCKED"),
754 QObject::tr("BUT_OK") );
759 if ( !isValid( msg ) ) {
764 erasePreview( false );
767 if ( ( !publish && !useTransaction ) || openCommand() ) {
768 SUIT_OverrideCursor wc;
769 SUIT_Session::session()->activeApplication()->putInfo( "" );
771 if ( !execute( objects ) || !getOperation()->IsDone() ) {
777 addSubshapesToStudy(); // add Subshapes if local selection
778 const int nbObjs = objects.size();
780 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
782 QString aName = getNewObjectName();
785 aName = getPrefix(*it);
787 // Try to find a unique name
788 aName = GEOMBase::GetDefaultName(aName);
790 // Don't check name uniqueness in case of numerous objects
791 aName = aName + "_" + QString::number(aNumber++);
794 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
795 if ( aName.isEmpty() )
796 aName = GEOMBase::GetDefaultName( getPrefix( *it ) );
798 addInStudy( *it, aName.latin1() );
800 display( *it, false );
803 // asv : fix of PAL6454. If publish==false, then the original shape
804 // was modified, and need to be re-cached in GEOM_Client before redisplay
805 clearShapeBuffer( *it );
806 // withChildren=true, updateView=false
807 redisplay( *it, true, false );
814 SUIT_Session::session()->activeApplication()->putInfo( QObject::tr("GEOM_PRP_DONE") );
821 catch( const SALOME::SALOME_Exception& e ) {
822 SalomeApp_Tools::QtCatchCorbaException( e );
832 //================================================================
833 // Function : showError
834 // Purpose : Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
835 //================================================================
836 void GEOMBase_Helper::showError()
839 if ( !getOperation()->_is_nil() )
840 msg = QObject::tr( getOperation()->GetErrorCode() );
843 msg = QObject::tr( "GEOM_PRP_ABORT" );
845 SUIT_MessageBox::error1( SUIT_Session::session()->activeApplication()->desktop(),
846 QObject::tr( "GEOM_ERROR_STATUS" ),
848 QObject::tr( "BUT_OK" ) );
851 //================================================================
852 // Function : showError
853 // Purpose : Shows a error message followed by <msg>
854 //================================================================
855 void GEOMBase_Helper::showError( const QString& msg )
857 QString str( QObject::tr( "GEOM_INCORRECT_INPUT" ) );
858 if ( !msg.isEmpty() )
860 SUIT_MessageBox::error1(SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ), str, QObject::tr( "BUT_OK" ) );
863 //////////////////////////////////////////////////////////////////
864 // Virtual methods to be redefined in dialogs
865 //////////////////////////////////////////////////////////////////
867 //================================================================
868 // Function : createOperation
869 // Purpose : Redefine this method to return proper IOperation reference
870 //================================================================
871 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::createOperation()
873 GEOM::GEOM_IOperations_var aNilOp;
874 return aNilOp._retn();
877 //================================================================
878 // Function : isValid
879 // Purpose : Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
880 //================================================================
881 bool GEOMBase_Helper::isValid( QString& )
886 //================================================================
887 // Function : execute
888 // Purpose : This method is called by onAccept().
889 // It should perform the required operation and put all new or modified objects into
890 // <objects> argument.Should return <false> if some error occurs during its execution.
891 //================================================================
892 bool GEOMBase_Helper::execute( ObjectList& objects )
897 //================================================================
898 // Function : getFather
899 // Purpose : This method is called by addInStudy(). It should return a father object
900 // for <theObj> or a nil reference if <theObj> should be published
901 // as a top-level object.
902 //================================================================
903 GEOM::GEOM_Object_ptr GEOMBase_Helper::getFather( GEOM::GEOM_Object_ptr theObj )
905 return GEOM::GEOM_Object::_nil();
908 //================================================================
909 // Function : getNewObjectName
910 // Purpose : Redefine this method to return proper name for a new object
911 //================================================================
912 const char* GEOMBase_Helper::getNewObjectName() const
917 //================================================================
918 // Function : getPrefix
919 // Purpose : Get prefix for name of created object
920 //================================================================
921 QString GEOMBase_Helper::getPrefix( GEOM::GEOM_Object_ptr theObj ) const
923 if ( !myPrefix.isEmpty() || theObj->_is_nil() )
926 //TopoDS_Shape aShape;
927 //if ( !GEOMBase::GetShape( theObj, aShape ) )
930 //long aType = aShape.ShapeType();
931 GEOM::shape_type aType = theObj->GetShapeType();
935 case GEOM::VERTEX : return QObject::tr( "GEOM_VERTEX" );
936 case GEOM::EDGE : return QObject::tr( "GEOM_EDGE" );
937 case GEOM::WIRE : return QObject::tr( "GEOM_WIRE" );
938 case GEOM::FACE : return QObject::tr( "GEOM_FACE" );
939 case GEOM::SHELL : return QObject::tr( "GEOM_SHELL" );
940 case GEOM::SOLID : return QObject::tr( "GEOM_SOLID" );
941 case GEOM::COMPSOLID: return QObject::tr( "GEOM_COMPOUNDSOLID" );
942 case GEOM::COMPOUND : return QObject::tr( "GEOM_COMPOUND" );
947 //================================================================
948 // Function : selectedIO
949 // Purpose : Return the list of selected SALOME_InteractiveObject's
950 //================================================================
951 const SALOME_ListIO& GEOMBase_Helper::selectedIO()
955 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
957 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
959 aSelMgr->selectedObjects( mySelected );
965 //================================================================
966 // Function : IObjectCount
967 // Purpose : Return the number of selected objects
968 //================================================================
969 int GEOMBase_Helper::IObjectCount()
971 return selectedIO().Extent();
974 //================================================================
975 // Function : firstIObject
976 // Purpose : Return the first selected object in the selected object list
977 //================================================================
978 Handle(SALOME_InteractiveObject) GEOMBase_Helper::firstIObject()
980 const SALOME_ListIO& aList = selectedIO();
981 return aList.Extent() > 0 ? aList.First() : Handle(SALOME_InteractiveObject)();
984 //================================================================
985 // Function : lastIObject
986 // Purpose : Return the last selected object in the selected object list
987 //================================================================
988 Handle(SALOME_InteractiveObject) GEOMBase_Helper::lastIObject()
990 const SALOME_ListIO& aList = selectedIO();
991 return aList.Extent() > 0 ? aList.Last() : Handle(SALOME_InteractiveObject)();
994 //================================================================
995 // Function : getDesktop
996 // Purpose : Returns myDesktop field. Initialized in constructor, usually as dynamic_cast<SUIT_Desktop*>(parentWidget())
997 //================================================================
998 SUIT_Desktop* GEOMBase_Helper::getDesktop() const
1003 //================================================================
1004 // Function : selectObjects
1005 // Purpose : Selects list of objects
1006 //================================================================
1007 bool GEOMBase_Helper::selectObjects( ObjectList& objects )
1009 SUIT_DataOwnerPtrList aList;
1010 ObjectList::iterator anIter;
1011 for ( anIter = objects.begin(); anIter != objects.end(); ++anIter )
1013 string entry = getEntry( *anIter );
1014 QString aEntry( entry.c_str() );
1015 LightApp_DataOwner* anOwher = new LightApp_DataOwner( aEntry );
1016 aList.append( anOwher );
1019 SUIT_Session* session = SUIT_Session::session();
1020 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1024 LightApp_SelectionMgr* aMgr = app->selectionMgr();
1028 aMgr->setSelected( aList, false );
1033 //================================================================
1034 // Function : findObjectInFather
1035 // Purpose : It should return an object if its founded in study or
1036 // return Null object if the object is not founded
1037 //================================================================
1038 GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather( GEOM::GEOM_Object_ptr theFather, const char* theName)
1040 SalomeApp_Application* app =
1041 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1042 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1043 _PTR(Study) aDStudy = appStudy->studyDS();
1044 string IOR = GEOMBase::GetIORFromObject( theFather );
1045 _PTR(SObject) SObj ( aDStudy->FindObjectIOR( IOR ) );
1047 bool inStudy = false;
1048 GEOM::GEOM_Object_var aReturnObject;
1049 for (_PTR(ChildIterator) iit (aDStudy->NewChildIterator( SObj )); iit->More() && !inStudy; iit->Next()) {
1050 _PTR(SObject) child (iit->Value());
1051 QString aChildName = child->GetName();
1052 if (aChildName == theName) {
1054 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(iit->Value());
1055 aReturnObject = GEOM::GEOM_Object::_narrow( corbaObj );
1059 return aReturnObject._retn();
1061 return GEOM::GEOM_Object::_nil();
1064 //================================================================
1065 // Function : addSubshapesToStudy
1066 // Purpose : Virtual method to add subshapes if needs
1067 //================================================================
1068 void GEOMBase_Helper::addSubshapesToStudy()
1070 //Impemented in Dialogs, called from Accept method
1073 //================================================================
1074 // Function : addSubshapesToFather
1075 // Purpose : Method to add Father Subshapes to Study if it`s not exist
1076 //================================================================
1077 void GEOMBase_Helper::addSubshapesToFather( QMap<QString, GEOM::GEOM_Object_var>& theMap )
1080 SalomeApp_Application* app =
1081 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1082 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1083 _PTR(Study) aDStudy = appStudy->studyDS();
1085 GEOM::GEOM_IGroupOperations_var anOp = getGeomEngine()->GetIGroupOperations( getStudyId() );
1087 for( QMap<QString, GEOM::GEOM_Object_var>::Iterator it = theMap.begin(); it != theMap.end(); it++ )
1089 if ( !anOp->_is_nil() ) {
1090 GEOM::GEOM_Object_var aFatherObj = anOp->GetMainShape( it.data() );
1091 if ( !aFatherObj->_is_nil() ) {
1092 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aFatherObj, it.key() );
1094 //Add Object to study if its not exist
1095 if ( aFindedObject == GEOM::GEOM_Object::_nil() )
1096 GeometryGUI::GetGeomGen()->AddInStudy(GeometryGUI::ClientStudyToStudy(aDStudy),
1097 it.data(), it.key(), aFatherObj );
1101 //cout << " anOperations is NULL! " << endl;