1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : GEOMBase_Helper.cxx
25 // Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
27 #include "GEOMBase_Helper.h"
29 #include "GEOM_Operation.h"
31 #include <GeometryGUI.h>
33 #include <SUIT_Desktop.h>
34 #include <SUIT_Session.h>
35 #include <SUIT_ViewManager.h>
36 #include <SUIT_ViewWindow.h>
37 #include <SUIT_ViewModel.h>
38 #include <SUIT_MessageBox.h>
39 #include <SUIT_OverrideCursor.h>
40 #include <SUIT_ResourceMgr.h>
42 #include <SalomeApp_Module.h>
43 #include <SalomeApp_Application.h>
44 #include <SalomeApp_Study.h>
45 #include <LightApp_SelectionMgr.h>
46 #include <LightApp_DataOwner.h>
47 #include <SalomeApp_Tools.h>
48 #include <SALOME_ListIteratorOfListIO.hxx>
50 #include <SALOME_Prs.h>
52 #include <OCCViewer_ViewModel.h>
53 #include <SVTK_ViewModel.h>
55 #include <TColStd_MapOfInteger.hxx>
56 #include <TCollection_AsciiString.hxx>
57 #include <TColStd_IndexedMapOfInteger.hxx>
59 //To disable automatic genericobj management, the following line should be commented.
60 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
61 #define WITHGENERICOBJ
63 //================================================================
64 // Function : getActiveView
65 // Purpose : Get active view window, returns 0 if no open study frame
66 //================================================================
67 SUIT_ViewWindow* GEOMBase_Helper::getActiveView()
69 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
71 return SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
77 //================================================================
78 // Function : getGeomEngine
79 // Purpose : Static method
80 //================================================================
81 GEOM::GEOM_Gen_ptr GEOMBase_Helper::getGeomEngine()
83 return GeometryGUI::GetGeomGen();
86 //================================================================
87 // Function : GEOMBase_Helper
89 //================================================================
90 GEOMBase_Helper::GEOMBase_Helper( SUIT_Desktop* desktop )
91 : myDesktop( desktop ), myViewWindow( 0 ), myDisplayer( 0 ), myCommand( 0 ), isPreview( false ),
92 myIsApplyAndClose( false ), myIsOptimizedBrowsing( false ), myIsWaitCursorEnabled( true ),
93 myIsDisableBrowsing(false), myIsDisplayResult(true)
97 //================================================================
98 // Function : ~GEOMBase_Helper
100 //================================================================
101 GEOMBase_Helper::~GEOMBase_Helper()
103 //rnv: Fix for the "IPAL21922 : WinTC5.1.4: incorrect quit salome"
104 if ( !SUIT_Session::session()->activeApplication() || !SUIT_Session::session()->activeApplication()->desktop() )
107 if ( myPreview.size() )
111 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
113 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
115 globalSelection(aGeomGUI->getLocalSelectionMode() , true );
120 if ( !CORBA::is_nil( myOperation ) )
121 myOperation->UnRegister();
124 //================================================================
125 // Function : display
127 //================================================================
128 void GEOMBase_Helper::display( const ObjectList& objList, const bool updateView )
130 ObjectList::const_iterator it;
131 for ( it = objList.begin(); it != objList.end(); it++ ) {
132 display( *it, false );
134 if ( !objList.empty() && updateView )
135 getDisplayer()->UpdateViewer();
138 //================================================================
139 // Function : display
140 // Purpose : Display object.
141 // Important : Object must be already in study
142 //================================================================
143 void GEOMBase_Helper::display( GEOM::GEOM_Object_ptr object, const bool updateView )
145 // Unset color of shape ( this color may be set during preview displaying )
146 // Default color will be used
147 // getDisplayer()->UnsetColor();
148 getDisplayer()->UnsetWidth();
150 MESSAGE("GEOMBase_Helper::display myTexture = "<<getDisplayer()->GetTexture())
152 // Enable activisation of selection
153 getDisplayer()->SetToActivate( true );
156 getDisplayer()->Display( object, updateView );
159 //================================================================
162 //================================================================
163 void GEOMBase_Helper::erase( const ObjectList& objList, const bool updateView )
165 ObjectList::const_iterator it = objList.begin();
166 for ( ; it != objList.end(); it++ ) {
169 if ( !objList.empty() && updateView )
170 getDisplayer()->UpdateViewer();
173 //================================================================
176 //================================================================
177 void GEOMBase_Helper::erase( GEOM::GEOM_Object_ptr object, const bool updateView )
179 if ( !object->_is_nil() ) {
180 QString entry = getEntry( object );
181 getDisplayer()->Erase( new SALOME_InteractiveObject(
182 entry.toLatin1().constData(),
183 "GEOM", strdup( GEOMBase::GetName( object ).toLatin1().constData() ) ), true, updateView );
187 //================================================================
188 // Function : redisplay
190 //================================================================
191 void GEOMBase_Helper::redisplay( const ObjectList& objList,
192 const bool withChildren,
193 const bool updateView )
195 ObjectList::const_iterator it = objList.begin();
196 for ( ; it != objList.end(); it++ ) {
197 redisplay( *it, withChildren, false );
199 if ( !objList.empty() && updateView )
200 getDisplayer()->UpdateViewer();
203 //================================================================
204 // Function : redisplay
206 //================================================================
207 void GEOMBase_Helper::redisplay( GEOM::GEOM_Object_ptr object,
208 const bool withChildren,
209 const bool updateView )
211 if ( !object->_is_nil() ) {
212 // Unset color of shape ( this color may be set during preview displaying )
213 // Default color will be used
214 getDisplayer()->UnsetColor();
215 getDisplayer()->UnsetWidth();
217 // Enable activisation of selection
218 getDisplayer()->SetToActivate( true );
220 QString entry = getEntry( object );
221 getDisplayer()->Redisplay(new SALOME_InteractiveObject
222 (entry.toLatin1().constData(), "GEOM", strdup(GEOMBase::GetName(object).toLatin1().constData())), false);
225 if ( withChildren ) {
226 SalomeApp_Study* aDoc = getStudy();
227 if ( aDoc && aDoc->studyDS() ) {
228 _PTR(Study) aStudy = aDoc->studyDS();
229 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string(object);
230 _PTR(SObject) aSObj (aStudy->FindObjectIOR(std::string(objStr.in())));
232 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
233 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
234 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow
235 (GeometryGUI::ClientSObjectToObject(anIt->Value()));
236 if ( !CORBA::is_nil( aChild ) ) {
237 if ( !aChild->_is_nil() ) {
238 QString entry = getEntry( aChild );
239 getDisplayer()->Redisplay( new SALOME_InteractiveObject(
240 entry.toLatin1().constData(), "GEOM", strdup( GEOMBase::GetName( aChild ).toLatin1().constData() ) ), false );
249 getDisplayer()->UpdateViewer();
252 //================================================================
253 // Function : displayPreview
254 // Purpose : Method for displaying preview based on execute() results
255 //================================================================
256 void GEOMBase_Helper::displayPreview( const bool display,
259 const bool toRemoveFromEngine,
260 const double lineWidth,
261 const int displayMode,
265 erasePreview( update );
271 if ( !isValid( msg ) )
273 erasePreview( update );
278 erasePreview( false );
281 SUIT_OverrideCursor wc;
284 if ( !isWaitCursorEnabled() )
287 if ( !execute( objects ) || !getOperation()->IsDone() ) {
291 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it )
293 GEOM::GEOM_Object_var obj=*it;
294 displayPreview( obj, true, activate, false, lineWidth, displayMode, color );
295 if ( toRemoveFromEngine )
300 catch( const SALOME::SALOME_Exception& e ) {
301 SalomeApp_Tools::QtCatchCorbaException( e );
310 //================================================================
311 // Function : displayPreview
312 // Purpose : Method for displaying preview of resulting shape
313 //================================================================
314 void GEOMBase_Helper::displayPreview( GEOM::GEOM_Object_ptr object,
318 const double lineWidth,
319 const int displayMode,
322 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
324 // Set color for preview shape
325 getDisplayer()->SetColor( color == -1 ? Quantity_NOC_VIOLET : color );
327 // set width of displayed shape
328 getDisplayer()->SetWidth( lineWidth == -1 ? resMgr->integerValue("Geometry", "preview_edge_width", -1) : lineWidth );
330 // set display mode of displayed shape
331 int aPrevDispMode = getDisplayer()->SetDisplayMode( displayMode == -1 ? resMgr->integerValue( "Geometry", "display_mode", 0 ) : displayMode );
333 // Disable activation of selection
334 getDisplayer()->SetToActivate( activate );
336 // Make a reference to GEOM_Object
337 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string( object );
338 getDisplayer()->SetName( objStr.in() );
341 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( object );
342 if ( aPrs == 0 || aPrs->IsNull() )
345 // Make preview not clippable
346 aPrs->SetClippable (false);
349 displayPreview( aPrs, append, update );
351 getDisplayer()->UnsetName();
352 getDisplayer()->UnsetColor();
353 getDisplayer()->SetDisplayMode( aPrevDispMode );
355 // Enable activation of displayed objects
356 getDisplayer()->SetToActivate( true );
359 //================================================================
360 // Function : displayPreview
361 // Purpose : Method for displaying arbitrary preview objects (not limited to shapes)
362 //================================================================
363 void GEOMBase_Helper::displayPreview( const SALOME_Prs* prs,
368 erasePreview( false );
370 // remember current view frame to make correct erase preview later
371 myViewWindow = getActiveView();
373 if ( myViewWindow == 0 )
377 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
378 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
379 aViewManager->getType() == SVTK_Viewer::Type() )
381 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
382 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
384 aView->Display( prs );
387 // Add prs to the preview list
388 myPreview.push_back( (SALOME_Prs*)prs );
392 getDisplayer()->UpdateViewer();
395 //================================================================
396 // Function : erasePreview
398 //================================================================
399 void GEOMBase_Helper::erasePreview( const bool update )
401 // check view frame where the preview was displayed
402 bool vfOK = checkViewWindow() && myViewWindow;
403 // Iterate through presentations and delete them
404 for ( PrsList::iterator anIter = myPreview.begin(); anIter != myPreview.end(); ++anIter ) {
407 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
408 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
409 aViewManager->getType() == SVTK_Viewer::Type() )
411 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
412 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
414 aView->Erase( *anIter, true );
426 //================================================================
427 // Function : localSelection
428 // Purpose : Activate selection of objects of a given type
429 // IMPORTANT : Works after localSelection( ... ) method call only
430 //================================================================
431 void GEOMBase_Helper::activate( const int theType )
433 if (!getStudy()) return;
434 _PTR(Study) aStudy = getStudy()->studyDS();
435 _PTR(SComponent) aGeom ( aStudy->FindComponent( "GEOM" ) );
440 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( aGeom ) );
441 for ( ; anIter->More(); anIter->Next() )
443 _PTR(SObject) aSO ( anIter->Value() );
446 _PTR(SObject) aRefSO;
447 if ( !aSO->ReferencedObject( aRefSO ) )
449 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow
450 (GeometryGUI::ClientSObjectToObject(aSO));
451 if ( !anObj->_is_nil() && anObj->GetType() == theType )
452 aList.Append( new SALOME_InteractiveObject( aSO->GetID().c_str(), "GEOM", aSO->GetName().c_str()) );
457 getDisplayer()->LocalSelection( aList, 0 );
460 //================================================================
461 // Function : localSelection
462 // Purpose : Activate selection of sub-shapes in accordance with mode
463 // theMode is from TopAbs_ShapeEnum
464 //================================================================
465 void GEOMBase_Helper::localSelection( const ObjectList& theObjs, const int theMode )
467 SALOME_ListIO aListOfIO;
469 ObjectList::const_iterator anIter = theObjs.begin();
470 for ( ; anIter != theObjs.end(); ++anIter )
472 GEOM::GEOM_Object_ptr anObj = *anIter;
473 if ( anObj->_is_nil() )
475 QString anEntry = getEntry( anObj );
477 aListOfIO.Append( new SALOME_InteractiveObject(
478 anEntry.toLatin1().constData(), "GEOM", strdup( GEOMBase::GetName( anObj ).toLatin1().constData() ) ) );
481 getDisplayer()->LocalSelection( aListOfIO, theMode );
484 //================================================================
485 // Function : localSelection
486 // Purpose : Activate selection of sub-shapes in accordance with mode
487 // theMode is from TopAbs_ShapeEnum
488 //================================================================
489 void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const int mode )
491 // If object is null local selection for all objects is activated
492 if ( obj->_is_nil() ) {
493 getDisplayer()->LocalSelection( Handle(SALOME_InteractiveObject)(), mode );
498 objList.push_back( obj );
499 localSelection( objList, mode );
503 //================================================================
504 // Function : globalSelection
505 // Purpose : Activate selection of sub-shapes. Set selection filters
506 // in accordance with mode. theMode is from GEOMImpl_Types
507 //================================================================
508 void GEOMBase_Helper::globalSelection( const int theMode, const bool update )
510 getDisplayer()->GlobalSelection( theMode, update );
513 //================================================================
514 // Function : globalSelection
515 // Purpose : Activate selection of sub-shapes. Set selection filters
516 // in accordance with mode. theMode is from GEOMImpl_Types
517 //================================================================
518 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
521 getDisplayer()->GlobalSelection( theModes, update );
524 //================================================================
525 // Function : globalSelection
526 // Purpose : Activate selection of sub-shapes. Set selection filters
527 // in accordance with mode. theMode is from GEOMImpl_Types
528 //================================================================
529 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
530 const QList<int>& subShapes,
533 getDisplayer()->GlobalSelection( theModes, update, &subShapes );
536 //================================================================
537 // Function : addInStudy
538 // Purpose : Add object in study
539 //================================================================
540 QString GEOMBase_Helper::addInStudy( GEOM::GEOM_Object_ptr theObj, const char* theName )
545 _PTR(Study) aStudy = getStudy()->studyDS();
546 if ( !aStudy || theObj->_is_nil() )
549 SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy(aStudy);
551 GEOM::GEOM_Object_ptr aFatherObj = getFather( theObj );
553 SALOMEDS::SObject_var aSO =
554 getGeomEngine()->AddInStudy(aStudyDS, theObj, theName, aFatherObj);
557 if ( !aSO->_is_nil() ) {
558 CORBA::String_var entry = aSO->GetID();
559 anEntry = entry.in();
561 // Each dialog is responsible for this method implementation,
562 // default implementation does nothing
563 restoreSubShapes(aStudyDS, aSO);
569 //================================================================
570 // Function : restoreSubShapes
571 // Purpose : restore tree of argument's sub-shapes under the resulting shape
572 //================================================================
573 void GEOMBase_Helper::restoreSubShapes (SALOMEDS::Study_ptr /*theStudy*/,
574 SALOMEDS::SObject_ptr /*theSObject*/)
576 // do nothing by default
578 // example of implementation in particular dialog:
579 // GEOM::ListOfGO anArgs;
580 // anArgs.length(0); // empty list means that all arguments should be restored
581 // getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
582 // /*theFindMethod=*/GEOM::FSM_GetInPlace,
583 // /*theInheritFirstArg=*/false);
586 //================================================================
587 // Function : updateObjBrowser
588 // Purpose : Update object browser
589 //================================================================
590 void GEOMBase_Helper::updateObjBrowser() const
592 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
594 CAM_Module* module = app->module( "Geometry" );
595 SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
597 appMod->updateObjBrowser( true );
602 //================================================================
603 // Function : updateViewer
604 // Purpose : Update active 3D view
605 //================================================================
606 void GEOMBase_Helper::updateViewer()
608 getDisplayer()->UpdateViewer();
611 //================================================================
612 // Function : getStudyId
613 // Purpose : Get study Id
614 //================================================================
615 int GEOMBase_Helper::getStudyId() const
619 anId = getStudy()->id();
623 //================================================================
624 // Function : getStudy
625 // Purpose : Returns the active study. It is recommended to use
626 // this method instead of direct desktop->getActiveStudy() calls
627 //================================================================
628 SalomeApp_Study* GEOMBase_Helper::getStudy() const
630 SUIT_Desktop* aDesktop = getDesktop();
634 QList<SUIT_Application*> anAppList = SUIT_Session::session()->applications();
636 SUIT_Application* anApp = 0;
637 QListIterator<SUIT_Application*> it( anAppList );
638 while ( it.hasNext() )
641 if ( anApp && anApp->desktop() == aDesktop )
645 return dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
648 //================================================================
649 // Function : getEntry
651 //================================================================
652 QString GEOMBase_Helper::getEntry( GEOM::GEOM_Object_ptr object ) const
654 SalomeApp_Study* study = getStudy();
656 QString objIOR = GEOMBase::GetIORFromObject( object );
657 if ( objIOR != "" ) {
658 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( objIOR.toLatin1().constData() ) );
660 return QString::fromStdString(SO->GetID());
666 //================================================================
667 // Function : getDisplayer
669 //================================================================
670 GEOM_Displayer* GEOMBase_Helper::getDisplayer()
673 myDisplayer = new GEOM_Displayer( getStudy() );
677 //================================================================
678 // Function : clearShapeBuffer
680 //================================================================
681 void GEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
683 GeometryGUI::ClearShapeBuffer(theObj);
686 //================================================================
687 // Function : openCommand
689 //================================================================
690 bool GEOMBase_Helper::openCommand()
693 if ( !getStudy() || hasCommand() )
695 MESSAGE("Getting out from openCommand()")
699 GEOM::GEOM_IOperations_var anOp = GEOM::GEOM_IOperations::_narrow( getOperation() );
700 if ( !anOp->_is_nil() ) {
701 myCommand = new GEOM_Operation( SUIT_Session::session()->activeApplication(), anOp.in() );
707 MESSAGE("anOp->_is_nil() = true")
713 //================================================================
714 // Function : abortCommand
716 //================================================================
717 bool GEOMBase_Helper::abortCommand()
723 delete myCommand; // I don't know where to delete this object here ?
729 //================================================================
730 // Function : commitCommand
732 //================================================================
733 bool GEOMBase_Helper::commitCommand( const char* )
739 delete myCommand; // I don't know where to delete this object here ?
745 //================================================================
746 // Function : hasCommand
748 //================================================================
749 bool GEOMBase_Helper::hasCommand() const
751 return (bool)myCommand;
754 //================================================================
755 // Function : getOperation
757 //================================================================
758 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::getOperation()
760 if ( myOperation->_is_nil() )
761 myOperation = createOperation();
768 //================================================================
769 // Function : checkViewWindow
771 //================================================================
772 bool GEOMBase_Helper::checkViewWindow()
775 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
776 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
777 while ( it.hasNext() )
779 if ( myViewWindow == it.next() )
787 //================================================================
788 // Function : onAccept
789 // Purpose : This method should be called from dialog's slots onOk() and onApply()
790 // It perfroms user input validation, then it
791 // performs a proper operation and manages transactions, etc.
792 //================================================================
793 bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction, bool erasePreviewFlag )
795 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
798 MESSAGE("appStudy is empty")
801 _PTR(Study) aStudy = appStudy->studyDS();
803 bool aLocked = (_PTR(AttributeStudyProperties) (aStudy->GetProperties()))->IsLocked();
805 MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
806 SUIT_MessageBox::warning ( (QWidget*)SUIT_Session::session()->activeApplication()->desktop(),
807 QObject::tr("WRN_WARNING"),
808 QObject::tr("WRN_STUDY_LOCKED"),
809 QObject::tr("BUT_OK") );
814 if ( !isValid( msg ) ) {
820 erasePreview( false );
825 if ( ( !publish && !useTransaction ) || openCommand() ) {
826 SUIT_OverrideCursor wc;
827 SUIT_Session::session()->activeApplication()->putInfo( "" );
829 if ( !execute( objects ) || !getOperation()->IsDone() ) {
835 addSubshapesToStudy(); // add Sub-shapes if local selection
836 const int nbObjs = objects.size();
837 QStringList anEntryList;
838 int currObj = 1, aNumber = 1;
839 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it, currObj++ ) {
840 GEOM::GEOM_Object_var obj=*it;
842 QString aName = getObjectName(obj);
843 if (aName.isEmpty()) {
844 aName = getNewObjectName(currObj);
847 aName = getPrefix(obj);
849 // Try to find a unique name
850 aName = GEOMBase::GetDefaultName(aName, extractPrefix());
852 // Don't check name uniqueness in case of numerous objects
853 aName = aName + "_" + QString::number(aNumber++);
856 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
857 if ( aName.isEmpty() )
858 aName = GEOMBase::GetDefaultName( getPrefix( obj ) );
861 anEntryList << addInStudy( obj, aName.toLatin1().constData() );
863 if( isDisplayResult() )
864 display( obj, false );
865 #ifdef WITHGENERICOBJ
866 // obj has been published in study. Its refcount has been incremented.
867 // It is safe to decrement its refcount
868 // so that it will be destroyed when the entry in study will be removed
873 // asv : fix of PAL6454. If publish==false, then the original shape
874 // was modified, and need to be re-cached in GEOM_Client before redisplay
875 clearShapeBuffer( obj );
876 // withChildren=true, updateView=false
877 if( isDisplayResult() )
878 redisplay( obj, true, false );
885 if( SUIT_Application* anApp = SUIT_Session::session()->activeApplication() ) {
886 LightApp_Application* aLightApp = dynamic_cast<LightApp_Application*>( anApp );
888 QString anOpName( typeid(*this).name() );
889 aLightApp->emitOperationFinished( "Geometry", anOpName, anEntryList );
891 if ( !isDisableBrowsing() )
892 aLightApp->browseObjects( anEntryList, isApplyAndClose(), isOptimizedBrowsing() );
894 anApp->putInfo( QObject::tr("GEOM_PRP_DONE") );
903 catch( const SALOME::SALOME_Exception& e ) {
904 SalomeApp_Tools::QtCatchCorbaException( e );
906 MESSAGE("Exception catched")
911 MESSAGE("result ="<<result)
916 //================================================================
917 // Function : showError
918 // Purpose : Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
919 //================================================================
920 void GEOMBase_Helper::showError()
923 if ( !getOperation()->_is_nil() )
924 msg = QObject::tr( getOperation()->GetErrorCode() );
927 msg = QObject::tr( "GEOM_PRP_ABORT" );
929 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
930 QObject::tr( "GEOM_ERROR_STATUS" ),
932 QObject::tr( "BUT_OK" ) );
935 //================================================================
936 // Function : showError
937 // Purpose : Shows a error message followed by <msg>
938 //================================================================
939 void GEOMBase_Helper::showError( const QString& msg )
941 QString str( QObject::tr( "GEOM_INCORRECT_INPUT" ) );
942 if ( !msg.isEmpty() )
944 SUIT_MessageBox::critical(SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ), str, QObject::tr( "BUT_OK" ) );
947 //////////////////////////////////////////////////////////////////
948 // Virtual methods to be redefined in dialogs
949 //////////////////////////////////////////////////////////////////
951 //================================================================
952 // Function : createOperation
953 // Purpose : Redefine this method to return proper IOperation reference
954 //================================================================
955 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::createOperation()
957 GEOM::GEOM_IOperations_var aNilOp;
958 return aNilOp._retn();
961 //================================================================
962 // Function : isValid
963 // Purpose : Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
964 //================================================================
965 bool GEOMBase_Helper::isValid( QString& )
970 //================================================================
971 // Function : execute
972 // Purpose : This method is called by onAccept().
973 // It should perform the required operation and put all new or modified objects into
974 // <objects> argument.Should return <false> if some error occurs during its execution.
975 //================================================================
976 bool GEOMBase_Helper::execute( ObjectList& objects )
981 //================================================================
982 // Function : getFather
983 // Purpose : This method is called by addInStudy(). It should return a father object
984 // for <theObj> or a nil reference if <theObj> should be published
985 // as a top-level object.
986 //================================================================
987 GEOM::GEOM_Object_ptr GEOMBase_Helper::getFather( GEOM::GEOM_Object_ptr theObj )
989 return GEOM::GEOM_Object::_nil();
992 //================================================================
993 // Function : getObjectName
994 // Purpose : Redefine this method to return proper name for the given object
995 //================================================================
996 QString GEOMBase_Helper::getObjectName(GEOM::GEOM_Object_ptr object) const
1001 //================================================================
1002 // Function : getNewObjectName
1003 // Purpose : Redefine this method to return proper name for a new object
1004 //================================================================
1005 QString GEOMBase_Helper::getNewObjectName (int) const
1010 //================================================================
1011 // Function : extractPrefix
1012 // Purpose : Redefine this method to return \c true if necessary
1013 // to extract prefix when generating new name for the
1014 // object(s) being created
1015 //================================================================
1016 bool GEOMBase_Helper::extractPrefix() const
1021 //================================================================
1022 // Function : getPrefix
1023 // Purpose : Get prefix for name of created object
1024 //================================================================
1025 QString GEOMBase_Helper::getPrefix( GEOM::GEOM_Object_ptr theObj ) const
1027 if ( !myPrefix.isEmpty() || theObj->_is_nil() )
1030 GEOM::shape_type aType = theObj->GetShapeType();
1034 case GEOM::VERTEX : return QObject::tr( "GEOM_VERTEX" );
1035 case GEOM::EDGE : return QObject::tr( "GEOM_EDGE" );
1036 case GEOM::WIRE : return QObject::tr( "GEOM_WIRE" );
1037 case GEOM::FACE : return QObject::tr( "GEOM_FACE" );
1038 case GEOM::SHELL : return QObject::tr( "GEOM_SHELL" );
1039 case GEOM::SOLID : return QObject::tr( "GEOM_SOLID" );
1040 case GEOM::COMPSOLID: return QObject::tr( "GEOM_COMPOUNDSOLID" );
1041 case GEOM::COMPOUND : return QObject::tr( "GEOM_COMPOUND" );
1042 default : return "";
1046 //================================================================
1047 // Function : getDesktop
1048 // Purpose : Returns myDesktop field. Initialized in constructor,
1049 // usually as dynamic_cast<SUIT_Desktop*>(parentWidget())
1050 //================================================================
1051 SUIT_Desktop* GEOMBase_Helper::getDesktop() const
1056 //================================================================
1057 // Function : selectObjects
1058 // Purpose : Selects list of objects
1059 //================================================================
1060 bool GEOMBase_Helper::selectObjects( ObjectList& objects )
1062 SUIT_DataOwnerPtrList aList;
1063 ObjectList::iterator anIter;
1064 for ( anIter = objects.begin(); anIter != objects.end(); ++anIter )
1066 QString anEntry = getEntry( *anIter );
1067 LightApp_DataOwner* anOwher = new LightApp_DataOwner( anEntry );
1068 aList.append( anOwher );
1071 SUIT_Session* session = SUIT_Session::session();
1072 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1076 LightApp_SelectionMgr* aMgr = app->selectionMgr();
1080 aMgr->setSelected( aList, false );
1085 //================================================================
1086 // Function : findObjectInFather
1087 // Purpose : It should return an object if its founded in study or
1088 // return Null object if the object is not founded
1089 //================================================================
1090 GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather (GEOM::GEOM_Object_ptr theFather,
1091 const QString& theName)
1093 SalomeApp_Application* app =
1094 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1095 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1096 _PTR(Study) aDStudy = appStudy->studyDS();
1097 QString IOR = GEOMBase::GetIORFromObject( theFather );
1098 _PTR(SObject) SObj ( aDStudy->FindObjectIOR( IOR.toLatin1().constData() ) );
1100 bool inStudy = false;
1101 GEOM::GEOM_Object_var aReturnObject;
1102 for (_PTR(ChildIterator) iit (aDStudy->NewChildIterator( SObj )); iit->More() && !inStudy; iit->Next()) {
1103 _PTR(SObject) child (iit->Value());
1104 QString aChildName = child->GetName().c_str();
1105 if (aChildName == theName) {
1107 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(iit->Value());
1108 aReturnObject = GEOM::GEOM_Object::_narrow( corbaObj );
1112 return aReturnObject._retn();
1114 return GEOM::GEOM_Object::_nil();
1117 //================================================================
1118 // Function : findObjectInFather
1119 // Purpose : It should return an object if its founded in study or
1120 // return Null object if the object is not founded
1121 //================================================================
1122 GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather( GEOM::GEOM_Object_ptr theFather,
1125 GEOM::GEOM_Object_var object;
1127 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
1129 _PTR(Study) studyDS = study->studyDS();
1130 QString IOR = GEOMBase::GetIORFromObject( theFather );
1131 _PTR(SObject) sobject( studyDS->FindObjectIOR( IOR.toLatin1().constData() ) );
1133 _PTR(ChildIterator) it( studyDS->NewChildIterator( sobject ) );
1134 for ( ; it->More(); it->Next() ) {
1135 GEOM::GEOM_Object_var cobject = GEOM::GEOM_Object::_narrow( GeometryGUI::ClientSObjectToObject( it->Value() ) );
1136 if ( !CORBA::is_nil( cobject ) ) {
1137 GEOM::ListOfLong_var indices = cobject->GetSubShapeIndices();
1138 int length = indices->length();
1139 // VSR 18/03/2014: we need only sub-shapes with single sub-shape index (to exclude groups, etc)
1140 if ( length == 1 && indices[0] == theIndex ) {
1149 return object._retn();
1152 //================================================================
1153 // Function : addSubshapesToStudy
1154 // Purpose : Virtual method to add sub-shapes if needs
1155 //================================================================
1156 void GEOMBase_Helper::addSubshapesToStudy()
1158 //Impemented in Dialogs, called from Accept method
1161 //================================================================
1162 // Function : getSelected
1163 // Purpose : Get selected object by specified type
1165 // Returns valid object if only one object of the specified type is selected
1166 // (no matter global or local selection is activated). If \a type is TopAbs_SHAPE,
1167 // geometrical object of any valid type is expected.
1169 // \param type type of the object 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( TopAbs_ShapeEnum type )
1174 QList<TopAbs_ShapeEnum> types;
1176 return getSelected( types );
1179 //================================================================
1180 // Function : getSelected
1181 // Purpose : Get selected object by specified types
1183 // Returns valid object if only one object of the specified type is selected
1184 // (no matter global or local selection is activated). The list of allowed
1185 // shape types is passed via \a types. If \a types includes TopAbs_SHAPE,
1186 // geometrical object of any valid type is expected.
1188 // \param types list of allowed shape types for the objects to be obtained from selection
1189 // \return selected geometrical object or nil object if selection is not satisfactory
1190 //================================================================
1191 GEOM::GeomObjPtr GEOMBase_Helper::getSelected( const QList<TopAbs_ShapeEnum>& types )
1193 QList<GEOM::GeomObjPtr> selected = getSelected( types, 1 );
1194 return selected.count() > 0 ? selected[0] : GEOM::GeomObjPtr();
1197 //================================================================
1198 // Function : getSelected
1199 // Purpose : Get selected object(s) by specified type
1201 // Returns list of selected objects if selection satisfies specifies selection options.
1202 // (no matter global or local selection is activated). If \a type is TopAbs_SHAPE,
1203 // geometrical objects of any valid type are expected.
1205 // The \a type parameter specifies allowed type of the object(s) being selected.
1206 // The \a count parameter specifies exact number of the objects to be retrieved from selection.
1207 // The \a strict parameter specifies policy being applied to the selection.
1208 // If \a count < 0, then any number of the selected objects is valid (including 0).
1209 // In this case, if \a strict is \c true (default), all selected objects should satisfy
1210 // the specified \a type.
1211 // If \a count > 0, only specified number of the objects is retrieved from the selection.
1212 // In this case, if \a strict is \c true (default), function returns empty list if total number of selected
1213 // objects does not correspond to the \a count parameter. Otherwise (if \a strict is \c false),
1214 // function returns valid list of objects if at least \a count objects satisfy specified \a type.
1216 // \param type type of the object(s) to be obtained from selection
1217 // \param count number of items to be retrieved from selection
1218 // \param strict selection policy
1219 // \return list of selected geometrical objects or empty list if selection is not satisfactory
1220 //================================================================
1221 QList<GEOM::GeomObjPtr> GEOMBase_Helper::getSelected( TopAbs_ShapeEnum type, int count, bool strict )
1223 QList<TopAbs_ShapeEnum> types;
1225 return getSelected( types, count, strict );
1228 static bool typeInList( TopAbs_ShapeEnum type, const QList<TopAbs_ShapeEnum>& types )
1231 for ( int i = 0; i < types.count() && !ok; i++ )
1232 ok = types[i] == TopAbs_SHAPE || types[i] == type;
1236 //================================================================
1237 // Function : getSelected
1238 // Purpose : Get selected objects by specified types
1240 // Returns list of selected objects if selection satisfies specifies selection options.
1241 // (no matter global or local selection is activated). If \a types includes TopAbs_SHAPE,
1242 // geometrical objects of any valid type are expected.
1244 // The \a types parameter specifies allowed types of the object(s) being selected.
1245 // The \a count parameter specifies exact number of the objects to be retrieved from selection.
1246 // The \a strict parameter specifies policy being applied to the selection.
1247 // If \a count < 0, then any number of the selected objects is valid (including 0).
1248 // In this case, if \a strict is \c true (default), all selected objects should satisfy
1249 // the specified \a type.
1250 // If \a count > 0, only specified number of the objects is retrieved from the selection.
1251 // In this case, if \a strict is \c true (default), function returns empty list if total number of selected
1252 // objects does not correspond to the \a count parameter. Otherwise (if \a strict is \c false),
1253 // function returns valid list of objects if at least \a count objects satisfy specified \a type.
1255 // \param types list of allowed shape types for the objects to be obtained from selection
1256 // \param count number of items to be retrieved from selection
1257 // \param strict selection policy
1258 // \return list of selected geometrical objects or empty list if selection is not satisfactory
1259 //================================================================
1260 QList<GEOM::GeomObjPtr> GEOMBase_Helper::getSelected( const QList<TopAbs_ShapeEnum>& types, int count, bool strict )
1262 SUIT_Session* session = SUIT_Session::session();
1263 QList<GEOM::GeomObjPtr> result;
1265 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1267 LightApp_SelectionMgr* selMgr = app->selectionMgr();
1269 SALOME_ListIO selected;
1270 selMgr->selectedObjects( selected );
1271 SALOME_ListIteratorOfListIO it( selected );
1272 bool stopped = false;
1273 for ( ; it.More() && !stopped; it.Next() ) {
1274 Handle(SALOME_InteractiveObject) IO = it.Value();
1275 GEOM::GeomObjPtr object = GEOMBase::ConvertIOinGEOMObject( IO );
1277 TColStd_IndexedMapOfInteger subShapes;
1278 selMgr->GetIndexes( IO, subShapes );
1279 int nbSubShapes = subShapes.Extent();
1280 if ( nbSubShapes == 0 ) {
1282 if ( typeInList( (TopAbs_ShapeEnum)(object->GetShapeType()), types ) ) {
1285 if ( strict && result.count() > count ) {
1289 else if ( !strict && result.count() == count )
1293 else if ( strict ) {
1300 for ( int i = 1; i <= nbSubShapes && !stopped; i++ ) {
1301 int idx = subShapes( i );
1302 GEOM::GeomObjPtr subShape = findObjectInFather( object.get(), idx );
1304 // sub-shape is not yet published in the study
1305 GEOM::ShapesOpPtr shapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
1306 subShape.take( shapesOp->GetSubShape( object.get(), idx ) ); // take ownership!
1308 if ( typeInList( (TopAbs_ShapeEnum)(subShape->GetShapeType()), types ) ) {
1311 if ( strict && result.count() > count ) {
1315 else if ( !strict && result.count() == count )
1319 else if ( strict ) {
1332 //================================================================
1333 // Function : setIsApplyAndClose
1334 // Purpose : Set value of the flag indicating that the dialog is
1335 // accepted by Apply & Close button
1336 //================================================================
1337 void GEOMBase_Helper::setIsApplyAndClose( const bool theFlag )
1339 myIsApplyAndClose = theFlag;
1342 //================================================================
1343 // Function : isApplyAndClose
1344 // Purpose : Get value of the flag indicating that the dialog is
1345 // accepted by Apply & Close button
1346 //================================================================
1347 bool GEOMBase_Helper::isApplyAndClose() const
1349 return myIsApplyAndClose;
1352 //================================================================
1353 // Function : setIsOptimizedBrowsing
1354 // Purpose : Set value of the flag switching to optimized
1355 // browsing mode (to select the first published
1357 //================================================================
1358 void GEOMBase_Helper::setIsOptimizedBrowsing( const bool theFlag )
1360 myIsOptimizedBrowsing = theFlag;
1363 //================================================================
1364 // Function : isOptimizedBrowsing
1365 // Purpose : Get value of the flag switching to optimized
1366 // browsing mode (to select the first published
1368 //================================================================
1369 bool GEOMBase_Helper::isOptimizedBrowsing() const
1371 return myIsOptimizedBrowsing;