1 // Copyright (C) 2007-2021 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, SUIT_ViewWindow* aVW )
92 : myDisplayer( 0 ), myCommand( 0 ), myViewWindow( aVW ), 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 //MESSAGE("anEntry: "<< anEntry.toStdString().c_str());
493 QString aName = GEOMBase::GetName( anObj );
494 aListOfIO.Append( new SALOME_InteractiveObject( anEntry.toUtf8().constData(),
495 "GEOM", aName.toUtf8().constData() ));
499 getDisplayer()->LocalSelection( aListOfIO, modes );
502 //================================================================
503 // Function : localSelection
504 // Purpose : Activate selection of sub-shapes in accordance with mode
505 // theMode is from TopAbs_ShapeEnum
506 //================================================================
507 void GEOMBase_Helper::localSelection( const ObjectList& theObjs, const int theMode )
509 std::list<int> modes;
510 modes.push_back( theMode );
511 localSelection( theObjs, modes );
514 //================================================================
515 // Function : localSelection
516 // Purpose : Activate selection of sub-shapes in accordance with mode
517 // modes are from TopAbs_ShapeEnum
518 //================================================================
519 void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const std::list<int> modes )
521 // If object is null local selection for all objects is activated
522 if ( obj->_is_nil() ) {
523 getDisplayer()->LocalSelection( Handle(SALOME_InteractiveObject)(), modes );
528 objList.push_back( obj );
529 localSelection( objList, modes );
532 //================================================================
533 // Function : localSelection
534 // Purpose : Activate selection of sub-shapes in accordance with mode
535 // mode is from TopAbs_ShapeEnum
536 //================================================================
537 void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const int mode )
539 std::list<int> modes;
540 modes.push_back( mode );
541 localSelection( obj, modes );
544 //================================================================
545 // Function : localSelection
546 // Purpose : Activate selection of sub-shapes in accordance with mode
547 // mode is from TopAbs_ShapeEnum
548 //================================================================
549 void GEOMBase_Helper::localSelection( const std::string& entry, const std::string& name, const std::list<int> modes)
551 SALOME_ListIO aListOfIO;
552 QString aName = name.c_str();
553 aListOfIO.Append( new SALOME_InteractiveObject( entry.c_str(),
554 "GEOM", aName.toUtf8().constData() ));
555 getDisplayer()->LocalSelection( aListOfIO, modes );
558 //================================================================
559 // Function : localSelection
560 // Purpose : Activate selection of sub-shapes in accordance with mode
561 // modes are from TopAbs_ShapeEnum
562 //================================================================
563 void GEOMBase_Helper::localSelection( const std::list<int> modes )
565 localSelection( GEOM::GEOM_Object::_nil(), modes );
568 //================================================================
569 // Function : localSelection
570 // Purpose : Activate selection of sub-shapes in accordance with mode
571 // mode is from TopAbs_ShapeEnum
572 //================================================================
573 void GEOMBase_Helper::localSelection( const int mode )
575 std::list<int> modes;
576 modes.push_back( mode );
577 localSelection( modes );
580 //================================================================
581 // Function : globalSelection
582 // Purpose : Activate selection of sub-shapes. Set selection filters
583 // in accordance with mode. theMode is from GEOMImpl_Types
584 //================================================================
585 void GEOMBase_Helper::globalSelection( const int theMode, const bool update )
587 getDisplayer()->GlobalSelection( theMode, update );
590 //================================================================
591 // Function : globalSelection
592 // Purpose : Activate selection of sub-shapes. Set selection filters
593 // in accordance with mode. theMode is from GEOMImpl_Types
594 //================================================================
595 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
598 getDisplayer()->GlobalSelection( theModes, update );
601 //================================================================
602 // Function : globalSelection
603 // Purpose : Activate selection of sub-shapes. Set selection filters
604 // in accordance with mode. theMode is from GEOMImpl_Types
605 //================================================================
606 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
607 const QList<int>& subShapes,
610 getDisplayer()->GlobalSelection( theModes, update, &subShapes );
613 //================================================================
614 // Function : addInStudy
615 // Purpose : Add object in study
616 //================================================================
617 QString GEOMBase_Helper::addInStudy( GEOM::GEOM_Object_ptr theObj, const char* theName )
622 _PTR(Study) aStudy = getStudy()->studyDS();
623 if ( !aStudy || theObj->_is_nil() )
626 GEOM::GEOM_Object_ptr aFatherObj = getFather( theObj );
628 SALOMEDS::SObject_var aSO =
629 getGeomEngine()->AddInStudy(theObj, theName, aFatherObj);
632 if ( !aSO->_is_nil() ) {
633 CORBA::String_var entry = aSO->GetID();
634 anEntry = entry.in();
636 // Each dialog is responsible for this method implementation,
637 // default implementation does nothing
638 restoreSubShapes(aSO);
644 //================================================================
645 // Function : restoreSubShapes
646 // Purpose : restore tree of argument's sub-shapes under the resulting shape
647 //================================================================
648 void GEOMBase_Helper::restoreSubShapes (SALOMEDS::SObject_ptr /*theSObject*/)
650 // do nothing by default
652 // example of implementation in particular dialog:
653 // GEOM::ListOfGO anArgs;
654 // anArgs.length(0); // empty list means that all arguments should be restored
655 // getGeomEngine()->RestoreSubShapesSO(theSObject, anArgs,
656 // /*theFindMethod=*/GEOM::FSM_GetInPlace,
657 // /*theInheritFirstArg=*/false);
660 //================================================================
661 // Function : updateObjBrowser
662 // Purpose : Update object browser
663 //================================================================
664 void GEOMBase_Helper::updateObjBrowser() const
666 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
668 CAM_Module* module = app->module( "Geometry" );
669 SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
671 appMod->updateObjBrowser();
676 //================================================================
677 // Function : updateViewer
678 // Purpose : Update active 3D view
679 //================================================================
680 void GEOMBase_Helper::updateViewer()
682 getDisplayer()->UpdateViewer();
685 //================================================================
686 // Function : getStudy
687 // Purpose : Returns the active study. It is recommended to use
688 // this method instead of direct desktop->getActiveStudy() calls
689 //================================================================
690 SalomeApp_Study* GEOMBase_Helper::getStudy() const
692 SUIT_Desktop* aDesktop = getDesktop();
696 QList<SUIT_Application*> anAppList = SUIT_Session::session()->applications();
698 SUIT_Application* anApp = 0;
699 QListIterator<SUIT_Application*> it( anAppList );
700 while ( it.hasNext() )
703 if ( anApp && anApp->desktop() == aDesktop )
707 return dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
710 //================================================================
711 // Function : getEntry
713 //================================================================
714 QString GEOMBase_Helper::getEntry( GEOM::GEOM_Object_ptr object ) const
716 SalomeApp_Study* study = getStudy();
718 QString objIOR = GEOMBase::GetIORFromObject( object );
719 if ( objIOR != "" ) {
720 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( objIOR.toUtf8().constData() ) );
722 return QString::fromStdString(SO->GetID());
728 //================================================================
729 // Function : getDisplayer
731 //================================================================
732 GEOM_Displayer* GEOMBase_Helper::getDisplayer()
735 myDisplayer = new GEOM_Displayer();
739 //================================================================
740 // Function : clearShapeBuffer
742 //================================================================
743 void GEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
745 GeometryGUI::ClearShapeBuffer(theObj);
748 //================================================================
749 // Function : openCommand
751 //================================================================
752 bool GEOMBase_Helper::openCommand()
755 if ( !getStudy() || hasCommand() )
757 MESSAGE("Getting out from openCommand()")
761 GEOM::GEOM_IOperations_var anOp = GEOM::GEOM_IOperations::_narrow( getOperation() );
762 if ( !anOp->_is_nil() ) {
763 myCommand = new GEOM_Operation( SUIT_Session::session()->activeApplication(), anOp.in() );
769 MESSAGE("anOp->_is_nil() = true")
775 //================================================================
776 // Function : abortCommand
778 //================================================================
779 bool GEOMBase_Helper::abortCommand()
785 delete myCommand; // I don't know where to delete this object here ?
791 //================================================================
792 // Function : commitCommand
794 //================================================================
795 bool GEOMBase_Helper::commitCommand( const char* )
801 delete myCommand; // I don't know where to delete this object here ?
807 //================================================================
808 // Function : hasCommand
810 //================================================================
811 bool GEOMBase_Helper::hasCommand() const
813 return (bool)myCommand;
816 //================================================================
817 // Function : getOperation
819 //================================================================
820 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::getOperation()
822 if ( myOperation->_is_nil() )
823 myOperation = createOperation();
830 //================================================================
831 // Function : checkViewWindow
833 //================================================================
834 bool GEOMBase_Helper::checkViewWindow()
837 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
838 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
839 while ( it.hasNext() )
841 if ( myViewWindow == it.next() )
849 //================================================================
850 // Function : onAccept
851 // Purpose : This method should be called from dialog's slots onOk() and onApply()
852 // It performs user input validation, then it
853 // performs a proper operation and manages transactions, etc.
854 //================================================================
855 bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction, bool erasePreviewFlag )
857 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
860 MESSAGE("appStudy is empty")
863 _PTR(Study) aStudy = appStudy->studyDS();
865 bool aLocked = (_PTR(AttributeStudyProperties) (aStudy->GetProperties()))->IsLocked();
867 MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
868 SUIT_MessageBox::warning ( (QWidget*)SUIT_Session::session()->activeApplication()->desktop(),
869 QObject::tr("WRN_WARNING"),
870 QObject::tr("WRN_STUDY_LOCKED"),
871 QObject::tr("BUT_OK") );
876 if ( !isValid( msg ) ) {
882 erasePreview( false );
887 if ( ( !publish && !useTransaction ) || openCommand() ) {
888 SUIT_OverrideCursor wc;
889 SUIT_Session::session()->activeApplication()->putInfo( "" );
891 if ( !execute( objects ) || !getOperation()->IsDone() ) {
897 QList<GEOM::GeomObjPtr> anObjectList = getSourceObjects( );
898 addSubshapesToStudy(); // add Sub-shapes if local selection
899 const int nbObjs = objects.size();
900 QStringList anEntryList;
901 int currObj = 1, aNumber = 1;
902 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it, currObj++ ) {
903 GEOM::GEOM_Object_var obj=*it;
905 QString aName = getObjectName(obj);
906 if (aName.isEmpty()) {
907 aName = getNewObjectName(currObj);
910 aName = getPrefix(obj);
912 // Try to find a unique name
913 aName = GEOMBase::GetDefaultName(aName, extractPrefix());
915 // Don't check name uniqueness in case of numerous objects
916 aName = aName + "_" + QString::number(aNumber++);
919 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
920 if ( aName.isEmpty() )
921 aName = GEOMBase::GetDefaultName( getPrefix( obj ) );
924 anEntryList << addInStudy( obj, aName.toUtf8().constData() );
926 if( isDisplayResult() )
927 display( obj, false );
928 #ifdef WITHGENERICOBJ
929 // obj has been published in study. Its refcount has been incremented.
930 // It is safe to decrement its refcount
931 // so that it will be destroyed when the entry in study will be removed
936 // asv : fix of PAL6454. If publish==false, then the original shape
937 // was modified, and need to be re-cached in GEOM_Client before redisplay
938 clearShapeBuffer( obj );
939 // withChildren=true, updateView=false
940 if( isDisplayResult() )
941 redisplay( obj, true, false );
948 if( SUIT_Application* anApp = SUIT_Session::session()->activeApplication() ) {
949 LightApp_Application* aLightApp = dynamic_cast<LightApp_Application*>( anApp );
951 QString anOpName( typeid(*this).name() );
952 aLightApp->emitOperationFinished( "Geometry", anOpName, anEntryList );
954 if ( !isDisableBrowsing() )
955 aLightApp->browseObjects( anEntryList, isApplyAndClose(), isOptimizedBrowsing() );
957 anApp->putInfo( QObject::tr("GEOM_PRP_DONE") );
959 if ( anObjectList.count() > 0 )
960 hideSourceObjects( anObjectList );
968 catch( const SALOME::SALOME_Exception& e ) {
969 SalomeApp_Tools::QtCatchCorbaException( e );
971 MESSAGE("Exception caught")
976 MESSAGE("result ="<<result)
981 //================================================================
982 // Function : showError
983 // Purpose : Shows a message box with information about an error taken from getOperation()->GetErrorCode()
984 //================================================================
985 void GEOMBase_Helper::showError()
988 if ( !getOperation()->_is_nil() )
989 msg = QObject::tr( getOperation()->GetErrorCode() );
992 msg = QObject::tr( "GEOM_PRP_ABORT" );
994 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
995 QObject::tr( "GEOM_ERROR_STATUS" ),
997 QObject::tr( "BUT_OK" ) );
1000 //================================================================
1001 // Function : showError
1002 // Purpose : Shows a error message followed by <msg>
1003 //================================================================
1004 void GEOMBase_Helper::showError( const QString& msg )
1006 QString str( QObject::tr( "GEOM_INCORRECT_INPUT" ) );
1007 if ( !msg.isEmpty() )
1009 SUIT_MessageBox::critical(SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ), str, QObject::tr( "BUT_OK" ) );
1012 //////////////////////////////////////////////////////////////////
1013 // Virtual methods to be redefined in dialogs
1014 //////////////////////////////////////////////////////////////////
1016 //================================================================
1017 // Function : createOperation
1018 // Purpose : Redefine this method to return proper IOperation reference
1019 //================================================================
1020 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::createOperation()
1022 GEOM::GEOM_IOperations_var aNilOp;
1023 return aNilOp._retn();
1026 //================================================================
1027 // Function : isValid
1028 // Purpose : Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
1029 //================================================================
1030 bool GEOMBase_Helper::isValid( QString& )
1035 //================================================================
1036 // Function : execute
1037 // Purpose : This method is called by onAccept().
1038 // It should perform the required operation and put all new or modified objects into
1039 // <objects> argument.Should return <false> if some error occurs during its execution.
1040 //================================================================
1041 bool GEOMBase_Helper::execute( ObjectList& )
1046 //================================================================
1047 // Function : getFather
1048 // Purpose : This method is called by addInStudy(). It should return a father object
1049 // for <theObj> or a nil reference if <theObj> should be published
1050 // as a top-level object.
1051 //================================================================
1052 GEOM::GEOM_Object_ptr GEOMBase_Helper::getFather( GEOM::GEOM_Object_ptr )
1054 return GEOM::GEOM_Object::_nil();
1057 //================================================================
1058 // Function : getObjectName
1059 // Purpose : Redefine this method to return proper name for the given object
1060 //================================================================
1061 QString GEOMBase_Helper::getObjectName( GEOM::GEOM_Object_ptr ) const
1066 //================================================================
1067 // Function : getNewObjectName
1068 // Purpose : Redefine this method to return proper name for a new object
1069 //================================================================
1070 QString GEOMBase_Helper::getNewObjectName( int ) const
1075 //================================================================
1076 // Function : extractPrefix
1077 // Purpose : Redefine this method to return \c true if necessary
1078 // to extract prefix when generating new name for the
1079 // object(s) being created
1080 //================================================================
1081 bool GEOMBase_Helper::extractPrefix() const
1086 //================================================================
1087 // Function : getPrefix
1088 // Purpose : Get prefix for name of created object
1089 //================================================================
1090 QString GEOMBase_Helper::getPrefix( GEOM::GEOM_Object_ptr theObj ) const
1092 if ( !myPrefix.isEmpty() || theObj->_is_nil() )
1095 GEOM::shape_type aType = theObj->GetShapeType();
1099 case GEOM::VERTEX : return QObject::tr( "GEOM_VERTEX" );
1100 case GEOM::EDGE : return QObject::tr( "GEOM_EDGE" );
1101 case GEOM::WIRE : return QObject::tr( "GEOM_WIRE" );
1102 case GEOM::FACE : return QObject::tr( "GEOM_FACE" );
1103 case GEOM::SHELL : return QObject::tr( "GEOM_SHELL" );
1104 case GEOM::SOLID : return QObject::tr( "GEOM_SOLID" );
1105 case GEOM::COMPSOLID: return QObject::tr( "GEOM_COMPOUNDSOLID" );
1106 case GEOM::COMPOUND : return QObject::tr( "GEOM_COMPOUND" );
1107 default : return "";
1111 //================================================================
1112 // Function : getDesktop
1113 // Purpose : Returns myDesktop field. Initialized in constructor,
1114 // usually as dynamic_cast<SUIT_Desktop*>(parentWidget())
1115 //================================================================
1116 SUIT_Desktop* GEOMBase_Helper::getDesktop() const
1121 //================================================================
1122 // Function : selectObjects
1123 // Purpose : Selects list of objects
1124 //================================================================
1125 bool GEOMBase_Helper::selectObjects( ObjectList& objects )
1127 SUIT_DataOwnerPtrList aList;
1128 ObjectList::iterator anIter;
1129 for ( anIter = objects.begin(); anIter != objects.end(); ++anIter )
1131 QString anEntry = getEntry( *anIter );
1132 LightApp_DataOwner* anOwher = new LightApp_DataOwner( anEntry );
1133 aList.append( anOwher );
1136 SUIT_Session* session = SUIT_Session::session();
1137 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1141 LightApp_SelectionMgr* aMgr = app->selectionMgr();
1145 aMgr->setSelected( aList, false );
1150 //================================================================
1151 // Function : findObjectInFather
1152 // Purpose : It should return an object if its founded in study or
1153 // return Null object if the object is not founded
1154 //================================================================
1155 GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather (GEOM::GEOM_Object_ptr theFather,
1156 const QString& theName)
1158 SalomeApp_Application* app =
1159 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1160 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1161 _PTR(Study) aDStudy = appStudy->studyDS();
1162 QString IOR = GEOMBase::GetIORFromObject( theFather );
1163 _PTR(SObject) SObj ( aDStudy->FindObjectIOR( IOR.toUtf8().constData() ) );
1165 bool inStudy = false;
1166 GEOM::GEOM_Object_var aReturnObject;
1167 for (_PTR(ChildIterator) iit (aDStudy->NewChildIterator( SObj )); iit->More() && !inStudy; iit->Next()) {
1168 _PTR(SObject) child (iit->Value());
1169 QString aChildName = child->GetName().c_str();
1170 if (aChildName == theName) {
1172 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(iit->Value());
1173 aReturnObject = GEOM::GEOM_Object::_narrow( corbaObj );
1177 return aReturnObject._retn();
1179 return GEOM::GEOM_Object::_nil();
1182 //================================================================
1183 // Function : findObjectInFather
1184 // Purpose : It should return an object if its founded in study or
1185 // return Null object if the object is not founded
1186 //================================================================
1187 GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather( GEOM::GEOM_Object_ptr theFather,
1190 GEOM::GEOM_Object_var object;
1192 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
1194 _PTR(Study) studyDS = study->studyDS();
1195 QString IOR = GEOMBase::GetIORFromObject( theFather );
1196 _PTR(SObject) sobject( studyDS->FindObjectIOR( IOR.toLatin1().constData() ) );
1198 _PTR(ChildIterator) it( studyDS->NewChildIterator( sobject ) );
1199 for ( ; it->More(); it->Next() ) {
1200 GEOM::GEOM_Object_var cobject = GEOM::GEOM_Object::_narrow( GeometryGUI::ClientSObjectToObject( it->Value() ) );
1201 if ( !CORBA::is_nil( cobject ) ) {
1202 GEOM::ListOfLong_var indices = cobject->GetSubShapeIndices();
1203 int length = indices->length();
1204 // VSR 18/03/2014: we need only sub-shapes with single sub-shape index (to exclude groups, etc)
1205 if ( length == 1 && indices[0] == theIndex ) {
1214 return object._retn();
1217 //================================================================
1218 // Function : addSubshapesToStudy
1219 // Purpose : Virtual method to add sub-shapes if needs
1220 //================================================================
1221 void GEOMBase_Helper::addSubshapesToStudy()
1223 //Implemented in Dialogs, called from Accept method
1226 //================================================================
1227 // Function : getSourceObjects
1228 // Purpose : Virtual method to get source objects
1229 //================================================================
1230 QList<GEOM::GeomObjPtr> GEOMBase_Helper::getSourceObjects()
1232 //Implemented in Dialogs, called from Accept method
1233 QList<GEOM::GeomObjPtr> res;
1237 //================================================================
1238 // Function : getSelected
1239 // Purpose : Get selected object by specified type
1241 // Returns valid object if only one object of the specified type is selected
1242 // (no matter global or local selection is activated). If \a type is TopAbs_SHAPE,
1243 // geometrical object of any valid type is expected.
1245 // \param type type of the object to be obtained from selection
1246 // \return selected geometrical object or nil object if selection is not satisfactory
1247 //================================================================
1248 GEOM::GeomObjPtr GEOMBase_Helper::getSelected( TopAbs_ShapeEnum type )
1250 QList<TopAbs_ShapeEnum> types;
1252 return getSelected( types );
1255 //================================================================
1256 // Function : getSelected
1257 // Purpose : Get selected object by specified types
1259 // Returns valid object if only one object of the specified type is selected
1260 // (no matter global or local selection is activated). The list of allowed
1261 // shape types is passed via \a types. If \a types includes TopAbs_SHAPE,
1262 // geometrical object of any valid type is expected.
1264 // \param types list of allowed shape types for the objects to be obtained from selection
1265 // \return selected geometrical object or nil object if selection is not satisfactory
1266 //================================================================
1267 GEOM::GeomObjPtr GEOMBase_Helper::getSelected( const QList<TopAbs_ShapeEnum>& types )
1269 QList<GEOM::GeomObjPtr> selected = getSelected( types, 1 );
1270 return selected.count() > 0 ? selected[0] : GEOM::GeomObjPtr();
1273 //================================================================
1274 // Function : getSelected
1275 // Purpose : Get selected object(s) by specified type
1277 // Returns list of selected objects if selection satisfies specifies selection options.
1278 // (no matter global or local selection is activated). If \a type is TopAbs_SHAPE,
1279 // geometrical objects of any valid type are expected.
1281 // The \a type parameter specifies allowed type of the object(s) being selected.
1282 // The \a count parameter specifies exact number of the objects to be retrieved from selection.
1283 // The \a strict parameter specifies policy being applied to the selection.
1284 // If \a count < 0, then any number of the selected objects is valid (including 0).
1285 // In this case, if \a strict is \c true (default), all selected objects should satisfy
1286 // the specified \a type.
1287 // If \a count > 0, only specified number of the objects is retrieved from the selection.
1288 // In this case, if \a strict is \c true (default), function returns empty list if total number of selected
1289 // objects does not correspond to the \a count parameter. Otherwise (if \a strict is \c false),
1290 // function returns valid list of objects if at least \a count objects satisfy specified \a type.
1292 // \param type type of the object(s) to be obtained from selection
1293 // \param count number of items to be retrieved from selection
1294 // \param strict selection policy
1295 // \return list of selected geometrical objects or empty list if selection is not satisfactory
1296 //================================================================
1297 QList<GEOM::GeomObjPtr> GEOMBase_Helper::getSelected( TopAbs_ShapeEnum type, int count, bool strict )
1299 QList<TopAbs_ShapeEnum> types;
1301 return getSelected( types, count, strict );
1304 static bool typeInList( TopAbs_ShapeEnum type, const QList<TopAbs_ShapeEnum>& types )
1307 for ( int i = 0; i < types.count() && !ok; i++ )
1308 ok = types[i] == TopAbs_SHAPE || types[i] == type;
1312 //================================================================
1313 // Function : getSelected
1314 // Purpose : Get selected objects by specified types
1316 // Returns list of selected objects if selection satisfies specifies selection options.
1317 // (no matter global or local selection is activated). If \a types includes TopAbs_SHAPE,
1318 // geometrical objects of any valid type are expected.
1320 // The \a types parameter specifies allowed types of the object(s) being selected.
1321 // The \a count parameter specifies exact number of the objects to be retrieved from selection.
1322 // The \a strict parameter specifies policy being applied to the selection.
1323 // If \a count < 0, then any number of the selected objects is valid (including 0).
1324 // In this case, if \a strict is \c true (default), all selected objects should satisfy
1325 // the specified \a type.
1326 // If \a count > 0, only specified number of the objects is retrieved from the selection.
1327 // In this case, if \a strict is \c true (default), function returns empty list if total number of selected
1328 // objects does not correspond to the \a count parameter. Otherwise (if \a strict is \c false),
1329 // function returns valid list of objects if at least \a count objects satisfy specified \a type.
1331 // \param types list of allowed shape types for the objects to be obtained from selection
1332 // \param count number of items to be retrieved from selection
1333 // \param strict selection policy
1334 // \return list of selected geometrical objects or empty list if selection is not satisfactory
1335 //================================================================
1336 QList<GEOM::GeomObjPtr> GEOMBase_Helper::getSelected( const QList<TopAbs_ShapeEnum>& types, int count, bool strict )
1338 SUIT_Session* session = SUIT_Session::session();
1339 QList<GEOM::GeomObjPtr> result;
1341 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1343 LightApp_SelectionMgr* selMgr = app->selectionMgr();
1345 SALOME_ListIO selected;
1346 selMgr->selectedObjects( selected );
1347 SALOME_ListIteratorOfListIO it( selected );
1348 bool stopped = false;
1349 for ( ; it.More() && !stopped; it.Next() ) {
1350 Handle(SALOME_InteractiveObject) IO = it.Value();
1351 GEOM::GeomObjPtr object = GEOMBase::ConvertIOinGEOMObject( IO );
1353 TColStd_IndexedMapOfInteger subShapes;
1354 selMgr->GetIndexes( IO, subShapes );
1355 int nbSubShapes = subShapes.Extent();
1356 if ( nbSubShapes == 0 ) {
1358 if ( typeInList( (TopAbs_ShapeEnum)(object->GetShapeType()), types ) ) {
1361 if ( strict && result.count() > count ) {
1365 else if ( !strict && result.count() == count )
1369 else if ( strict ) {
1376 for ( int i = 1; i <= nbSubShapes && !stopped; i++ ) {
1377 int idx = subShapes( i );
1378 GEOM::GeomObjPtr subShape = findObjectInFather( object.get(), idx );
1380 // sub-shape is not yet published in the study
1381 GEOM::ShapesOpPtr shapesOp = getGeomEngine()->GetIShapesOperations();
1382 subShape.take( shapesOp->GetSubShape( object.get(), idx ) ); // take ownership!
1384 if ( typeInList( (TopAbs_ShapeEnum)(subShape->GetShapeType()), types ) ) {
1387 if ( strict && result.count() > count ) {
1391 else if ( !strict && result.count() == count )
1395 else if ( strict ) {
1407 //================================================================
1408 // Function : hideSourceObject
1410 //================================================================
1411 void GEOMBase_Helper::hideSourceObjects( QList<GEOM::GeomObjPtr> theObject )
1413 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1414 if ( resMgr->booleanValue( "Geometry", "hide_input_object", true) ) {
1415 GEOM_Displayer* aDisplayer = getDisplayer();
1416 for ( int i = 0; i < theObject.count(); i++ )
1417 aDisplayer->Erase( theObject[i].get() );
1421 //================================================================
1422 // Function : setIsApplyAndClose
1423 // Purpose : Set value of the flag indicating that the dialog is
1424 // accepted by Apply & Close button
1425 //================================================================
1426 void GEOMBase_Helper::setIsApplyAndClose( const bool theFlag )
1428 myIsApplyAndClose = theFlag;
1431 //================================================================
1432 // Function : isApplyAndClose
1433 // Purpose : Get value of the flag indicating that the dialog is
1434 // accepted by Apply & Close button
1435 //================================================================
1436 bool GEOMBase_Helper::isApplyAndClose() const
1438 return myIsApplyAndClose;
1441 //================================================================
1442 // Function : setIsOptimizedBrowsing
1443 // Purpose : Set value of the flag switching to optimized
1444 // browsing mode (to select the first published
1446 //================================================================
1447 void GEOMBase_Helper::setIsOptimizedBrowsing( const bool theFlag )
1449 myIsOptimizedBrowsing = theFlag;
1452 //================================================================
1453 // Function : isOptimizedBrowsing
1454 // Purpose : Get value of the flag switching to optimized
1455 // browsing mode (to select the first published
1457 //================================================================
1458 bool GEOMBase_Helper::isOptimizedBrowsing() const
1460 return myIsOptimizedBrowsing;