1 // Copyright (C) 2007-2019 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 <TCollection_AsciiString.hxx>
58 #include <TColStd_IndexedMapOfInteger.hxx>
60 //To disable automatic genericobj management, the following line should be commented.
61 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
62 #define WITHGENERICOBJ
64 //================================================================
65 // Function : getActiveView
66 // Purpose : Get active view window, returns 0 if no open study frame
67 //================================================================
68 SUIT_ViewWindow* GEOMBase_Helper::getActiveView()
70 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
72 return SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
78 //================================================================
79 // Function : getGeomEngine
80 // Purpose : Static method
81 //================================================================
82 GEOM::GEOM_Gen_ptr GEOMBase_Helper::getGeomEngine()
84 return GeometryGUI::GetGeomGen();
87 //================================================================
88 // Function : GEOMBase_Helper
90 //================================================================
91 GEOMBase_Helper::GEOMBase_Helper( SUIT_Desktop* desktop )
92 : myDisplayer( 0 ), myCommand( 0 ), myViewWindow( 0 ), isPreview( false ), myDesktop( desktop ),
93 myIsApplyAndClose( false ), myIsOptimizedBrowsing( false ), myIsWaitCursorEnabled( true ),
94 myIsDisableBrowsing(false), myIsDisplayResult(true)
98 //================================================================
99 // Function : ~GEOMBase_Helper
101 //================================================================
102 GEOMBase_Helper::~GEOMBase_Helper()
104 //rnv: Fix for the "IPAL21922 : WinTC5.1.4: incorrect quit salome"
105 if ( !SUIT_Session::session()->activeApplication() || !SUIT_Session::session()->activeApplication()->desktop() )
108 if ( myPreview.size() )
112 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
114 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
116 globalSelection(aGeomGUI->getLocalSelectionMode() , true );
121 if ( !CORBA::is_nil( myOperation ) )
122 myOperation->UnRegister();
125 //================================================================
126 // Function : display
128 //================================================================
129 void GEOMBase_Helper::display( const ObjectList& objList, const bool updateView )
131 ObjectList::const_iterator it;
132 for ( it = objList.begin(); it != objList.end(); it++ ) {
133 display( *it, false );
135 if ( !objList.empty() && updateView )
136 getDisplayer()->UpdateViewer();
139 //================================================================
140 // Function : display
141 // Purpose : Display object.
142 // Important : Object must be already in study
143 //================================================================
144 void GEOMBase_Helper::display( GEOM::GEOM_Object_ptr object, const bool updateView )
146 // Unset color of shape ( this color may be set during preview displaying )
147 // Default color will be used
148 // getDisplayer()->UnsetColor();
149 getDisplayer()->UnsetWidth();
151 MESSAGE("GEOMBase_Helper::display myTexture = "<<getDisplayer()->GetTexture());
153 // Enable activisation of selection
154 getDisplayer()->SetToActivate( true );
157 getDisplayer()->Display( object, updateView );
160 //================================================================
163 //================================================================
164 void GEOMBase_Helper::erase( const ObjectList& objList, const bool updateView )
166 ObjectList::const_iterator it = objList.begin();
167 for ( ; it != objList.end(); it++ ) {
170 if ( !objList.empty() && updateView )
171 getDisplayer()->UpdateViewer();
174 //================================================================
177 //================================================================
178 void GEOMBase_Helper::erase( GEOM::GEOM_Object_ptr object, const bool updateView )
180 if ( !object->_is_nil() ) {
181 QString entry = getEntry( object );
182 QString name = GEOMBase::GetName( object );
183 getDisplayer()->Erase ( new SALOME_InteractiveObject(entry.toUtf8().constData(),
185 name.toUtf8().constData() ),
190 //================================================================
191 // Function : redisplay
193 //================================================================
194 void GEOMBase_Helper::redisplay( const ObjectList& objList,
195 const bool withChildren,
196 const bool updateView )
198 ObjectList::const_iterator it = objList.begin();
199 for ( ; it != objList.end(); it++ ) {
200 redisplay( *it, withChildren, false );
202 if ( !objList.empty() && updateView )
203 getDisplayer()->UpdateViewer();
206 //================================================================
207 // Function : redisplay
209 //================================================================
210 void GEOMBase_Helper::redisplay( GEOM::GEOM_Object_ptr object,
211 const bool withChildren,
212 const bool updateView )
214 if ( !object->_is_nil() ) {
215 // Unset color of shape ( this color may be set during preview displaying )
216 // Default color will be used
217 getDisplayer()->UnsetColor();
218 getDisplayer()->UnsetWidth();
220 // Enable activisation of selection
221 getDisplayer()->SetToActivate( true );
223 QString entry = getEntry( object );
224 QString name = GEOMBase::GetName( object );
225 getDisplayer()->Redisplay
226 (new SALOME_InteractiveObject (entry.toUtf8().constData(),
228 name.toUtf8().constData()),
232 if ( withChildren ) {
233 SalomeApp_Study* aDoc = getStudy();
234 if ( aDoc && aDoc->studyDS() ) {
235 _PTR(Study) aStudy = aDoc->studyDS();
236 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string(object);
237 _PTR(SObject) aSObj (aStudy->FindObjectIOR(std::string(objStr.in())));
239 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
240 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
241 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow
242 (GeometryGUI::ClientSObjectToObject(anIt->Value()));
243 if ( !CORBA::is_nil( aChild ) ) {
244 if ( !aChild->_is_nil() ) {
245 QString entry = getEntry( aChild );
246 QString name = GEOMBase::GetName( aChild );
247 getDisplayer()->Redisplay
248 ( new SALOME_InteractiveObject( entry.toUtf8().constData(),
250 name.toUtf8().constData() ),
260 getDisplayer()->UpdateViewer();
263 //================================================================
264 // Function : displayPreview
265 // Purpose : Method for displaying preview based on execute() results
266 //================================================================
267 void GEOMBase_Helper::displayPreview( const bool display,
270 const bool toRemoveFromEngine,
271 const double lineWidth,
272 const int displayMode,
277 erasePreview( update );
283 if ( !isValid( msg ) )
285 erasePreview( update );
291 erasePreview( false );
294 SUIT_OverrideCursor wc;
297 if ( !isWaitCursorEnabled() )
300 if ( !execute( objects ) || !getOperation()->IsDone() ) {
304 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it )
306 GEOM::GEOM_Object_var obj = *it;
307 displayPreview( obj, true, activate, false, lineWidth, displayMode, color );
308 if ( toRemoveFromEngine )
313 catch( const SALOME::SALOME_Exception& e ) {
314 SalomeApp_Tools::QtCatchCorbaException( e );
323 //================================================================
324 // Function : displayPreview
325 // Purpose : Method for displaying preview of resulting shape
326 //================================================================
327 void GEOMBase_Helper::displayPreview( GEOM::GEOM_Object_ptr object,
331 const double lineWidth,
332 const int displayMode,
335 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
337 // Set color for preview shape
338 getDisplayer()->SetColor( color == -1 ? Quantity_NOC_VIOLET : color );
340 // set width of displayed shape
341 getDisplayer()->SetWidth( lineWidth == -1 ? resMgr->integerValue("Geometry", "preview_edge_width", -1) : lineWidth );
343 // set display mode of displayed shape
344 int aPrevDispMode = getDisplayer()->SetDisplayMode( displayMode == -1 ? resMgr->integerValue( "Geometry", "display_mode", 0 ) : displayMode );
346 // Disable activation of selection
347 getDisplayer()->SetToActivate( activate );
349 // Make a reference to GEOM_Object
350 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string( object );
351 getDisplayer()->SetName( objStr.in() );
354 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( object );
355 if ( aPrs == 0 || aPrs->IsNull() )
358 // Make preview not clippable
359 aPrs->SetClippable (false);
362 displayPreview( aPrs, append, update );
364 getDisplayer()->UnsetName();
365 getDisplayer()->UnsetColor();
366 getDisplayer()->SetDisplayMode( aPrevDispMode );
368 // Enable activation of displayed objects
369 getDisplayer()->SetToActivate( true );
372 //================================================================
373 // Function : displayPreview
374 // Purpose : Method for displaying arbitrary preview objects (not limited to shapes)
375 //================================================================
376 void GEOMBase_Helper::displayPreview( const SALOME_Prs* prs,
381 erasePreview( false );
383 // remember current view frame to make correct erase preview later
384 myViewWindow = getActiveView();
386 if ( myViewWindow == 0 )
390 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
391 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
392 aViewManager->getType() == SVTK_Viewer::Type() )
394 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
395 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
397 aView->Display( getDisplayer(), prs );
400 // Add prs to the preview list
401 myPreview.push_back( (SALOME_Prs*)prs );
405 getDisplayer()->UpdateViewer();
408 //================================================================
409 // Function : erasePreview
411 //================================================================
412 void GEOMBase_Helper::erasePreview( const bool update )
414 // check view frame where the preview was displayed
415 bool vfOK = checkViewWindow() && myViewWindow;
416 // Iterate through presentations and delete them
417 for ( PrsList::iterator anIter = myPreview.begin(); anIter != myPreview.end(); ++anIter )
421 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
422 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
423 aViewManager->getType() == SVTK_Viewer::Type() )
425 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
426 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
428 aView->Erase( getDisplayer(), *anIter, true );
440 //================================================================
441 // Function : localSelection
442 // Purpose : Activate selection of objects of a given type
443 // IMPORTANT : Works after localSelection( ... ) method call only
444 //================================================================
445 void GEOMBase_Helper::activate( const int theType )
447 if (!getStudy()) return;
448 _PTR(Study) aStudy = getStudy()->studyDS();
449 _PTR(SComponent) aGeom ( aStudy->FindComponent( "GEOM" ) );
454 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( aGeom ) );
455 for ( ; anIter->More(); anIter->Next() )
457 _PTR(SObject) aSO ( anIter->Value() );
460 _PTR(SObject) aRefSO;
461 if ( !aSO->ReferencedObject( aRefSO ) )
463 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow
464 (GeometryGUI::ClientSObjectToObject(aSO));
465 if ( !anObj->_is_nil() && anObj->GetType() == theType )
466 aList.Append( new SALOME_InteractiveObject( aSO->GetID().c_str(), "GEOM", aSO->GetName().c_str()) );
471 getDisplayer()->LocalSelection( aList, 0 );
474 //================================================================
475 // Function : localSelection
476 // Purpose : Activate selection of sub-shapes in accordance with mode
477 // modes are from TopAbs_ShapeEnum
478 //================================================================
479 void GEOMBase_Helper::localSelection( const ObjectList& theObjs, const std::list<int> modes )
481 SALOME_ListIO aListOfIO;
483 ObjectList::const_iterator anIter = theObjs.begin();
484 for ( ; anIter != theObjs.end(); ++anIter )
486 GEOM::GEOM_Object_ptr anObj = *anIter;
487 if ( anObj->_is_nil() )
489 QString anEntry = getEntry( anObj );
492 QString aName = GEOMBase::GetName( anObj );
493 aListOfIO.Append( new SALOME_InteractiveObject( anEntry.toUtf8().constData(),
494 "GEOM", aName.toUtf8().constData() ));
498 getDisplayer()->LocalSelection( aListOfIO, modes );
501 //================================================================
502 // Function : localSelection
503 // Purpose : Activate selection of sub-shapes in accordance with mode
504 // theMode is from TopAbs_ShapeEnum
505 //================================================================
506 void GEOMBase_Helper::localSelection( const ObjectList& theObjs, const int theMode )
508 std::list<int> modes;
509 modes.push_back( theMode );
510 localSelection( theObjs, modes );
513 //================================================================
514 // Function : localSelection
515 // Purpose : Activate selection of sub-shapes in accordance with mode
516 // modes are from TopAbs_ShapeEnum
517 //================================================================
518 void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const std::list<int> modes )
520 // If object is null local selection for all objects is activated
521 if ( obj->_is_nil() ) {
522 getDisplayer()->LocalSelection( Handle(SALOME_InteractiveObject)(), modes );
527 objList.push_back( obj );
528 localSelection( objList, modes );
531 //================================================================
532 // Function : localSelection
533 // Purpose : Activate selection of sub-shapes in accordance with mode
534 // mode is from TopAbs_ShapeEnum
535 //================================================================
536 void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const int mode )
538 std::list<int> modes;
539 modes.push_back( mode );
540 localSelection( obj, modes );
543 //================================================================
544 // Function : localSelection
545 // Purpose : Activate selection of sub-shapes in accordance with mode
546 // modes are from TopAbs_ShapeEnum
547 //================================================================
548 void GEOMBase_Helper::localSelection( const std::list<int> modes )
550 localSelection( GEOM::GEOM_Object::_nil(), modes );
553 //================================================================
554 // Function : localSelection
555 // Purpose : Activate selection of sub-shapes in accordance with mode
556 // mode is from TopAbs_ShapeEnum
557 //================================================================
558 void GEOMBase_Helper::localSelection( const int mode )
560 std::list<int> modes;
561 modes.push_back( mode );
562 localSelection( modes );
565 //================================================================
566 // Function : globalSelection
567 // Purpose : Activate selection of sub-shapes. Set selection filters
568 // in accordance with mode. theMode is from GEOMImpl_Types
569 //================================================================
570 void GEOMBase_Helper::globalSelection( const int theMode, const bool update )
572 getDisplayer()->GlobalSelection( theMode, update );
575 //================================================================
576 // Function : globalSelection
577 // Purpose : Activate selection of sub-shapes. Set selection filters
578 // in accordance with mode. theMode is from GEOMImpl_Types
579 //================================================================
580 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
583 getDisplayer()->GlobalSelection( theModes, update );
586 //================================================================
587 // Function : globalSelection
588 // Purpose : Activate selection of sub-shapes. Set selection filters
589 // in accordance with mode. theMode is from GEOMImpl_Types
590 //================================================================
591 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
592 const QList<int>& subShapes,
595 getDisplayer()->GlobalSelection( theModes, update, &subShapes );
598 //================================================================
599 // Function : addInStudy
600 // Purpose : Add object in study
601 //================================================================
602 QString GEOMBase_Helper::addInStudy( GEOM::GEOM_Object_ptr theObj, const char* theName )
607 _PTR(Study) aStudy = getStudy()->studyDS();
608 if ( !aStudy || theObj->_is_nil() )
611 GEOM::GEOM_Object_ptr aFatherObj = getFather( theObj );
613 SALOMEDS::SObject_var aSO =
614 getGeomEngine()->AddInStudy(theObj, theName, aFatherObj);
617 if ( !aSO->_is_nil() ) {
618 CORBA::String_var entry = aSO->GetID();
619 anEntry = entry.in();
621 // Each dialog is responsible for this method implementation,
622 // default implementation does nothing
623 restoreSubShapes(aSO);
629 //================================================================
630 // Function : restoreSubShapes
631 // Purpose : restore tree of argument's sub-shapes under the resulting shape
632 //================================================================
633 void GEOMBase_Helper::restoreSubShapes (SALOMEDS::SObject_ptr /*theSObject*/)
635 // do nothing by default
637 // example of implementation in particular dialog:
638 // GEOM::ListOfGO anArgs;
639 // anArgs.length(0); // empty list means that all arguments should be restored
640 // getGeomEngine()->RestoreSubShapesSO(theSObject, anArgs,
641 // /*theFindMethod=*/GEOM::FSM_GetInPlace,
642 // /*theInheritFirstArg=*/false);
645 //================================================================
646 // Function : updateObjBrowser
647 // Purpose : Update object browser
648 //================================================================
649 void GEOMBase_Helper::updateObjBrowser() const
651 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
653 CAM_Module* module = app->module( "Geometry" );
654 SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
656 appMod->updateObjBrowser();
661 //================================================================
662 // Function : updateViewer
663 // Purpose : Update active 3D view
664 //================================================================
665 void GEOMBase_Helper::updateViewer()
667 getDisplayer()->UpdateViewer();
670 //================================================================
671 // Function : getStudy
672 // Purpose : Returns the active study. It is recommended to use
673 // this method instead of direct desktop->getActiveStudy() calls
674 //================================================================
675 SalomeApp_Study* GEOMBase_Helper::getStudy() const
677 SUIT_Desktop* aDesktop = getDesktop();
681 QList<SUIT_Application*> anAppList = SUIT_Session::session()->applications();
683 SUIT_Application* anApp = 0;
684 QListIterator<SUIT_Application*> it( anAppList );
685 while ( it.hasNext() )
688 if ( anApp && anApp->desktop() == aDesktop )
692 return dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
695 //================================================================
696 // Function : getEntry
698 //================================================================
699 QString GEOMBase_Helper::getEntry( GEOM::GEOM_Object_ptr object ) const
701 SalomeApp_Study* study = getStudy();
703 QString objIOR = GEOMBase::GetIORFromObject( object );
704 if ( objIOR != "" ) {
705 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( objIOR.toUtf8().constData() ) );
707 return QString::fromStdString(SO->GetID());
713 //================================================================
714 // Function : getDisplayer
716 //================================================================
717 GEOM_Displayer* GEOMBase_Helper::getDisplayer()
720 myDisplayer = new GEOM_Displayer();
724 //================================================================
725 // Function : clearShapeBuffer
727 //================================================================
728 void GEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
730 GeometryGUI::ClearShapeBuffer(theObj);
733 //================================================================
734 // Function : openCommand
736 //================================================================
737 bool GEOMBase_Helper::openCommand()
740 if ( !getStudy() || hasCommand() )
742 MESSAGE("Getting out from openCommand()")
746 GEOM::GEOM_IOperations_var anOp = GEOM::GEOM_IOperations::_narrow( getOperation() );
747 if ( !anOp->_is_nil() ) {
748 myCommand = new GEOM_Operation( SUIT_Session::session()->activeApplication(), anOp.in() );
754 MESSAGE("anOp->_is_nil() = true")
760 //================================================================
761 // Function : abortCommand
763 //================================================================
764 bool GEOMBase_Helper::abortCommand()
770 delete myCommand; // I don't know where to delete this object here ?
776 //================================================================
777 // Function : commitCommand
779 //================================================================
780 bool GEOMBase_Helper::commitCommand( const char* )
786 delete myCommand; // I don't know where to delete this object here ?
792 //================================================================
793 // Function : hasCommand
795 //================================================================
796 bool GEOMBase_Helper::hasCommand() const
798 return (bool)myCommand;
801 //================================================================
802 // Function : getOperation
804 //================================================================
805 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::getOperation()
807 if ( myOperation->_is_nil() )
808 myOperation = createOperation();
815 //================================================================
816 // Function : checkViewWindow
818 //================================================================
819 bool GEOMBase_Helper::checkViewWindow()
822 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
823 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
824 while ( it.hasNext() )
826 if ( myViewWindow == it.next() )
834 //================================================================
835 // Function : onAccept
836 // Purpose : This method should be called from dialog's slots onOk() and onApply()
837 // It performs user input validation, then it
838 // performs a proper operation and manages transactions, etc.
839 //================================================================
840 bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction, bool erasePreviewFlag )
842 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
845 MESSAGE("appStudy is empty")
848 _PTR(Study) aStudy = appStudy->studyDS();
850 bool aLocked = (_PTR(AttributeStudyProperties) (aStudy->GetProperties()))->IsLocked();
852 MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
853 SUIT_MessageBox::warning ( (QWidget*)SUIT_Session::session()->activeApplication()->desktop(),
854 QObject::tr("WRN_WARNING"),
855 QObject::tr("WRN_STUDY_LOCKED"),
856 QObject::tr("BUT_OK") );
861 if ( !isValid( msg ) ) {
867 erasePreview( false );
872 if ( ( !publish && !useTransaction ) || openCommand() ) {
873 SUIT_OverrideCursor wc;
874 SUIT_Session::session()->activeApplication()->putInfo( "" );
876 if ( !execute( objects ) || !getOperation()->IsDone() ) {
882 QList<GEOM::GeomObjPtr> anObjectList = getSourceObjects( );
883 addSubshapesToStudy(); // add Sub-shapes if local selection
884 const int nbObjs = objects.size();
885 QStringList anEntryList;
886 int currObj = 1, aNumber = 1;
887 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it, currObj++ ) {
888 GEOM::GEOM_Object_var obj=*it;
890 QString aName = getObjectName(obj);
891 if (aName.isEmpty()) {
892 aName = getNewObjectName(currObj);
895 aName = getPrefix(obj);
897 // Try to find a unique name
898 aName = GEOMBase::GetDefaultName(aName, extractPrefix());
900 // Don't check name uniqueness in case of numerous objects
901 aName = aName + "_" + QString::number(aNumber++);
904 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
905 if ( aName.isEmpty() )
906 aName = GEOMBase::GetDefaultName( getPrefix( obj ) );
909 anEntryList << addInStudy( obj, aName.toUtf8().constData() );
911 if( isDisplayResult() )
912 display( obj, false );
913 #ifdef WITHGENERICOBJ
914 // obj has been published in study. Its refcount has been incremented.
915 // It is safe to decrement its refcount
916 // so that it will be destroyed when the entry in study will be removed
921 // asv : fix of PAL6454. If publish==false, then the original shape
922 // was modified, and need to be re-cached in GEOM_Client before redisplay
923 clearShapeBuffer( obj );
924 // withChildren=true, updateView=false
925 if( isDisplayResult() )
926 redisplay( obj, true, false );
933 if( SUIT_Application* anApp = SUIT_Session::session()->activeApplication() ) {
934 LightApp_Application* aLightApp = dynamic_cast<LightApp_Application*>( anApp );
936 QString anOpName( typeid(*this).name() );
937 aLightApp->emitOperationFinished( "Geometry", anOpName, anEntryList );
939 if ( !isDisableBrowsing() )
940 aLightApp->browseObjects( anEntryList, isApplyAndClose(), isOptimizedBrowsing() );
942 anApp->putInfo( QObject::tr("GEOM_PRP_DONE") );
944 if ( anObjectList.count() > 0 )
945 hideSourceObjects( anObjectList );
953 catch( const SALOME::SALOME_Exception& e ) {
954 SalomeApp_Tools::QtCatchCorbaException( e );
956 MESSAGE("Exception caught")
961 MESSAGE("result ="<<result)
966 //================================================================
967 // Function : showError
968 // Purpose : Shows a message box with information about an error taken from getOperation()->GetErrorCode()
969 //================================================================
970 void GEOMBase_Helper::showError()
973 if ( !getOperation()->_is_nil() )
974 msg = QObject::tr( getOperation()->GetErrorCode() );
977 msg = QObject::tr( "GEOM_PRP_ABORT" );
979 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
980 QObject::tr( "GEOM_ERROR_STATUS" ),
982 QObject::tr( "BUT_OK" ) );
985 //================================================================
986 // Function : showError
987 // Purpose : Shows a error message followed by <msg>
988 //================================================================
989 void GEOMBase_Helper::showError( const QString& msg )
991 QString str( QObject::tr( "GEOM_INCORRECT_INPUT" ) );
992 if ( !msg.isEmpty() )
994 SUIT_MessageBox::critical(SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ), str, QObject::tr( "BUT_OK" ) );
997 //////////////////////////////////////////////////////////////////
998 // Virtual methods to be redefined in dialogs
999 //////////////////////////////////////////////////////////////////
1001 //================================================================
1002 // Function : createOperation
1003 // Purpose : Redefine this method to return proper IOperation reference
1004 //================================================================
1005 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::createOperation()
1007 GEOM::GEOM_IOperations_var aNilOp;
1008 return aNilOp._retn();
1011 //================================================================
1012 // Function : isValid
1013 // Purpose : Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
1014 //================================================================
1015 bool GEOMBase_Helper::isValid( QString& )
1020 //================================================================
1021 // Function : execute
1022 // Purpose : This method is called by onAccept().
1023 // It should perform the required operation and put all new or modified objects into
1024 // <objects> argument.Should return <false> if some error occurs during its execution.
1025 //================================================================
1026 bool GEOMBase_Helper::execute( ObjectList& objects )
1031 //================================================================
1032 // Function : getFather
1033 // Purpose : This method is called by addInStudy(). It should return a father object
1034 // for <theObj> or a nil reference if <theObj> should be published
1035 // as a top-level object.
1036 //================================================================
1037 GEOM::GEOM_Object_ptr GEOMBase_Helper::getFather( GEOM::GEOM_Object_ptr theObj )
1039 return GEOM::GEOM_Object::_nil();
1042 //================================================================
1043 // Function : getObjectName
1044 // Purpose : Redefine this method to return proper name for the given object
1045 //================================================================
1046 QString GEOMBase_Helper::getObjectName(GEOM::GEOM_Object_ptr object) const
1051 //================================================================
1052 // Function : getNewObjectName
1053 // Purpose : Redefine this method to return proper name for a new object
1054 //================================================================
1055 QString GEOMBase_Helper::getNewObjectName (int) const
1060 //================================================================
1061 // Function : extractPrefix
1062 // Purpose : Redefine this method to return \c true if necessary
1063 // to extract prefix when generating new name for the
1064 // object(s) being created
1065 //================================================================
1066 bool GEOMBase_Helper::extractPrefix() const
1071 //================================================================
1072 // Function : getPrefix
1073 // Purpose : Get prefix for name of created object
1074 //================================================================
1075 QString GEOMBase_Helper::getPrefix( GEOM::GEOM_Object_ptr theObj ) const
1077 if ( !myPrefix.isEmpty() || theObj->_is_nil() )
1080 GEOM::shape_type aType = theObj->GetShapeType();
1084 case GEOM::VERTEX : return QObject::tr( "GEOM_VERTEX" );
1085 case GEOM::EDGE : return QObject::tr( "GEOM_EDGE" );
1086 case GEOM::WIRE : return QObject::tr( "GEOM_WIRE" );
1087 case GEOM::FACE : return QObject::tr( "GEOM_FACE" );
1088 case GEOM::SHELL : return QObject::tr( "GEOM_SHELL" );
1089 case GEOM::SOLID : return QObject::tr( "GEOM_SOLID" );
1090 case GEOM::COMPSOLID: return QObject::tr( "GEOM_COMPOUNDSOLID" );
1091 case GEOM::COMPOUND : return QObject::tr( "GEOM_COMPOUND" );
1092 default : return "";
1096 //================================================================
1097 // Function : getDesktop
1098 // Purpose : Returns myDesktop field. Initialized in constructor,
1099 // usually as dynamic_cast<SUIT_Desktop*>(parentWidget())
1100 //================================================================
1101 SUIT_Desktop* GEOMBase_Helper::getDesktop() const
1106 //================================================================
1107 // Function : selectObjects
1108 // Purpose : Selects list of objects
1109 //================================================================
1110 bool GEOMBase_Helper::selectObjects( ObjectList& objects )
1112 SUIT_DataOwnerPtrList aList;
1113 ObjectList::iterator anIter;
1114 for ( anIter = objects.begin(); anIter != objects.end(); ++anIter )
1116 QString anEntry = getEntry( *anIter );
1117 LightApp_DataOwner* anOwher = new LightApp_DataOwner( anEntry );
1118 aList.append( anOwher );
1121 SUIT_Session* session = SUIT_Session::session();
1122 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1126 LightApp_SelectionMgr* aMgr = app->selectionMgr();
1130 aMgr->setSelected( aList, false );
1135 //================================================================
1136 // Function : findObjectInFather
1137 // Purpose : It should return an object if its founded in study or
1138 // return Null object if the object is not founded
1139 //================================================================
1140 GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather (GEOM::GEOM_Object_ptr theFather,
1141 const QString& theName)
1143 SalomeApp_Application* app =
1144 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1145 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1146 _PTR(Study) aDStudy = appStudy->studyDS();
1147 QString IOR = GEOMBase::GetIORFromObject( theFather );
1148 _PTR(SObject) SObj ( aDStudy->FindObjectIOR( IOR.toUtf8().constData() ) );
1150 bool inStudy = false;
1151 GEOM::GEOM_Object_var aReturnObject;
1152 for (_PTR(ChildIterator) iit (aDStudy->NewChildIterator( SObj )); iit->More() && !inStudy; iit->Next()) {
1153 _PTR(SObject) child (iit->Value());
1154 QString aChildName = child->GetName().c_str();
1155 if (aChildName == theName) {
1157 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(iit->Value());
1158 aReturnObject = GEOM::GEOM_Object::_narrow( corbaObj );
1162 return aReturnObject._retn();
1164 return GEOM::GEOM_Object::_nil();
1167 //================================================================
1168 // Function : findObjectInFather
1169 // Purpose : It should return an object if its founded in study or
1170 // return Null object if the object is not founded
1171 //================================================================
1172 GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather( GEOM::GEOM_Object_ptr theFather,
1175 GEOM::GEOM_Object_var object;
1177 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
1179 _PTR(Study) studyDS = study->studyDS();
1180 QString IOR = GEOMBase::GetIORFromObject( theFather );
1181 _PTR(SObject) sobject( studyDS->FindObjectIOR( IOR.toLatin1().constData() ) );
1183 _PTR(ChildIterator) it( studyDS->NewChildIterator( sobject ) );
1184 for ( ; it->More(); it->Next() ) {
1185 GEOM::GEOM_Object_var cobject = GEOM::GEOM_Object::_narrow( GeometryGUI::ClientSObjectToObject( it->Value() ) );
1186 if ( !CORBA::is_nil( cobject ) ) {
1187 GEOM::ListOfLong_var indices = cobject->GetSubShapeIndices();
1188 int length = indices->length();
1189 // VSR 18/03/2014: we need only sub-shapes with single sub-shape index (to exclude groups, etc)
1190 if ( length == 1 && indices[0] == theIndex ) {
1199 return object._retn();
1202 //================================================================
1203 // Function : addSubshapesToStudy
1204 // Purpose : Virtual method to add sub-shapes if needs
1205 //================================================================
1206 void GEOMBase_Helper::addSubshapesToStudy()
1208 //Implemented in Dialogs, called from Accept method
1211 //================================================================
1212 // Function : getSourceObjects
1213 // Purpose : Virtual method to get source objects
1214 //================================================================
1215 QList<GEOM::GeomObjPtr> GEOMBase_Helper::getSourceObjects()
1217 //Implemented in Dialogs, called from Accept method
1218 QList<GEOM::GeomObjPtr> res;
1222 //================================================================
1223 // Function : getSelected
1224 // Purpose : Get selected object by specified type
1226 // Returns valid object if only one object of the specified type is selected
1227 // (no matter global or local selection is activated). If \a type is TopAbs_SHAPE,
1228 // geometrical object of any valid type is expected.
1230 // \param type type of the object 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( TopAbs_ShapeEnum type )
1235 QList<TopAbs_ShapeEnum> types;
1237 return getSelected( types );
1240 //================================================================
1241 // Function : getSelected
1242 // Purpose : Get selected object by specified types
1244 // Returns valid object if only one object of the specified type is selected
1245 // (no matter global or local selection is activated). The list of allowed
1246 // shape types is passed via \a types. If \a types includes TopAbs_SHAPE,
1247 // geometrical object of any valid type is expected.
1249 // \param types list of allowed shape types for the objects to be obtained from selection
1250 // \return selected geometrical object or nil object if selection is not satisfactory
1251 //================================================================
1252 GEOM::GeomObjPtr GEOMBase_Helper::getSelected( const QList<TopAbs_ShapeEnum>& types )
1254 QList<GEOM::GeomObjPtr> selected = getSelected( types, 1 );
1255 return selected.count() > 0 ? selected[0] : GEOM::GeomObjPtr();
1258 //================================================================
1259 // Function : getSelected
1260 // Purpose : Get selected object(s) by specified type
1262 // Returns list of selected objects if selection satisfies specifies selection options.
1263 // (no matter global or local selection is activated). If \a type is TopAbs_SHAPE,
1264 // geometrical objects of any valid type are expected.
1266 // The \a type parameter specifies allowed type of the object(s) being selected.
1267 // The \a count parameter specifies exact number of the objects to be retrieved from selection.
1268 // The \a strict parameter specifies policy being applied to the selection.
1269 // If \a count < 0, then any number of the selected objects is valid (including 0).
1270 // In this case, if \a strict is \c true (default), all selected objects should satisfy
1271 // the specified \a type.
1272 // If \a count > 0, only specified number of the objects is retrieved from the selection.
1273 // In this case, if \a strict is \c true (default), function returns empty list if total number of selected
1274 // objects does not correspond to the \a count parameter. Otherwise (if \a strict is \c false),
1275 // function returns valid list of objects if at least \a count objects satisfy specified \a type.
1277 // \param type type of the object(s) to be obtained from selection
1278 // \param count number of items to be retrieved from selection
1279 // \param strict selection policy
1280 // \return list of selected geometrical objects or empty list if selection is not satisfactory
1281 //================================================================
1282 QList<GEOM::GeomObjPtr> GEOMBase_Helper::getSelected( TopAbs_ShapeEnum type, int count, bool strict )
1284 QList<TopAbs_ShapeEnum> types;
1286 return getSelected( types, count, strict );
1289 static bool typeInList( TopAbs_ShapeEnum type, const QList<TopAbs_ShapeEnum>& types )
1292 for ( int i = 0; i < types.count() && !ok; i++ )
1293 ok = types[i] == TopAbs_SHAPE || types[i] == type;
1297 //================================================================
1298 // Function : getSelected
1299 // Purpose : Get selected objects by specified types
1301 // Returns list of selected objects if selection satisfies specifies selection options.
1302 // (no matter global or local selection is activated). If \a types includes TopAbs_SHAPE,
1303 // geometrical objects of any valid type are expected.
1305 // The \a types parameter specifies allowed types of the object(s) being selected.
1306 // The \a count parameter specifies exact number of the objects to be retrieved from selection.
1307 // The \a strict parameter specifies policy being applied to the selection.
1308 // If \a count < 0, then any number of the selected objects is valid (including 0).
1309 // In this case, if \a strict is \c true (default), all selected objects should satisfy
1310 // the specified \a type.
1311 // If \a count > 0, only specified number of the objects is retrieved from the selection.
1312 // In this case, if \a strict is \c true (default), function returns empty list if total number of selected
1313 // objects does not correspond to the \a count parameter. Otherwise (if \a strict is \c false),
1314 // function returns valid list of objects if at least \a count objects satisfy specified \a type.
1316 // \param types list of allowed shape types for the objects to be obtained from selection
1317 // \param count number of items to be retrieved from selection
1318 // \param strict selection policy
1319 // \return list of selected geometrical objects or empty list if selection is not satisfactory
1320 //================================================================
1321 QList<GEOM::GeomObjPtr> GEOMBase_Helper::getSelected( const QList<TopAbs_ShapeEnum>& types, int count, bool strict )
1323 SUIT_Session* session = SUIT_Session::session();
1324 QList<GEOM::GeomObjPtr> result;
1326 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1328 LightApp_SelectionMgr* selMgr = app->selectionMgr();
1330 SALOME_ListIO selected;
1331 selMgr->selectedObjects( selected );
1332 SALOME_ListIteratorOfListIO it( selected );
1333 bool stopped = false;
1334 for ( ; it.More() && !stopped; it.Next() ) {
1335 Handle(SALOME_InteractiveObject) IO = it.Value();
1336 GEOM::GeomObjPtr object = GEOMBase::ConvertIOinGEOMObject( IO );
1338 TColStd_IndexedMapOfInteger subShapes;
1339 selMgr->GetIndexes( IO, subShapes );
1340 int nbSubShapes = subShapes.Extent();
1341 if ( nbSubShapes == 0 ) {
1343 if ( typeInList( (TopAbs_ShapeEnum)(object->GetShapeType()), types ) ) {
1346 if ( strict && result.count() > count ) {
1350 else if ( !strict && result.count() == count )
1354 else if ( strict ) {
1361 for ( int i = 1; i <= nbSubShapes && !stopped; i++ ) {
1362 int idx = subShapes( i );
1363 GEOM::GeomObjPtr subShape = findObjectInFather( object.get(), idx );
1365 // sub-shape is not yet published in the study
1366 GEOM::ShapesOpPtr shapesOp = getGeomEngine()->GetIShapesOperations();
1367 subShape.take( shapesOp->GetSubShape( object.get(), idx ) ); // take ownership!
1369 if ( typeInList( (TopAbs_ShapeEnum)(subShape->GetShapeType()), types ) ) {
1372 if ( strict && result.count() > count ) {
1376 else if ( !strict && result.count() == count )
1380 else if ( strict ) {
1392 //================================================================
1393 // Function : hideSourceObject
1395 //================================================================
1396 void GEOMBase_Helper::hideSourceObjects( QList<GEOM::GeomObjPtr> theObject )
1398 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1399 if ( resMgr->booleanValue( "Geometry", "hide_input_object", true) ) {
1400 GEOM_Displayer* aDisplayer = getDisplayer();
1401 for ( int i = 0; i < theObject.count(); i++ )
1402 aDisplayer->Erase( theObject[i].get() );
1406 //================================================================
1407 // Function : setIsApplyAndClose
1408 // Purpose : Set value of the flag indicating that the dialog is
1409 // accepted by Apply & Close button
1410 //================================================================
1411 void GEOMBase_Helper::setIsApplyAndClose( const bool theFlag )
1413 myIsApplyAndClose = theFlag;
1416 //================================================================
1417 // Function : isApplyAndClose
1418 // Purpose : Get value of the flag indicating that the dialog is
1419 // accepted by Apply & Close button
1420 //================================================================
1421 bool GEOMBase_Helper::isApplyAndClose() const
1423 return myIsApplyAndClose;
1426 //================================================================
1427 // Function : setIsOptimizedBrowsing
1428 // Purpose : Set value of the flag switching to optimized
1429 // browsing mode (to select the first published
1431 //================================================================
1432 void GEOMBase_Helper::setIsOptimizedBrowsing( const bool theFlag )
1434 myIsOptimizedBrowsing = theFlag;
1437 //================================================================
1438 // Function : isOptimizedBrowsing
1439 // Purpose : Get value of the flag switching to optimized
1440 // browsing mode (to select the first published
1442 //================================================================
1443 bool GEOMBase_Helper::isOptimizedBrowsing() const
1445 return myIsOptimizedBrowsing;