1 // Copyright (C) 2007-2015 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_ListIO.hxx>
49 #include "utilities.h"
51 #include <SALOME_Prs.h>
52 #include "utilities.h"
54 #include <OCCViewer_ViewModel.h>
55 #include <SVTK_ViewModel.h>
57 #include <TColStd_MapOfInteger.hxx>
58 #include <TCollection_AsciiString.hxx>
59 #include <TColStd_IndexedMapOfInteger.hxx>
61 //To disable automatic genericobj management, the following line should be commented.
62 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
63 #define WITHGENERICOBJ
65 //================================================================
66 // Function : getActiveView
67 // Purpose : Get active view window, returns 0 if no open study frame
68 //================================================================
69 SUIT_ViewWindow* GEOMBase_Helper::getActiveView()
71 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
73 return SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
79 //================================================================
80 // Function : getGeomEngine
81 // Purpose : Static method
82 //================================================================
83 GEOM::GEOM_Gen_ptr GEOMBase_Helper::getGeomEngine()
85 return GeometryGUI::GetGeomGen();
88 //================================================================
89 // Function : GEOMBase_Helper
91 //================================================================
92 GEOMBase_Helper::GEOMBase_Helper( SUIT_Desktop* desktop )
93 : myDesktop( desktop ), myViewWindow( 0 ), myDisplayer( 0 ), myCommand( 0 ), isPreview( false ),
94 myIsApplyAndClose( false ), myIsOptimizedBrowsing( false ), myIsWaitCursorEnabled( true ),
95 myIsDisableBrowsing(false), myIsDisplayResult(true)
99 //================================================================
100 // Function : ~GEOMBase_Helper
102 //================================================================
103 GEOMBase_Helper::~GEOMBase_Helper()
105 //rnv: Fix for the "IPAL21922 : WinTC5.1.4: incorrect quit salome"
106 if ( !SUIT_Session::session()->activeApplication() || !SUIT_Session::session()->activeApplication()->desktop() )
109 if ( myPreview.size() )
113 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
115 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
117 globalSelection(aGeomGUI->getLocalSelectionMode() , true );
122 if ( !CORBA::is_nil( myOperation ) )
123 myOperation->UnRegister();
126 //================================================================
127 // Function : display
129 //================================================================
130 void GEOMBase_Helper::display( const ObjectList& objList, const bool updateView )
132 ObjectList::const_iterator it;
133 for ( it = objList.begin(); it != objList.end(); it++ ) {
134 display( *it, false );
136 if ( !objList.empty() && updateView )
137 getDisplayer()->UpdateViewer();
140 //================================================================
141 // Function : display
142 // Purpose : Display object.
143 // Important : Object must be already in study
144 //================================================================
145 void GEOMBase_Helper::display( GEOM::GEOM_Object_ptr object, const bool updateView )
147 // Unset color of shape ( this color may be set during preview displaying )
148 // Default color will be used
149 // getDisplayer()->UnsetColor();
150 getDisplayer()->UnsetWidth();
152 MESSAGE("GEOMBase_Helper::display myTexture = "<<getDisplayer()->GetTexture())
154 // Enable activisation of selection
155 getDisplayer()->SetToActivate( true );
158 getDisplayer()->Display( object, updateView );
161 //================================================================
164 //================================================================
165 void GEOMBase_Helper::erase( const ObjectList& objList, const bool updateView )
167 ObjectList::const_iterator it = objList.begin();
168 for ( ; it != objList.end(); it++ ) {
171 if ( !objList.empty() && updateView )
172 getDisplayer()->UpdateViewer();
175 //================================================================
178 //================================================================
179 void GEOMBase_Helper::erase( GEOM::GEOM_Object_ptr object, const bool updateView )
181 if ( !object->_is_nil() ) {
182 QString entry = getEntry( object );
183 getDisplayer()->Erase( new SALOME_InteractiveObject(
184 entry.toLatin1().constData(),
185 "GEOM", strdup( GEOMBase::GetName( object ).toLatin1().constData() ) ), true, updateView );
189 //================================================================
190 // Function : redisplay
192 //================================================================
193 void GEOMBase_Helper::redisplay( const ObjectList& objList,
194 const bool withChildren,
195 const bool updateView )
197 ObjectList::const_iterator it = objList.begin();
198 for ( ; it != objList.end(); it++ ) {
199 redisplay( *it, withChildren, false );
201 if ( !objList.empty() && updateView )
202 getDisplayer()->UpdateViewer();
205 //================================================================
206 // Function : redisplay
208 //================================================================
209 void GEOMBase_Helper::redisplay( GEOM::GEOM_Object_ptr object,
210 const bool withChildren,
211 const bool updateView )
213 if ( !object->_is_nil() ) {
214 // Unset color of shape ( this color may be set during preview displaying )
215 // Default color will be used
216 getDisplayer()->UnsetColor();
217 getDisplayer()->UnsetWidth();
219 // Enable activisation of selection
220 getDisplayer()->SetToActivate( true );
222 QString entry = getEntry( object );
223 getDisplayer()->Redisplay(new SALOME_InteractiveObject
224 (entry.toLatin1().constData(), "GEOM", strdup(GEOMBase::GetName(object).toLatin1().constData())), false);
227 if ( withChildren ) {
228 SalomeApp_Study* aDoc = getStudy();
229 if ( aDoc && aDoc->studyDS() ) {
230 _PTR(Study) aStudy = aDoc->studyDS();
231 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string(object);
232 _PTR(SObject) aSObj (aStudy->FindObjectIOR(std::string(objStr.in())));
234 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
235 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
236 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow
237 (GeometryGUI::ClientSObjectToObject(anIt->Value()));
238 if ( !CORBA::is_nil( aChild ) ) {
239 if ( !aChild->_is_nil() ) {
240 QString entry = getEntry( aChild );
241 getDisplayer()->Redisplay( new SALOME_InteractiveObject(
242 entry.toLatin1().constData(), "GEOM", strdup( GEOMBase::GetName( aChild ).toLatin1().constData() ) ), false );
251 getDisplayer()->UpdateViewer();
254 //================================================================
255 // Function : displayPreview
256 // Purpose : Method for displaying preview based on execute() results
257 //================================================================
258 void GEOMBase_Helper::displayPreview( const bool display,
261 const bool toRemoveFromEngine,
262 const double lineWidth,
263 const int displayMode,
268 erasePreview( update );
274 if ( !isValid( msg ) )
276 erasePreview( update );
282 erasePreview( false );
285 SUIT_OverrideCursor wc;
288 if ( !isWaitCursorEnabled() )
291 if ( !execute( objects ) || !getOperation()->IsDone() ) {
295 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it )
297 GEOM::GEOM_Object_var obj=*it;
298 displayPreview( obj, true, activate, false, lineWidth, displayMode, color );
299 if ( toRemoveFromEngine )
304 catch( const SALOME::SALOME_Exception& e ) {
305 SalomeApp_Tools::QtCatchCorbaException( e );
314 //================================================================
315 // Function : displayPreview
316 // Purpose : Method for displaying preview of resulting shape
317 //================================================================
318 void GEOMBase_Helper::displayPreview( GEOM::GEOM_Object_ptr object,
322 const double lineWidth,
323 const int displayMode,
326 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
328 // Set color for preview shape
329 getDisplayer()->SetColor( color == -1 ? Quantity_NOC_VIOLET : color );
331 // set width of displayed shape
332 getDisplayer()->SetWidth( lineWidth == -1 ? resMgr->integerValue("Geometry", "preview_edge_width", -1) : lineWidth );
334 // set display mode of displayed shape
335 int aPrevDispMode = getDisplayer()->SetDisplayMode( displayMode == -1 ? resMgr->integerValue( "Geometry", "display_mode", 0 ) : displayMode );
337 // Disable activation of selection
338 getDisplayer()->SetToActivate( activate );
340 // Make a reference to GEOM_Object
341 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string( object );
342 getDisplayer()->SetName( objStr.in() );
345 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( object );
346 if ( aPrs == 0 || aPrs->IsNull() )
349 // Make preview not clippable
350 aPrs->SetClippable (false);
353 displayPreview( aPrs, append, update );
355 getDisplayer()->UnsetName();
356 getDisplayer()->UnsetColor();
357 getDisplayer()->SetDisplayMode( aPrevDispMode );
359 // Enable activation of displayed objects
360 getDisplayer()->SetToActivate( true );
363 //================================================================
364 // Function : displayPreview
365 // Purpose : Method for displaying arbitrary preview objects (not limited to shapes)
366 //================================================================
367 void GEOMBase_Helper::displayPreview( const SALOME_Prs* prs,
372 erasePreview( false );
374 // remember current view frame to make correct erase preview later
375 myViewWindow = getActiveView();
377 if ( myViewWindow == 0 )
381 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
382 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
383 aViewManager->getType() == SVTK_Viewer::Type() )
385 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
386 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
388 aView->Display( getDisplayer(), prs );
391 // Add prs to the preview list
392 myPreview.push_back( (SALOME_Prs*)prs );
396 getDisplayer()->UpdateViewer();
399 //================================================================
400 // Function : erasePreview
402 //================================================================
403 void GEOMBase_Helper::erasePreview( const bool update )
405 // check view frame where the preview was displayed
406 bool vfOK = checkViewWindow() && myViewWindow;
407 // Iterate through presentations and delete them
408 for ( PrsList::iterator anIter = myPreview.begin(); anIter != myPreview.end(); ++anIter )
412 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
413 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
414 aViewManager->getType() == SVTK_Viewer::Type() )
416 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
417 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
419 aView->Erase( getDisplayer(), *anIter, true );
431 //================================================================
432 // Function : localSelection
433 // Purpose : Activate selection of objects of a given type
434 // IMPORTANT : Works after localSelection( ... ) method call only
435 //================================================================
436 void GEOMBase_Helper::activate( const int theType )
438 if (!getStudy()) return;
439 _PTR(Study) aStudy = getStudy()->studyDS();
440 _PTR(SComponent) aGeom ( aStudy->FindComponent( "GEOM" ) );
445 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( aGeom ) );
446 for ( ; anIter->More(); anIter->Next() )
448 _PTR(SObject) aSO ( anIter->Value() );
451 _PTR(SObject) aRefSO;
452 if ( !aSO->ReferencedObject( aRefSO ) )
454 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow
455 (GeometryGUI::ClientSObjectToObject(aSO));
456 if ( !anObj->_is_nil() && anObj->GetType() == theType )
457 aList.Append( new SALOME_InteractiveObject( aSO->GetID().c_str(), "GEOM", aSO->GetName().c_str()) );
462 getDisplayer()->LocalSelection( aList, 0 );
465 //================================================================
466 // Function : localSelection
467 // Purpose : Activate selection of sub-shapes in accordance with mode
468 // modes are from TopAbs_ShapeEnum
469 //================================================================
470 void GEOMBase_Helper::localSelection( const ObjectList& theObjs, const std::list<int> modes )
472 SALOME_ListIO aListOfIO;
474 ObjectList::const_iterator anIter = theObjs.begin();
475 for ( ; anIter != theObjs.end(); ++anIter )
477 GEOM::GEOM_Object_ptr anObj = *anIter;
478 if ( anObj->_is_nil() )
480 QString anEntry = getEntry( anObj );
482 aListOfIO.Append( new SALOME_InteractiveObject(
483 anEntry.toLatin1().constData(), "GEOM", strdup( GEOMBase::GetName( anObj ).toLatin1().constData() ) ) );
486 getDisplayer()->LocalSelection( aListOfIO, modes );
489 //================================================================
490 // Function : localSelection
491 // Purpose : Activate selection of sub-shapes in accordance with mode
492 // theMode is from TopAbs_ShapeEnum
493 //================================================================
494 void GEOMBase_Helper::localSelection( const ObjectList& theObjs, const int theMode )
496 std::list<int> modes;
497 modes.push_back( theMode );
498 localSelection( theObjs, modes );
501 //================================================================
502 // Function : localSelection
503 // Purpose : Activate selection of sub-shapes in accordance with mode
504 // modes are from TopAbs_ShapeEnum
505 //================================================================
506 void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const std::list<int> modes )
508 // If object is null local selection for all objects is activated
509 if ( obj->_is_nil() ) {
510 getDisplayer()->LocalSelection( Handle(SALOME_InteractiveObject)(), modes );
515 objList.push_back( obj );
516 localSelection( objList, modes );
519 //================================================================
520 // Function : localSelection
521 // Purpose : Activate selection of sub-shapes in accordance with mode
522 // mode is from TopAbs_ShapeEnum
523 //================================================================
524 void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const int mode )
526 std::list<int> modes;
527 modes.push_back( mode );
528 localSelection( obj, modes );
531 //================================================================
532 // Function : globalSelection
533 // Purpose : Activate selection of sub-shapes. Set selection filters
534 // in accordance with mode. theMode is from GEOMImpl_Types
535 //================================================================
536 void GEOMBase_Helper::globalSelection( const int theMode, const bool update )
538 getDisplayer()->GlobalSelection( theMode, update );
541 //================================================================
542 // Function : globalSelection
543 // Purpose : Activate selection of sub-shapes. Set selection filters
544 // in accordance with mode. theMode is from GEOMImpl_Types
545 //================================================================
546 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
549 getDisplayer()->GlobalSelection( theModes, update );
552 //================================================================
553 // Function : globalSelection
554 // Purpose : Activate selection of sub-shapes. Set selection filters
555 // in accordance with mode. theMode is from GEOMImpl_Types
556 //================================================================
557 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
558 const QList<int>& subShapes,
561 getDisplayer()->GlobalSelection( theModes, update, &subShapes );
564 //================================================================
565 // Function : addInStudy
566 // Purpose : Add object in study
567 //================================================================
568 QString GEOMBase_Helper::addInStudy( GEOM::GEOM_Object_ptr theObj, const char* theName )
573 _PTR(Study) aStudy = getStudy()->studyDS();
574 if ( !aStudy || theObj->_is_nil() )
577 SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy(aStudy);
579 GEOM::GEOM_Object_ptr aFatherObj = getFather( theObj );
581 SALOMEDS::SObject_var aSO =
582 getGeomEngine()->AddInStudy(aStudyDS, theObj, theName, aFatherObj);
585 if ( !aSO->_is_nil() ) {
586 CORBA::String_var entry = aSO->GetID();
587 anEntry = entry.in();
589 // Each dialog is responsible for this method implementation,
590 // default implementation does nothing
591 restoreSubShapes(aStudyDS, aSO);
597 //================================================================
598 // Function : restoreSubShapes
599 // Purpose : restore tree of argument's sub-shapes under the resulting shape
600 //================================================================
601 void GEOMBase_Helper::restoreSubShapes (SALOMEDS::Study_ptr /*theStudy*/,
602 SALOMEDS::SObject_ptr /*theSObject*/)
604 // do nothing by default
606 // example of implementation in particular dialog:
607 // GEOM::ListOfGO anArgs;
608 // anArgs.length(0); // empty list means that all arguments should be restored
609 // getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
610 // /*theFindMethod=*/GEOM::FSM_GetInPlace,
611 // /*theInheritFirstArg=*/false);
614 //================================================================
615 // Function : updateObjBrowser
616 // Purpose : Update object browser
617 //================================================================
618 void GEOMBase_Helper::updateObjBrowser() const
620 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
622 CAM_Module* module = app->module( "Geometry" );
623 SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
625 appMod->updateObjBrowser( true );
630 //================================================================
631 // Function : updateViewer
632 // Purpose : Update active 3D view
633 //================================================================
634 void GEOMBase_Helper::updateViewer()
636 getDisplayer()->UpdateViewer();
639 //================================================================
640 // Function : getStudyId
641 // Purpose : Get study Id
642 //================================================================
643 int GEOMBase_Helper::getStudyId() const
647 anId = getStudy()->id();
651 //================================================================
652 // Function : getStudy
653 // Purpose : Returns the active study. It is recommended to use
654 // this method instead of direct desktop->getActiveStudy() calls
655 //================================================================
656 SalomeApp_Study* GEOMBase_Helper::getStudy() const
658 SUIT_Desktop* aDesktop = getDesktop();
662 QList<SUIT_Application*> anAppList = SUIT_Session::session()->applications();
664 SUIT_Application* anApp = 0;
665 QListIterator<SUIT_Application*> it( anAppList );
666 while ( it.hasNext() )
669 if ( anApp && anApp->desktop() == aDesktop )
673 return dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
676 //================================================================
677 // Function : getEntry
679 //================================================================
680 QString GEOMBase_Helper::getEntry( GEOM::GEOM_Object_ptr object ) const
682 SalomeApp_Study* study = getStudy();
684 QString objIOR = GEOMBase::GetIORFromObject( object );
685 if ( objIOR != "" ) {
686 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( objIOR.toLatin1().constData() ) );
688 return QString::fromStdString(SO->GetID());
694 //================================================================
695 // Function : getDisplayer
697 //================================================================
698 GEOM_Displayer* GEOMBase_Helper::getDisplayer()
701 myDisplayer = new GEOM_Displayer( getStudy() );
705 //================================================================
706 // Function : clearShapeBuffer
708 //================================================================
709 void GEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
711 GeometryGUI::ClearShapeBuffer(theObj);
714 //================================================================
715 // Function : openCommand
717 //================================================================
718 bool GEOMBase_Helper::openCommand()
721 if ( !getStudy() || hasCommand() )
723 MESSAGE("Getting out from openCommand()")
727 GEOM::GEOM_IOperations_var anOp = GEOM::GEOM_IOperations::_narrow( getOperation() );
728 if ( !anOp->_is_nil() ) {
729 myCommand = new GEOM_Operation( SUIT_Session::session()->activeApplication(), anOp.in() );
735 MESSAGE("anOp->_is_nil() = true")
741 //================================================================
742 // Function : abortCommand
744 //================================================================
745 bool GEOMBase_Helper::abortCommand()
751 delete myCommand; // I don't know where to delete this object here ?
757 //================================================================
758 // Function : commitCommand
760 //================================================================
761 bool GEOMBase_Helper::commitCommand( const char* )
767 delete myCommand; // I don't know where to delete this object here ?
773 //================================================================
774 // Function : hasCommand
776 //================================================================
777 bool GEOMBase_Helper::hasCommand() const
779 return (bool)myCommand;
782 //================================================================
783 // Function : getOperation
785 //================================================================
786 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::getOperation()
788 if ( myOperation->_is_nil() )
789 myOperation = createOperation();
796 //================================================================
797 // Function : checkViewWindow
799 //================================================================
800 bool GEOMBase_Helper::checkViewWindow()
803 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
804 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
805 while ( it.hasNext() )
807 if ( myViewWindow == it.next() )
815 //================================================================
816 // Function : onAccept
817 // Purpose : This method should be called from dialog's slots onOk() and onApply()
818 // It perfroms user input validation, then it
819 // performs a proper operation and manages transactions, etc.
820 //================================================================
821 bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction, bool erasePreviewFlag )
823 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
826 MESSAGE("appStudy is empty")
829 _PTR(Study) aStudy = appStudy->studyDS();
831 bool aLocked = (_PTR(AttributeStudyProperties) (aStudy->GetProperties()))->IsLocked();
833 MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
834 SUIT_MessageBox::warning ( (QWidget*)SUIT_Session::session()->activeApplication()->desktop(),
835 QObject::tr("WRN_WARNING"),
836 QObject::tr("WRN_STUDY_LOCKED"),
837 QObject::tr("BUT_OK") );
842 if ( !isValid( msg ) ) {
848 erasePreview( false );
853 if ( ( !publish && !useTransaction ) || openCommand() ) {
854 SUIT_OverrideCursor wc;
855 SUIT_Session::session()->activeApplication()->putInfo( "" );
857 if ( !execute( objects ) || !getOperation()->IsDone() ) {
863 QList<GEOM::GeomObjPtr> anObjectList = getSourceObjects( );
864 addSubshapesToStudy(); // add Sub-shapes if local selection
865 const int nbObjs = objects.size();
866 QStringList anEntryList;
867 int currObj = 1, aNumber = 1;
868 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it, currObj++ ) {
869 GEOM::GEOM_Object_var obj=*it;
871 QString aName = getObjectName(obj);
872 if (aName.isEmpty()) {
873 aName = getNewObjectName(currObj);
876 aName = getPrefix(obj);
878 // Try to find a unique name
879 aName = GEOMBase::GetDefaultName(aName, extractPrefix());
881 // Don't check name uniqueness in case of numerous objects
882 aName = aName + "_" + QString::number(aNumber++);
885 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
886 if ( aName.isEmpty() )
887 aName = GEOMBase::GetDefaultName( getPrefix( obj ) );
890 anEntryList << addInStudy( obj, aName.toLatin1().constData() );
892 if( isDisplayResult() )
893 display( obj, false );
894 #ifdef WITHGENERICOBJ
895 // obj has been published in study. Its refcount has been incremented.
896 // It is safe to decrement its refcount
897 // so that it will be destroyed when the entry in study will be removed
902 // asv : fix of PAL6454. If publish==false, then the original shape
903 // was modified, and need to be re-cached in GEOM_Client before redisplay
904 clearShapeBuffer( obj );
905 // withChildren=true, updateView=false
906 if( isDisplayResult() )
907 redisplay( obj, true, false );
914 if( SUIT_Application* anApp = SUIT_Session::session()->activeApplication() ) {
915 LightApp_Application* aLightApp = dynamic_cast<LightApp_Application*>( anApp );
917 QString anOpName( typeid(*this).name() );
918 aLightApp->emitOperationFinished( "Geometry", anOpName, anEntryList );
920 if ( !isDisableBrowsing() )
921 aLightApp->browseObjects( anEntryList, isApplyAndClose(), isOptimizedBrowsing() );
923 anApp->putInfo( QObject::tr("GEOM_PRP_DONE") );
925 if ( anObjectList.count() > 0 )
926 hideSourceObjects( anObjectList );
934 catch( const SALOME::SALOME_Exception& e ) {
935 SalomeApp_Tools::QtCatchCorbaException( e );
937 MESSAGE("Exception catched")
942 MESSAGE("result ="<<result)
947 //================================================================
948 // Function : showError
949 // Purpose : Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
950 //================================================================
951 void GEOMBase_Helper::showError()
954 if ( !getOperation()->_is_nil() )
955 msg = QObject::tr( getOperation()->GetErrorCode() );
958 msg = QObject::tr( "GEOM_PRP_ABORT" );
960 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
961 QObject::tr( "GEOM_ERROR_STATUS" ),
963 QObject::tr( "BUT_OK" ) );
966 //================================================================
967 // Function : showError
968 // Purpose : Shows a error message followed by <msg>
969 //================================================================
970 void GEOMBase_Helper::showError( const QString& msg )
972 QString str( QObject::tr( "GEOM_INCORRECT_INPUT" ) );
973 if ( !msg.isEmpty() )
975 SUIT_MessageBox::critical(SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ), str, QObject::tr( "BUT_OK" ) );
978 //////////////////////////////////////////////////////////////////
979 // Virtual methods to be redefined in dialogs
980 //////////////////////////////////////////////////////////////////
982 //================================================================
983 // Function : createOperation
984 // Purpose : Redefine this method to return proper IOperation reference
985 //================================================================
986 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::createOperation()
988 GEOM::GEOM_IOperations_var aNilOp;
989 return aNilOp._retn();
992 //================================================================
993 // Function : isValid
994 // Purpose : Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
995 //================================================================
996 bool GEOMBase_Helper::isValid( QString& )
1001 //================================================================
1002 // Function : execute
1003 // Purpose : This method is called by onAccept().
1004 // It should perform the required operation and put all new or modified objects into
1005 // <objects> argument.Should return <false> if some error occurs during its execution.
1006 //================================================================
1007 bool GEOMBase_Helper::execute( ObjectList& objects )
1012 //================================================================
1013 // Function : getFather
1014 // Purpose : This method is called by addInStudy(). It should return a father object
1015 // for <theObj> or a nil reference if <theObj> should be published
1016 // as a top-level object.
1017 //================================================================
1018 GEOM::GEOM_Object_ptr GEOMBase_Helper::getFather( GEOM::GEOM_Object_ptr theObj )
1020 return GEOM::GEOM_Object::_nil();
1023 //================================================================
1024 // Function : getObjectName
1025 // Purpose : Redefine this method to return proper name for the given object
1026 //================================================================
1027 QString GEOMBase_Helper::getObjectName(GEOM::GEOM_Object_ptr object) const
1032 //================================================================
1033 // Function : getNewObjectName
1034 // Purpose : Redefine this method to return proper name for a new object
1035 //================================================================
1036 QString GEOMBase_Helper::getNewObjectName (int) const
1041 //================================================================
1042 // Function : extractPrefix
1043 // Purpose : Redefine this method to return \c true if necessary
1044 // to extract prefix when generating new name for the
1045 // object(s) being created
1046 //================================================================
1047 bool GEOMBase_Helper::extractPrefix() const
1052 //================================================================
1053 // Function : getPrefix
1054 // Purpose : Get prefix for name of created object
1055 //================================================================
1056 QString GEOMBase_Helper::getPrefix( GEOM::GEOM_Object_ptr theObj ) const
1058 if ( !myPrefix.isEmpty() || theObj->_is_nil() )
1061 GEOM::shape_type aType = theObj->GetShapeType();
1065 case GEOM::VERTEX : return QObject::tr( "GEOM_VERTEX" );
1066 case GEOM::EDGE : return QObject::tr( "GEOM_EDGE" );
1067 case GEOM::WIRE : return QObject::tr( "GEOM_WIRE" );
1068 case GEOM::FACE : return QObject::tr( "GEOM_FACE" );
1069 case GEOM::SHELL : return QObject::tr( "GEOM_SHELL" );
1070 case GEOM::SOLID : return QObject::tr( "GEOM_SOLID" );
1071 case GEOM::COMPSOLID: return QObject::tr( "GEOM_COMPOUNDSOLID" );
1072 case GEOM::COMPOUND : return QObject::tr( "GEOM_COMPOUND" );
1073 default : return "";
1077 //================================================================
1078 // Function : getDesktop
1079 // Purpose : Returns myDesktop field. Initialized in constructor,
1080 // usually as dynamic_cast<SUIT_Desktop*>(parentWidget())
1081 //================================================================
1082 SUIT_Desktop* GEOMBase_Helper::getDesktop() const
1087 //================================================================
1088 // Function : selectObjects
1089 // Purpose : Selects list of objects
1090 //================================================================
1091 bool GEOMBase_Helper::selectObjects( ObjectList& objects )
1093 SUIT_DataOwnerPtrList aList;
1094 ObjectList::iterator anIter;
1095 for ( anIter = objects.begin(); anIter != objects.end(); ++anIter )
1097 QString anEntry = getEntry( *anIter );
1098 LightApp_DataOwner* anOwher = new LightApp_DataOwner( anEntry );
1099 aList.append( anOwher );
1102 SUIT_Session* session = SUIT_Session::session();
1103 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1107 LightApp_SelectionMgr* aMgr = app->selectionMgr();
1111 aMgr->setSelected( aList, false );
1116 //================================================================
1117 // Function : findObjectInFather
1118 // Purpose : It should return an object if its founded in study or
1119 // return Null object if the object is not founded
1120 //================================================================
1121 GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather (GEOM::GEOM_Object_ptr theFather,
1122 const QString& theName)
1124 SalomeApp_Application* app =
1125 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1126 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1127 _PTR(Study) aDStudy = appStudy->studyDS();
1128 QString IOR = GEOMBase::GetIORFromObject( theFather );
1129 _PTR(SObject) SObj ( aDStudy->FindObjectIOR( IOR.toLatin1().constData() ) );
1131 bool inStudy = false;
1132 GEOM::GEOM_Object_var aReturnObject;
1133 for (_PTR(ChildIterator) iit (aDStudy->NewChildIterator( SObj )); iit->More() && !inStudy; iit->Next()) {
1134 _PTR(SObject) child (iit->Value());
1135 QString aChildName = child->GetName().c_str();
1136 if (aChildName == theName) {
1138 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(iit->Value());
1139 aReturnObject = GEOM::GEOM_Object::_narrow( corbaObj );
1143 return aReturnObject._retn();
1145 return GEOM::GEOM_Object::_nil();
1148 //================================================================
1149 // Function : findObjectInFather
1150 // Purpose : It should return an object if its founded in study or
1151 // return Null object if the object is not founded
1152 //================================================================
1153 GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather( GEOM::GEOM_Object_ptr theFather,
1156 GEOM::GEOM_Object_var object;
1158 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
1160 _PTR(Study) studyDS = study->studyDS();
1161 QString IOR = GEOMBase::GetIORFromObject( theFather );
1162 _PTR(SObject) sobject( studyDS->FindObjectIOR( IOR.toLatin1().constData() ) );
1164 _PTR(ChildIterator) it( studyDS->NewChildIterator( sobject ) );
1165 for ( ; it->More(); it->Next() ) {
1166 GEOM::GEOM_Object_var cobject = GEOM::GEOM_Object::_narrow( GeometryGUI::ClientSObjectToObject( it->Value() ) );
1167 if ( !CORBA::is_nil( cobject ) ) {
1168 GEOM::ListOfLong_var indices = cobject->GetSubShapeIndices();
1169 int length = indices->length();
1170 // VSR 18/03/2014: we need only sub-shapes with single sub-shape index (to exclude groups, etc)
1171 if ( length == 1 && indices[0] == theIndex ) {
1180 return object._retn();
1183 //================================================================
1184 // Function : addSubshapesToStudy
1185 // Purpose : Virtual method to add sub-shapes if needs
1186 //================================================================
1187 void GEOMBase_Helper::addSubshapesToStudy()
1189 //Impemented in Dialogs, called from Accept method
1192 //================================================================
1193 // Function : getSourceObjects
1194 // Purpose : Virtual method to get source objects
1195 //================================================================
1196 QList<GEOM::GeomObjPtr> GEOMBase_Helper::getSourceObjects()
1198 //Impemented in Dialogs, called from Accept method
1199 QList<GEOM::GeomObjPtr> res;
1203 //================================================================
1204 // Function : getSelected
1205 // Purpose : Get selected object by specified type
1207 // Returns valid object if only one object of the specified type is selected
1208 // (no matter global or local selection is activated). If \a type is TopAbs_SHAPE,
1209 // geometrical object of any valid type is expected.
1211 // \param type type of the object to be obtained from selection
1212 // \return selected geometrical object or nil object if selection is not satisfactory
1213 //================================================================
1214 GEOM::GeomObjPtr GEOMBase_Helper::getSelected( TopAbs_ShapeEnum type )
1216 QList<TopAbs_ShapeEnum> types;
1218 return getSelected( types );
1221 //================================================================
1222 // Function : getSelected
1223 // Purpose : Get selected object by specified types
1225 // Returns valid object if only one object of the specified type is selected
1226 // (no matter global or local selection is activated). The list of allowed
1227 // shape types is passed via \a types. If \a types includes TopAbs_SHAPE,
1228 // geometrical object of any valid type is expected.
1230 // \param types list of allowed shape types for the objects to be obtained from selection
1231 // \return selected geometrical object or nil object if selection is not satisfactory
1232 //================================================================
1233 GEOM::GeomObjPtr GEOMBase_Helper::getSelected( const QList<TopAbs_ShapeEnum>& types )
1235 QList<GEOM::GeomObjPtr> selected = getSelected( types, 1 );
1236 return selected.count() > 0 ? selected[0] : GEOM::GeomObjPtr();
1239 //================================================================
1240 // Function : getSelected
1241 // Purpose : Get selected object(s) by specified type
1243 // Returns list of selected objects if selection satisfies specifies selection options.
1244 // (no matter global or local selection is activated). If \a type is TopAbs_SHAPE,
1245 // geometrical objects of any valid type are expected.
1247 // The \a type parameter specifies allowed type of the object(s) being selected.
1248 // The \a count parameter specifies exact number of the objects to be retrieved from selection.
1249 // The \a strict parameter specifies policy being applied to the selection.
1250 // If \a count < 0, then any number of the selected objects is valid (including 0).
1251 // In this case, if \a strict is \c true (default), all selected objects should satisfy
1252 // the specified \a type.
1253 // If \a count > 0, only specified number of the objects is retrieved from the selection.
1254 // In this case, if \a strict is \c true (default), function returns empty list if total number of selected
1255 // objects does not correspond to the \a count parameter. Otherwise (if \a strict is \c false),
1256 // function returns valid list of objects if at least \a count objects satisfy specified \a type.
1258 // \param type type of the object(s) to be obtained from selection
1259 // \param count number of items to be retrieved from selection
1260 // \param strict selection policy
1261 // \return list of selected geometrical objects or empty list if selection is not satisfactory
1262 //================================================================
1263 QList<GEOM::GeomObjPtr> GEOMBase_Helper::getSelected( TopAbs_ShapeEnum type, int count, bool strict )
1265 QList<TopAbs_ShapeEnum> types;
1267 return getSelected( types, count, strict );
1270 static bool typeInList( TopAbs_ShapeEnum type, const QList<TopAbs_ShapeEnum>& types )
1273 for ( int i = 0; i < types.count() && !ok; i++ )
1274 ok = types[i] == TopAbs_SHAPE || types[i] == type;
1278 //================================================================
1279 // Function : getSelected
1280 // Purpose : Get selected objects by specified types
1282 // Returns list of selected objects if selection satisfies specifies selection options.
1283 // (no matter global or local selection is activated). If \a types includes TopAbs_SHAPE,
1284 // geometrical objects of any valid type are expected.
1286 // The \a types parameter specifies allowed types of the object(s) being selected.
1287 // The \a count parameter specifies exact number of the objects to be retrieved from selection.
1288 // The \a strict parameter specifies policy being applied to the selection.
1289 // If \a count < 0, then any number of the selected objects is valid (including 0).
1290 // In this case, if \a strict is \c true (default), all selected objects should satisfy
1291 // the specified \a type.
1292 // If \a count > 0, only specified number of the objects is retrieved from the selection.
1293 // In this case, if \a strict is \c true (default), function returns empty list if total number of selected
1294 // objects does not correspond to the \a count parameter. Otherwise (if \a strict is \c false),
1295 // function returns valid list of objects if at least \a count objects satisfy specified \a type.
1297 // \param types list of allowed shape types for the objects to be obtained from selection
1298 // \param count number of items to be retrieved from selection
1299 // \param strict selection policy
1300 // \return list of selected geometrical objects or empty list if selection is not satisfactory
1301 //================================================================
1302 QList<GEOM::GeomObjPtr> GEOMBase_Helper::getSelected( const QList<TopAbs_ShapeEnum>& types, int count, bool strict )
1304 SUIT_Session* session = SUIT_Session::session();
1305 QList<GEOM::GeomObjPtr> result;
1307 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1309 LightApp_SelectionMgr* selMgr = app->selectionMgr();
1311 SALOME_ListIO selected;
1312 selMgr->selectedObjects( selected );
1313 SALOME_ListIteratorOfListIO it( selected );
1314 bool stopped = false;
1315 for ( ; it.More() && !stopped; it.Next() ) {
1316 Handle(SALOME_InteractiveObject) IO = it.Value();
1317 GEOM::GeomObjPtr object = GEOMBase::ConvertIOinGEOMObject( IO );
1319 TColStd_IndexedMapOfInteger subShapes;
1320 selMgr->GetIndexes( IO, subShapes );
1321 int nbSubShapes = subShapes.Extent();
1322 if ( nbSubShapes == 0 ) {
1324 if ( typeInList( (TopAbs_ShapeEnum)(object->GetShapeType()), types ) ) {
1327 if ( strict && result.count() > count ) {
1331 else if ( !strict && result.count() == count )
1335 else if ( strict ) {
1342 for ( int i = 1; i <= nbSubShapes && !stopped; i++ ) {
1343 int idx = subShapes( i );
1344 GEOM::GeomObjPtr subShape = findObjectInFather( object.get(), idx );
1346 // sub-shape is not yet published in the study
1347 GEOM::ShapesOpPtr shapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
1348 subShape.take( shapesOp->GetSubShape( object.get(), idx ) ); // take ownership!
1350 if ( typeInList( (TopAbs_ShapeEnum)(subShape->GetShapeType()), types ) ) {
1353 if ( strict && result.count() > count ) {
1357 else if ( !strict && result.count() == count )
1361 else if ( strict ) {
1373 //================================================================
1374 // Function : hideSourceObject
1376 //================================================================
1377 void GEOMBase_Helper::hideSourceObjects( QList<GEOM::GeomObjPtr> theObject )
1379 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1380 if ( resMgr->booleanValue( "Geometry", "hide_input_object", true) ) {
1381 GEOM_Displayer* aDisplayer = getDisplayer();
1382 for ( int i = 0; i < theObject.count(); i++ )
1383 aDisplayer->Erase( theObject[i].get() );
1387 //================================================================
1388 // Function : setIsApplyAndClose
1389 // Purpose : Set value of the flag indicating that the dialog is
1390 // accepted by Apply & Close button
1391 //================================================================
1392 void GEOMBase_Helper::setIsApplyAndClose( const bool theFlag )
1394 myIsApplyAndClose = theFlag;
1397 //================================================================
1398 // Function : isApplyAndClose
1399 // Purpose : Get value of the flag indicating that the dialog is
1400 // accepted by Apply & Close button
1401 //================================================================
1402 bool GEOMBase_Helper::isApplyAndClose() const
1404 return myIsApplyAndClose;
1407 //================================================================
1408 // Function : setIsOptimizedBrowsing
1409 // Purpose : Set value of the flag switching to optimized
1410 // browsing mode (to select the first published
1412 //================================================================
1413 void GEOMBase_Helper::setIsOptimizedBrowsing( const bool theFlag )
1415 myIsOptimizedBrowsing = theFlag;
1418 //================================================================
1419 // Function : isOptimizedBrowsing
1420 // Purpose : Get value of the flag switching to optimized
1421 // browsing mode (to select the first published
1423 //================================================================
1424 bool GEOMBase_Helper::isOptimizedBrowsing() const
1426 return myIsOptimizedBrowsing;