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 );
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 std::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 std::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(std::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 std::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 std::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 : globalSelection
494 // Purpose : Activate selection of subshapes. Set selection filters
495 // in accordance with mode. theMode is from GEOMImpl_Types
496 //================================================================
497 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
498 const QList<int>& subShapes,
501 getDisplayer()->GlobalSelection( theModes, update, &subShapes );
504 //================================================================
505 // Function : addInStudy
506 // Purpose : Add object in study
507 //================================================================
508 void GEOMBase_Helper::addInStudy( GEOM::GEOM_Object_ptr theObj, const char* theName )
513 _PTR(Study) aStudy = getStudy()->studyDS();
514 if ( !aStudy || theObj->_is_nil() )
517 SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy(aStudy);
519 GEOM::GEOM_Object_ptr aFatherObj = getFather( theObj );
521 SALOMEDS::SObject_var aSO =
522 getGeomEngine()->AddInStudy(aStudyDS, theObj, theName, aFatherObj);
524 // Each dialog is responsible for this method implementation,
525 // default implementation does nothing
526 restoreSubShapes(aStudyDS, aSO);
529 //================================================================
530 // Function : restoreSubShapes
531 // Purpose : restore tree of argument's sub-shapes under the resulting shape
532 //================================================================
533 void GEOMBase_Helper::restoreSubShapes (SALOMEDS::Study_ptr /*theStudy*/,
534 SALOMEDS::SObject_ptr /*theSObject*/)
536 // do nothing by default
538 // example of implementation in particular dialog:
539 // GEOM::ListOfGO anArgs;
540 // anArgs.length(0); // empty list means that all arguments should be restored
541 // getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
542 // /*theFindMethod=*/GEOM::FSM_GetInPlace,
543 // /*theInheritFirstArg=*/false);
546 //================================================================
547 // Function : updateObjBrowser
548 // Purpose : Update object browser
549 //================================================================
550 void GEOMBase_Helper::updateObjBrowser() const
552 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
554 CAM_Module* module = app->module( "Geometry" );
555 SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
557 appMod->updateObjBrowser( true );
562 //================================================================
563 // Function : updateViewer
564 // Purpose : Update active 3D view
565 //================================================================
566 void GEOMBase_Helper::updateViewer()
568 getDisplayer()->UpdateViewer();
571 //================================================================
572 // Function : getStudyId
573 // Purpose : Get study Id
574 //================================================================
575 int GEOMBase_Helper::getStudyId() const
579 anId = getStudy()->id();
583 //================================================================
584 // Function : getStudy
585 // Purpose : Returns the active study. It is recommended to use
586 // this method instead of direct desktop->getActiveStudy() calls
587 //================================================================
588 SalomeApp_Study* GEOMBase_Helper::getStudy() const
590 SUIT_Desktop* aDesktop = getDesktop();
594 QList<SUIT_Application*> anAppList = SUIT_Session::session()->applications();
596 SUIT_Application* anApp = 0;
597 QListIterator<SUIT_Application*> it( anAppList );
598 while ( it.hasNext() )
601 if ( anApp && anApp->desktop() == aDesktop )
605 return dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
608 //================================================================
609 // Function : getEntry
611 //================================================================
612 char* GEOMBase_Helper::getEntry( GEOM::GEOM_Object_ptr object ) const
614 SalomeApp_Study* study = getStudy();
616 char * objIOR = GEOMBase::GetIORFromObject( object );
617 std::string IOR( objIOR );
620 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
622 return (char*) TCollection_AsciiString((char*)SO->GetID().c_str()).ToCString();
629 //================================================================
630 // Function : getDisplayer
632 //================================================================
633 GEOM_Displayer* GEOMBase_Helper::getDisplayer()
636 myDisplayer = new GEOM_Displayer( getStudy() );
640 //================================================================
641 // Function : clearShapeBuffer
643 //================================================================
644 void GEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
646 if ( CORBA::is_nil( theObj ) )
649 CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( theObj );
650 TCollection_AsciiString asciiIOR( (char *)IOR.in() );
651 GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
653 if ( !getStudy() || !getStudy()->studyDS() )
656 _PTR(Study) aStudy = getStudy()->studyDS();
657 _PTR(SObject) aSObj ( aStudy->FindObjectIOR( std::string( IOR ) ) );
661 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
662 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
663 _PTR(GenericAttribute) anAttr;
664 if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
665 _PTR(AttributeIOR) anIOR ( anAttr );
666 TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
667 GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
672 //================================================================
673 // Function : openCommand
675 //================================================================
676 bool GEOMBase_Helper::openCommand()
679 if ( !getStudy() || hasCommand() )
682 GEOM::GEOM_IOperations_var anOp = GEOM::GEOM_IOperations::_narrow( getOperation() );
683 if ( !anOp->_is_nil() ) {
684 myCommand = new GEOM_Operation( SUIT_Session::session()->activeApplication(), anOp.in() );
692 //================================================================
693 // Function : abortCommand
695 //================================================================
696 bool GEOMBase_Helper::abortCommand()
707 //================================================================
708 // Function : commitCommand
710 //================================================================
711 bool GEOMBase_Helper::commitCommand( const char* )
722 //================================================================
723 // Function : hasCommand
725 //================================================================
726 bool GEOMBase_Helper::hasCommand() const
728 return (bool)myCommand;
731 //================================================================
732 // Function : getOperation
734 //================================================================
735 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::getOperation()
737 if ( myOperation->_is_nil() )
738 myOperation = createOperation();
745 //================================================================
746 // Function : checkViewWindow
748 //================================================================
749 bool GEOMBase_Helper::checkViewWindow()
752 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
753 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
754 while ( it.hasNext() )
756 if ( myViewWindow == it.next() )
764 //================================================================
765 // Function : onAccept
766 // Purpose : This method should be called from dialog's slots onOk() and onApply()
767 // It perfroms user input validation, then it
768 // performs a proper operation and manages transactions, etc.
769 //================================================================
770 bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction )
772 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
773 if ( !appStudy ) return false;
774 _PTR(Study) aStudy = appStudy->studyDS();
776 bool aLocked = (_PTR(AttributeStudyProperties) (aStudy->GetProperties()))->IsLocked();
778 MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
779 SUIT_MessageBox::warning ( (QWidget*)SUIT_Session::session()->activeApplication()->desktop(),
780 QObject::tr("WRN_WARNING"),
781 QObject::tr("WRN_STUDY_LOCKED"),
782 QObject::tr("BUT_OK") );
787 if ( !isValid( msg ) ) {
792 erasePreview( false );
795 if ( ( !publish && !useTransaction ) || openCommand() ) {
796 SUIT_OverrideCursor wc;
797 SUIT_Session::session()->activeApplication()->putInfo( "" );
799 if ( !execute( objects ) || !getOperation()->IsDone() ) {
805 addSubshapesToStudy(); // add Subshapes if local selection
806 const int nbObjs = objects.size();
808 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
810 QString aName = getNewObjectName();
813 aName = getPrefix(*it);
815 // Try to find a unique name
816 aName = GEOMBase::GetDefaultName(aName);
818 // Don't check name uniqueness in case of numerous objects
819 aName = aName + "_" + QString::number(aNumber++);
822 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
823 if ( aName.isEmpty() )
824 aName = GEOMBase::GetDefaultName( getPrefix( *it ) );
826 addInStudy( *it, aName.toLatin1().constData() );
828 display( *it, false );
831 // asv : fix of PAL6454. If publish==false, then the original shape
832 // was modified, and need to be re-cached in GEOM_Client before redisplay
833 clearShapeBuffer( *it );
834 // withChildren=true, updateView=false
835 redisplay( *it, true, false );
842 SUIT_Session::session()->activeApplication()->putInfo( QObject::tr("GEOM_PRP_DONE") );
849 catch( const SALOME::SALOME_Exception& e ) {
850 SalomeApp_Tools::QtCatchCorbaException( e );
860 //================================================================
861 // Function : showError
862 // Purpose : Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
863 //================================================================
864 void GEOMBase_Helper::showError()
867 if ( !getOperation()->_is_nil() )
868 msg = QObject::tr( getOperation()->GetErrorCode() );
871 msg = QObject::tr( "GEOM_PRP_ABORT" );
873 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
874 QObject::tr( "GEOM_ERROR_STATUS" ),
876 QObject::tr( "BUT_OK" ) );
879 //================================================================
880 // Function : showError
881 // Purpose : Shows a error message followed by <msg>
882 //================================================================
883 void GEOMBase_Helper::showError( const QString& msg )
885 QString str( QObject::tr( "GEOM_INCORRECT_INPUT" ) );
886 if ( !msg.isEmpty() )
888 SUIT_MessageBox::critical(SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ), str, QObject::tr( "BUT_OK" ) );
891 //////////////////////////////////////////////////////////////////
892 // Virtual methods to be redefined in dialogs
893 //////////////////////////////////////////////////////////////////
895 //================================================================
896 // Function : createOperation
897 // Purpose : Redefine this method to return proper IOperation reference
898 //================================================================
899 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::createOperation()
901 GEOM::GEOM_IOperations_var aNilOp;
902 return aNilOp._retn();
905 //================================================================
906 // Function : isValid
907 // Purpose : Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
908 //================================================================
909 bool GEOMBase_Helper::isValid( QString& )
914 //================================================================
915 // Function : execute
916 // Purpose : This method is called by onAccept().
917 // It should perform the required operation and put all new or modified objects into
918 // <objects> argument.Should return <false> if some error occurs during its execution.
919 //================================================================
920 bool GEOMBase_Helper::execute( ObjectList& objects )
925 //================================================================
926 // Function : getFather
927 // Purpose : This method is called by addInStudy(). It should return a father object
928 // for <theObj> or a nil reference if <theObj> should be published
929 // as a top-level object.
930 //================================================================
931 GEOM::GEOM_Object_ptr GEOMBase_Helper::getFather( GEOM::GEOM_Object_ptr theObj )
933 return GEOM::GEOM_Object::_nil();
936 //================================================================
937 // Function : getNewObjectName
938 // Purpose : Redefine this method to return proper name for a new object
939 //================================================================
940 QString GEOMBase_Helper::getNewObjectName() const
942 return QString::null;
945 //================================================================
946 // Function : getPrefix
947 // Purpose : Get prefix for name of created object
948 //================================================================
949 QString GEOMBase_Helper::getPrefix( GEOM::GEOM_Object_ptr theObj ) const
951 if ( !myPrefix.isEmpty() || theObj->_is_nil() )
954 //TopoDS_Shape aShape;
955 //if ( !GEOMBase::GetShape( theObj, aShape ) )
958 //long aType = aShape.ShapeType();
959 GEOM::shape_type aType = theObj->GetShapeType();
963 case GEOM::VERTEX : return QObject::tr( "GEOM_VERTEX" );
964 case GEOM::EDGE : return QObject::tr( "GEOM_EDGE" );
965 case GEOM::WIRE : return QObject::tr( "GEOM_WIRE" );
966 case GEOM::FACE : return QObject::tr( "GEOM_FACE" );
967 case GEOM::SHELL : return QObject::tr( "GEOM_SHELL" );
968 case GEOM::SOLID : return QObject::tr( "GEOM_SOLID" );
969 case GEOM::COMPSOLID: return QObject::tr( "GEOM_COMPOUNDSOLID" );
970 case GEOM::COMPOUND : return QObject::tr( "GEOM_COMPOUND" );
975 //================================================================
976 // Function : getDesktop
977 // Purpose : Returns myDesktop field. Initialized in constructor,
978 // usually as dynamic_cast<SUIT_Desktop*>(parentWidget())
979 //================================================================
980 SUIT_Desktop* GEOMBase_Helper::getDesktop() const
985 //================================================================
986 // Function : selectObjects
987 // Purpose : Selects list of objects
988 //================================================================
989 bool GEOMBase_Helper::selectObjects( ObjectList& objects )
991 SUIT_DataOwnerPtrList aList;
992 ObjectList::iterator anIter;
993 for ( anIter = objects.begin(); anIter != objects.end(); ++anIter )
995 std::string entry = getEntry( *anIter );
996 QString aEntry( entry.c_str() );
997 LightApp_DataOwner* anOwher = new LightApp_DataOwner( aEntry );
998 aList.append( anOwher );
1001 SUIT_Session* session = SUIT_Session::session();
1002 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1006 LightApp_SelectionMgr* aMgr = app->selectionMgr();
1010 aMgr->setSelected( aList, false );
1015 //================================================================
1016 // Function : findObjectInFather
1017 // Purpose : It should return an object if its founded in study or
1018 // return Null object if the object is not founded
1019 //================================================================
1020 GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather (GEOM::GEOM_Object_ptr theFather,
1021 const QString& theName)
1023 SalomeApp_Application* app =
1024 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1025 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1026 _PTR(Study) aDStudy = appStudy->studyDS();
1027 std::string IOR = GEOMBase::GetIORFromObject( theFather );
1028 _PTR(SObject) SObj ( aDStudy->FindObjectIOR( IOR ) );
1030 bool inStudy = false;
1031 GEOM::GEOM_Object_var aReturnObject;
1032 for (_PTR(ChildIterator) iit (aDStudy->NewChildIterator( SObj )); iit->More() && !inStudy; iit->Next()) {
1033 _PTR(SObject) child (iit->Value());
1034 QString aChildName = child->GetName().c_str();
1035 if (aChildName == theName) {
1037 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(iit->Value());
1038 aReturnObject = GEOM::GEOM_Object::_narrow( corbaObj );
1042 return aReturnObject._retn();
1044 return GEOM::GEOM_Object::_nil();
1047 //================================================================
1048 // Function : addSubshapesToStudy
1049 // Purpose : Virtual method to add subshapes if needs
1050 //================================================================
1051 void GEOMBase_Helper::addSubshapesToStudy()
1053 //Impemented in Dialogs, called from Accept method
1056 //================================================================
1057 // Function : addSubshapesToFather
1058 // Purpose : Method to add Father Subshapes to Study if it`s not exist
1059 //================================================================
1060 void GEOMBase_Helper::addSubshapesToFather( QMap<QString, GEOM::GEOM_Object_var>& theMap )
1063 SalomeApp_Application* app =
1064 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1065 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1066 _PTR(Study) aDStudy = appStudy->studyDS();
1068 GEOM::GEOM_IGroupOperations_var anOp = getGeomEngine()->GetIGroupOperations( getStudyId() );
1070 for( QMap<QString, GEOM::GEOM_Object_var>::Iterator it = theMap.begin(); it != theMap.end(); it++ )
1072 if ( !anOp->_is_nil() ) {
1073 GEOM::GEOM_Object_var aFatherObj = anOp->GetMainShape( it.value() );
1074 if ( !aFatherObj->_is_nil() ) {
1075 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aFatherObj, it.key().toLatin1().data() );
1077 //Add Object to study if its not exist
1078 if ( aFindedObject == GEOM::GEOM_Object::_nil() )
1079 GeometryGUI::GetGeomGen()->AddInStudy(GeometryGUI::ClientStudyToStudy(aDStudy),
1080 it.value(), it.key().toLatin1().data(), aFatherObj );
1084 //cout << " anOperations is NULL! " << endl;