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 addSubshapesToStudy(); // add Sub-shapes if local selection
864 const int nbObjs = objects.size();
865 QStringList anEntryList;
866 int currObj = 1, aNumber = 1;
867 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it, currObj++ ) {
868 GEOM::GEOM_Object_var obj=*it;
870 QString aName = getObjectName(obj);
871 if (aName.isEmpty()) {
872 aName = getNewObjectName(currObj);
875 aName = getPrefix(obj);
877 // Try to find a unique name
878 aName = GEOMBase::GetDefaultName(aName, extractPrefix());
880 // Don't check name uniqueness in case of numerous objects
881 aName = aName + "_" + QString::number(aNumber++);
884 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
885 if ( aName.isEmpty() )
886 aName = GEOMBase::GetDefaultName( getPrefix( obj ) );
889 anEntryList << addInStudy( obj, aName.toLatin1().constData() );
891 if( isDisplayResult() )
892 display( obj, false );
893 #ifdef WITHGENERICOBJ
894 // obj has been published in study. Its refcount has been incremented.
895 // It is safe to decrement its refcount
896 // so that it will be destroyed when the entry in study will be removed
901 // asv : fix of PAL6454. If publish==false, then the original shape
902 // was modified, and need to be re-cached in GEOM_Client before redisplay
903 clearShapeBuffer( obj );
904 // withChildren=true, updateView=false
905 if( isDisplayResult() )
906 redisplay( obj, true, false );
913 if( SUIT_Application* anApp = SUIT_Session::session()->activeApplication() ) {
914 LightApp_Application* aLightApp = dynamic_cast<LightApp_Application*>( anApp );
916 QString anOpName( typeid(*this).name() );
917 aLightApp->emitOperationFinished( "Geometry", anOpName, anEntryList );
919 if ( !isDisableBrowsing() )
920 aLightApp->browseObjects( anEntryList, isApplyAndClose(), isOptimizedBrowsing() );
922 anApp->putInfo( QObject::tr("GEOM_PRP_DONE") );
931 catch( const SALOME::SALOME_Exception& e ) {
932 SalomeApp_Tools::QtCatchCorbaException( e );
934 MESSAGE("Exception catched")
939 MESSAGE("result ="<<result)
944 //================================================================
945 // Function : showError
946 // Purpose : Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
947 //================================================================
948 void GEOMBase_Helper::showError()
951 if ( !getOperation()->_is_nil() )
952 msg = QObject::tr( getOperation()->GetErrorCode() );
955 msg = QObject::tr( "GEOM_PRP_ABORT" );
957 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
958 QObject::tr( "GEOM_ERROR_STATUS" ),
960 QObject::tr( "BUT_OK" ) );
963 //================================================================
964 // Function : showError
965 // Purpose : Shows a error message followed by <msg>
966 //================================================================
967 void GEOMBase_Helper::showError( const QString& msg )
969 QString str( QObject::tr( "GEOM_INCORRECT_INPUT" ) );
970 if ( !msg.isEmpty() )
972 SUIT_MessageBox::critical(SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ), str, QObject::tr( "BUT_OK" ) );
975 //////////////////////////////////////////////////////////////////
976 // Virtual methods to be redefined in dialogs
977 //////////////////////////////////////////////////////////////////
979 //================================================================
980 // Function : createOperation
981 // Purpose : Redefine this method to return proper IOperation reference
982 //================================================================
983 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::createOperation()
985 GEOM::GEOM_IOperations_var aNilOp;
986 return aNilOp._retn();
989 //================================================================
990 // Function : isValid
991 // Purpose : Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
992 //================================================================
993 bool GEOMBase_Helper::isValid( QString& )
998 //================================================================
999 // Function : execute
1000 // Purpose : This method is called by onAccept().
1001 // It should perform the required operation and put all new or modified objects into
1002 // <objects> argument.Should return <false> if some error occurs during its execution.
1003 //================================================================
1004 bool GEOMBase_Helper::execute( ObjectList& objects )
1009 //================================================================
1010 // Function : getFather
1011 // Purpose : This method is called by addInStudy(). It should return a father object
1012 // for <theObj> or a nil reference if <theObj> should be published
1013 // as a top-level object.
1014 //================================================================
1015 GEOM::GEOM_Object_ptr GEOMBase_Helper::getFather( GEOM::GEOM_Object_ptr theObj )
1017 return GEOM::GEOM_Object::_nil();
1020 //================================================================
1021 // Function : getObjectName
1022 // Purpose : Redefine this method to return proper name for the given object
1023 //================================================================
1024 QString GEOMBase_Helper::getObjectName(GEOM::GEOM_Object_ptr object) const
1029 //================================================================
1030 // Function : getNewObjectName
1031 // Purpose : Redefine this method to return proper name for a new object
1032 //================================================================
1033 QString GEOMBase_Helper::getNewObjectName (int) const
1038 //================================================================
1039 // Function : extractPrefix
1040 // Purpose : Redefine this method to return \c true if necessary
1041 // to extract prefix when generating new name for the
1042 // object(s) being created
1043 //================================================================
1044 bool GEOMBase_Helper::extractPrefix() const
1049 //================================================================
1050 // Function : getPrefix
1051 // Purpose : Get prefix for name of created object
1052 //================================================================
1053 QString GEOMBase_Helper::getPrefix( GEOM::GEOM_Object_ptr theObj ) const
1055 if ( !myPrefix.isEmpty() || theObj->_is_nil() )
1058 GEOM::shape_type aType = theObj->GetShapeType();
1062 case GEOM::VERTEX : return QObject::tr( "GEOM_VERTEX" );
1063 case GEOM::EDGE : return QObject::tr( "GEOM_EDGE" );
1064 case GEOM::WIRE : return QObject::tr( "GEOM_WIRE" );
1065 case GEOM::FACE : return QObject::tr( "GEOM_FACE" );
1066 case GEOM::SHELL : return QObject::tr( "GEOM_SHELL" );
1067 case GEOM::SOLID : return QObject::tr( "GEOM_SOLID" );
1068 case GEOM::COMPSOLID: return QObject::tr( "GEOM_COMPOUNDSOLID" );
1069 case GEOM::COMPOUND : return QObject::tr( "GEOM_COMPOUND" );
1070 default : return "";
1074 //================================================================
1075 // Function : getDesktop
1076 // Purpose : Returns myDesktop field. Initialized in constructor,
1077 // usually as dynamic_cast<SUIT_Desktop*>(parentWidget())
1078 //================================================================
1079 SUIT_Desktop* GEOMBase_Helper::getDesktop() const
1084 //================================================================
1085 // Function : selectObjects
1086 // Purpose : Selects list of objects
1087 //================================================================
1088 bool GEOMBase_Helper::selectObjects( ObjectList& objects )
1090 SUIT_DataOwnerPtrList aList;
1091 ObjectList::iterator anIter;
1092 for ( anIter = objects.begin(); anIter != objects.end(); ++anIter )
1094 QString anEntry = getEntry( *anIter );
1095 LightApp_DataOwner* anOwher = new LightApp_DataOwner( anEntry );
1096 aList.append( anOwher );
1099 SUIT_Session* session = SUIT_Session::session();
1100 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1104 LightApp_SelectionMgr* aMgr = app->selectionMgr();
1108 aMgr->setSelected( aList, false );
1113 //================================================================
1114 // Function : findObjectInFather
1115 // Purpose : It should return an object if its founded in study or
1116 // return Null object if the object is not founded
1117 //================================================================
1118 GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather (GEOM::GEOM_Object_ptr theFather,
1119 const QString& theName)
1121 SalomeApp_Application* app =
1122 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1123 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1124 _PTR(Study) aDStudy = appStudy->studyDS();
1125 QString IOR = GEOMBase::GetIORFromObject( theFather );
1126 _PTR(SObject) SObj ( aDStudy->FindObjectIOR( IOR.toLatin1().constData() ) );
1128 bool inStudy = false;
1129 GEOM::GEOM_Object_var aReturnObject;
1130 for (_PTR(ChildIterator) iit (aDStudy->NewChildIterator( SObj )); iit->More() && !inStudy; iit->Next()) {
1131 _PTR(SObject) child (iit->Value());
1132 QString aChildName = child->GetName().c_str();
1133 if (aChildName == theName) {
1135 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(iit->Value());
1136 aReturnObject = GEOM::GEOM_Object::_narrow( corbaObj );
1140 return aReturnObject._retn();
1142 return GEOM::GEOM_Object::_nil();
1145 //================================================================
1146 // Function : findObjectInFather
1147 // Purpose : It should return an object if its founded in study or
1148 // return Null object if the object is not founded
1149 //================================================================
1150 GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather( GEOM::GEOM_Object_ptr theFather,
1153 GEOM::GEOM_Object_var object;
1155 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
1157 _PTR(Study) studyDS = study->studyDS();
1158 QString IOR = GEOMBase::GetIORFromObject( theFather );
1159 _PTR(SObject) sobject( studyDS->FindObjectIOR( IOR.toLatin1().constData() ) );
1161 _PTR(ChildIterator) it( studyDS->NewChildIterator( sobject ) );
1162 for ( ; it->More(); it->Next() ) {
1163 GEOM::GEOM_Object_var cobject = GEOM::GEOM_Object::_narrow( GeometryGUI::ClientSObjectToObject( it->Value() ) );
1164 if ( !CORBA::is_nil( cobject ) ) {
1165 GEOM::ListOfLong_var indices = cobject->GetSubShapeIndices();
1166 int length = indices->length();
1167 // VSR 18/03/2014: we need only sub-shapes with single sub-shape index (to exclude groups, etc)
1168 if ( length == 1 && indices[0] == theIndex ) {
1177 return object._retn();
1180 //================================================================
1181 // Function : addSubshapesToStudy
1182 // Purpose : Virtual method to add sub-shapes if needs
1183 //================================================================
1184 void GEOMBase_Helper::addSubshapesToStudy()
1186 //Impemented in Dialogs, called from Accept method
1189 //================================================================
1190 // Function : getSelected
1191 // Purpose : Get selected object by specified type
1193 // Returns valid object if only one object of the specified type is selected
1194 // (no matter global or local selection is activated). If \a type is TopAbs_SHAPE,
1195 // geometrical object of any valid type is expected.
1197 // \param type type of the object to be obtained from selection
1198 // \return selected geometrical object or nil object if selection is not satisfactory
1199 //================================================================
1200 GEOM::GeomObjPtr GEOMBase_Helper::getSelected( TopAbs_ShapeEnum type )
1202 QList<TopAbs_ShapeEnum> types;
1204 return getSelected( types );
1207 //================================================================
1208 // Function : getSelected
1209 // Purpose : Get selected object by specified types
1211 // Returns valid object if only one object of the specified type is selected
1212 // (no matter global or local selection is activated). The list of allowed
1213 // shape types is passed via \a types. If \a types includes TopAbs_SHAPE,
1214 // geometrical object of any valid type is expected.
1216 // \param types list of allowed shape types for the objects to be obtained from selection
1217 // \return selected geometrical object or nil object if selection is not satisfactory
1218 //================================================================
1219 GEOM::GeomObjPtr GEOMBase_Helper::getSelected( const QList<TopAbs_ShapeEnum>& types )
1221 QList<GEOM::GeomObjPtr> selected = getSelected( types, 1 );
1222 return selected.count() > 0 ? selected[0] : GEOM::GeomObjPtr();
1225 //================================================================
1226 // Function : getSelected
1227 // Purpose : Get selected object(s) by specified type
1229 // Returns list of selected objects if selection satisfies specifies selection options.
1230 // (no matter global or local selection is activated). If \a type is TopAbs_SHAPE,
1231 // geometrical objects of any valid type are expected.
1233 // The \a type parameter specifies allowed type of the object(s) being selected.
1234 // The \a count parameter specifies exact number of the objects to be retrieved from selection.
1235 // The \a strict parameter specifies policy being applied to the selection.
1236 // If \a count < 0, then any number of the selected objects is valid (including 0).
1237 // In this case, if \a strict is \c true (default), all selected objects should satisfy
1238 // the specified \a type.
1239 // If \a count > 0, only specified number of the objects is retrieved from the selection.
1240 // In this case, if \a strict is \c true (default), function returns empty list if total number of selected
1241 // objects does not correspond to the \a count parameter. Otherwise (if \a strict is \c false),
1242 // function returns valid list of objects if at least \a count objects satisfy specified \a type.
1244 // \param type type of the object(s) to be obtained from selection
1245 // \param count number of items to be retrieved from selection
1246 // \param strict selection policy
1247 // \return list of selected geometrical objects or empty list if selection is not satisfactory
1248 //================================================================
1249 QList<GEOM::GeomObjPtr> GEOMBase_Helper::getSelected( TopAbs_ShapeEnum type, int count, bool strict )
1251 QList<TopAbs_ShapeEnum> types;
1253 return getSelected( types, count, strict );
1256 static bool typeInList( TopAbs_ShapeEnum type, const QList<TopAbs_ShapeEnum>& types )
1259 for ( int i = 0; i < types.count() && !ok; i++ )
1260 ok = types[i] == TopAbs_SHAPE || types[i] == type;
1264 //================================================================
1265 // Function : getSelected
1266 // Purpose : Get selected objects by specified types
1268 // Returns list of selected objects if selection satisfies specifies selection options.
1269 // (no matter global or local selection is activated). If \a types includes TopAbs_SHAPE,
1270 // geometrical objects of any valid type are expected.
1272 // The \a types parameter specifies allowed types of the object(s) being selected.
1273 // The \a count parameter specifies exact number of the objects to be retrieved from selection.
1274 // The \a strict parameter specifies policy being applied to the selection.
1275 // If \a count < 0, then any number of the selected objects is valid (including 0).
1276 // In this case, if \a strict is \c true (default), all selected objects should satisfy
1277 // the specified \a type.
1278 // If \a count > 0, only specified number of the objects is retrieved from the selection.
1279 // In this case, if \a strict is \c true (default), function returns empty list if total number of selected
1280 // objects does not correspond to the \a count parameter. Otherwise (if \a strict is \c false),
1281 // function returns valid list of objects if at least \a count objects satisfy specified \a type.
1283 // \param types list of allowed shape types for the objects to be obtained from selection
1284 // \param count number of items to be retrieved from selection
1285 // \param strict selection policy
1286 // \return list of selected geometrical objects or empty list if selection is not satisfactory
1287 //================================================================
1288 QList<GEOM::GeomObjPtr> GEOMBase_Helper::getSelected( const QList<TopAbs_ShapeEnum>& types, int count, bool strict )
1290 SUIT_Session* session = SUIT_Session::session();
1291 QList<GEOM::GeomObjPtr> result;
1293 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1295 LightApp_SelectionMgr* selMgr = app->selectionMgr();
1297 SALOME_ListIO selected;
1298 selMgr->selectedObjects( selected );
1299 SALOME_ListIteratorOfListIO it( selected );
1300 bool stopped = false;
1301 for ( ; it.More() && !stopped; it.Next() ) {
1302 Handle(SALOME_InteractiveObject) IO = it.Value();
1303 GEOM::GeomObjPtr object = GEOMBase::ConvertIOinGEOMObject( IO );
1305 TColStd_IndexedMapOfInteger subShapes;
1306 selMgr->GetIndexes( IO, subShapes );
1307 int nbSubShapes = subShapes.Extent();
1308 if ( nbSubShapes == 0 ) {
1310 if ( typeInList( (TopAbs_ShapeEnum)(object->GetShapeType()), types ) ) {
1313 if ( strict && result.count() > count ) {
1317 else if ( !strict && result.count() == count )
1321 else if ( strict ) {
1328 for ( int i = 1; i <= nbSubShapes && !stopped; i++ ) {
1329 int idx = subShapes( i );
1330 GEOM::GeomObjPtr subShape = findObjectInFather( object.get(), idx );
1332 // sub-shape is not yet published in the study
1333 GEOM::ShapesOpPtr shapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
1334 subShape.take( shapesOp->GetSubShape( object.get(), idx ) ); // take ownership!
1336 if ( typeInList( (TopAbs_ShapeEnum)(subShape->GetShapeType()), types ) ) {
1339 if ( strict && result.count() > count ) {
1343 else if ( !strict && result.count() == count )
1347 else if ( strict ) {
1360 //================================================================
1361 // Function : setIsApplyAndClose
1362 // Purpose : Set value of the flag indicating that the dialog is
1363 // accepted by Apply & Close button
1364 //================================================================
1365 void GEOMBase_Helper::setIsApplyAndClose( const bool theFlag )
1367 myIsApplyAndClose = theFlag;
1370 //================================================================
1371 // Function : isApplyAndClose
1372 // Purpose : Get value of the flag indicating that the dialog is
1373 // accepted by Apply & Close button
1374 //================================================================
1375 bool GEOMBase_Helper::isApplyAndClose() const
1377 return myIsApplyAndClose;
1380 //================================================================
1381 // Function : setIsOptimizedBrowsing
1382 // Purpose : Set value of the flag switching to optimized
1383 // browsing mode (to select the first published
1385 //================================================================
1386 void GEOMBase_Helper::setIsOptimizedBrowsing( const bool theFlag )
1388 myIsOptimizedBrowsing = theFlag;
1391 //================================================================
1392 // Function : isOptimizedBrowsing
1393 // Purpose : Get value of the flag switching to optimized
1394 // browsing mode (to select the first published
1396 //================================================================
1397 bool GEOMBase_Helper::isOptimizedBrowsing() const
1399 return myIsOptimizedBrowsing;