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
28 #include <SUIT_ViewModel.h>
30 #include "GEOMBase_Helper.h"
32 #include "GEOM_Operation.h"
33 #include "GeometryGUI.h"
34 #include "GEOM_Displayer.h"
35 #include "GEOMImpl_Types.hxx"
37 #include <SUIT_Session.h>
38 #include <SUIT_ViewWindow.h>
39 #include <SUIT_MessageBox.h>
40 #include <SUIT_OverrideCursor.h>
42 #include <SalomeApp_Module.h>
43 #include <SalomeApp_Application.h>
44 #include <SalomeApp_Study.h>
45 #include <LightApp_SelectionMgr.h>
46 #include <LightApp_DataOwner.h>
47 #include <SalomeApp_Tools.h>
48 #include <SalomeApp_DataModel.h>
50 #include <OCCViewer_ViewModel.h>
51 #include <SVTK_ViewModel.h>
53 #include <OB_Browser.h>
55 #include <TColStd_MapOfInteger.hxx>
56 #include <TCollection_AsciiString.hxx>
60 #include <SALOMEDSClient.hxx>
63 //================================================================
64 // Function : getActiveView
65 // Purpose : Get active view window, returns 0 if no open study frame
66 //================================================================
67 static SUIT_ViewWindow* getActiveView()
69 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
71 return SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
77 //================================================================
78 // Function : getGeomEngine
79 // Purpose : Static method
80 //================================================================
81 GEOM::GEOM_Gen_ptr GEOMBase_Helper::getGeomEngine()
83 return GeometryGUI::GetGeomGen();
86 //================================================================
87 // Function : GEOMBase_Helper
89 //================================================================
90 GEOMBase_Helper::GEOMBase_Helper( SUIT_Desktop* desktop )
91 : myDesktop( desktop ), myViewWindow( 0 ), myDisplayer( 0 ), myCommand( 0 ), isPreview( false )
95 //================================================================
96 // Function : ~GEOMBase_Helper
98 //================================================================
99 GEOMBase_Helper::~GEOMBase_Helper()
101 if ( !SUIT_Session::session()->activeApplication()->desktop() )
104 if ( myPreview.size() )
108 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
110 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
112 globalSelection(aGeomGUI->getLocalSelectionMode() , true );
119 //================================================================
120 // Function : display
122 //================================================================
123 void GEOMBase_Helper::display( const ObjectList& objList, const bool updateView )
125 ObjectList::const_iterator it;
126 for ( it = objList.begin(); it != objList.end(); it++ ) {
127 display( *it, false );
129 if ( !objList.empty() && updateView )
130 getDisplayer()->UpdateViewer();
133 //================================================================
134 // Function : display
135 // Purpose : Display object.
136 // Important : Object must be already in study
137 //================================================================
138 void GEOMBase_Helper::display( GEOM::GEOM_Object_ptr object, const bool updateView )
140 // Unset color of shape ( this color may be set during preview displaying )
141 // Default color will be used
142 getDisplayer()->UnsetColor();
143 getDisplayer()->UnsetWidth();
145 // Enable activisation of selection
146 getDisplayer()->SetToActivate( true );
149 getDisplayer()->Display( object, updateView );
152 //================================================================
155 //================================================================
156 void GEOMBase_Helper::erase( const ObjectList& objList, const bool updateView )
158 ObjectList::const_iterator it = objList.begin();
159 for ( ; it != objList.end(); it++ ) {
162 if ( !objList.empty() && updateView )
163 getDisplayer()->UpdateViewer();
166 //================================================================
169 //================================================================
170 void GEOMBase_Helper::erase( GEOM::GEOM_Object_ptr object, const bool updateView )
172 if ( !object->_is_nil() ) {
173 string entry = getEntry( object );
174 getDisplayer()->Erase( new SALOME_InteractiveObject(
175 entry.c_str(), "GEOM", strdup( GEOMBase::GetName( object ) ) ), true, updateView );
179 //================================================================
180 // Function : redisplay
182 //================================================================
183 void GEOMBase_Helper::redisplay( const ObjectList& objList,
184 const bool withChildren,
185 const bool updateView )
187 ObjectList::const_iterator it = objList.begin();
188 for ( ; it != objList.end(); it++ ) {
189 redisplay( *it, withChildren, false );
191 if ( !objList.empty() && updateView )
192 getDisplayer()->UpdateViewer();
195 //================================================================
196 // Function : redisplay
198 //================================================================
199 void GEOMBase_Helper::redisplay( GEOM::GEOM_Object_ptr object,
200 const bool withChildren,
201 const bool updateView )
203 if ( !object->_is_nil() ) {
204 // Unset color of shape ( this color may be set during preview displaying )
205 // Default color will be used
206 getDisplayer()->UnsetColor();
207 getDisplayer()->UnsetWidth();
209 // Enable activisation of selection
210 getDisplayer()->SetToActivate( true );
212 string entry = getEntry( object );
213 getDisplayer()->Redisplay(new SALOME_InteractiveObject
214 (entry.c_str(), "GEOM", strdup(GEOMBase::GetName(object))), false);
217 if ( withChildren ) {
218 SalomeApp_Study* aDoc = getStudy();
219 if ( aDoc && aDoc->studyDS() ) {
220 _PTR(Study) aStudy = aDoc->studyDS();
221 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string(object);
222 _PTR(SObject) aSObj (aStudy->FindObjectIOR(string(objStr.in())));
224 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
225 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
226 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow
227 (GeometryGUI::ClientSObjectToObject(anIt->Value()));
228 if ( !CORBA::is_nil( aChild ) ) {
229 if ( !aChild->_is_nil() ) {
230 string entry = getEntry( aChild );
231 getDisplayer()->Redisplay( new SALOME_InteractiveObject(
232 entry.c_str(), "GEOM", strdup( GEOMBase::GetName( aChild ) ) ), false );
241 getDisplayer()->UpdateViewer();
244 //================================================================
245 // Function : displayPreview
246 // Purpose : Method for displaying preview based on execute() results
247 //================================================================
248 void GEOMBase_Helper::displayPreview( const bool activate,
250 const bool toRemoveFromEngine,
251 const double lineWidth,
252 const int displayMode,
257 if ( !isValid( msg ) )
259 erasePreview( update );
264 erasePreview( false );
267 SUIT_OverrideCursor wc;
269 if ( !execute( objects ) || !getOperation()->IsDone() ) {
273 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it )
275 displayPreview( *it, true, activate, false, lineWidth, displayMode, color );
276 if ( toRemoveFromEngine )
277 getGeomEngine()->RemoveObject( *it );
281 catch( const SALOME::SALOME_Exception& e ) {
282 SalomeApp_Tools::QtCatchCorbaException( e );
291 //================================================================
292 // Function : displayPreview
293 // Purpose : Method for displaying preview of resulting shape
294 //================================================================
295 void GEOMBase_Helper::displayPreview( GEOM::GEOM_Object_ptr object,
299 const double lineWidth,
300 const int displayMode,
303 // Set color for preview shape
304 getDisplayer()->SetColor( color == -1 ? Quantity_NOC_VIOLET : color );
306 // set width of displayed shape
307 getDisplayer()->SetWidth( lineWidth );
309 // set display mode of displayed shape
310 int aPrevDispMode = getDisplayer()->SetDisplayMode( displayMode );
312 // Disable activation of selection
313 getDisplayer()->SetToActivate( activate );
315 // Make a reference to GEOM_Object
316 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string( object );
317 getDisplayer()->SetName( objStr.in() );
320 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( object );
321 if ( aPrs == 0 || aPrs->IsNull() )
325 displayPreview( aPrs, append, update );
327 getDisplayer()->UnsetName();
328 getDisplayer()->UnsetColor();
329 getDisplayer()->SetDisplayMode( aPrevDispMode );
331 // Enable activation of displayed objects
332 getDisplayer()->SetToActivate( true );
335 //================================================================
336 // Function : displayPreview
337 // Purpose : Method for displaying arbitrary preview objects (not limited to shapes)
338 //================================================================
339 void GEOMBase_Helper::displayPreview( const SALOME_Prs* prs,
344 erasePreview( false );
346 // remember current view frame to make correct erase preview later
347 myViewWindow = getActiveView();
349 if ( myViewWindow == 0 )
353 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
354 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
355 aViewManager->getType() == SVTK_Viewer::Type() )
357 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
358 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
360 aView->Display( prs );
363 // Add prs to the preview list
364 myPreview.push_back( (SALOME_Prs*)prs );
368 getDisplayer()->UpdateViewer();
371 //================================================================
372 // Function : erasePreview
374 //================================================================
375 void GEOMBase_Helper::erasePreview( const bool update )
377 // check view frame where the preview was displayed
378 bool vfOK = checkViewWindow() && myViewWindow;
379 // Iterate through presentations and delete them
380 for ( PrsList::iterator anIter = myPreview.begin(); anIter != myPreview.end(); ++anIter ) {
383 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
384 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
385 aViewManager->getType() == SVTK_Viewer::Type() )
387 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
388 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
390 aView->Erase( *anIter, true );
402 //================================================================
403 // Function : localSelection
404 // Purpose : Activate selection of objects of a given type
405 // IMPORTANT : Works after localSelection( ... ) method call only
406 //================================================================
407 void GEOMBase_Helper::activate( const int theType )
409 if (!getStudy()) return;
410 _PTR(Study) aStudy = getStudy()->studyDS();
411 _PTR(SComponent) aGeom ( aStudy->FindComponent( "GEOM" ) );
416 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( aGeom ) );
417 for ( ; anIter->More(); anIter->Next() )
419 _PTR(SObject) aSO ( anIter->Value() );
422 _PTR(SObject) aRefSO;
423 if ( !aSO->ReferencedObject( aRefSO ) )
425 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow
426 (GeometryGUI::ClientSObjectToObject(aSO));
427 if ( !anObj->_is_nil() && anObj->GetType() == theType )
428 aList.Append( new SALOME_InteractiveObject( aSO->GetID().c_str(), "GEOM", aSO->GetName().c_str()) );
433 getDisplayer()->LocalSelection( aList, 0 );
436 //================================================================
437 // Function : localSelection
438 // Purpose : Activate selection of subshapes in accordance with mode
439 // theMode is from TopAbs_ShapeEnum
440 //================================================================
441 void GEOMBase_Helper::localSelection( const ObjectList& theObjs, const int theMode )
443 SALOME_ListIO aListOfIO;
445 ObjectList::const_iterator anIter = theObjs.begin();
446 for ( ; anIter != theObjs.end(); ++anIter )
448 GEOM::GEOM_Object_ptr anObj = *anIter;
449 if ( anObj->_is_nil() )
451 string aEntry = getEntry( anObj );
453 aListOfIO.Append( new SALOME_InteractiveObject(
454 aEntry.c_str(), "GEOM", strdup( GEOMBase::GetName( anObj ) ) ) );
457 getDisplayer()->LocalSelection( aListOfIO, theMode );
460 //================================================================
461 // Function : localSelection
462 // Purpose : Activate selection of subshapes in accordance with mode
463 // theMode is from TopAbs_ShapeEnum
464 //================================================================
465 void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const int mode )
467 // If object is null local selection for all objects is activated
468 if ( obj->_is_nil() ) {
469 getDisplayer()->LocalSelection( Handle(SALOME_InteractiveObject)(), mode );
474 objList.push_back( obj );
475 localSelection( objList, mode );
479 //================================================================
480 // Function : globalSelection
481 // Purpose : Activate selection of subshapes. Set selection filters
482 // in accordance with mode. theMode is from GEOMImpl_Types
483 //================================================================
484 void GEOMBase_Helper::globalSelection( const int theMode, const bool update )
486 getDisplayer()->GlobalSelection( theMode, update );
489 //================================================================
490 // Function : globalSelection
491 // Purpose : Activate selection of subshapes. Set selection filters
492 // in accordance with mode. theMode is from GEOMImpl_Types
493 //================================================================
494 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
497 getDisplayer()->GlobalSelection( theModes, update );
500 //================================================================
501 // Function : globalSelection
502 // Purpose : Activate selection of subshapes. Set selection filters
503 // in accordance with mode. theMode is from GEOMImpl_Types
504 //================================================================
505 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
506 const QValueList<int>& subShapes,
509 getDisplayer()->GlobalSelection( theModes, update, &subShapes);
512 //================================================================
513 // Function : addInStudy
514 // Purpose : Add object in study
515 //================================================================
516 void GEOMBase_Helper::addInStudy( GEOM::GEOM_Object_ptr theObj, const char* theName )
521 _PTR(Study) aStudy = getStudy()->studyDS();
522 if ( !aStudy || theObj->_is_nil() )
525 SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy(aStudy);
527 GEOM::GEOM_Object_ptr aFatherObj = getFather( theObj );
529 SALOMEDS::SObject_var aSO =
530 getGeomEngine()->AddInStudy(aStudyDS, theObj, theName, aFatherObj);
532 // Each dialog is responsible for this method implementation,
533 // default implementation does nothing
534 restoreSubShapes(aStudyDS, aSO);
537 //================================================================
538 // Function : restoreSubShapes
539 // Purpose : restore tree of argument's sub-shapes under the resulting shape
540 //================================================================
541 void GEOMBase_Helper::restoreSubShapes (SALOMEDS::Study_ptr /*theStudy*/,
542 SALOMEDS::SObject_ptr /*theSObject*/)
544 // do nothing by default
546 // example of implementation in particular dialog:
547 // GEOM::ListOfGO anArgs;
548 // anArgs.length(0); // empty list means that all arguments should be restored
549 // getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
550 // /*theFindMethod=*/GEOM::FSM_GetInPlace,
551 // /*theInheritFirstArg=*/false);
554 //================================================================
555 // Function : updateObjBrowser
556 // Purpose : Update object browser
557 //================================================================
558 void GEOMBase_Helper::updateObjBrowser() const
560 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
562 CAM_Module* module = app->module( "Geometry" );
563 SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
565 appMod->updateObjBrowser( true );
570 //================================================================
571 // Function : updateViewer
572 // Purpose : Update active 3D view
573 //================================================================
574 void GEOMBase_Helper::updateViewer()
576 getDisplayer()->UpdateViewer();
579 //================================================================
580 // Function : getStudyId
581 // Purpose : Get study Id
582 //================================================================
583 int GEOMBase_Helper::getStudyId() const
587 anId = getStudy()->id();
591 //================================================================
592 // Function : getStudy
593 // Purpose : Returns the active study. It is recommended to use
594 // this method instead of direct desktop->getActiveStudy() calls
595 //================================================================
596 SalomeApp_Study* GEOMBase_Helper::getStudy() const
598 SUIT_Desktop* aDesktop = getDesktop();
602 QPtrList<SUIT_Application> anAppList = SUIT_Session::session()->applications();
604 SUIT_Application* anApp = 0;
605 for ( QPtrListIterator<SUIT_Application> it( anAppList ); it.current() ; ++it )
607 anApp = it.current();
608 if ( anApp->desktop() == aDesktop )
612 return dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
615 //================================================================
616 // Function : getEntry
618 //================================================================
619 char* GEOMBase_Helper::getEntry( GEOM::GEOM_Object_ptr object ) const
621 SalomeApp_Study* study = getStudy();
623 char * objIOR = GEOMBase::GetIORFromObject( object );
624 string IOR( objIOR );
627 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
629 return (char*) TCollection_AsciiString((char*)SO->GetID().c_str()).ToCString();
636 //================================================================
637 // Function : getDisplayer
639 //================================================================
640 GEOM_Displayer* GEOMBase_Helper::getDisplayer()
643 myDisplayer = new GEOM_Displayer( getStudy() );
647 //================================================================
648 // Function : clearShapeBuffer
650 //================================================================
651 void GEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
653 if ( CORBA::is_nil( theObj ) )
656 CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( theObj );
657 TCollection_AsciiString asciiIOR( (char *)IOR.in() );
658 GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
660 if ( !getStudy() || !getStudy()->studyDS() )
663 _PTR(Study) aStudy = getStudy()->studyDS();
664 _PTR(SObject) aSObj ( aStudy->FindObjectIOR( string( IOR ) ) );
668 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
669 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
670 _PTR(GenericAttribute) anAttr;
671 if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
672 _PTR(AttributeIOR) anIOR ( anAttr );
673 TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
674 GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
679 //================================================================
680 // Function : openCommand
682 //================================================================
683 bool GEOMBase_Helper::openCommand()
686 if ( !getStudy() || hasCommand() )
689 GEOM::GEOM_IOperations_var anOp = GEOM::GEOM_IOperations::_narrow( getOperation() );
690 if ( !anOp->_is_nil() ) {
691 myCommand = new GEOM_Operation( SUIT_Session::session()->activeApplication(), anOp.in() );
699 //================================================================
700 // Function : abortCommand
702 //================================================================
703 bool GEOMBase_Helper::abortCommand()
714 //================================================================
715 // Function : commitCommand
717 //================================================================
718 bool GEOMBase_Helper::commitCommand( const char* )
729 //================================================================
730 // Function : hasCommand
732 //================================================================
733 bool GEOMBase_Helper::hasCommand() const
735 return (bool)myCommand;
738 //================================================================
739 // Function : getOperation
741 //================================================================
742 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::getOperation()
744 if ( myOperation->_is_nil() )
745 myOperation = createOperation();
752 //================================================================
753 // Function : checkViewWindow
755 //================================================================
756 bool GEOMBase_Helper::checkViewWindow()
759 QPtrList<SUIT_ViewWindow> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
760 for ( QPtrListIterator<SUIT_ViewWindow> it( aViewWindowsList ); it.current(); ++it )
762 if ( myViewWindow == it.current() )
770 //================================================================
771 // Function : onAccept
772 // Purpose : This method should be called from dialog's slots onOk() and onApply()
773 // It perfroms user input validation, then it
774 // performs a proper operation and manages transactions, etc.
775 //================================================================
776 bool GEOMBase_Helper::onAccept (const bool publish, const bool useTransaction)
778 SalomeApp_Study* appStudy =
779 dynamic_cast<SalomeApp_Study*>(SUIT_Session::session()->activeApplication()->activeStudy());
780 if (!appStudy) return false;
781 _PTR(Study) aStudy = appStudy->studyDS();
783 bool aLocked = (_PTR(AttributeStudyProperties) (aStudy->GetProperties()))->IsLocked();
785 MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
786 SUIT_MessageBox::warn1 ( (QWidget*)SUIT_Session::session()->activeApplication()->desktop(),
787 QObject::tr("WRN_WARNING"),
788 QObject::tr("WRN_STUDY_LOCKED"),
789 QObject::tr("BUT_OK") );
794 if ( !isValid( msg ) ) {
799 erasePreview( false );
802 if ( ( !publish && !useTransaction ) || openCommand() ) {
803 SUIT_OverrideCursor wc;
804 SUIT_Session::session()->activeApplication()->putInfo( "" );
806 if ( !execute( objects ) || !getOperation()->IsDone() ) {
812 addSubshapesToStudy(); // add Subshapes if local selection
813 const int nbObjs = objects.size();
815 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
817 QString aName = getNewObjectName();
820 aName = getPrefix(*it);
822 // Try to find a unique name
823 aName = GEOMBase::GetDefaultName(aName);
825 // Don't check name uniqueness in case of numerous objects
826 aName = aName + "_" + QString::number(aNumber++);
829 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
830 if ( aName.isEmpty() )
831 aName = GEOMBase::GetDefaultName( getPrefix( *it ) );
833 addInStudy( *it, aName.latin1() );
835 display( *it, false );
838 // asv : fix of PAL6454. If publish==false, then the original shape
839 // was modified, and need to be re-cached in GEOM_Client before redisplay
840 clearShapeBuffer( *it );
841 // withChildren=true, updateView=false
842 redisplay( *it, true, false );
849 SUIT_Session::session()->activeApplication()->putInfo( QObject::tr("GEOM_PRP_DONE") );
856 catch( const SALOME::SALOME_Exception& e ) {
857 SalomeApp_Tools::QtCatchCorbaException( e );
867 //================================================================
868 // Function : showError
869 // Purpose : Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
870 //================================================================
871 void GEOMBase_Helper::showError()
874 if ( !getOperation()->_is_nil() )
875 msg = QObject::tr( getOperation()->GetErrorCode() );
878 msg = QObject::tr( "GEOM_PRP_ABORT" );
880 SUIT_MessageBox::error1( SUIT_Session::session()->activeApplication()->desktop(),
881 QObject::tr( "GEOM_ERROR_STATUS" ),
883 QObject::tr( "BUT_OK" ) );
886 //================================================================
887 // Function : showError
888 // Purpose : Shows a error message followed by <msg>
889 //================================================================
890 void GEOMBase_Helper::showError( const QString& msg )
892 QString str( QObject::tr( "GEOM_INCORRECT_INPUT" ) );
893 if ( !msg.isEmpty() )
895 SUIT_MessageBox::error1(SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ), str, QObject::tr( "BUT_OK" ) );
898 //////////////////////////////////////////////////////////////////
899 // Virtual methods to be redefined in dialogs
900 //////////////////////////////////////////////////////////////////
902 //================================================================
903 // Function : createOperation
904 // Purpose : Redefine this method to return proper IOperation reference
905 //================================================================
906 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::createOperation()
908 GEOM::GEOM_IOperations_var aNilOp;
909 return aNilOp._retn();
912 //================================================================
913 // Function : isValid
914 // Purpose : Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
915 //================================================================
916 bool GEOMBase_Helper::isValid( QString& )
921 //================================================================
922 // Function : execute
923 // Purpose : This method is called by onAccept().
924 // It should perform the required operation and put all new or modified objects into
925 // <objects> argument.Should return <false> if some error occurs during its execution.
926 //================================================================
927 bool GEOMBase_Helper::execute( ObjectList& objects )
932 //================================================================
933 // Function : getFather
934 // Purpose : This method is called by addInStudy(). It should return a father object
935 // for <theObj> or a nil reference if <theObj> should be published
936 // as a top-level object.
937 //================================================================
938 GEOM::GEOM_Object_ptr GEOMBase_Helper::getFather( GEOM::GEOM_Object_ptr theObj )
940 return GEOM::GEOM_Object::_nil();
943 //================================================================
944 // Function : getNewObjectName
945 // Purpose : Redefine this method to return proper name for a new object
946 //================================================================
947 const char* GEOMBase_Helper::getNewObjectName() const
952 //================================================================
953 // Function : getPrefix
954 // Purpose : Get prefix for name of created object
955 //================================================================
956 QString GEOMBase_Helper::getPrefix( GEOM::GEOM_Object_ptr theObj ) const
958 if ( !myPrefix.isEmpty() || theObj->_is_nil() )
961 //TopoDS_Shape aShape;
962 //if ( !GEOMBase::GetShape( theObj, aShape ) )
965 //long aType = aShape.ShapeType();
966 GEOM::shape_type aType = theObj->GetShapeType();
970 case GEOM::VERTEX : return QObject::tr( "GEOM_VERTEX" );
971 case GEOM::EDGE : return QObject::tr( "GEOM_EDGE" );
972 case GEOM::WIRE : return QObject::tr( "GEOM_WIRE" );
973 case GEOM::FACE : return QObject::tr( "GEOM_FACE" );
974 case GEOM::SHELL : return QObject::tr( "GEOM_SHELL" );
975 case GEOM::SOLID : return QObject::tr( "GEOM_SOLID" );
976 case GEOM::COMPSOLID: return QObject::tr( "GEOM_COMPOUNDSOLID" );
977 case GEOM::COMPOUND : return QObject::tr( "GEOM_COMPOUND" );
982 //================================================================
983 // Function : selectedIO
984 // Purpose : Return the list of selected SALOME_InteractiveObject's
985 //================================================================
986 const SALOME_ListIO& GEOMBase_Helper::selectedIO()
990 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
992 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
994 aSelMgr->selectedObjects( mySelected );
1000 //================================================================
1001 // Function : IObjectCount
1002 // Purpose : Return the number of selected objects
1003 //================================================================
1004 int GEOMBase_Helper::IObjectCount()
1006 return selectedIO().Extent();
1009 //================================================================
1010 // Function : firstIObject
1011 // Purpose : Return the first selected object in the selected object list
1012 //================================================================
1013 Handle(SALOME_InteractiveObject) GEOMBase_Helper::firstIObject()
1015 const SALOME_ListIO& aList = selectedIO();
1016 return aList.Extent() > 0 ? aList.First() : Handle(SALOME_InteractiveObject)();
1019 //================================================================
1020 // Function : lastIObject
1021 // Purpose : Return the last selected object in the selected object list
1022 //================================================================
1023 Handle(SALOME_InteractiveObject) GEOMBase_Helper::lastIObject()
1025 const SALOME_ListIO& aList = selectedIO();
1026 return aList.Extent() > 0 ? aList.Last() : Handle(SALOME_InteractiveObject)();
1029 //================================================================
1030 // Function : getDesktop
1031 // Purpose : Returns myDesktop field. Initialized in constructor, usually as dynamic_cast<SUIT_Desktop*>(parentWidget())
1032 //================================================================
1033 SUIT_Desktop* GEOMBase_Helper::getDesktop() const
1038 //================================================================
1039 // Function : selectObjects
1040 // Purpose : Selects list of objects
1041 //================================================================
1042 bool GEOMBase_Helper::selectObjects( ObjectList& objects )
1044 SUIT_DataOwnerPtrList aList;
1045 ObjectList::iterator anIter;
1046 for ( anIter = objects.begin(); anIter != objects.end(); ++anIter )
1048 string entry = getEntry( *anIter );
1049 QString aEntry( entry.c_str() );
1050 LightApp_DataOwner* anOwher = new LightApp_DataOwner( aEntry );
1051 aList.append( anOwher );
1054 SUIT_Session* session = SUIT_Session::session();
1055 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1059 LightApp_SelectionMgr* aMgr = app->selectionMgr();
1063 aMgr->setSelected( aList, false );
1068 //================================================================
1069 // Function : findObjectInFather
1070 // Purpose : It should return an object if its founded in study or
1071 // return Null object if the object is not founded
1072 //================================================================
1073 GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather( GEOM::GEOM_Object_ptr theFather, const char* theName)
1075 SalomeApp_Application* app =
1076 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1077 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1078 _PTR(Study) aDStudy = appStudy->studyDS();
1079 string IOR = GEOMBase::GetIORFromObject( theFather );
1080 _PTR(SObject) SObj ( aDStudy->FindObjectIOR( IOR ) );
1082 bool inStudy = false;
1083 GEOM::GEOM_Object_var aReturnObject;
1084 for (_PTR(ChildIterator) iit (aDStudy->NewChildIterator( SObj )); iit->More() && !inStudy; iit->Next()) {
1085 _PTR(SObject) child (iit->Value());
1086 QString aChildName = child->GetName();
1087 if (aChildName == theName) {
1089 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(iit->Value());
1090 aReturnObject = GEOM::GEOM_Object::_narrow( corbaObj );
1094 return aReturnObject._retn();
1096 return GEOM::GEOM_Object::_nil();
1099 //================================================================
1100 // Function : addSubshapesToStudy
1101 // Purpose : Virtual method to add subshapes if needs
1102 //================================================================
1103 void GEOMBase_Helper::addSubshapesToStudy()
1105 //Impemented in Dialogs, called from Accept method
1108 //================================================================
1109 // Function : addSubshapesToFather
1110 // Purpose : Method to add Father Subshapes to Study if it`s not exist
1111 //================================================================
1112 void GEOMBase_Helper::addSubshapesToFather( QMap<QString, GEOM::GEOM_Object_var>& theMap )
1115 SalomeApp_Application* app =
1116 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1117 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1118 _PTR(Study) aDStudy = appStudy->studyDS();
1120 GEOM::GEOM_IGroupOperations_var anOp = getGeomEngine()->GetIGroupOperations( getStudyId() );
1122 for( QMap<QString, GEOM::GEOM_Object_var>::Iterator it = theMap.begin(); it != theMap.end(); it++ )
1124 if ( !anOp->_is_nil() ) {
1125 GEOM::GEOM_Object_var aFatherObj = anOp->GetMainShape( it.data() );
1126 if ( !aFatherObj->_is_nil() ) {
1127 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aFatherObj, it.key() );
1129 //Add Object to study if its not exist
1130 if ( aFindedObject == GEOM::GEOM_Object::_nil() )
1131 GeometryGUI::GetGeomGen()->AddInStudy(GeometryGUI::ClientStudyToStudy(aDStudy),
1132 it.data(), it.key(), aFatherObj );
1136 //cout << " anOperations is NULL! " << endl;