1 // Copyright (C) 2007-2012 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>
39 #include <SUIT_ResourceMgr.h>
41 #include <SalomeApp_Module.h>
42 #include <SalomeApp_Application.h>
43 #include <SalomeApp_Study.h>
44 #include <LightApp_SelectionMgr.h>
45 #include <LightApp_DataOwner.h>
46 #include <SalomeApp_Tools.h>
47 #include <SALOME_ListIteratorOfListIO.hxx>
49 #include <SALOME_Prs.h>
51 #include <OCCViewer_ViewModel.h>
52 #include <SVTK_ViewModel.h>
54 #include <TColStd_MapOfInteger.hxx>
55 #include <TCollection_AsciiString.hxx>
56 #include <TColStd_IndexedMapOfInteger.hxx>
58 //To disable automatic genericobj management, the following line should be commented.
59 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
60 #define WITHGENERICOBJ
62 //================================================================
63 // Function : getActiveView
64 // Purpose : Get active view window, returns 0 if no open study frame
65 //================================================================
66 static SUIT_ViewWindow* getActiveView()
68 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
70 return SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
76 //================================================================
77 // Function : getGeomEngine
78 // Purpose : Static method
79 //================================================================
80 GEOM::GEOM_Gen_ptr GEOMBase_Helper::getGeomEngine()
82 return GeometryGUI::GetGeomGen();
85 //================================================================
86 // Function : GEOMBase_Helper
88 //================================================================
89 GEOMBase_Helper::GEOMBase_Helper( SUIT_Desktop* desktop )
90 : myDesktop( desktop ), myViewWindow( 0 ), myDisplayer( 0 ), myCommand( 0 ), isPreview( false ),
91 myIsApplyAndClose( false ), myIsOptimizedBrowsing( false ), myIsWaitCursorEnabled( true ),
92 myIsDisableBrowsing(false), myIsDisplayResult(true)
96 //================================================================
97 // Function : ~GEOMBase_Helper
99 //================================================================
100 GEOMBase_Helper::~GEOMBase_Helper()
102 //rnv: Fix for the "IPAL21922 : WinTC5.1.4: incorrect quit salome"
103 if ( !SUIT_Session::session()->activeApplication() || !SUIT_Session::session()->activeApplication()->desktop() )
106 if ( myPreview.size() )
110 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
112 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
114 globalSelection(aGeomGUI->getLocalSelectionMode() , true );
119 if ( !CORBA::is_nil( myOperation ) )
120 myOperation->UnRegister();
123 //================================================================
124 // Function : display
126 //================================================================
127 void GEOMBase_Helper::display( const ObjectList& objList, const bool updateView )
129 ObjectList::const_iterator it;
130 for ( it = objList.begin(); it != objList.end(); it++ ) {
131 display( *it, false );
133 if ( !objList.empty() && updateView )
134 getDisplayer()->UpdateViewer();
137 //================================================================
138 // Function : display
139 // Purpose : Display object.
140 // Important : Object must be already in study
141 //================================================================
142 void GEOMBase_Helper::display( GEOM::GEOM_Object_ptr object, const bool updateView )
144 // Unset color of shape ( this color may be set during preview displaying )
145 // Default color will be used
146 // getDisplayer()->UnsetColor();
147 getDisplayer()->UnsetWidth();
149 MESSAGE("GEOMBase_Helper::display myTexture = "<<getDisplayer()->GetTexture())
151 // Enable activisation of selection
152 getDisplayer()->SetToActivate( true );
155 getDisplayer()->Display( object, updateView );
158 //================================================================
161 //================================================================
162 void GEOMBase_Helper::erase( const ObjectList& objList, const bool updateView )
164 ObjectList::const_iterator it = objList.begin();
165 for ( ; it != objList.end(); it++ ) {
168 if ( !objList.empty() && updateView )
169 getDisplayer()->UpdateViewer();
172 //================================================================
175 //================================================================
176 void GEOMBase_Helper::erase( GEOM::GEOM_Object_ptr object, const bool updateView )
178 if ( !object->_is_nil() ) {
179 QString entry = getEntry( object );
180 getDisplayer()->Erase( new SALOME_InteractiveObject(
181 entry.toLatin1().constData(),
182 "GEOM", strdup( GEOMBase::GetName( object ).toLatin1().constData() ) ), true, updateView );
186 //================================================================
187 // Function : redisplay
189 //================================================================
190 void GEOMBase_Helper::redisplay( const ObjectList& objList,
191 const bool withChildren,
192 const bool updateView )
194 ObjectList::const_iterator it = objList.begin();
195 for ( ; it != objList.end(); it++ ) {
196 redisplay( *it, withChildren, false );
198 if ( !objList.empty() && updateView )
199 getDisplayer()->UpdateViewer();
202 //================================================================
203 // Function : redisplay
205 //================================================================
206 void GEOMBase_Helper::redisplay( GEOM::GEOM_Object_ptr object,
207 const bool withChildren,
208 const bool updateView )
210 if ( !object->_is_nil() ) {
211 // Unset color of shape ( this color may be set during preview displaying )
212 // Default color will be used
213 getDisplayer()->UnsetColor();
214 getDisplayer()->UnsetWidth();
216 // Enable activisation of selection
217 getDisplayer()->SetToActivate( true );
219 QString entry = getEntry( object );
220 getDisplayer()->Redisplay(new SALOME_InteractiveObject
221 (entry.toLatin1().constData(), "GEOM", strdup(GEOMBase::GetName(object).toLatin1().constData())), false);
224 if ( withChildren ) {
225 SalomeApp_Study* aDoc = getStudy();
226 if ( aDoc && aDoc->studyDS() ) {
227 _PTR(Study) aStudy = aDoc->studyDS();
228 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string(object);
229 _PTR(SObject) aSObj (aStudy->FindObjectIOR(std::string(objStr.in())));
231 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
232 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
233 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow
234 (GeometryGUI::ClientSObjectToObject(anIt->Value()));
235 if ( !CORBA::is_nil( aChild ) ) {
236 if ( !aChild->_is_nil() ) {
237 QString entry = getEntry( aChild );
238 getDisplayer()->Redisplay( new SALOME_InteractiveObject(
239 entry.toLatin1().constData(), "GEOM", strdup( GEOMBase::GetName( aChild ).toLatin1().constData() ) ), false );
248 getDisplayer()->UpdateViewer();
251 //================================================================
252 // Function : displayPreview
253 // Purpose : Method for displaying preview based on execute() results
254 //================================================================
255 void GEOMBase_Helper::displayPreview( const bool display,
258 const bool toRemoveFromEngine,
259 const double lineWidth,
260 const int displayMode,
264 erasePreview( update );
270 if ( !isValid( msg ) )
272 erasePreview( update );
277 erasePreview( false );
280 SUIT_OverrideCursor wc;
283 if ( !isWaitCursorEnabled() )
286 if ( !execute( objects ) || !getOperation()->IsDone() ) {
290 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it )
292 GEOM::GEOM_Object_var obj=*it;
293 displayPreview( obj, true, activate, false, lineWidth, displayMode, color );
294 if ( toRemoveFromEngine )
299 catch( const SALOME::SALOME_Exception& e ) {
300 SalomeApp_Tools::QtCatchCorbaException( e );
309 //================================================================
310 // Function : displayPreview
311 // Purpose : Method for displaying preview of resulting shape
312 //================================================================
313 void GEOMBase_Helper::displayPreview( GEOM::GEOM_Object_ptr object,
317 const double lineWidth,
318 const int displayMode,
321 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
323 // Set color for preview shape
324 getDisplayer()->SetColor( color == -1 ? Quantity_NOC_VIOLET : color );
326 // set width of displayed shape
327 getDisplayer()->SetWidth( lineWidth == -1 ? resMgr->integerValue("Geometry", "preview_edge_width", -1) : lineWidth );
329 // set display mode of displayed shape
330 int aPrevDispMode = getDisplayer()->SetDisplayMode( displayMode == -1 ? resMgr->integerValue( "Geometry", "display_mode", 0 ) : displayMode );
332 // Disable activation of selection
333 getDisplayer()->SetToActivate( activate );
335 // Make a reference to GEOM_Object
336 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string( object );
337 getDisplayer()->SetName( objStr.in() );
340 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( object );
341 if ( aPrs == 0 || aPrs->IsNull() )
345 displayPreview( aPrs, append, update );
347 getDisplayer()->UnsetName();
348 getDisplayer()->UnsetColor();
349 getDisplayer()->SetDisplayMode( aPrevDispMode );
351 // Enable activation of displayed objects
352 getDisplayer()->SetToActivate( true );
355 //================================================================
356 // Function : displayPreview
357 // Purpose : Method for displaying arbitrary preview objects (not limited to shapes)
358 //================================================================
359 void GEOMBase_Helper::displayPreview( const SALOME_Prs* prs,
364 erasePreview( false );
366 // remember current view frame to make correct erase preview later
367 myViewWindow = getActiveView();
369 if ( myViewWindow == 0 )
373 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
374 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
375 aViewManager->getType() == SVTK_Viewer::Type() )
377 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
378 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
380 aView->Display( prs );
383 // Add prs to the preview list
384 myPreview.push_back( (SALOME_Prs*)prs );
388 getDisplayer()->UpdateViewer();
391 //================================================================
392 // Function : erasePreview
394 //================================================================
395 void GEOMBase_Helper::erasePreview( const bool update )
397 // check view frame where the preview was displayed
398 bool vfOK = checkViewWindow() && myViewWindow;
399 // Iterate through presentations and delete them
400 for ( PrsList::iterator anIter = myPreview.begin(); anIter != myPreview.end(); ++anIter ) {
403 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
404 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
405 aViewManager->getType() == SVTK_Viewer::Type() )
407 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
408 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
410 aView->Erase( *anIter, true );
422 //================================================================
423 // Function : localSelection
424 // Purpose : Activate selection of objects of a given type
425 // IMPORTANT : Works after localSelection( ... ) method call only
426 //================================================================
427 void GEOMBase_Helper::activate( const int theType )
429 if (!getStudy()) return;
430 _PTR(Study) aStudy = getStudy()->studyDS();
431 _PTR(SComponent) aGeom ( aStudy->FindComponent( "GEOM" ) );
436 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( aGeom ) );
437 for ( ; anIter->More(); anIter->Next() )
439 _PTR(SObject) aSO ( anIter->Value() );
442 _PTR(SObject) aRefSO;
443 if ( !aSO->ReferencedObject( aRefSO ) )
445 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow
446 (GeometryGUI::ClientSObjectToObject(aSO));
447 if ( !anObj->_is_nil() && anObj->GetType() == theType )
448 aList.Append( new SALOME_InteractiveObject( aSO->GetID().c_str(), "GEOM", aSO->GetName().c_str()) );
453 getDisplayer()->LocalSelection( aList, 0 );
456 //================================================================
457 // Function : localSelection
458 // Purpose : Activate selection of sub-shapes in accordance with mode
459 // theMode is from TopAbs_ShapeEnum
460 //================================================================
461 void GEOMBase_Helper::localSelection( const ObjectList& theObjs, const int theMode )
463 SALOME_ListIO aListOfIO;
465 ObjectList::const_iterator anIter = theObjs.begin();
466 for ( ; anIter != theObjs.end(); ++anIter )
468 GEOM::GEOM_Object_ptr anObj = *anIter;
469 if ( anObj->_is_nil() )
471 QString anEntry = getEntry( anObj );
473 aListOfIO.Append( new SALOME_InteractiveObject(
474 anEntry.toLatin1().constData(), "GEOM", strdup( GEOMBase::GetName( anObj ).toLatin1().constData() ) ) );
477 getDisplayer()->LocalSelection( aListOfIO, theMode );
480 //================================================================
481 // Function : localSelection
482 // Purpose : Activate selection of sub-shapes in accordance with mode
483 // theMode is from TopAbs_ShapeEnum
484 //================================================================
485 void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const int mode )
487 // If object is null local selection for all objects is activated
488 if ( obj->_is_nil() ) {
489 getDisplayer()->LocalSelection( Handle(SALOME_InteractiveObject)(), mode );
494 objList.push_back( obj );
495 localSelection( objList, mode );
499 //================================================================
500 // Function : globalSelection
501 // Purpose : Activate selection of sub-shapes. Set selection filters
502 // in accordance with mode. theMode is from GEOMImpl_Types
503 //================================================================
504 void GEOMBase_Helper::globalSelection( const int theMode, const bool update )
506 getDisplayer()->GlobalSelection( theMode, update );
509 //================================================================
510 // Function : globalSelection
511 // Purpose : Activate selection of sub-shapes. Set selection filters
512 // in accordance with mode. theMode is from GEOMImpl_Types
513 //================================================================
514 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
517 getDisplayer()->GlobalSelection( theModes, update );
520 //================================================================
521 // Function : globalSelection
522 // Purpose : Activate selection of sub-shapes. Set selection filters
523 // in accordance with mode. theMode is from GEOMImpl_Types
524 //================================================================
525 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
526 const QList<int>& subShapes,
529 getDisplayer()->GlobalSelection( theModes, update, &subShapes );
532 //================================================================
533 // Function : addInStudy
534 // Purpose : Add object in study
535 //================================================================
536 QString GEOMBase_Helper::addInStudy( GEOM::GEOM_Object_ptr theObj, const char* theName )
541 _PTR(Study) aStudy = getStudy()->studyDS();
542 if ( !aStudy || theObj->_is_nil() )
545 SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy(aStudy);
547 GEOM::GEOM_Object_ptr aFatherObj = getFather( theObj );
549 SALOMEDS::SObject_var aSO =
550 getGeomEngine()->AddInStudy(aStudyDS, theObj, theName, aFatherObj);
553 if ( !aSO->_is_nil() ) {
554 CORBA::String_var entry = aSO->GetID();
555 anEntry = entry.in();
557 // Each dialog is responsible for this method implementation,
558 // default implementation does nothing
559 restoreSubShapes(aStudyDS, aSO);
565 //================================================================
566 // Function : restoreSubShapes
567 // Purpose : restore tree of argument's sub-shapes under the resulting shape
568 //================================================================
569 void GEOMBase_Helper::restoreSubShapes (SALOMEDS::Study_ptr /*theStudy*/,
570 SALOMEDS::SObject_ptr /*theSObject*/)
572 // do nothing by default
574 // example of implementation in particular dialog:
575 // GEOM::ListOfGO anArgs;
576 // anArgs.length(0); // empty list means that all arguments should be restored
577 // getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
578 // /*theFindMethod=*/GEOM::FSM_GetInPlace,
579 // /*theInheritFirstArg=*/false);
582 //================================================================
583 // Function : updateObjBrowser
584 // Purpose : Update object browser
585 //================================================================
586 void GEOMBase_Helper::updateObjBrowser() const
588 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
590 CAM_Module* module = app->module( "Geometry" );
591 SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
593 appMod->updateObjBrowser( true );
598 //================================================================
599 // Function : updateViewer
600 // Purpose : Update active 3D view
601 //================================================================
602 void GEOMBase_Helper::updateViewer()
604 getDisplayer()->UpdateViewer();
607 //================================================================
608 // Function : getStudyId
609 // Purpose : Get study Id
610 //================================================================
611 int GEOMBase_Helper::getStudyId() const
615 anId = getStudy()->id();
619 //================================================================
620 // Function : getStudy
621 // Purpose : Returns the active study. It is recommended to use
622 // this method instead of direct desktop->getActiveStudy() calls
623 //================================================================
624 SalomeApp_Study* GEOMBase_Helper::getStudy() const
626 SUIT_Desktop* aDesktop = getDesktop();
630 QList<SUIT_Application*> anAppList = SUIT_Session::session()->applications();
632 SUIT_Application* anApp = 0;
633 QListIterator<SUIT_Application*> it( anAppList );
634 while ( it.hasNext() )
637 if ( anApp && anApp->desktop() == aDesktop )
641 return dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
644 //================================================================
645 // Function : getEntry
647 //================================================================
648 QString GEOMBase_Helper::getEntry( GEOM::GEOM_Object_ptr object ) const
650 SalomeApp_Study* study = getStudy();
652 QString objIOR = GEOMBase::GetIORFromObject( object );
653 if ( objIOR != "" ) {
654 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( objIOR.toLatin1().constData() ) );
656 return QString::fromStdString(SO->GetID());
662 //================================================================
663 // Function : getDisplayer
665 //================================================================
666 GEOM_Displayer* GEOMBase_Helper::getDisplayer()
669 myDisplayer = new GEOM_Displayer( getStudy() );
673 //================================================================
674 // Function : clearShapeBuffer
676 //================================================================
677 void GEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
679 GeometryGUI::ClearShapeBuffer(theObj);
682 //================================================================
683 // Function : openCommand
685 //================================================================
686 bool GEOMBase_Helper::openCommand()
689 if ( !getStudy() || hasCommand() )
691 MESSAGE("Getting out from openCommand()")
695 GEOM::GEOM_IOperations_var anOp = GEOM::GEOM_IOperations::_narrow( getOperation() );
696 if ( !anOp->_is_nil() ) {
697 myCommand = new GEOM_Operation( SUIT_Session::session()->activeApplication(), anOp.in() );
703 MESSAGE("anOp->_is_nil() = true")
709 //================================================================
710 // Function : abortCommand
712 //================================================================
713 bool GEOMBase_Helper::abortCommand()
719 delete myCommand; // I don't know where to delete this object here ?
725 //================================================================
726 // Function : commitCommand
728 //================================================================
729 bool GEOMBase_Helper::commitCommand( const char* )
735 delete myCommand; // I don't know where to delete this object here ?
741 //================================================================
742 // Function : hasCommand
744 //================================================================
745 bool GEOMBase_Helper::hasCommand() const
747 return (bool)myCommand;
750 //================================================================
751 // Function : getOperation
753 //================================================================
754 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::getOperation()
756 if ( myOperation->_is_nil() )
757 myOperation = createOperation();
764 //================================================================
765 // Function : checkViewWindow
767 //================================================================
768 bool GEOMBase_Helper::checkViewWindow()
771 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
772 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
773 while ( it.hasNext() )
775 if ( myViewWindow == it.next() )
783 //================================================================
784 // Function : onAccept
785 // Purpose : This method should be called from dialog's slots onOk() and onApply()
786 // It perfroms user input validation, then it
787 // performs a proper operation and manages transactions, etc.
788 //================================================================
789 bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction, bool erasePreviewFlag )
791 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
794 MESSAGE("appStudy is empty")
797 _PTR(Study) aStudy = appStudy->studyDS();
799 bool aLocked = (_PTR(AttributeStudyProperties) (aStudy->GetProperties()))->IsLocked();
801 MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
802 SUIT_MessageBox::warning ( (QWidget*)SUIT_Session::session()->activeApplication()->desktop(),
803 QObject::tr("WRN_WARNING"),
804 QObject::tr("WRN_STUDY_LOCKED"),
805 QObject::tr("BUT_OK") );
810 if ( !isValid( msg ) ) {
816 erasePreview( false );
821 if ( ( !publish && !useTransaction ) || openCommand() ) {
822 SUIT_OverrideCursor wc;
823 SUIT_Session::session()->activeApplication()->putInfo( "" );
825 if ( !execute( objects ) || !getOperation()->IsDone() ) {
831 addSubshapesToStudy(); // add Sub-shapes if local selection
832 const int nbObjs = objects.size();
833 QStringList anEntryList;
834 int currObj = 1, aNumber = 1;
835 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it, currObj++ ) {
836 GEOM::GEOM_Object_var obj=*it;
838 QString aName = getNewObjectName(currObj);
841 aName = getPrefix(obj);
843 // Try to find a unique name
844 aName = GEOMBase::GetDefaultName(aName, extractPrefix());
846 // Don't check name uniqueness in case of numerous objects
847 aName = aName + "_" + QString::number(aNumber++);
850 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
851 if ( aName.isEmpty() )
852 aName = GEOMBase::GetDefaultName( getPrefix( obj ) );
854 anEntryList << addInStudy( obj, aName.toLatin1().constData() );
856 if( isDisplayResult() )
857 display( obj, false );
858 #ifdef WITHGENERICOBJ
859 // obj has been published in study. Its refcount has been incremented.
860 // It is safe to decrement its refcount
861 // so that it will be destroyed when the entry in study will be removed
866 // asv : fix of PAL6454. If publish==false, then the original shape
867 // was modified, and need to be re-cached in GEOM_Client before redisplay
868 clearShapeBuffer( obj );
869 // withChildren=true, updateView=false
870 if( isDisplayResult() )
871 redisplay( obj, true, false );
878 if( SUIT_Application* anApp = SUIT_Session::session()->activeApplication() ) {
879 LightApp_Application* aLightApp = dynamic_cast<LightApp_Application*>( anApp );
880 if(aLightApp && !isDisableBrowsing() )
881 aLightApp->browseObjects( anEntryList, isApplyAndClose(), isOptimizedBrowsing() );
882 anApp->putInfo( QObject::tr("GEOM_PRP_DONE") );
891 catch( const SALOME::SALOME_Exception& e ) {
892 SalomeApp_Tools::QtCatchCorbaException( e );
894 MESSAGE("Exception catched")
899 MESSAGE("result ="<<result)
904 //================================================================
905 // Function : showError
906 // Purpose : Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
907 //================================================================
908 void GEOMBase_Helper::showError()
911 if ( !getOperation()->_is_nil() )
912 msg = QObject::tr( getOperation()->GetErrorCode() );
915 msg = QObject::tr( "GEOM_PRP_ABORT" );
917 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
918 QObject::tr( "GEOM_ERROR_STATUS" ),
920 QObject::tr( "BUT_OK" ) );
923 //================================================================
924 // Function : showError
925 // Purpose : Shows a error message followed by <msg>
926 //================================================================
927 void GEOMBase_Helper::showError( const QString& msg )
929 QString str( QObject::tr( "GEOM_INCORRECT_INPUT" ) );
930 if ( !msg.isEmpty() )
932 SUIT_MessageBox::critical(SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ), str, QObject::tr( "BUT_OK" ) );
935 //////////////////////////////////////////////////////////////////
936 // Virtual methods to be redefined in dialogs
937 //////////////////////////////////////////////////////////////////
939 //================================================================
940 // Function : createOperation
941 // Purpose : Redefine this method to return proper IOperation reference
942 //================================================================
943 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::createOperation()
945 GEOM::GEOM_IOperations_var aNilOp;
946 return aNilOp._retn();
949 //================================================================
950 // Function : isValid
951 // Purpose : Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
952 //================================================================
953 bool GEOMBase_Helper::isValid( QString& )
958 //================================================================
959 // Function : execute
960 // Purpose : This method is called by onAccept().
961 // It should perform the required operation and put all new or modified objects into
962 // <objects> argument.Should return <false> if some error occurs during its execution.
963 //================================================================
964 bool GEOMBase_Helper::execute( ObjectList& objects )
969 //================================================================
970 // Function : getFather
971 // Purpose : This method is called by addInStudy(). It should return a father object
972 // for <theObj> or a nil reference if <theObj> should be published
973 // as a top-level object.
974 //================================================================
975 GEOM::GEOM_Object_ptr GEOMBase_Helper::getFather( GEOM::GEOM_Object_ptr theObj )
977 return GEOM::GEOM_Object::_nil();
980 //================================================================
981 // Function : getNewObjectName
982 // Purpose : Redefine this method to return proper name for a new object
983 //================================================================
984 QString GEOMBase_Helper::getNewObjectName (int) const
986 return QString::null;
989 //================================================================
990 // Function : extractPrefix
991 // Purpose : Redefine this method to return \c true if necessary
992 // to extract prefix when generating new name for the
993 // object(s) being created
994 //================================================================
995 bool GEOMBase_Helper::extractPrefix() const
1000 //================================================================
1001 // Function : getPrefix
1002 // Purpose : Get prefix for name of created object
1003 //================================================================
1004 QString GEOMBase_Helper::getPrefix( GEOM::GEOM_Object_ptr theObj ) const
1006 if ( !myPrefix.isEmpty() || theObj->_is_nil() )
1009 GEOM::shape_type aType = theObj->GetShapeType();
1013 case GEOM::VERTEX : return QObject::tr( "GEOM_VERTEX" );
1014 case GEOM::EDGE : return QObject::tr( "GEOM_EDGE" );
1015 case GEOM::WIRE : return QObject::tr( "GEOM_WIRE" );
1016 case GEOM::FACE : return QObject::tr( "GEOM_FACE" );
1017 case GEOM::SHELL : return QObject::tr( "GEOM_SHELL" );
1018 case GEOM::SOLID : return QObject::tr( "GEOM_SOLID" );
1019 case GEOM::COMPSOLID: return QObject::tr( "GEOM_COMPOUNDSOLID" );
1020 case GEOM::COMPOUND : return QObject::tr( "GEOM_COMPOUND" );
1021 default : return "";
1025 //================================================================
1026 // Function : getDesktop
1027 // Purpose : Returns myDesktop field. Initialized in constructor,
1028 // usually as dynamic_cast<SUIT_Desktop*>(parentWidget())
1029 //================================================================
1030 SUIT_Desktop* GEOMBase_Helper::getDesktop() const
1035 //================================================================
1036 // Function : selectObjects
1037 // Purpose : Selects list of objects
1038 //================================================================
1039 bool GEOMBase_Helper::selectObjects( ObjectList& objects )
1041 SUIT_DataOwnerPtrList aList;
1042 ObjectList::iterator anIter;
1043 for ( anIter = objects.begin(); anIter != objects.end(); ++anIter )
1045 QString anEntry = getEntry( *anIter );
1046 LightApp_DataOwner* anOwher = new LightApp_DataOwner( anEntry );
1047 aList.append( anOwher );
1050 SUIT_Session* session = SUIT_Session::session();
1051 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1055 LightApp_SelectionMgr* aMgr = app->selectionMgr();
1059 aMgr->setSelected( aList, false );
1064 //================================================================
1065 // Function : findObjectInFather
1066 // Purpose : It should return an object if its founded in study or
1067 // return Null object if the object is not founded
1068 //================================================================
1069 GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather (GEOM::GEOM_Object_ptr theFather,
1070 const QString& theName)
1072 SalomeApp_Application* app =
1073 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1074 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1075 _PTR(Study) aDStudy = appStudy->studyDS();
1076 QString IOR = GEOMBase::GetIORFromObject( theFather );
1077 _PTR(SObject) SObj ( aDStudy->FindObjectIOR( IOR.toLatin1().constData() ) );
1079 bool inStudy = false;
1080 GEOM::GEOM_Object_var aReturnObject;
1081 for (_PTR(ChildIterator) iit (aDStudy->NewChildIterator( SObj )); iit->More() && !inStudy; iit->Next()) {
1082 _PTR(SObject) child (iit->Value());
1083 QString aChildName = child->GetName().c_str();
1084 if (aChildName == theName) {
1086 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(iit->Value());
1087 aReturnObject = GEOM::GEOM_Object::_narrow( corbaObj );
1091 return aReturnObject._retn();
1093 return GEOM::GEOM_Object::_nil();
1096 //================================================================
1097 // Function : findObjectInFather
1098 // Purpose : It should return an object if its founded in study or
1099 // return Null object if the object is not founded
1100 //================================================================
1101 GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather( GEOM::GEOM_Object_ptr theFather,
1104 GEOM::GEOM_Object_var object;
1107 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
1109 _PTR(Study) studyDS = study->studyDS();
1110 QString IOR = GEOMBase::GetIORFromObject( theFather );
1111 _PTR(SObject) sobject( studyDS->FindObjectIOR( IOR.toLatin1().constData() ) );
1113 _PTR(ChildIterator) it( studyDS->NewChildIterator( sobject ) );
1114 for ( ; it->More() && !found; it->Next() ) {
1115 GEOM::GEOM_Object_var cobject = GEOM::GEOM_Object::_narrow( GeometryGUI::ClientSObjectToObject( it->Value() ) );
1116 if ( !CORBA::is_nil( cobject ) ) {
1117 GEOM::ListOfLong_var indices = cobject->GetSubShapeIndices();
1118 int length = indices->length();
1119 for ( int i = 0; i < length && !found; i++ ) {
1120 if ( indices[i] == theIndex ) {
1130 return object._retn();
1133 //================================================================
1134 // Function : addSubshapesToStudy
1135 // Purpose : Virtual method to add sub-shapes if needs
1136 //================================================================
1137 void GEOMBase_Helper::addSubshapesToStudy()
1139 //Impemented in Dialogs, called from Accept method
1142 //================================================================
1143 // Function : getSelected
1144 // Purpose : Get selected object by specified type
1146 // Returns valid object if only one object of the specified type is selected
1147 // (no matter global or local selection is activated). If \a type is TopAbs_SHAPE,
1148 // geometrical object of any valid type is expected.
1150 // \param type type of the object to be obtained from selection
1151 // \return selected geometrical object or nil object if selection is not satisfactory
1152 //================================================================
1153 GEOM::GeomObjPtr GEOMBase_Helper::getSelected( TopAbs_ShapeEnum type )
1155 QList<TopAbs_ShapeEnum> types;
1157 return getSelected( types );
1160 //================================================================
1161 // Function : getSelected
1162 // Purpose : Get selected object by specified types
1164 // Returns valid object if only one object of the specified type is selected
1165 // (no matter global or local selection is activated). The list of allowed
1166 // shape types is passed via \a types. If \a types includes TopAbs_SHAPE,
1167 // geometrical object of any valid type is expected.
1169 // \param types list of allowed shape types for the objects to be obtained from selection
1170 // \return selected geometrical object or nil object if selection is not satisfactory
1171 //================================================================
1172 GEOM::GeomObjPtr GEOMBase_Helper::getSelected( const QList<TopAbs_ShapeEnum>& types )
1174 QList<GEOM::GeomObjPtr> selected = getSelected( types, 1 );
1175 return selected.count() > 0 ? selected[0] : GEOM::GeomObjPtr();
1178 //================================================================
1179 // Function : getSelected
1180 // Purpose : Get selected object(s) by specified type
1182 // Returns list of selected objects if selection satisfies specifies selection options.
1183 // (no matter global or local selection is activated). If \a type is TopAbs_SHAPE,
1184 // geometrical objects of any valid type are expected.
1186 // The \a type parameter specifies allowed type of the object(s) being selected.
1187 // The \a count parameter specifies exact number of the objects to be retrieved from selection.
1188 // The \a strict parameter specifies policy being applied to the selection.
1189 // If \a count < 0, then any number of the selected objects is valid (including 0).
1190 // In this case, if \a strict is \c true (default), all selected objects should satisfy
1191 // the specified \a type.
1192 // If \a count > 0, only specified number of the objects is retrieved from the selection.
1193 // In this case, if \a strict is \c true (default), function returns empty list if total number of selected
1194 // objects does not correspond to the \a count parameter. Otherwise (if \a strict is \c false),
1195 // function returns valid list of objects if at least \a count objects satisfy specified \a type.
1197 // \param type type of the object(s) to be obtained from selection
1198 // \param count number of items to be retrieved from selection
1199 // \param strict selection policy
1200 // \return list of selected geometrical objects or empty list if selection is not satisfactory
1201 //================================================================
1202 QList<GEOM::GeomObjPtr> GEOMBase_Helper::getSelected( TopAbs_ShapeEnum type, int count, bool strict )
1204 QList<TopAbs_ShapeEnum> types;
1206 return getSelected( types, count, strict );
1209 static bool typeInList( TopAbs_ShapeEnum type, const QList<TopAbs_ShapeEnum>& types )
1212 for ( int i = 0; i < types.count() && !ok; i++ )
1213 ok = types[i] == TopAbs_SHAPE || types[i] == type;
1217 //================================================================
1218 // Function : getSelected
1219 // Purpose : Get selected objects by specified types
1221 // Returns list of selected objects if selection satisfies specifies selection options.
1222 // (no matter global or local selection is activated). If \a types includes TopAbs_SHAPE,
1223 // geometrical objects of any valid type are expected.
1225 // The \a types parameter specifies allowed types of the object(s) being selected.
1226 // The \a count parameter specifies exact number of the objects to be retrieved from selection.
1227 // The \a strict parameter specifies policy being applied to the selection.
1228 // If \a count < 0, then any number of the selected objects is valid (including 0).
1229 // In this case, if \a strict is \c true (default), all selected objects should satisfy
1230 // the specified \a type.
1231 // If \a count > 0, only specified number of the objects is retrieved from the selection.
1232 // In this case, if \a strict is \c true (default), function returns empty list if total number of selected
1233 // objects does not correspond to the \a count parameter. Otherwise (if \a strict is \c false),
1234 // function returns valid list of objects if at least \a count objects satisfy specified \a type.
1236 // \param types list of allowed shape types for the objects to be obtained from selection
1237 // \param count number of items to be retrieved from selection
1238 // \param strict selection policy
1239 // \return list of selected geometrical objects or empty list if selection is not satisfactory
1240 //================================================================
1241 QList<GEOM::GeomObjPtr> GEOMBase_Helper::getSelected( const QList<TopAbs_ShapeEnum>& types, int count, bool strict )
1243 SUIT_Session* session = SUIT_Session::session();
1244 QList<GEOM::GeomObjPtr> result;
1246 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1248 LightApp_SelectionMgr* selMgr = app->selectionMgr();
1250 SALOME_ListIO selected;
1251 selMgr->selectedObjects( selected );
1252 SALOME_ListIteratorOfListIO it( selected );
1253 bool stopped = false;
1254 for ( ; it.More() && !stopped; it.Next() ) {
1255 Handle(SALOME_InteractiveObject) IO = it.Value();
1256 GEOM::GeomObjPtr object = GEOMBase::ConvertIOinGEOMObject( IO );
1258 TColStd_IndexedMapOfInteger subShapes;
1259 selMgr->GetIndexes( IO, subShapes );
1260 int nbSubShapes = subShapes.Extent();
1261 if ( nbSubShapes == 0 ) {
1263 if ( typeInList( (TopAbs_ShapeEnum)(object->GetShapeType()), types ) ) {
1266 if ( strict && result.count() > count ) {
1270 else if ( !strict && result.count() == count )
1274 else if ( strict ) {
1281 for ( int i = 1; i <= nbSubShapes && !stopped; i++ ) {
1282 int idx = subShapes( i );
1283 GEOM::GeomObjPtr subShape = findObjectInFather( object.get(), idx );
1285 // sub-shape is not yet published in the study
1286 GEOM::ShapesOpPtr shapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
1287 subShape.take( shapesOp->GetSubShape( object.get(), idx ) ); // take ownership!
1289 if ( typeInList( (TopAbs_ShapeEnum)(subShape->GetShapeType()), types ) ) {
1292 if ( strict && result.count() > count ) {
1296 else if ( !strict && result.count() == count )
1300 else if ( strict ) {
1313 //================================================================
1314 // Function : setIsApplyAndClose
1315 // Purpose : Set value of the flag indicating that the dialog is
1316 // accepted by Apply & Close button
1317 //================================================================
1318 void GEOMBase_Helper::setIsApplyAndClose( const bool theFlag )
1320 myIsApplyAndClose = theFlag;
1323 //================================================================
1324 // Function : isApplyAndClose
1325 // Purpose : Get value of the flag indicating that the dialog is
1326 // accepted by Apply & Close button
1327 //================================================================
1328 bool GEOMBase_Helper::isApplyAndClose() const
1330 return myIsApplyAndClose;
1333 //================================================================
1334 // Function : setIsOptimizedBrowsing
1335 // Purpose : Set value of the flag switching to optimized
1336 // browsing mode (to select the first published
1338 //================================================================
1339 void GEOMBase_Helper::setIsOptimizedBrowsing( const bool theFlag )
1341 myIsOptimizedBrowsing = theFlag;
1344 //================================================================
1345 // Function : isOptimizedBrowsing
1346 // Purpose : Get value of the flag switching to optimized
1347 // browsing mode (to select the first published
1349 //================================================================
1350 bool GEOMBase_Helper::isOptimizedBrowsing() const
1352 return myIsOptimizedBrowsing;