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 //To disable automatic genericobj management, the following line should be commented.
56 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
57 //#define WITHGENERICOBJ
59 //================================================================
60 // Function : getActiveView
61 // Purpose : Get active view window, returns 0 if no open study frame
62 //================================================================
63 static SUIT_ViewWindow* getActiveView()
65 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
67 return SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
73 //================================================================
74 // Function : getGeomEngine
75 // Purpose : Static method
76 //================================================================
77 GEOM::GEOM_Gen_ptr GEOMBase_Helper::getGeomEngine()
79 return GeometryGUI::GetGeomGen();
82 //================================================================
83 // Function : GEOMBase_Helper
85 //================================================================
86 GEOMBase_Helper::GEOMBase_Helper( SUIT_Desktop* desktop )
87 : myDesktop( desktop ), myViewWindow( 0 ), myDisplayer( 0 ), myCommand( 0 ), isPreview( false )
91 //================================================================
92 // Function : ~GEOMBase_Helper
94 //================================================================
95 GEOMBase_Helper::~GEOMBase_Helper()
97 if ( !SUIT_Session::session()->activeApplication()->desktop() )
100 if ( myPreview.size() )
104 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
106 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
108 globalSelection(aGeomGUI->getLocalSelectionMode() , true );
113 if ( !CORBA::is_nil( myOperation ) )
114 myOperation->Destroy();
117 //================================================================
118 // Function : display
120 //================================================================
121 void GEOMBase_Helper::display( const ObjectList& objList, const bool updateView )
123 ObjectList::const_iterator it;
124 for ( it = objList.begin(); it != objList.end(); it++ ) {
125 display( *it, false );
127 if ( !objList.empty() && updateView )
128 getDisplayer()->UpdateViewer();
131 //================================================================
132 // Function : display
133 // Purpose : Display object.
134 // Important : Object must be already in study
135 //================================================================
136 void GEOMBase_Helper::display( GEOM::GEOM_Object_ptr object, const bool updateView )
138 // Unset color of shape ( this color may be set during preview displaying )
139 // Default color will be used
140 getDisplayer()->UnsetColor();
141 getDisplayer()->UnsetWidth();
143 // Enable activisation of selection
144 getDisplayer()->SetToActivate( true );
147 getDisplayer()->Display( object, updateView );
150 //================================================================
153 //================================================================
154 void GEOMBase_Helper::erase( const ObjectList& objList, const bool updateView )
156 ObjectList::const_iterator it = objList.begin();
157 for ( ; it != objList.end(); it++ ) {
160 if ( !objList.empty() && updateView )
161 getDisplayer()->UpdateViewer();
164 //================================================================
167 //================================================================
168 void GEOMBase_Helper::erase( GEOM::GEOM_Object_ptr object, const bool updateView )
170 if ( !object->_is_nil() ) {
171 std::string entry = getEntry( object );
172 getDisplayer()->Erase( new SALOME_InteractiveObject(
173 entry.c_str(), "GEOM", strdup( GEOMBase::GetName( object ).toLatin1().constData() ) ), true, updateView );
177 //================================================================
178 // Function : redisplay
180 //================================================================
181 void GEOMBase_Helper::redisplay( const ObjectList& objList,
182 const bool withChildren,
183 const bool updateView )
185 ObjectList::const_iterator it = objList.begin();
186 for ( ; it != objList.end(); it++ ) {
187 redisplay( *it, withChildren, false );
189 if ( !objList.empty() && updateView )
190 getDisplayer()->UpdateViewer();
193 //================================================================
194 // Function : redisplay
196 //================================================================
197 void GEOMBase_Helper::redisplay( GEOM::GEOM_Object_ptr object,
198 const bool withChildren,
199 const bool updateView )
201 if ( !object->_is_nil() ) {
202 // Unset color of shape ( this color may be set during preview displaying )
203 // Default color will be used
204 getDisplayer()->UnsetColor();
205 getDisplayer()->UnsetWidth();
207 // Enable activisation of selection
208 getDisplayer()->SetToActivate( true );
210 std::string entry = getEntry( object );
211 getDisplayer()->Redisplay(new SALOME_InteractiveObject
212 (entry.c_str(), "GEOM", strdup(GEOMBase::GetName(object).toLatin1().constData())), false);
215 if ( withChildren ) {
216 SalomeApp_Study* aDoc = getStudy();
217 if ( aDoc && aDoc->studyDS() ) {
218 _PTR(Study) aStudy = aDoc->studyDS();
219 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string(object);
220 _PTR(SObject) aSObj (aStudy->FindObjectIOR(std::string(objStr.in())));
222 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
223 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
224 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow
225 (GeometryGUI::ClientSObjectToObject(anIt->Value()));
226 if ( !CORBA::is_nil( aChild ) ) {
227 if ( !aChild->_is_nil() ) {
228 std::string entry = getEntry( aChild );
229 getDisplayer()->Redisplay( new SALOME_InteractiveObject(
230 entry.c_str(), "GEOM", strdup( GEOMBase::GetName( aChild ).toLatin1().constData() ) ), false );
239 getDisplayer()->UpdateViewer();
242 //================================================================
243 // Function : displayPreview
244 // Purpose : Method for displaying preview based on execute() results
245 //================================================================
246 void GEOMBase_Helper::displayPreview( const bool activate,
248 const bool toRemoveFromEngine,
249 const double lineWidth,
250 const int displayMode,
255 if ( !isValid( msg ) )
257 erasePreview( update );
262 erasePreview( false );
265 SUIT_OverrideCursor wc;
267 if ( !execute( objects ) || !getOperation()->IsDone() ) {
271 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it )
273 GEOM::GEOM_Object_var obj=*it;
274 displayPreview( obj, true, activate, false, lineWidth, displayMode, color );
275 if ( toRemoveFromEngine )
280 catch( const SALOME::SALOME_Exception& e ) {
281 SalomeApp_Tools::QtCatchCorbaException( e );
290 //================================================================
291 // Function : displayPreview
292 // Purpose : Method for displaying preview of resulting shape
293 //================================================================
294 void GEOMBase_Helper::displayPreview( GEOM::GEOM_Object_ptr object,
298 const double lineWidth,
299 const int displayMode,
302 // Set color for preview shape
303 getDisplayer()->SetColor( color == -1 ? Quantity_NOC_VIOLET : color );
305 // set width of displayed shape
306 getDisplayer()->SetWidth( lineWidth );
308 // set display mode of displayed shape
309 int aPrevDispMode = getDisplayer()->SetDisplayMode( displayMode );
311 // Disable activation of selection
312 getDisplayer()->SetToActivate( activate );
314 // Make a reference to GEOM_Object
315 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string( object );
316 getDisplayer()->SetName( objStr.in() );
319 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( object );
320 if ( aPrs == 0 || aPrs->IsNull() )
324 displayPreview( aPrs, append, update );
326 getDisplayer()->UnsetName();
327 getDisplayer()->UnsetColor();
328 getDisplayer()->SetDisplayMode( aPrevDispMode );
330 // Enable activation of displayed objects
331 getDisplayer()->SetToActivate( true );
334 //================================================================
335 // Function : displayPreview
336 // Purpose : Method for displaying arbitrary preview objects (not limited to shapes)
337 //================================================================
338 void GEOMBase_Helper::displayPreview( const SALOME_Prs* prs,
343 erasePreview( false );
345 // remember current view frame to make correct erase preview later
346 myViewWindow = getActiveView();
348 if ( myViewWindow == 0 )
352 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
353 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
354 aViewManager->getType() == SVTK_Viewer::Type() )
356 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
357 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
359 aView->Display( prs );
362 // Add prs to the preview list
363 myPreview.push_back( (SALOME_Prs*)prs );
367 getDisplayer()->UpdateViewer();
370 //================================================================
371 // Function : erasePreview
373 //================================================================
374 void GEOMBase_Helper::erasePreview( const bool update )
376 // check view frame where the preview was displayed
377 bool vfOK = checkViewWindow() && myViewWindow;
378 // Iterate through presentations and delete them
379 for ( PrsList::iterator anIter = myPreview.begin(); anIter != myPreview.end(); ++anIter ) {
382 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
383 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
384 aViewManager->getType() == SVTK_Viewer::Type() )
386 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
387 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
389 aView->Erase( *anIter, true );
401 //================================================================
402 // Function : localSelection
403 // Purpose : Activate selection of objects of a given type
404 // IMPORTANT : Works after localSelection( ... ) method call only
405 //================================================================
406 void GEOMBase_Helper::activate( const int theType )
408 if (!getStudy()) return;
409 _PTR(Study) aStudy = getStudy()->studyDS();
410 _PTR(SComponent) aGeom ( aStudy->FindComponent( "GEOM" ) );
415 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( aGeom ) );
416 for ( ; anIter->More(); anIter->Next() )
418 _PTR(SObject) aSO ( anIter->Value() );
421 _PTR(SObject) aRefSO;
422 if ( !aSO->ReferencedObject( aRefSO ) )
424 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow
425 (GeometryGUI::ClientSObjectToObject(aSO));
426 if ( !anObj->_is_nil() && anObj->GetType() == theType )
427 aList.Append( new SALOME_InteractiveObject( aSO->GetID().c_str(), "GEOM", aSO->GetName().c_str()) );
432 getDisplayer()->LocalSelection( aList, 0 );
435 //================================================================
436 // Function : localSelection
437 // Purpose : Activate selection of subshapes in accordance with mode
438 // theMode is from TopAbs_ShapeEnum
439 //================================================================
440 void GEOMBase_Helper::localSelection( const ObjectList& theObjs, const int theMode )
442 SALOME_ListIO aListOfIO;
444 ObjectList::const_iterator anIter = theObjs.begin();
445 for ( ; anIter != theObjs.end(); ++anIter )
447 GEOM::GEOM_Object_ptr anObj = *anIter;
448 if ( anObj->_is_nil() )
450 std::string aEntry = getEntry( anObj );
452 aListOfIO.Append( new SALOME_InteractiveObject(
453 aEntry.c_str(), "GEOM", strdup( GEOMBase::GetName( anObj ).toLatin1().constData() ) ) );
456 getDisplayer()->LocalSelection( aListOfIO, theMode );
459 //================================================================
460 // Function : localSelection
461 // Purpose : Activate selection of subshapes in accordance with mode
462 // theMode is from TopAbs_ShapeEnum
463 //================================================================
464 void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const int mode )
466 // If object is null local selection for all objects is activated
467 if ( obj->_is_nil() ) {
468 getDisplayer()->LocalSelection( Handle(SALOME_InteractiveObject)(), mode );
473 objList.push_back( obj );
474 localSelection( objList, mode );
478 //================================================================
479 // Function : globalSelection
480 // Purpose : Activate selection of subshapes. Set selection filters
481 // in accordance with mode. theMode is from GEOMImpl_Types
482 //================================================================
483 void GEOMBase_Helper::globalSelection( const int theMode, const bool update )
485 getDisplayer()->GlobalSelection( theMode, update );
488 //================================================================
489 // Function : globalSelection
490 // Purpose : Activate selection of subshapes. Set selection filters
491 // in accordance with mode. theMode is from GEOMImpl_Types
492 //================================================================
493 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
496 getDisplayer()->GlobalSelection( theModes, update );
499 //================================================================
500 // Function : globalSelection
501 // Purpose : Activate selection of subshapes. Set selection filters
502 // in accordance with mode. theMode is from GEOMImpl_Types
503 //================================================================
504 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
505 const QList<int>& subShapes,
508 getDisplayer()->GlobalSelection( theModes, update, &subShapes );
511 //================================================================
512 // Function : addInStudy
513 // Purpose : Add object in study
514 //================================================================
515 void GEOMBase_Helper::addInStudy( GEOM::GEOM_Object_ptr theObj, const char* theName )
520 _PTR(Study) aStudy = getStudy()->studyDS();
521 if ( !aStudy || theObj->_is_nil() )
524 SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy(aStudy);
526 GEOM::GEOM_Object_ptr aFatherObj = getFather( theObj );
528 SALOMEDS::SObject_var aSO =
529 getGeomEngine()->AddInStudy(aStudyDS, theObj, theName, aFatherObj);
531 // Each dialog is responsible for this method implementation,
532 // default implementation does nothing
533 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 QList<SUIT_Application*> anAppList = SUIT_Session::session()->applications();
604 SUIT_Application* anApp = 0;
605 QListIterator<SUIT_Application*> it( anAppList );
606 while ( it.hasNext() )
609 if ( anApp && anApp->desktop() == aDesktop )
613 return dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
616 //================================================================
617 // Function : getEntry
619 //================================================================
620 char* GEOMBase_Helper::getEntry( GEOM::GEOM_Object_ptr object ) const
622 SalomeApp_Study* study = getStudy();
624 char * objIOR = GEOMBase::GetIORFromObject( object );
625 std::string IOR( objIOR );
628 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
630 return (char*) TCollection_AsciiString((char*)SO->GetID().c_str()).ToCString();
637 //================================================================
638 // Function : getDisplayer
640 //================================================================
641 GEOM_Displayer* GEOMBase_Helper::getDisplayer()
644 myDisplayer = new GEOM_Displayer( getStudy() );
648 //================================================================
649 // Function : clearShapeBuffer
651 //================================================================
652 void GEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
654 if ( CORBA::is_nil( theObj ) )
657 CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( theObj );
658 TCollection_AsciiString asciiIOR( (char *)IOR.in() );
659 GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
661 if ( !getStudy() || !getStudy()->studyDS() )
664 _PTR(Study) aStudy = getStudy()->studyDS();
665 _PTR(SObject) aSObj ( aStudy->FindObjectIOR( std::string( IOR ) ) );
669 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
670 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
671 _PTR(GenericAttribute) anAttr;
672 if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
673 _PTR(AttributeIOR) anIOR ( anAttr );
674 TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
675 GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
680 //================================================================
681 // Function : openCommand
683 //================================================================
684 bool GEOMBase_Helper::openCommand()
687 if ( !getStudy() || hasCommand() )
690 GEOM::GEOM_IOperations_var anOp = GEOM::GEOM_IOperations::_narrow( getOperation() );
691 if ( !anOp->_is_nil() ) {
692 myCommand = new GEOM_Operation( SUIT_Session::session()->activeApplication(), anOp.in() );
700 //================================================================
701 // Function : abortCommand
703 //================================================================
704 bool GEOMBase_Helper::abortCommand()
710 delete myCommand; // I don't know where to delete this object here ?
716 //================================================================
717 // Function : commitCommand
719 //================================================================
720 bool GEOMBase_Helper::commitCommand( const char* )
726 delete myCommand; // I don't know where to delete this object here ?
732 //================================================================
733 // Function : hasCommand
735 //================================================================
736 bool GEOMBase_Helper::hasCommand() const
738 return (bool)myCommand;
741 //================================================================
742 // Function : getOperation
744 //================================================================
745 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::getOperation()
747 if ( myOperation->_is_nil() )
748 myOperation = createOperation();
755 //================================================================
756 // Function : checkViewWindow
758 //================================================================
759 bool GEOMBase_Helper::checkViewWindow()
762 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
763 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
764 while ( it.hasNext() )
766 if ( myViewWindow == it.next() )
774 //================================================================
775 // Function : onAccept
776 // Purpose : This method should be called from dialog's slots onOk() and onApply()
777 // It perfroms user input validation, then it
778 // performs a proper operation and manages transactions, etc.
779 //================================================================
780 bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction )
782 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
783 if ( !appStudy ) return false;
784 _PTR(Study) aStudy = appStudy->studyDS();
786 bool aLocked = (_PTR(AttributeStudyProperties) (aStudy->GetProperties()))->IsLocked();
788 MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
789 SUIT_MessageBox::warning ( (QWidget*)SUIT_Session::session()->activeApplication()->desktop(),
790 QObject::tr("WRN_WARNING"),
791 QObject::tr("WRN_STUDY_LOCKED"),
792 QObject::tr("BUT_OK") );
797 if ( !isValid( msg ) ) {
802 erasePreview( false );
805 if ( ( !publish && !useTransaction ) || openCommand() ) {
806 SUIT_OverrideCursor wc;
807 SUIT_Session::session()->activeApplication()->putInfo( "" );
809 if ( !execute( objects ) || !getOperation()->IsDone() ) {
815 addSubshapesToStudy(); // add Subshapes if local selection
816 const int nbObjs = objects.size();
818 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
819 GEOM::GEOM_Object_var obj=*it;
821 QString aName = getNewObjectName();
824 aName = getPrefix(obj);
826 // Try to find a unique name
827 aName = GEOMBase::GetDefaultName(aName);
829 // Don't check name uniqueness in case of numerous objects
830 aName = aName + "_" + QString::number(aNumber++);
833 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
834 if ( aName.isEmpty() )
835 aName = GEOMBase::GetDefaultName( getPrefix( obj ) );
837 addInStudy( obj, aName.toLatin1().constData() );
839 display( obj, false );
840 #ifdef WITHGENERICOBJ
841 // obj has been published in study. Its refcount has been incremented.
842 // It is safe to decrement its refcount
843 // so that it will be destroyed when the entry in study will be removed
848 // asv : fix of PAL6454. If publish==false, then the original shape
849 // was modified, and need to be re-cached in GEOM_Client before redisplay
850 clearShapeBuffer( obj );
851 // withChildren=true, updateView=false
852 redisplay( obj, true, false );
859 SUIT_Session::session()->activeApplication()->putInfo( QObject::tr("GEOM_PRP_DONE") );
866 catch( const SALOME::SALOME_Exception& e ) {
867 SalomeApp_Tools::QtCatchCorbaException( e );
877 //================================================================
878 // Function : showError
879 // Purpose : Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
880 //================================================================
881 void GEOMBase_Helper::showError()
884 if ( !getOperation()->_is_nil() )
885 msg = QObject::tr( getOperation()->GetErrorCode() );
888 msg = QObject::tr( "GEOM_PRP_ABORT" );
890 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
891 QObject::tr( "GEOM_ERROR_STATUS" ),
893 QObject::tr( "BUT_OK" ) );
896 //================================================================
897 // Function : showError
898 // Purpose : Shows a error message followed by <msg>
899 //================================================================
900 void GEOMBase_Helper::showError( const QString& msg )
902 QString str( QObject::tr( "GEOM_INCORRECT_INPUT" ) );
903 if ( !msg.isEmpty() )
905 SUIT_MessageBox::critical(SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ), str, QObject::tr( "BUT_OK" ) );
908 //////////////////////////////////////////////////////////////////
909 // Virtual methods to be redefined in dialogs
910 //////////////////////////////////////////////////////////////////
912 //================================================================
913 // Function : createOperation
914 // Purpose : Redefine this method to return proper IOperation reference
915 //================================================================
916 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::createOperation()
918 GEOM::GEOM_IOperations_var aNilOp;
919 return aNilOp._retn();
922 //================================================================
923 // Function : isValid
924 // Purpose : Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
925 //================================================================
926 bool GEOMBase_Helper::isValid( QString& )
931 //================================================================
932 // Function : execute
933 // Purpose : This method is called by onAccept().
934 // It should perform the required operation and put all new or modified objects into
935 // <objects> argument.Should return <false> if some error occurs during its execution.
936 //================================================================
937 bool GEOMBase_Helper::execute( ObjectList& objects )
942 //================================================================
943 // Function : getFather
944 // Purpose : This method is called by addInStudy(). It should return a father object
945 // for <theObj> or a nil reference if <theObj> should be published
946 // as a top-level object.
947 //================================================================
948 GEOM::GEOM_Object_ptr GEOMBase_Helper::getFather( GEOM::GEOM_Object_ptr theObj )
950 return GEOM::GEOM_Object::_nil();
953 //================================================================
954 // Function : getNewObjectName
955 // Purpose : Redefine this method to return proper name for a new object
956 //================================================================
957 QString GEOMBase_Helper::getNewObjectName() const
959 return QString::null;
962 //================================================================
963 // Function : getPrefix
964 // Purpose : Get prefix for name of created object
965 //================================================================
966 QString GEOMBase_Helper::getPrefix( GEOM::GEOM_Object_ptr theObj ) const
968 if ( !myPrefix.isEmpty() || theObj->_is_nil() )
971 //TopoDS_Shape aShape;
972 //if ( !GEOMBase::GetShape( theObj, aShape ) )
975 //long aType = aShape.ShapeType();
976 GEOM::shape_type aType = theObj->GetShapeType();
980 case GEOM::VERTEX : return QObject::tr( "GEOM_VERTEX" );
981 case GEOM::EDGE : return QObject::tr( "GEOM_EDGE" );
982 case GEOM::WIRE : return QObject::tr( "GEOM_WIRE" );
983 case GEOM::FACE : return QObject::tr( "GEOM_FACE" );
984 case GEOM::SHELL : return QObject::tr( "GEOM_SHELL" );
985 case GEOM::SOLID : return QObject::tr( "GEOM_SOLID" );
986 case GEOM::COMPSOLID: return QObject::tr( "GEOM_COMPOUNDSOLID" );
987 case GEOM::COMPOUND : return QObject::tr( "GEOM_COMPOUND" );
992 //================================================================
993 // Function : getDesktop
994 // Purpose : Returns myDesktop field. Initialized in constructor,
995 // usually as dynamic_cast<SUIT_Desktop*>(parentWidget())
996 //================================================================
997 SUIT_Desktop* GEOMBase_Helper::getDesktop() const
1002 //================================================================
1003 // Function : selectObjects
1004 // Purpose : Selects list of objects
1005 //================================================================
1006 bool GEOMBase_Helper::selectObjects( ObjectList& objects )
1008 SUIT_DataOwnerPtrList aList;
1009 ObjectList::iterator anIter;
1010 for ( anIter = objects.begin(); anIter != objects.end(); ++anIter )
1012 std::string entry = getEntry( *anIter );
1013 QString aEntry( entry.c_str() );
1014 LightApp_DataOwner* anOwher = new LightApp_DataOwner( aEntry );
1015 aList.append( anOwher );
1018 SUIT_Session* session = SUIT_Session::session();
1019 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1023 LightApp_SelectionMgr* aMgr = app->selectionMgr();
1027 aMgr->setSelected( aList, false );
1032 //================================================================
1033 // Function : findObjectInFather
1034 // Purpose : It should return an object if its founded in study or
1035 // return Null object if the object is not founded
1036 //================================================================
1037 GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather (GEOM::GEOM_Object_ptr theFather,
1038 const QString& theName)
1040 SalomeApp_Application* app =
1041 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1042 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1043 _PTR(Study) aDStudy = appStudy->studyDS();
1044 std::string IOR = GEOMBase::GetIORFromObject( theFather );
1045 _PTR(SObject) SObj ( aDStudy->FindObjectIOR( IOR ) );
1047 bool inStudy = false;
1048 GEOM::GEOM_Object_var aReturnObject;
1049 for (_PTR(ChildIterator) iit (aDStudy->NewChildIterator( SObj )); iit->More() && !inStudy; iit->Next()) {
1050 _PTR(SObject) child (iit->Value());
1051 QString aChildName = child->GetName().c_str();
1052 if (aChildName == theName) {
1054 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(iit->Value());
1055 aReturnObject = GEOM::GEOM_Object::_narrow( corbaObj );
1059 return aReturnObject._retn();
1061 return GEOM::GEOM_Object::_nil();
1064 //================================================================
1065 // Function : addSubshapesToStudy
1066 // Purpose : Virtual method to add subshapes if needs
1067 //================================================================
1068 void GEOMBase_Helper::addSubshapesToStudy()
1070 //Impemented in Dialogs, called from Accept method
1073 //================================================================
1074 // Function : addSubshapesToFather
1075 // Purpose : Method to add Father Subshapes to Study if it`s not exist
1076 //================================================================
1077 void GEOMBase_Helper::addSubshapesToFather( QMap<QString, GEOM::GEOM_Object_var>& theMap )
1080 SalomeApp_Application* app =
1081 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1082 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1083 _PTR(Study) aDStudy = appStudy->studyDS();
1085 GEOM::GEOM_IGroupOperations_var anOp = getGeomEngine()->GetIGroupOperations( getStudyId() );
1087 for( QMap<QString, GEOM::GEOM_Object_var>::Iterator it = theMap.begin(); it != theMap.end(); it++ )
1089 if ( !anOp->_is_nil() ) {
1090 GEOM::GEOM_Object_var aFatherObj = anOp->GetMainShape( it.value() );
1091 if ( !aFatherObj->_is_nil() ) {
1092 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aFatherObj, it.key().toLatin1().data() );
1094 //Add Object to study if its not exist
1095 if ( aFindedObject == GEOM::GEOM_Object::_nil() )
1096 GeometryGUI::GetGeomGen()->AddInStudy(GeometryGUI::ClientStudyToStudy(aDStudy),
1097 it.value(), it.key().toLatin1().data(), aFatherObj );
1101 //cout << " anOperations is NULL! " << endl;