1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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 // GEOM GEOMGUI : GUI for Geometry component
23 // File : GEOMBase_Helper.cxx
24 // 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 );
109 myOperation->Destroy();
112 //================================================================
113 // Function : display
115 //================================================================
116 void GEOMBase_Helper::display( const ObjectList& objList, const bool updateView )
118 ObjectList::const_iterator it;
119 for ( it = objList.begin(); it != objList.end(); it++ ) {
120 display( *it, false );
122 if ( !objList.empty() && updateView )
123 getDisplayer()->UpdateViewer();
126 //================================================================
127 // Function : display
128 // Purpose : Display object.
129 // Important : Object must be already in study
130 //================================================================
131 void GEOMBase_Helper::display( GEOM::GEOM_Object_ptr object, const bool updateView )
133 // Unset color of shape ( this color may be set during preview displaying )
134 // Default color will be used
135 getDisplayer()->UnsetColor();
136 getDisplayer()->UnsetWidth();
138 // Enable activisation of selection
139 getDisplayer()->SetToActivate( true );
142 getDisplayer()->Display( object, updateView );
145 //================================================================
148 //================================================================
149 void GEOMBase_Helper::erase( const ObjectList& objList, const bool updateView )
151 ObjectList::const_iterator it = objList.begin();
152 for ( ; it != objList.end(); it++ ) {
155 if ( !objList.empty() && updateView )
156 getDisplayer()->UpdateViewer();
159 //================================================================
162 //================================================================
163 void GEOMBase_Helper::erase( GEOM::GEOM_Object_ptr object, const bool updateView )
165 if ( !object->_is_nil() ) {
166 std::string entry = getEntry( object );
167 getDisplayer()->Erase( new SALOME_InteractiveObject(
168 entry.c_str(), "GEOM", strdup( GEOMBase::GetName( object ).toLatin1().constData() ) ), true, updateView );
172 //================================================================
173 // Function : redisplay
175 //================================================================
176 void GEOMBase_Helper::redisplay( const ObjectList& objList,
177 const bool withChildren,
178 const bool updateView )
180 ObjectList::const_iterator it = objList.begin();
181 for ( ; it != objList.end(); it++ ) {
182 redisplay( *it, withChildren, false );
184 if ( !objList.empty() && updateView )
185 getDisplayer()->UpdateViewer();
188 //================================================================
189 // Function : redisplay
191 //================================================================
192 void GEOMBase_Helper::redisplay( GEOM::GEOM_Object_ptr object,
193 const bool withChildren,
194 const bool updateView )
196 if ( !object->_is_nil() ) {
197 // Unset color of shape ( this color may be set during preview displaying )
198 // Default color will be used
199 getDisplayer()->UnsetColor();
200 getDisplayer()->UnsetWidth();
202 // Enable activisation of selection
203 getDisplayer()->SetToActivate( true );
205 std::string entry = getEntry( object );
206 getDisplayer()->Redisplay(new SALOME_InteractiveObject
207 (entry.c_str(), "GEOM", strdup(GEOMBase::GetName(object).toLatin1().constData())), false);
210 if ( withChildren ) {
211 SalomeApp_Study* aDoc = getStudy();
212 if ( aDoc && aDoc->studyDS() ) {
213 _PTR(Study) aStudy = aDoc->studyDS();
214 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string(object);
215 _PTR(SObject) aSObj (aStudy->FindObjectIOR(std::string(objStr.in())));
217 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
218 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
219 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow
220 (GeometryGUI::ClientSObjectToObject(anIt->Value()));
221 if ( !CORBA::is_nil( aChild ) ) {
222 if ( !aChild->_is_nil() ) {
223 std::string entry = getEntry( aChild );
224 getDisplayer()->Redisplay( new SALOME_InteractiveObject(
225 entry.c_str(), "GEOM", strdup( GEOMBase::GetName( aChild ).toLatin1().constData() ) ), false );
234 getDisplayer()->UpdateViewer();
237 //================================================================
238 // Function : displayPreview
239 // Purpose : Method for displaying preview based on execute() results
240 //================================================================
241 void GEOMBase_Helper::displayPreview( const bool activate,
243 const bool toRemoveFromEngine,
244 const double lineWidth,
245 const int displayMode,
250 if ( !isValid( msg ) )
252 erasePreview( update );
257 erasePreview( false );
260 SUIT_OverrideCursor wc;
262 if ( !execute( objects ) || !getOperation()->IsDone() ) {
266 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it )
268 GEOM::GEOM_Object_var obj=*it;
269 displayPreview( obj, true, activate, false, lineWidth, displayMode, color );
270 if ( toRemoveFromEngine )
275 catch( const SALOME::SALOME_Exception& e ) {
276 SalomeApp_Tools::QtCatchCorbaException( e );
285 //================================================================
286 // Function : displayPreview
287 // Purpose : Method for displaying preview of resulting shape
288 //================================================================
289 void GEOMBase_Helper::displayPreview( GEOM::GEOM_Object_ptr object,
293 const double lineWidth,
294 const int displayMode,
297 // Set color for preview shape
298 getDisplayer()->SetColor( color == -1 ? Quantity_NOC_VIOLET : color );
300 // set width of displayed shape
301 getDisplayer()->SetWidth( lineWidth );
303 // set display mode of displayed shape
304 int aPrevDispMode = getDisplayer()->SetDisplayMode( displayMode );
306 // Disable activation of selection
307 getDisplayer()->SetToActivate( activate );
309 // Make a reference to GEOM_Object
310 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string( object );
311 getDisplayer()->SetName( objStr.in() );
314 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( object );
315 if ( aPrs == 0 || aPrs->IsNull() )
319 displayPreview( aPrs, append, update );
321 getDisplayer()->UnsetName();
322 getDisplayer()->UnsetColor();
323 getDisplayer()->SetDisplayMode( aPrevDispMode );
325 // Enable activation of displayed objects
326 getDisplayer()->SetToActivate( true );
329 //================================================================
330 // Function : displayPreview
331 // Purpose : Method for displaying arbitrary preview objects (not limited to shapes)
332 //================================================================
333 void GEOMBase_Helper::displayPreview( const SALOME_Prs* prs,
338 erasePreview( false );
340 // remember current view frame to make correct erase preview later
341 myViewWindow = getActiveView();
343 if ( myViewWindow == 0 )
347 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
348 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
349 aViewManager->getType() == SVTK_Viewer::Type() )
351 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
352 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
354 aView->Display( prs );
357 // Add prs to the preview list
358 myPreview.push_back( (SALOME_Prs*)prs );
362 getDisplayer()->UpdateViewer();
365 //================================================================
366 // Function : erasePreview
368 //================================================================
369 void GEOMBase_Helper::erasePreview( const bool update )
371 // check view frame where the preview was displayed
372 bool vfOK = checkViewWindow() && myViewWindow;
373 // Iterate through presentations and delete them
374 for ( PrsList::iterator anIter = myPreview.begin(); anIter != myPreview.end(); ++anIter ) {
377 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
378 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
379 aViewManager->getType() == SVTK_Viewer::Type() )
381 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
382 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
384 aView->Erase( *anIter, true );
396 //================================================================
397 // Function : localSelection
398 // Purpose : Activate selection of objects of a given type
399 // IMPORTANT : Works after localSelection( ... ) method call only
400 //================================================================
401 void GEOMBase_Helper::activate( const int theType )
403 if (!getStudy()) return;
404 _PTR(Study) aStudy = getStudy()->studyDS();
405 _PTR(SComponent) aGeom ( aStudy->FindComponent( "GEOM" ) );
410 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( aGeom ) );
411 for ( ; anIter->More(); anIter->Next() )
413 _PTR(SObject) aSO ( anIter->Value() );
416 _PTR(SObject) aRefSO;
417 if ( !aSO->ReferencedObject( aRefSO ) )
419 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow
420 (GeometryGUI::ClientSObjectToObject(aSO));
421 if ( !anObj->_is_nil() && anObj->GetType() == theType )
422 aList.Append( new SALOME_InteractiveObject( aSO->GetID().c_str(), "GEOM", aSO->GetName().c_str()) );
427 getDisplayer()->LocalSelection( aList, 0 );
430 //================================================================
431 // Function : localSelection
432 // Purpose : Activate selection of subshapes in accordance with mode
433 // theMode is from TopAbs_ShapeEnum
434 //================================================================
435 void GEOMBase_Helper::localSelection( const ObjectList& theObjs, const int theMode )
437 SALOME_ListIO aListOfIO;
439 ObjectList::const_iterator anIter = theObjs.begin();
440 for ( ; anIter != theObjs.end(); ++anIter )
442 GEOM::GEOM_Object_ptr anObj = *anIter;
443 if ( anObj->_is_nil() )
445 std::string aEntry = getEntry( anObj );
447 aListOfIO.Append( new SALOME_InteractiveObject(
448 aEntry.c_str(), "GEOM", strdup( GEOMBase::GetName( anObj ).toLatin1().constData() ) ) );
451 getDisplayer()->LocalSelection( aListOfIO, theMode );
454 //================================================================
455 // Function : localSelection
456 // Purpose : Activate selection of subshapes in accordance with mode
457 // theMode is from TopAbs_ShapeEnum
458 //================================================================
459 void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const int mode )
461 // If object is null local selection for all objects is activated
462 if ( obj->_is_nil() ) {
463 getDisplayer()->LocalSelection( Handle(SALOME_InteractiveObject)(), mode );
468 objList.push_back( obj );
469 localSelection( objList, mode );
473 //================================================================
474 // Function : globalSelection
475 // Purpose : Activate selection of subshapes. Set selection filters
476 // in accordance with mode. theMode is from GEOMImpl_Types
477 //================================================================
478 void GEOMBase_Helper::globalSelection( const int theMode, const bool update )
480 getDisplayer()->GlobalSelection( theMode, update );
483 //================================================================
484 // Function : globalSelection
485 // Purpose : Activate selection of subshapes. Set selection filters
486 // in accordance with mode. theMode is from GEOMImpl_Types
487 //================================================================
488 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
491 getDisplayer()->GlobalSelection( theModes, update );
494 //================================================================
495 // Function : globalSelection
496 // Purpose : Activate selection of subshapes. Set selection filters
497 // in accordance with mode. theMode is from GEOMImpl_Types
498 //================================================================
499 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
500 const QList<int>& subShapes,
503 getDisplayer()->GlobalSelection( theModes, update, &subShapes );
506 //================================================================
507 // Function : addInStudy
508 // Purpose : Add object in study
509 //================================================================
510 void GEOMBase_Helper::addInStudy( GEOM::GEOM_Object_ptr theObj, const char* theName )
515 _PTR(Study) aStudy = getStudy()->studyDS();
516 if ( !aStudy || theObj->_is_nil() )
519 SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy(aStudy);
521 GEOM::GEOM_Object_ptr aFatherObj = getFather( theObj );
523 SALOMEDS::SObject_var aSO =
524 getGeomEngine()->AddInStudy(aStudyDS, theObj, theName, aFatherObj);
526 // Each dialog is responsible for this method implementation,
527 // default implementation does nothing
528 restoreSubShapes(aStudyDS, aSO);
532 //================================================================
533 // Function : restoreSubShapes
534 // Purpose : restore tree of argument's sub-shapes under the resulting shape
535 //================================================================
536 void GEOMBase_Helper::restoreSubShapes (SALOMEDS::Study_ptr /*theStudy*/,
537 SALOMEDS::SObject_ptr /*theSObject*/)
539 // do nothing by default
541 // example of implementation in particular dialog:
542 // GEOM::ListOfGO anArgs;
543 // anArgs.length(0); // empty list means that all arguments should be restored
544 // getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
545 // /*theFindMethod=*/GEOM::FSM_GetInPlace,
546 // /*theInheritFirstArg=*/false);
549 //================================================================
550 // Function : updateObjBrowser
551 // Purpose : Update object browser
552 //================================================================
553 void GEOMBase_Helper::updateObjBrowser() const
555 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
557 CAM_Module* module = app->module( "Geometry" );
558 SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
560 appMod->updateObjBrowser( true );
565 //================================================================
566 // Function : updateViewer
567 // Purpose : Update active 3D view
568 //================================================================
569 void GEOMBase_Helper::updateViewer()
571 getDisplayer()->UpdateViewer();
574 //================================================================
575 // Function : getStudyId
576 // Purpose : Get study Id
577 //================================================================
578 int GEOMBase_Helper::getStudyId() const
582 anId = getStudy()->id();
586 //================================================================
587 // Function : getStudy
588 // Purpose : Returns the active study. It is recommended to use
589 // this method instead of direct desktop->getActiveStudy() calls
590 //================================================================
591 SalomeApp_Study* GEOMBase_Helper::getStudy() const
593 SUIT_Desktop* aDesktop = getDesktop();
597 QList<SUIT_Application*> anAppList = SUIT_Session::session()->applications();
599 SUIT_Application* anApp = 0;
600 QListIterator<SUIT_Application*> it( anAppList );
601 while ( it.hasNext() )
604 if ( anApp && anApp->desktop() == aDesktop )
608 return dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
611 //================================================================
612 // Function : getEntry
614 //================================================================
615 char* GEOMBase_Helper::getEntry( GEOM::GEOM_Object_ptr object ) const
617 SalomeApp_Study* study = getStudy();
619 char * objIOR = GEOMBase::GetIORFromObject( object );
620 std::string IOR( objIOR );
623 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
625 return (char*) TCollection_AsciiString((char*)SO->GetID().c_str()).ToCString();
632 //================================================================
633 // Function : getDisplayer
635 //================================================================
636 GEOM_Displayer* GEOMBase_Helper::getDisplayer()
639 myDisplayer = new GEOM_Displayer( getStudy() );
643 //================================================================
644 // Function : clearShapeBuffer
646 //================================================================
647 void GEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
649 if ( CORBA::is_nil( theObj ) )
652 CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( theObj );
653 TCollection_AsciiString asciiIOR( (char *)IOR.in() );
654 GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
656 if ( !getStudy() || !getStudy()->studyDS() )
659 _PTR(Study) aStudy = getStudy()->studyDS();
660 _PTR(SObject) aSObj ( aStudy->FindObjectIOR( std::string( IOR ) ) );
664 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
665 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
666 _PTR(GenericAttribute) anAttr;
667 if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
668 _PTR(AttributeIOR) anIOR ( anAttr );
669 TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
670 GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
675 //================================================================
676 // Function : openCommand
678 //================================================================
679 bool GEOMBase_Helper::openCommand()
682 if ( !getStudy() || hasCommand() )
685 GEOM::GEOM_IOperations_var anOp = GEOM::GEOM_IOperations::_narrow( getOperation() );
686 if ( !anOp->_is_nil() ) {
687 myCommand = new GEOM_Operation( SUIT_Session::session()->activeApplication(), anOp.in() );
695 //================================================================
696 // Function : abortCommand
698 //================================================================
699 bool GEOMBase_Helper::abortCommand()
705 delete myCommand; // I don't know where to delete this object here ?
711 //================================================================
712 // Function : commitCommand
714 //================================================================
715 bool GEOMBase_Helper::commitCommand( const char* )
721 delete myCommand; // I don't know where to delete this object here ?
727 //================================================================
728 // Function : hasCommand
730 //================================================================
731 bool GEOMBase_Helper::hasCommand() const
733 return (bool)myCommand;
736 //================================================================
737 // Function : getOperation
739 //================================================================
740 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::getOperation()
742 if ( myOperation->_is_nil() )
743 myOperation = createOperation();
750 //================================================================
751 // Function : checkViewWindow
753 //================================================================
754 bool GEOMBase_Helper::checkViewWindow()
757 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
758 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
759 while ( it.hasNext() )
761 if ( myViewWindow == it.next() )
769 //================================================================
770 // Function : onAccept
771 // Purpose : This method should be called from dialog's slots onOk() and onApply()
772 // It perfroms user input validation, then it
773 // performs a proper operation and manages transactions, etc.
774 //================================================================
775 bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction )
777 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
778 if ( !appStudy ) return false;
779 _PTR(Study) aStudy = appStudy->studyDS();
781 bool aLocked = (_PTR(AttributeStudyProperties) (aStudy->GetProperties()))->IsLocked();
783 MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
784 SUIT_MessageBox::warning ( (QWidget*)SUIT_Session::session()->activeApplication()->desktop(),
785 QObject::tr("WRN_WARNING"),
786 QObject::tr("WRN_STUDY_LOCKED"),
787 QObject::tr("BUT_OK") );
792 if ( !isValid( msg ) ) {
797 erasePreview( false );
800 if ( ( !publish && !useTransaction ) || openCommand() ) {
801 SUIT_OverrideCursor wc;
802 SUIT_Session::session()->activeApplication()->putInfo( "" );
804 if ( !execute( objects ) || !getOperation()->IsDone() ) {
810 addSubshapesToStudy(); // add Subshapes if local selection
811 const int nbObjs = objects.size();
813 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
814 GEOM::GEOM_Object_var obj=*it;
816 QString aName = getNewObjectName();
819 aName = getPrefix(obj);
821 // Try to find a unique name
822 aName = GEOMBase::GetDefaultName(aName);
824 // Don't check name uniqueness in case of numerous objects
825 aName = aName + "_" + QString::number(aNumber++);
828 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
829 if ( aName.isEmpty() )
830 aName = GEOMBase::GetDefaultName( getPrefix( obj ) );
832 addInStudy( obj, aName.toLatin1().constData() );
834 display( obj, false );
835 // obj has been published in study. Its refcount has been incremented.
836 // It is safe to decrement its refcount
837 // so that it will be destroyed when the entry in study will be removed
841 // asv : fix of PAL6454. If publish==false, then the original shape
842 // was modified, and need to be re-cached in GEOM_Client before redisplay
843 clearShapeBuffer( obj );
844 // withChildren=true, updateView=false
845 redisplay( obj, true, false );
852 SUIT_Session::session()->activeApplication()->putInfo( QObject::tr("GEOM_PRP_DONE") );
859 catch( const SALOME::SALOME_Exception& e ) {
860 SalomeApp_Tools::QtCatchCorbaException( e );
870 //================================================================
871 // Function : showError
872 // Purpose : Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
873 //================================================================
874 void GEOMBase_Helper::showError()
877 if ( !getOperation()->_is_nil() )
878 msg = QObject::tr( getOperation()->GetErrorCode() );
881 msg = QObject::tr( "GEOM_PRP_ABORT" );
883 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
884 QObject::tr( "GEOM_ERROR_STATUS" ),
886 QObject::tr( "BUT_OK" ) );
889 //================================================================
890 // Function : showError
891 // Purpose : Shows a error message followed by <msg>
892 //================================================================
893 void GEOMBase_Helper::showError( const QString& msg )
895 QString str( QObject::tr( "GEOM_INCORRECT_INPUT" ) );
896 if ( !msg.isEmpty() )
898 SUIT_MessageBox::critical(SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ), str, QObject::tr( "BUT_OK" ) );
901 //////////////////////////////////////////////////////////////////
902 // Virtual methods to be redefined in dialogs
903 //////////////////////////////////////////////////////////////////
905 //================================================================
906 // Function : createOperation
907 // Purpose : Redefine this method to return proper IOperation reference
908 //================================================================
909 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::createOperation()
911 GEOM::GEOM_IOperations_var aNilOp;
912 return aNilOp._retn();
915 //================================================================
916 // Function : isValid
917 // Purpose : Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
918 //================================================================
919 bool GEOMBase_Helper::isValid( QString& )
924 //================================================================
925 // Function : execute
926 // Purpose : This method is called by onAccept().
927 // It should perform the required operation and put all new or modified objects into
928 // <objects> argument.Should return <false> if some error occurs during its execution.
929 //================================================================
930 bool GEOMBase_Helper::execute( ObjectList& objects )
935 //================================================================
936 // Function : getFather
937 // Purpose : This method is called by addInStudy(). It should return a father object
938 // for <theObj> or a nil reference if <theObj> should be published
939 // as a top-level object.
940 //================================================================
941 GEOM::GEOM_Object_ptr GEOMBase_Helper::getFather( GEOM::GEOM_Object_ptr theObj )
943 return GEOM::GEOM_Object::_nil();
946 //================================================================
947 // Function : getNewObjectName
948 // Purpose : Redefine this method to return proper name for a new object
949 //================================================================
950 QString GEOMBase_Helper::getNewObjectName() const
952 return QString::null;
955 //================================================================
956 // Function : getPrefix
957 // Purpose : Get prefix for name of created object
958 //================================================================
959 QString GEOMBase_Helper::getPrefix( GEOM::GEOM_Object_ptr theObj ) const
961 if ( !myPrefix.isEmpty() || theObj->_is_nil() )
964 //TopoDS_Shape aShape;
965 //if ( !GEOMBase::GetShape( theObj, aShape ) )
968 //long aType = aShape.ShapeType();
969 GEOM::shape_type aType = theObj->GetShapeType();
973 case GEOM::VERTEX : return QObject::tr( "GEOM_VERTEX" );
974 case GEOM::EDGE : return QObject::tr( "GEOM_EDGE" );
975 case GEOM::WIRE : return QObject::tr( "GEOM_WIRE" );
976 case GEOM::FACE : return QObject::tr( "GEOM_FACE" );
977 case GEOM::SHELL : return QObject::tr( "GEOM_SHELL" );
978 case GEOM::SOLID : return QObject::tr( "GEOM_SOLID" );
979 case GEOM::COMPSOLID: return QObject::tr( "GEOM_COMPOUNDSOLID" );
980 case GEOM::COMPOUND : return QObject::tr( "GEOM_COMPOUND" );
985 //================================================================
986 // Function : getDesktop
987 // Purpose : Returns myDesktop field. Initialized in constructor,
988 // usually as dynamic_cast<SUIT_Desktop*>(parentWidget())
989 //================================================================
990 SUIT_Desktop* GEOMBase_Helper::getDesktop() const
995 //================================================================
996 // Function : selectObjects
997 // Purpose : Selects list of objects
998 //================================================================
999 bool GEOMBase_Helper::selectObjects( ObjectList& objects )
1001 SUIT_DataOwnerPtrList aList;
1002 ObjectList::iterator anIter;
1003 for ( anIter = objects.begin(); anIter != objects.end(); ++anIter )
1005 std::string entry = getEntry( *anIter );
1006 QString aEntry( entry.c_str() );
1007 LightApp_DataOwner* anOwher = new LightApp_DataOwner( aEntry );
1008 aList.append( anOwher );
1011 SUIT_Session* session = SUIT_Session::session();
1012 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1016 LightApp_SelectionMgr* aMgr = app->selectionMgr();
1020 aMgr->setSelected( aList, false );
1025 //================================================================
1026 // Function : findObjectInFather
1027 // Purpose : It should return an object if its founded in study or
1028 // return Null object if the object is not founded
1029 //================================================================
1030 GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather (GEOM::GEOM_Object_ptr theFather,
1031 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 std::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;