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>
55 //================================================================
56 // Function : getActiveView
57 // Purpose : Get active view window, returns 0 if no open study frame
58 //================================================================
59 static SUIT_ViewWindow* getActiveView()
61 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
63 return SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
69 //================================================================
70 // Function : getGeomEngine
71 // Purpose : Static method
72 //================================================================
73 GEOM::GEOM_Gen_ptr GEOMBase_Helper::getGeomEngine()
75 return GeometryGUI::GetGeomGen();
78 //================================================================
79 // Function : GEOMBase_Helper
81 //================================================================
82 GEOMBase_Helper::GEOMBase_Helper( SUIT_Desktop* desktop )
83 : myDesktop( desktop ), myViewWindow( 0 ), myDisplayer( 0 ), myCommand( 0 ), isPreview( false )
87 //================================================================
88 // Function : ~GEOMBase_Helper
90 //================================================================
91 GEOMBase_Helper::~GEOMBase_Helper()
93 if ( !SUIT_Session::session()->activeApplication()->desktop() )
96 if ( myPreview.size() )
100 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
102 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
104 globalSelection(aGeomGUI->getLocalSelectionMode() , true );
111 //================================================================
112 // Function : display
114 //================================================================
115 void GEOMBase_Helper::display( const ObjectList& objList, const bool updateView )
117 ObjectList::const_iterator it;
118 for ( it = objList.begin(); it != objList.end(); it++ ) {
119 display( *it, false );
121 if ( !objList.empty() && updateView )
122 getDisplayer()->UpdateViewer();
125 //================================================================
126 // Function : display
127 // Purpose : Display object.
128 // Important : Object must be already in study
129 //================================================================
130 void GEOMBase_Helper::display( GEOM::GEOM_Object_ptr object, const bool updateView )
132 // Unset color of shape ( this color may be set during preview displaying )
133 // Default color will be used
134 getDisplayer()->UnsetColor();
135 getDisplayer()->UnsetWidth();
137 // Enable activisation of selection
138 getDisplayer()->SetToActivate( true );
141 getDisplayer()->Display( object, updateView );
144 //================================================================
147 //================================================================
148 void GEOMBase_Helper::erase( const ObjectList& objList, const bool updateView )
150 ObjectList::const_iterator it = objList.begin();
151 for ( ; it != objList.end(); it++ ) {
154 if ( !objList.empty() && updateView )
155 getDisplayer()->UpdateViewer();
158 //================================================================
161 //================================================================
162 void GEOMBase_Helper::erase( GEOM::GEOM_Object_ptr object, const bool updateView )
164 if ( !object->_is_nil() ) {
165 string entry = getEntry( object );
166 getDisplayer()->Erase( new SALOME_InteractiveObject(
167 entry.c_str(), "GEOM", strdup( GEOMBase::GetName( object ).toLatin1().constData() ) ), true, updateView );
171 //================================================================
172 // Function : redisplay
174 //================================================================
175 void GEOMBase_Helper::redisplay( const ObjectList& objList,
176 const bool withChildren,
177 const bool updateView )
179 ObjectList::const_iterator it = objList.begin();
180 for ( ; it != objList.end(); it++ ) {
181 redisplay( *it, withChildren, false );
183 if ( !objList.empty() && updateView )
184 getDisplayer()->UpdateViewer();
187 //================================================================
188 // Function : redisplay
190 //================================================================
191 void GEOMBase_Helper::redisplay( GEOM::GEOM_Object_ptr object,
192 const bool withChildren,
193 const bool updateView )
195 if ( !object->_is_nil() ) {
196 // Unset color of shape ( this color may be set during preview displaying )
197 // Default color will be used
198 getDisplayer()->UnsetColor();
199 getDisplayer()->UnsetWidth();
201 // Enable activisation of selection
202 getDisplayer()->SetToActivate( true );
204 string entry = getEntry( object );
205 getDisplayer()->Redisplay(new SALOME_InteractiveObject
206 (entry.c_str(), "GEOM", strdup(GEOMBase::GetName(object).toLatin1().constData())), false);
209 if ( withChildren ) {
210 SalomeApp_Study* aDoc = getStudy();
211 if ( aDoc && aDoc->studyDS() ) {
212 _PTR(Study) aStudy = aDoc->studyDS();
213 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string(object);
214 _PTR(SObject) aSObj (aStudy->FindObjectIOR(string(objStr.in())));
216 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
217 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
218 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow
219 (GeometryGUI::ClientSObjectToObject(anIt->Value()));
220 if ( !CORBA::is_nil( aChild ) ) {
221 if ( !aChild->_is_nil() ) {
222 string entry = getEntry( aChild );
223 getDisplayer()->Redisplay( new SALOME_InteractiveObject(
224 entry.c_str(), "GEOM", strdup( GEOMBase::GetName( aChild ).toLatin1().constData() ) ), false );
233 getDisplayer()->UpdateViewer();
236 //================================================================
237 // Function : displayPreview
238 // Purpose : Method for displaying preview based on execute() results
239 //================================================================
240 void GEOMBase_Helper::displayPreview( const bool activate,
242 const bool toRemoveFromEngine,
243 const double lineWidth,
244 const int displayMode,
249 if ( !isValid( msg ) )
251 erasePreview( update );
256 erasePreview( false );
259 SUIT_OverrideCursor wc;
261 if ( !execute( objects ) || !getOperation()->IsDone() ) {
265 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it )
267 displayPreview( *it, true, activate, false, lineWidth, displayMode, color );
268 if ( toRemoveFromEngine )
269 getGeomEngine()->RemoveObject( *it );
273 catch( const SALOME::SALOME_Exception& e ) {
274 SalomeApp_Tools::QtCatchCorbaException( e );
283 //================================================================
284 // Function : displayPreview
285 // Purpose : Method for displaying preview of resulting shape
286 //================================================================
287 void GEOMBase_Helper::displayPreview( GEOM::GEOM_Object_ptr object,
291 const double lineWidth,
292 const int displayMode,
295 // Set color for preview shape
296 getDisplayer()->SetColor( color == -1 ? Quantity_NOC_VIOLET : color );
298 // set width of displayed shape
299 getDisplayer()->SetWidth( lineWidth );
301 // set display mode of displayed shape
302 int aPrevDispMode = getDisplayer()->SetDisplayMode( displayMode );
304 // Disable activation of selection
305 getDisplayer()->SetToActivate( activate );
307 // Make a reference to GEOM_Object
308 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string( object );
309 getDisplayer()->SetName( objStr.in() );
312 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( object );
313 if ( aPrs == 0 || aPrs->IsNull() )
317 displayPreview( aPrs, append, update );
319 getDisplayer()->UnsetName();
320 getDisplayer()->UnsetColor();
321 getDisplayer()->SetDisplayMode( aPrevDispMode );
323 // Enable activation of displayed objects
324 getDisplayer()->SetToActivate( true );
327 //================================================================
328 // Function : displayPreview
329 // Purpose : Method for displaying arbitrary preview objects (not limited to shapes)
330 //================================================================
331 void GEOMBase_Helper::displayPreview( const SALOME_Prs* prs,
336 erasePreview( false );
338 // remember current view frame to make correct erase preview later
339 myViewWindow = getActiveView();
341 if ( myViewWindow == 0 )
345 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
346 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
347 aViewManager->getType() == SVTK_Viewer::Type() )
349 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
350 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
352 aView->Display( prs );
355 // Add prs to the preview list
356 myPreview.push_back( (SALOME_Prs*)prs );
360 getDisplayer()->UpdateViewer();
363 //================================================================
364 // Function : erasePreview
366 //================================================================
367 void GEOMBase_Helper::erasePreview( const bool update )
369 // check view frame where the preview was displayed
370 bool vfOK = checkViewWindow() && myViewWindow;
371 // Iterate through presentations and delete them
372 for ( PrsList::iterator anIter = myPreview.begin(); anIter != myPreview.end(); ++anIter ) {
375 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
376 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
377 aViewManager->getType() == SVTK_Viewer::Type() )
379 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
380 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
382 aView->Erase( *anIter, true );
394 //================================================================
395 // Function : localSelection
396 // Purpose : Activate selection of objects of a given type
397 // IMPORTANT : Works after localSelection( ... ) method call only
398 //================================================================
399 void GEOMBase_Helper::activate( const int theType )
401 if (!getStudy()) return;
402 _PTR(Study) aStudy = getStudy()->studyDS();
403 _PTR(SComponent) aGeom ( aStudy->FindComponent( "GEOM" ) );
408 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( aGeom ) );
409 for ( ; anIter->More(); anIter->Next() )
411 _PTR(SObject) aSO ( anIter->Value() );
414 _PTR(SObject) aRefSO;
415 if ( !aSO->ReferencedObject( aRefSO ) )
417 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow
418 (GeometryGUI::ClientSObjectToObject(aSO));
419 if ( !anObj->_is_nil() && anObj->GetType() == theType )
420 aList.Append( new SALOME_InteractiveObject( aSO->GetID().c_str(), "GEOM", aSO->GetName().c_str()) );
425 getDisplayer()->LocalSelection( aList, 0 );
428 //================================================================
429 // Function : localSelection
430 // Purpose : Activate selection of subshapes in accordance with mode
431 // theMode is from TopAbs_ShapeEnum
432 //================================================================
433 void GEOMBase_Helper::localSelection( const ObjectList& theObjs, const int theMode )
435 SALOME_ListIO aListOfIO;
437 ObjectList::const_iterator anIter = theObjs.begin();
438 for ( ; anIter != theObjs.end(); ++anIter )
440 GEOM::GEOM_Object_ptr anObj = *anIter;
441 if ( anObj->_is_nil() )
443 string aEntry = getEntry( anObj );
445 aListOfIO.Append( new SALOME_InteractiveObject(
446 aEntry.c_str(), "GEOM", strdup( GEOMBase::GetName( anObj ).toLatin1().constData() ) ) );
449 getDisplayer()->LocalSelection( aListOfIO, theMode );
452 //================================================================
453 // Function : localSelection
454 // Purpose : Activate selection of subshapes in accordance with mode
455 // theMode is from TopAbs_ShapeEnum
456 //================================================================
457 void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const int mode )
459 // If object is null local selection for all objects is activated
460 if ( obj->_is_nil() ) {
461 getDisplayer()->LocalSelection( Handle(SALOME_InteractiveObject)(), mode );
466 objList.push_back( obj );
467 localSelection( objList, mode );
471 //================================================================
472 // Function : globalSelection
473 // Purpose : Activate selection of subshapes. Set selection filters
474 // in accordance with mode. theMode is from GEOMImpl_Types
475 //================================================================
476 void GEOMBase_Helper::globalSelection( const int theMode, const bool update )
478 getDisplayer()->GlobalSelection( theMode, update );
481 //================================================================
482 // Function : globalSelection
483 // Purpose : Activate selection of subshapes. Set selection filters
484 // in accordance with mode. theMode is from GEOMImpl_Types
485 //================================================================
486 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
489 getDisplayer()->GlobalSelection( theModes, update );
492 //================================================================
493 // Function : addInStudy
494 // Purpose : Add object in study
495 //================================================================
496 void GEOMBase_Helper::addInStudy( GEOM::GEOM_Object_ptr theObj, const char* theName )
501 _PTR(Study) aStudy = getStudy()->studyDS();
502 if ( !aStudy || theObj->_is_nil() )
505 GEOM::GEOM_Object_ptr aFatherObj = getFather( theObj );
507 getGeomEngine()->AddInStudy(GeometryGUI::ClientStudyToStudy(aStudy),
508 theObj, theName, aFatherObj);
511 //================================================================
512 // Function : updateObjBrowser
513 // Purpose : Update object browser
514 //================================================================
515 void GEOMBase_Helper::updateObjBrowser() const
517 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
519 CAM_Module* module = app->module( "Geometry" );
520 SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
522 appMod->updateObjBrowser( true );
527 //================================================================
528 // Function : updateViewer
529 // Purpose : Update active 3D view
530 //================================================================
531 void GEOMBase_Helper::updateViewer()
533 getDisplayer()->UpdateViewer();
536 //================================================================
537 // Function : getStudyId
538 // Purpose : Get study Id
539 //================================================================
540 int GEOMBase_Helper::getStudyId() const
544 anId = getStudy()->id();
548 //================================================================
549 // Function : getStudy
550 // Purpose : Returns the active study. It is recommended to use
551 // this method instead of direct desktop->getActiveStudy() calls
552 //================================================================
553 SalomeApp_Study* GEOMBase_Helper::getStudy() const
555 SUIT_Desktop* aDesktop = getDesktop();
559 QList<SUIT_Application*> anAppList = SUIT_Session::session()->applications();
561 SUIT_Application* anApp = 0;
562 QListIterator<SUIT_Application*> it( anAppList );
563 while ( it.hasNext() )
566 if ( anApp && anApp->desktop() == aDesktop )
570 return dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
573 //================================================================
574 // Function : getEntry
576 //================================================================
577 char* GEOMBase_Helper::getEntry( GEOM::GEOM_Object_ptr object ) const
579 SalomeApp_Study* study = getStudy();
581 char * objIOR = GEOMBase::GetIORFromObject( object );
582 string IOR( objIOR );
585 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
587 return TCollection_AsciiString((char*)SO->GetID().c_str()).ToCString();
594 //================================================================
595 // Function : getDisplayer
597 //================================================================
598 GEOM_Displayer* GEOMBase_Helper::getDisplayer()
601 myDisplayer = new GEOM_Displayer( getStudy() );
605 //================================================================
606 // Function : clearShapeBuffer
608 //================================================================
609 void GEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
611 if ( CORBA::is_nil( theObj ) )
614 CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( theObj );
615 TCollection_AsciiString asciiIOR( (char *)IOR.in() );
616 GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
618 if ( !getStudy() || !getStudy()->studyDS() )
621 _PTR(Study) aStudy = getStudy()->studyDS();
622 _PTR(SObject) aSObj ( aStudy->FindObjectIOR( string( IOR ) ) );
626 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
627 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
628 _PTR(GenericAttribute) anAttr;
629 if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
630 _PTR(AttributeIOR) anIOR ( anAttr );
631 TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
632 GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
637 //================================================================
638 // Function : openCommand
640 //================================================================
641 bool GEOMBase_Helper::openCommand()
644 if ( !getStudy() || hasCommand() )
647 GEOM::GEOM_IOperations_var anOp = GEOM::GEOM_IOperations::_narrow( getOperation() );
648 if ( !anOp->_is_nil() ) {
649 myCommand = new GEOM_Operation( SUIT_Session::session()->activeApplication(), anOp.in() );
657 //================================================================
658 // Function : abortCommand
660 //================================================================
661 bool GEOMBase_Helper::abortCommand()
672 //================================================================
673 // Function : commitCommand
675 //================================================================
676 bool GEOMBase_Helper::commitCommand( const char* )
687 //================================================================
688 // Function : hasCommand
690 //================================================================
691 bool GEOMBase_Helper::hasCommand() const
693 return (bool)myCommand;
696 //================================================================
697 // Function : getOperation
699 //================================================================
700 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::getOperation()
702 if ( myOperation->_is_nil() )
703 myOperation = createOperation();
710 //================================================================
711 // Function : checkViewWindow
713 //================================================================
714 bool GEOMBase_Helper::checkViewWindow()
717 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
718 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
719 while ( it.hasNext() )
721 if ( myViewWindow == it.next() )
729 //================================================================
730 // Function : onAccept
731 // Purpose : This method should be called from dialog's slots onOk() and onApply()
732 // It perfroms user input validation, then it
733 // performs a proper operation and manages transactions, etc.
734 //================================================================
735 bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction )
737 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
738 if ( !appStudy ) return false;
739 _PTR(Study) aStudy = appStudy->studyDS();
741 bool aLocked = (_PTR(AttributeStudyProperties) (aStudy->GetProperties()))->IsLocked();
743 MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
744 SUIT_MessageBox::warning ( (QWidget*)SUIT_Session::session()->activeApplication()->desktop(),
745 QObject::tr("WRN_WARNING"),
746 QObject::tr("WRN_STUDY_LOCKED"),
747 QObject::tr("BUT_OK") );
752 if ( !isValid( msg ) ) {
757 erasePreview( false );
760 if ( ( !publish && !useTransaction ) || openCommand() ) {
761 SUIT_OverrideCursor wc;
762 SUIT_Session::session()->activeApplication()->putInfo( "" );
764 if ( !execute( objects ) || !getOperation()->IsDone() ) {
770 addSubshapesToStudy(); // add Subshapes if local selection
771 const int nbObjs = objects.size();
773 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
775 QString aName = getNewObjectName();
778 aName = getPrefix(*it);
780 // Try to find a unique name
781 aName = GEOMBase::GetDefaultName(aName);
783 // Don't check name uniqueness in case of numerous objects
784 aName = aName + "_" + QString::number(aNumber++);
787 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
788 if ( aName.isEmpty() )
789 aName = GEOMBase::GetDefaultName( getPrefix( *it ) );
791 addInStudy( *it, aName.toLatin1().constData() );
793 display( *it, false );
796 // asv : fix of PAL6454. If publish==false, then the original shape
797 // was modified, and need to be re-cached in GEOM_Client before redisplay
798 clearShapeBuffer( *it );
799 // withChildren=true, updateView=false
800 redisplay( *it, true, false );
807 SUIT_Session::session()->activeApplication()->putInfo( QObject::tr("GEOM_PRP_DONE") );
814 catch( const SALOME::SALOME_Exception& e ) {
815 SalomeApp_Tools::QtCatchCorbaException( e );
825 //================================================================
826 // Function : showError
827 // Purpose : Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
828 //================================================================
829 void GEOMBase_Helper::showError()
832 if ( !getOperation()->_is_nil() )
833 msg = QObject::tr( getOperation()->GetErrorCode() );
836 msg = QObject::tr( "GEOM_PRP_ABORT" );
838 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
839 QObject::tr( "GEOM_ERROR_STATUS" ),
841 QObject::tr( "BUT_OK" ) );
844 //================================================================
845 // Function : showError
846 // Purpose : Shows a error message followed by <msg>
847 //================================================================
848 void GEOMBase_Helper::showError( const QString& msg )
850 QString str( QObject::tr( "GEOM_INCORRECT_INPUT" ) );
851 if ( !msg.isEmpty() )
853 SUIT_MessageBox::critical(SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ), str, QObject::tr( "BUT_OK" ) );
856 //////////////////////////////////////////////////////////////////
857 // Virtual methods to be redefined in dialogs
858 //////////////////////////////////////////////////////////////////
860 //================================================================
861 // Function : createOperation
862 // Purpose : Redefine this method to return proper IOperation reference
863 //================================================================
864 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::createOperation()
866 GEOM::GEOM_IOperations_var aNilOp;
867 return aNilOp._retn();
870 //================================================================
871 // Function : isValid
872 // Purpose : Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
873 //================================================================
874 bool GEOMBase_Helper::isValid( QString& )
879 //================================================================
880 // Function : execute
881 // Purpose : This method is called by onAccept().
882 // It should perform the required operation and put all new or modified objects into
883 // <objects> argument.Should return <false> if some error occurs during its execution.
884 //================================================================
885 bool GEOMBase_Helper::execute( ObjectList& objects )
890 //================================================================
891 // Function : getFather
892 // Purpose : This method is called by addInStudy(). It should return a father object
893 // for <theObj> or a nil reference if <theObj> should be published
894 // as a top-level object.
895 //================================================================
896 GEOM::GEOM_Object_ptr GEOMBase_Helper::getFather( GEOM::GEOM_Object_ptr theObj )
898 return GEOM::GEOM_Object::_nil();
901 //================================================================
902 // Function : getNewObjectName
903 // Purpose : Redefine this method to return proper name for a new object
904 //================================================================
905 const char* GEOMBase_Helper::getNewObjectName() const
910 //================================================================
911 // Function : getPrefix
912 // Purpose : Get prefix for name of created object
913 //================================================================
914 QString GEOMBase_Helper::getPrefix( GEOM::GEOM_Object_ptr theObj ) const
916 if ( !myPrefix.isEmpty() || theObj->_is_nil() )
919 //TopoDS_Shape aShape;
920 //if ( !GEOMBase::GetShape( theObj, aShape ) )
923 //long aType = aShape.ShapeType();
924 GEOM::shape_type aType = theObj->GetShapeType();
928 case GEOM::VERTEX : return QObject::tr( "GEOM_VERTEX" );
929 case GEOM::EDGE : return QObject::tr( "GEOM_EDGE" );
930 case GEOM::WIRE : return QObject::tr( "GEOM_WIRE" );
931 case GEOM::FACE : return QObject::tr( "GEOM_FACE" );
932 case GEOM::SHELL : return QObject::tr( "GEOM_SHELL" );
933 case GEOM::SOLID : return QObject::tr( "GEOM_SOLID" );
934 case GEOM::COMPSOLID: return QObject::tr( "GEOM_COMPOUNDSOLID" );
935 case GEOM::COMPOUND : return QObject::tr( "GEOM_COMPOUND" );
940 //================================================================
941 // Function : selectedIO
942 // Purpose : Return the list of selected SALOME_InteractiveObject's
943 //================================================================
944 const SALOME_ListIO& GEOMBase_Helper::selectedIO()
948 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
950 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
952 aSelMgr->selectedObjects( mySelected );
958 //================================================================
959 // Function : IObjectCount
960 // Purpose : Return the number of selected objects
961 //================================================================
962 int GEOMBase_Helper::IObjectCount()
964 return selectedIO().Extent();
967 //================================================================
968 // Function : firstIObject
969 // Purpose : Return the first selected object in the selected object list
970 //================================================================
971 Handle(SALOME_InteractiveObject) GEOMBase_Helper::firstIObject()
973 const SALOME_ListIO& aList = selectedIO();
974 return aList.Extent() > 0 ? aList.First() : Handle(SALOME_InteractiveObject)();
977 //================================================================
978 // Function : lastIObject
979 // Purpose : Return the last selected object in the selected object list
980 //================================================================
981 Handle(SALOME_InteractiveObject) GEOMBase_Helper::lastIObject()
983 const SALOME_ListIO& aList = selectedIO();
984 return aList.Extent() > 0 ? aList.Last() : Handle(SALOME_InteractiveObject)();
987 //================================================================
988 // Function : getDesktop
989 // Purpose : Returns myDesktop field. Initialized in constructor, usually as dynamic_cast<SUIT_Desktop*>(parentWidget())
990 //================================================================
991 SUIT_Desktop* GEOMBase_Helper::getDesktop() const
996 //================================================================
997 // Function : selectObjects
998 // Purpose : Selects list of objects
999 //================================================================
1000 bool GEOMBase_Helper::selectObjects( ObjectList& objects )
1002 SUIT_DataOwnerPtrList aList;
1003 ObjectList::iterator anIter;
1004 for ( anIter = objects.begin(); anIter != objects.end(); ++anIter )
1006 string entry = getEntry( *anIter );
1007 QString aEntry( entry.c_str() );
1008 LightApp_DataOwner* anOwher = new LightApp_DataOwner( aEntry );
1009 aList.append( anOwher );
1012 SUIT_Session* session = SUIT_Session::session();
1013 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1017 LightApp_SelectionMgr* aMgr = app->selectionMgr();
1021 aMgr->setSelected( aList, false );
1026 //================================================================
1027 // Function : findObjectInFather
1028 // Purpose : It should return an object if its founded in study or
1029 // return Null object if the object is not founded
1030 //================================================================
1031 GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather( GEOM::GEOM_Object_ptr theFather, const QString& theName)
1033 SalomeApp_Application* app =
1034 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1035 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1036 _PTR(Study) aDStudy = appStudy->studyDS();
1037 string IOR = GEOMBase::GetIORFromObject( theFather );
1038 _PTR(SObject) SObj ( aDStudy->FindObjectIOR( IOR ) );
1040 bool inStudy = false;
1041 GEOM::GEOM_Object_var aReturnObject;
1042 for (_PTR(ChildIterator) iit (aDStudy->NewChildIterator( SObj )); iit->More() && !inStudy; iit->Next()) {
1043 _PTR(SObject) child (iit->Value());
1044 QString aChildName = child->GetName().c_str();
1045 if (aChildName == theName) {
1047 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(iit->Value());
1048 aReturnObject = GEOM::GEOM_Object::_narrow( corbaObj );
1052 return aReturnObject._retn();
1054 return GEOM::GEOM_Object::_nil();
1057 //================================================================
1058 // Function : addSubshapesToStudy
1059 // Purpose : Virtual method to add subshapes if needs
1060 //================================================================
1061 void GEOMBase_Helper::addSubshapesToStudy()
1063 //Impemented in Dialogs, called from Accept method
1066 //================================================================
1067 // Function : addSubshapesToFather
1068 // Purpose : Method to add Father Subshapes to Study if it`s not exist
1069 //================================================================
1070 void GEOMBase_Helper::addSubshapesToFather( QMap<QString, GEOM::GEOM_Object_var>& theMap )
1073 SalomeApp_Application* app =
1074 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1075 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1076 _PTR(Study) aDStudy = appStudy->studyDS();
1078 GEOM::GEOM_IGroupOperations_var anOp = getGeomEngine()->GetIGroupOperations( getStudyId() );
1080 for( QMap<QString, GEOM::GEOM_Object_var>::Iterator it = theMap.begin(); it != theMap.end(); it++ )
1082 if ( !anOp->_is_nil() ) {
1083 GEOM::GEOM_Object_var aFatherObj = anOp->GetMainShape( it.value() );
1084 if ( !aFatherObj->_is_nil() ) {
1085 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aFatherObj, it.key().toLatin1().data() );
1087 //Add Object to study if its not exist
1088 if ( aFindedObject == GEOM::GEOM_Object::_nil() )
1089 GeometryGUI::GetGeomGen()->AddInStudy(GeometryGUI::ClientStudyToStudy(aDStudy),
1090 it.value(), it.key().toLatin1().data(), aFatherObj );
1094 //cout << " anOperations is NULL! " << endl;