1 // Copyright (C) 2007-2024 CEA, EDF, 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)
29 #include "GEOMBase_Helper.h"
31 #include "GEOM_Operation.h"
33 #include <GeometryGUI.h>
35 #include <SUIT_Desktop.h>
36 #include <SUIT_Session.h>
37 #include <SUIT_ViewManager.h>
38 #include <SUIT_ViewWindow.h>
39 #include <SUIT_ViewModel.h>
40 #include <SUIT_MessageBox.h>
41 #include <SUIT_OverrideCursor.h>
42 #include <SUIT_ResourceMgr.h>
44 #include <SalomeApp_Module.h>
45 #include <SalomeApp_Application.h>
46 #include <SalomeApp_Study.h>
47 #include <LightApp_SelectionMgr.h>
48 #include <LightApp_DataOwner.h>
49 #include <SalomeApp_Tools.h>
50 #include <SALOME_ListIO.hxx>
51 #include "utilities.h"
53 #include <SALOME_Prs.h>
54 #include "utilities.h"
56 #include <OCCViewer_ViewModel.h>
57 #include <SVTK_ViewModel.h>
59 #include <TCollection_AsciiString.hxx>
60 #include <TColStd_IndexedMapOfInteger.hxx>
62 //To disable automatic genericobj management, the following line should be commented.
63 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
64 #define WITHGENERICOBJ
66 //================================================================
67 // Function : getActiveView
68 // Purpose : Get active view window, returns 0 if no open study frame
69 //================================================================
70 SUIT_ViewWindow* GEOMBase_Helper::getActiveView()
72 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
74 return SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
80 //================================================================
81 // Function : getGeomEngine
82 // Purpose : Static method
83 //================================================================
84 GEOM::GEOM_Gen_ptr GEOMBase_Helper::getGeomEngine()
86 return GeometryGUI::GetGeomGen();
89 //================================================================
90 // Function : GEOMBase_Helper
92 //================================================================
93 GEOMBase_Helper::GEOMBase_Helper( SUIT_Desktop* desktop, SUIT_ViewWindow* aVW )
94 : myDisplayer( 0 ), myCommand( 0 ), myViewWindow( aVW ), isPreview( false ), myDesktop( desktop ),
95 myIsApplyAndClose( false ), myIsOptimizedBrowsing( false ), myIsWaitCursorEnabled( true ),
96 myIsDisableBrowsing(false), myIsDisplayResult(true)
100 //================================================================
101 // Function : ~GEOMBase_Helper
103 //================================================================
104 GEOMBase_Helper::~GEOMBase_Helper()
106 //rnv: Fix for the "IPAL21922 : WinTC5.1.4: incorrect quit salome"
107 if ( !SUIT_Session::session()->activeApplication() || !SUIT_Session::session()->activeApplication()->desktop() )
110 if ( myPreview.size() )
114 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
116 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
118 globalSelection(aGeomGUI->getLocalSelectionMode() , true );
123 if ( !CORBA::is_nil( myOperation ) )
124 myOperation->UnRegister();
127 //================================================================
128 // Function : display
130 //================================================================
131 void GEOMBase_Helper::display( const ObjectList& objList, const bool updateView )
133 ObjectList::const_iterator it;
134 for ( it = objList.begin(); it != objList.end(); it++ ) {
135 display( *it, false );
137 if ( !objList.empty() && updateView )
138 getDisplayer()->UpdateViewer();
141 //================================================================
142 // Function : display
143 // Purpose : Display object.
144 // Important : Object must be already in study
145 //================================================================
146 void GEOMBase_Helper::display( GEOM::GEOM_Object_ptr object, const bool updateView )
148 // Unset color of shape ( this color may be set during preview displaying )
149 // Default color will be used
150 // getDisplayer()->UnsetColor();
151 getDisplayer()->UnsetWidth();
153 MESSAGE("GEOMBase_Helper::display myTexture = "<<getDisplayer()->GetTexture());
155 // Enable activisation of selection
156 getDisplayer()->SetToActivate( true );
159 getDisplayer()->Display( object, updateView );
162 //================================================================
165 //================================================================
166 void GEOMBase_Helper::erase( const ObjectList& objList, const bool updateView )
168 ObjectList::const_iterator it = objList.begin();
169 for ( ; it != objList.end(); it++ ) {
172 if ( !objList.empty() && updateView )
173 getDisplayer()->UpdateViewer();
176 //================================================================
179 //================================================================
180 void GEOMBase_Helper::erase( GEOM::GEOM_Object_ptr object, const bool updateView )
182 if ( !object->_is_nil() ) {
183 QString entry = getEntry( object );
184 QString name = GEOMBase::GetName( object );
185 getDisplayer()->Erase ( new SALOME_InteractiveObject(entry.toUtf8().constData(),
187 name.toUtf8().constData() ),
192 //================================================================
193 // Function : redisplay
195 //================================================================
196 void GEOMBase_Helper::redisplay( const ObjectList& objList,
197 const bool withChildren,
198 const bool updateView )
200 ObjectList::const_iterator it = objList.begin();
201 for ( ; it != objList.end(); it++ ) {
202 redisplay( *it, withChildren, false );
204 if ( !objList.empty() && updateView )
205 getDisplayer()->UpdateViewer();
208 //================================================================
209 // Function : redisplay
211 //================================================================
212 void GEOMBase_Helper::redisplay( GEOM::GEOM_Object_ptr object,
213 const bool withChildren,
214 const bool updateView )
216 if ( !object->_is_nil() ) {
217 // Unset color of shape ( this color may be set during preview displaying )
218 // Default color will be used
219 getDisplayer()->UnsetColor();
220 getDisplayer()->UnsetWidth();
222 // Enable activisation of selection
223 getDisplayer()->SetToActivate( true );
225 QString entry = getEntry( object );
226 QString name = GEOMBase::GetName( object );
227 getDisplayer()->Redisplay
228 (new SALOME_InteractiveObject (entry.toUtf8().constData(),
230 name.toUtf8().constData()),
234 if ( withChildren ) {
235 SalomeApp_Study* aDoc = getStudy();
236 if ( aDoc && aDoc->studyDS() ) {
237 _PTR(Study) aStudy = aDoc->studyDS();
238 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string(object);
239 _PTR(SObject) aSObj (aStudy->FindObjectIOR(std::string(objStr.in())));
241 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
242 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
243 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow
244 (GeometryGUI::ClientSObjectToObject(anIt->Value()));
245 if ( !CORBA::is_nil( aChild ) ) {
246 if ( !aChild->_is_nil() ) {
247 QString entry = getEntry( aChild );
248 QString name = GEOMBase::GetName( aChild );
249 getDisplayer()->Redisplay
250 ( new SALOME_InteractiveObject( entry.toUtf8().constData(),
252 name.toUtf8().constData() ),
262 getDisplayer()->UpdateViewer();
265 //================================================================
266 // Function : displayPreview
267 // Purpose : Method for displaying preview based on execute() results
268 //================================================================
269 void GEOMBase_Helper::displayPreview( const bool display,
272 const bool toRemoveFromEngine,
273 const double lineWidth,
274 const int displayMode,
279 erasePreview( update );
285 if ( !isValid( msg ) )
287 erasePreview( update );
293 erasePreview( false );
296 SUIT_OverrideCursor wc;
299 if ( !isWaitCursorEnabled() )
302 if ( !execute( objects ) || !getOperation()->IsDone() ) {
306 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it )
308 GEOM::GEOM_Object_var obj = *it;
309 displayPreview( obj, true, activate, false, lineWidth, displayMode, color );
310 if ( toRemoveFromEngine )
315 catch( const SALOME::SALOME_Exception& e ) {
316 SalomeApp_Tools::QtCatchCorbaException( e );
325 //================================================================
326 // Function : displayPreview
327 // Purpose : Method for displaying preview of resulting shape
328 //================================================================
329 void GEOMBase_Helper::displayPreview( GEOM::GEOM_Object_ptr object,
333 const double lineWidth,
334 const int displayMode,
337 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
339 // Set color for preview shape
340 getDisplayer()->SetColor( color == -1 ? Quantity_NOC_VIOLET : color );
342 // set width of displayed shape
343 getDisplayer()->SetWidth( lineWidth == -1 ? resMgr->integerValue("Geometry", "preview_edge_width", -1) : lineWidth );
345 // set display mode of displayed shape
346 int aPrevDispMode = getDisplayer()->SetDisplayMode( displayMode == -1 ? resMgr->integerValue( "Geometry", "display_mode", 0 ) : displayMode );
348 // Disable activation of selection
349 getDisplayer()->SetToActivate( activate );
351 // Make a reference to GEOM_Object
352 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string( object );
353 getDisplayer()->SetName( objStr.in() );
356 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( object );
357 if ( aPrs == 0 || aPrs->IsNull() )
360 // Make preview not clippable
361 aPrs->SetClippable (false);
364 displayPreview( aPrs, append, update );
366 getDisplayer()->UnsetName();
367 getDisplayer()->UnsetColor();
368 getDisplayer()->SetDisplayMode( aPrevDispMode );
370 // Enable activation of displayed objects
371 getDisplayer()->SetToActivate( true );
374 //================================================================
375 // Function : displayPreview
376 // Purpose : Method for displaying arbitrary preview objects (not limited to shapes)
377 //================================================================
378 void GEOMBase_Helper::displayPreview( const SALOME_Prs* prs,
383 erasePreview( false );
385 // remember current view frame to make correct erase preview later
386 myViewWindow = getActiveView();
388 if ( myViewWindow == 0 )
392 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
393 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
394 aViewManager->getType() == SVTK_Viewer::Type() )
396 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
397 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
399 aView->Display( getDisplayer(), prs );
402 // Add prs to the preview list
403 myPreview.push_back( (SALOME_Prs*)prs );
407 getDisplayer()->UpdateViewer();
410 //================================================================
411 // Function : erasePreview
413 //================================================================
414 void GEOMBase_Helper::erasePreview( const bool update )
416 // check view frame where the preview was displayed
417 bool vfOK = checkViewWindow() && myViewWindow;
418 // Iterate through presentations and delete them
419 for ( PrsList::iterator anIter = myPreview.begin(); anIter != myPreview.end(); ++anIter )
423 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
424 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
425 aViewManager->getType() == SVTK_Viewer::Type() )
427 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
428 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
430 aView->Erase( getDisplayer(), *anIter, true );
442 //================================================================
443 // Function : localSelection
444 // Purpose : Activate selection of objects of a given type
445 // IMPORTANT : Works after localSelection( ... ) method call only
446 //================================================================
447 void GEOMBase_Helper::activate( const int theType )
449 if (!getStudy()) return;
450 _PTR(Study) aStudy = getStudy()->studyDS();
451 _PTR(SComponent) aGeom ( aStudy->FindComponent( "GEOM" ) );
456 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( aGeom ) );
457 for ( ; anIter->More(); anIter->Next() )
459 _PTR(SObject) aSO ( anIter->Value() );
462 _PTR(SObject) aRefSO;
463 if ( !aSO->ReferencedObject( aRefSO ) )
465 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow
466 (GeometryGUI::ClientSObjectToObject(aSO));
467 if ( !anObj->_is_nil() && anObj->GetType() == theType )
468 aList.Append( new SALOME_InteractiveObject( aSO->GetID().c_str(), "GEOM", aSO->GetName().c_str()) );
473 getDisplayer()->LocalSelection( aList, 0 );
476 //================================================================
477 // Function : localSelection
478 // Purpose : Activate selection of sub-shapes in accordance with mode
479 // modes are from TopAbs_ShapeEnum
480 //================================================================
481 void GEOMBase_Helper::localSelection( const ObjectList& theObjs, const std::list<int> modes )
483 SALOME_ListIO aListOfIO;
485 ObjectList::const_iterator anIter = theObjs.begin();
486 for ( ; anIter != theObjs.end(); ++anIter )
488 GEOM::GEOM_Object_ptr anObj = *anIter;
489 if ( anObj->_is_nil() )
491 QString anEntry = getEntry( anObj );
494 //MESSAGE("anEntry: "<< anEntry.toStdString().c_str());
495 QString aName = GEOMBase::GetName( anObj );
496 aListOfIO.Append( new SALOME_InteractiveObject( anEntry.toUtf8().constData(),
497 "GEOM", aName.toUtf8().constData() ));
501 getDisplayer()->LocalSelection( aListOfIO, modes );
504 //================================================================
505 // Function : localSelection
506 // Purpose : Activate selection of sub-shapes in accordance with mode
507 // theMode is from TopAbs_ShapeEnum
508 //================================================================
509 void GEOMBase_Helper::localSelection( const ObjectList& theObjs, const int theMode )
511 std::list<int> modes;
512 modes.push_back( theMode );
513 localSelection( theObjs, modes );
516 //================================================================
517 // Function : localSelection
518 // Purpose : Activate selection of sub-shapes in accordance with mode
519 // modes are from TopAbs_ShapeEnum
520 //================================================================
521 void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const std::list<int> modes )
523 // If object is null local selection for all objects is activated
524 if ( obj->_is_nil() ) {
525 getDisplayer()->LocalSelection( Handle(SALOME_InteractiveObject)(), modes );
530 objList.push_back( obj );
531 localSelection( objList, modes );
534 //================================================================
535 // Function : localSelection
536 // Purpose : Activate selection of sub-shapes in accordance with mode
537 // mode is from TopAbs_ShapeEnum
538 //================================================================
539 void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const int mode )
541 std::list<int> modes;
542 modes.push_back( mode );
543 localSelection( obj, modes );
546 //================================================================
547 // Function : localSelection
548 // Purpose : Activate selection of sub-shapes in accordance with mode
549 // mode is from TopAbs_ShapeEnum
550 //================================================================
551 void GEOMBase_Helper::localSelection( const std::string& entry, const std::string& name, const std::list<int> modes)
553 SALOME_ListIO aListOfIO;
554 QString aName = name.c_str();
555 aListOfIO.Append( new SALOME_InteractiveObject( entry.c_str(),
556 "GEOM", aName.toUtf8().constData() ));
557 getDisplayer()->LocalSelection( aListOfIO, modes );
560 //================================================================
561 // Function : localSelection
562 // Purpose : Activate selection of sub-shapes in accordance with mode
563 // modes are from TopAbs_ShapeEnum
564 //================================================================
565 void GEOMBase_Helper::localSelection( const std::list<int> modes )
567 localSelection( GEOM::GEOM_Object::_nil(), modes );
570 //================================================================
571 // Function : localSelection
572 // Purpose : Activate selection of sub-shapes in accordance with mode
573 // mode is from TopAbs_ShapeEnum
574 //================================================================
575 void GEOMBase_Helper::localSelection( const int mode )
577 std::list<int> modes;
578 modes.push_back( mode );
579 localSelection( modes );
582 //================================================================
583 // Function : globalSelection
584 // Purpose : Activate selection of sub-shapes. Set selection filters
585 // in accordance with mode. theMode is from GEOMImpl_Types
586 //================================================================
587 void GEOMBase_Helper::globalSelection( const int theMode, const bool update )
589 getDisplayer()->GlobalSelection( theMode, update );
592 //================================================================
593 // Function : globalSelection
594 // Purpose : Activate selection of sub-shapes. Set selection filters
595 // in accordance with mode. theMode is from GEOMImpl_Types
596 //================================================================
597 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
600 getDisplayer()->GlobalSelection( theModes, update );
603 //================================================================
604 // Function : globalSelection
605 // Purpose : Activate selection of sub-shapes. Set selection filters
606 // in accordance with mode. theMode is from GEOMImpl_Types
607 //================================================================
608 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
609 const QList<int>& subShapes,
612 getDisplayer()->GlobalSelection( theModes, update, &subShapes );
615 //================================================================
616 // Function : addInStudy
617 // Purpose : Add object in study
618 //================================================================
619 QString GEOMBase_Helper::addInStudy( GEOM::GEOM_Object_ptr theObj, const char* theName )
624 _PTR(Study) aStudy = getStudy()->studyDS();
625 if ( !aStudy || theObj->_is_nil() )
628 GEOM::GEOM_Object_ptr aFatherObj = getFather( theObj );
630 SALOMEDS::SObject_var aSO =
631 getGeomEngine()->AddInStudy(theObj, theName, aFatherObj);
634 if ( !aSO->_is_nil() ) {
635 CORBA::String_var entry = aSO->GetID();
636 anEntry = entry.in();
638 // Each dialog is responsible for this method implementation,
639 // default implementation does nothing
640 restoreSubShapes(aSO);
646 //================================================================
647 // Function : restoreSubShapes
648 // Purpose : restore tree of argument's sub-shapes under the resulting shape
649 //================================================================
650 void GEOMBase_Helper::restoreSubShapes (SALOMEDS::SObject_ptr /*theSObject*/)
652 // do nothing by default
654 // example of implementation in particular dialog:
655 // GEOM::ListOfGO anArgs;
656 // anArgs.length(0); // empty list means that all arguments should be restored
657 // getGeomEngine()->RestoreSubShapesSO(theSObject, anArgs,
658 // /*theFindMethod=*/GEOM::FSM_GetInPlace,
659 // /*theInheritFirstArg=*/false);
662 //================================================================
663 // Function : updateObjBrowser
664 // Purpose : Update object browser
665 //================================================================
666 void GEOMBase_Helper::updateObjBrowser() const
668 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
670 CAM_Module* module = app->module( "Geometry" );
671 SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
673 appMod->updateObjBrowser();
678 //================================================================
679 // Function : updateViewer
680 // Purpose : Update active 3D view
681 //================================================================
682 void GEOMBase_Helper::updateViewer()
684 getDisplayer()->UpdateViewer();
687 //================================================================
688 // Function : getStudy
689 // Purpose : Returns the active study. It is recommended to use
690 // this method instead of direct desktop->getActiveStudy() calls
691 //================================================================
692 SalomeApp_Study* GEOMBase_Helper::getStudy() const
694 SUIT_Desktop* aDesktop = getDesktop();
698 QList<SUIT_Application*> anAppList = SUIT_Session::session()->applications();
700 SUIT_Application* anApp = 0;
701 QListIterator<SUIT_Application*> it( anAppList );
702 while ( it.hasNext() )
705 if ( anApp && anApp->desktop() == aDesktop )
709 return dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
712 //================================================================
713 // Function : getEntry
715 //================================================================
716 QString GEOMBase_Helper::getEntry( GEOM::GEOM_Object_ptr object ) const
718 SalomeApp_Study* study = getStudy();
720 QString objIOR = GEOMBase::GetIORFromObject( object );
721 if ( objIOR != "" ) {
722 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( objIOR.toUtf8().constData() ) );
724 return QString::fromStdString(SO->GetID());
730 //================================================================
731 // Function : getDisplayer
733 //================================================================
734 GEOM_Displayer* GEOMBase_Helper::getDisplayer()
737 myDisplayer = new GEOM_Displayer();
741 //================================================================
742 // Function : clearShapeBuffer
744 //================================================================
745 void GEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
747 GeometryGUI::ClearShapeBuffer(theObj);
750 //================================================================
751 // Function : openCommand
753 //================================================================
754 bool GEOMBase_Helper::openCommand()
757 if ( !getStudy() || hasCommand() )
759 MESSAGE("Getting out from openCommand()");
763 GEOM::GEOM_IOperations_var anOp = GEOM::GEOM_IOperations::_narrow( getOperation() );
764 if ( !anOp->_is_nil() ) {
765 myCommand = new GEOM_Operation( SUIT_Session::session()->activeApplication(), anOp.in() );
771 MESSAGE("anOp->_is_nil() = true");
777 //================================================================
778 // Function : abortCommand
780 //================================================================
781 bool GEOMBase_Helper::abortCommand()
787 delete myCommand; // I don't know where to delete this object here ?
793 //================================================================
794 // Function : commitCommand
796 //================================================================
797 bool GEOMBase_Helper::commitCommand( const char* )
803 delete myCommand; // I don't know where to delete this object here ?
809 //================================================================
810 // Function : hasCommand
812 //================================================================
813 bool GEOMBase_Helper::hasCommand() const
815 return (bool)myCommand;
818 //================================================================
819 // Function : getOperation
821 //================================================================
822 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::getOperation()
824 if ( myOperation->_is_nil() )
825 myOperation = createOperation();
832 //================================================================
833 // Function : checkViewWindow
835 //================================================================
836 bool GEOMBase_Helper::checkViewWindow()
839 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
840 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
841 while ( it.hasNext() )
843 if ( myViewWindow == it.next() )
851 //================================================================
852 // Function : onAccept
853 // Purpose : This method should be called from dialog's slots onOk() and onApply()
854 // It performs user input validation, then it
855 // performs a proper operation and manages transactions, etc.
856 //================================================================
857 bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction, bool erasePreviewFlag )
859 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
862 MESSAGE("appStudy is empty");
865 _PTR(Study) aStudy = appStudy->studyDS();
867 bool aLocked = (_PTR(AttributeStudyProperties) (aStudy->GetProperties()))->IsLocked();
869 MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
870 SUIT_MessageBox::warning ( (QWidget*)SUIT_Session::session()->activeApplication()->desktop(),
871 QObject::tr("WRN_WARNING"),
872 QObject::tr("WRN_STUDY_LOCKED"),
873 QObject::tr("BUT_OK") );
878 if ( !isValid( msg ) ) {
884 erasePreview( false );
889 if ( ( !publish && !useTransaction ) || openCommand() ) {
890 SUIT_OverrideCursor wc;
891 SUIT_Session::session()->activeApplication()->putInfo( "" );
893 if ( !execute( objects ) || !getOperation()->IsDone() ) {
899 QList<GEOM::GeomObjPtr> anObjectList = getSourceObjects( );
900 addSubshapesToStudy(); // add Sub-shapes if local selection
901 const int nbObjs = objects.size();
902 QStringList anEntryList;
903 int currObj = 1, aNumber = 1;
904 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it, currObj++ ) {
905 GEOM::GEOM_Object_var obj=*it;
907 QString aName = getObjectName(obj);
908 if (aName.isEmpty()) {
909 aName = getNewObjectName(currObj);
912 aName = getPrefix(obj);
914 // Try to find a unique name
915 aName = GEOMBase::GetDefaultName(aName, extractPrefix());
917 // Don't check name uniqueness in case of numerous objects
918 aName = aName + "_" + QString::number(aNumber++);
921 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
922 if ( aName.isEmpty() )
923 aName = GEOMBase::GetDefaultName( getPrefix( obj ) );
926 anEntryList << addInStudy( obj, aName.toUtf8().constData() );
928 if( isDisplayResult() )
929 display( obj, false );
930 #ifdef WITHGENERICOBJ
931 // obj has been published in study. Its refcount has been incremented.
932 // It is safe to decrement its refcount
933 // so that it will be destroyed when the entry in study will be removed
938 // asv : fix of PAL6454. If publish==false, then the original shape
939 // was modified, and need to be re-cached in GEOM_Client before redisplay
940 clearShapeBuffer( obj );
941 // withChildren=true, updateView=false
942 if( isDisplayResult() )
943 redisplay( obj, true, false );
948 const QString anOpName( typeid(*this).name() );
949 // The operator name may have the following format: 24PrimitiveGUI_CylinderDlg
950 // clean it up to get the simple operator (here Cylinder) name into the log.
951 const QRegExp rx("^[^\w]*_(.*)Dlg$");
952 const int pos = rx.indexIn(anOpName);
953 SalomeApp_Application::logStructuredUserEvent( "Geom",
955 pos == -1 ? anOpName : rx.cap(1),
959 if( SUIT_Application* anApp = SUIT_Session::session()->activeApplication() ) {
960 LightApp_Application* aLightApp = dynamic_cast<LightApp_Application*>( anApp );
962 aLightApp->emitOperationFinished( "Geometry", anOpName, anEntryList );
964 if ( !isDisableBrowsing() )
965 aLightApp->browseObjects( anEntryList, isApplyAndClose(), isOptimizedBrowsing() );
967 anApp->putInfo( QObject::tr("GEOM_PRP_DONE") );
969 if ( anObjectList.count() > 0 )
970 hideSourceObjects( anObjectList );
978 catch( const SALOME::SALOME_Exception& e ) {
979 SalomeApp_Tools::QtCatchCorbaException( e );
981 MESSAGE("Exception caught");
986 MESSAGE("result ="<<result);
991 //================================================================
992 // Function : showError
993 // Purpose : Shows a message box with information about an error taken from getOperation()->GetErrorCode()
994 //================================================================
995 void GEOMBase_Helper::showError()
998 if ( !getOperation()->_is_nil() )
999 msg = QObject::tr( getOperation()->GetErrorCode() );
1001 if ( msg.isEmpty() )
1002 msg = QObject::tr( "GEOM_PRP_ABORT" );
1004 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
1005 QObject::tr( "GEOM_ERROR_STATUS" ),
1007 QObject::tr( "BUT_OK" ) );
1010 //================================================================
1011 // Function : showError
1012 // Purpose : Shows a error message followed by <msg>
1013 //================================================================
1014 void GEOMBase_Helper::showError( const QString& msg )
1016 QString str( QObject::tr( "GEOM_INCORRECT_INPUT" ) );
1017 if ( !msg.isEmpty() )
1019 SUIT_MessageBox::critical(SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ), str, QObject::tr( "BUT_OK" ) );
1022 //////////////////////////////////////////////////////////////////
1023 // Virtual methods to be redefined in dialogs
1024 //////////////////////////////////////////////////////////////////
1026 //================================================================
1027 // Function : createOperation
1028 // Purpose : Redefine this method to return proper IOperation reference
1029 //================================================================
1030 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::createOperation()
1032 GEOM::GEOM_IOperations_var aNilOp;
1033 return aNilOp._retn();
1036 //================================================================
1037 // Function : isValid
1038 // Purpose : Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
1039 //================================================================
1040 bool GEOMBase_Helper::isValid( QString& )
1045 //================================================================
1046 // Function : execute
1047 // Purpose : This method is called by onAccept().
1048 // It should perform the required operation and put all new or modified objects into
1049 // <objects> argument.Should return <false> if some error occurs during its execution.
1050 //================================================================
1051 bool GEOMBase_Helper::execute( ObjectList& )
1056 //================================================================
1057 // Function : getFather
1058 // Purpose : This method is called by addInStudy(). It should return a father object
1059 // for <theObj> or a nil reference if <theObj> should be published
1060 // as a top-level object.
1061 //================================================================
1062 GEOM::GEOM_Object_ptr GEOMBase_Helper::getFather( GEOM::GEOM_Object_ptr )
1064 return GEOM::GEOM_Object::_nil();
1067 //================================================================
1068 // Function : getObjectName
1069 // Purpose : Redefine this method to return proper name for the given object
1070 //================================================================
1071 QString GEOMBase_Helper::getObjectName( GEOM::GEOM_Object_ptr ) const
1076 //================================================================
1077 // Function : getNewObjectName
1078 // Purpose : Redefine this method to return proper name for a new object
1079 //================================================================
1080 QString GEOMBase_Helper::getNewObjectName( int ) const
1085 //================================================================
1086 // Function : extractPrefix
1087 // Purpose : Redefine this method to return \c true if necessary
1088 // to extract prefix when generating new name for the
1089 // object(s) being created
1090 //================================================================
1091 bool GEOMBase_Helper::extractPrefix() const
1096 //================================================================
1097 // Function : getPrefix
1098 // Purpose : Get prefix for name of created object
1099 //================================================================
1100 QString GEOMBase_Helper::getPrefix( GEOM::GEOM_Object_ptr theObj ) const
1102 if ( !myPrefix.isEmpty() || theObj->_is_nil() )
1105 GEOM::shape_type aType = theObj->GetShapeType();
1109 case GEOM::VERTEX : return QObject::tr( "GEOM_VERTEX" );
1110 case GEOM::EDGE : return QObject::tr( "GEOM_EDGE" );
1111 case GEOM::WIRE : return QObject::tr( "GEOM_WIRE" );
1112 case GEOM::FACE : return QObject::tr( "GEOM_FACE" );
1113 case GEOM::SHELL : return QObject::tr( "GEOM_SHELL" );
1114 case GEOM::SOLID : return QObject::tr( "GEOM_SOLID" );
1115 case GEOM::COMPSOLID: return QObject::tr( "GEOM_COMPOUNDSOLID" );
1116 case GEOM::COMPOUND : return QObject::tr( "GEOM_COMPOUND" );
1117 default : return "";
1121 //================================================================
1122 // Function : getDesktop
1123 // Purpose : Returns myDesktop field. Initialized in constructor,
1124 // usually as dynamic_cast<SUIT_Desktop*>(parentWidget())
1125 //================================================================
1126 SUIT_Desktop* GEOMBase_Helper::getDesktop() const
1131 //================================================================
1132 // Function : selectObjects
1133 // Purpose : Selects list of objects
1134 //================================================================
1135 bool GEOMBase_Helper::selectObjects( ObjectList& objects )
1137 SUIT_DataOwnerPtrList aList;
1138 ObjectList::iterator anIter;
1139 for ( anIter = objects.begin(); anIter != objects.end(); ++anIter )
1141 QString anEntry = getEntry( *anIter );
1142 LightApp_DataOwner* anOwher = new LightApp_DataOwner( anEntry );
1143 aList.append( anOwher );
1146 SUIT_Session* session = SUIT_Session::session();
1147 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1151 LightApp_SelectionMgr* aMgr = app->selectionMgr();
1155 aMgr->setSelected( aList, false );
1160 //================================================================
1161 // Function : findObjectInFather
1162 // Purpose : It should return an object if its founded in study or
1163 // return Null object if the object is not founded
1164 //================================================================
1165 GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather (GEOM::GEOM_Object_ptr theFather,
1166 const QString& theName)
1168 SalomeApp_Application* app =
1169 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1170 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1171 _PTR(Study) aDStudy = appStudy->studyDS();
1172 QString IOR = GEOMBase::GetIORFromObject( theFather );
1173 _PTR(SObject) SObj ( aDStudy->FindObjectIOR( IOR.toUtf8().constData() ) );
1175 bool inStudy = false;
1176 GEOM::GEOM_Object_var aReturnObject;
1177 for (_PTR(ChildIterator) iit (aDStudy->NewChildIterator( SObj )); iit->More() && !inStudy; iit->Next()) {
1178 _PTR(SObject) child (iit->Value());
1179 QString aChildName = child->GetName().c_str();
1180 if (aChildName == theName) {
1182 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(iit->Value());
1183 aReturnObject = GEOM::GEOM_Object::_narrow( corbaObj );
1187 return aReturnObject._retn();
1189 return GEOM::GEOM_Object::_nil();
1192 //================================================================
1193 // Function : findObjectInFather
1194 // Purpose : It should return an object if its founded in study or
1195 // return Null object if the object is not founded
1196 //================================================================
1197 GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather( GEOM::GEOM_Object_ptr theFather,
1200 GEOM::GEOM_Object_var object;
1202 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
1204 _PTR(Study) studyDS = study->studyDS();
1205 QString IOR = GEOMBase::GetIORFromObject( theFather );
1206 _PTR(SObject) sobject( studyDS->FindObjectIOR( IOR.toLatin1().constData() ) );
1208 _PTR(ChildIterator) it( studyDS->NewChildIterator( sobject ) );
1209 for ( ; it->More(); it->Next() ) {
1210 GEOM::GEOM_Object_var cobject = GEOM::GEOM_Object::_narrow( GeometryGUI::ClientSObjectToObject( it->Value() ) );
1211 if ( !CORBA::is_nil( cobject ) ) {
1212 GEOM::ListOfLong_var indices = cobject->GetSubShapeIndices();
1213 int length = indices->length();
1214 // VSR 18/03/2014: we need only sub-shapes with single sub-shape index (to exclude groups, etc)
1215 if ( length == 1 && indices[0] == theIndex ) {
1224 return object._retn();
1227 //================================================================
1228 // Function : addSubshapesToStudy
1229 // Purpose : Virtual method to add sub-shapes if needs
1230 //================================================================
1231 void GEOMBase_Helper::addSubshapesToStudy()
1233 //Implemented in Dialogs, called from Accept method
1236 //================================================================
1237 // Function : getSourceObjects
1238 // Purpose : Virtual method to get source objects
1239 //================================================================
1240 QList<GEOM::GeomObjPtr> GEOMBase_Helper::getSourceObjects()
1242 //Implemented in Dialogs, called from Accept method
1243 QList<GEOM::GeomObjPtr> res;
1247 //================================================================
1248 // Function : getSelected
1249 // Purpose : Get selected object by specified type
1251 // Returns valid object if only one object of the specified type is selected
1252 // (no matter global or local selection is activated). If \a type is TopAbs_SHAPE,
1253 // geometrical object of any valid type is expected.
1255 // \param type type of the object to be obtained from selection
1256 // \return selected geometrical object or nil object if selection is not satisfactory
1257 //================================================================
1258 GEOM::GeomObjPtr GEOMBase_Helper::getSelected( TopAbs_ShapeEnum type )
1260 QList<TopAbs_ShapeEnum> types;
1262 return getSelected( types );
1265 //================================================================
1266 // Function : getSelected
1267 // Purpose : Get selected object by specified types
1269 // Returns valid object if only one object of the specified type is selected
1270 // (no matter global or local selection is activated). The list of allowed
1271 // shape types is passed via \a types. If \a types includes TopAbs_SHAPE,
1272 // geometrical object of any valid type is expected.
1274 // \param types list of allowed shape types for the objects to be obtained from selection
1275 // \return selected geometrical object or nil object if selection is not satisfactory
1276 //================================================================
1277 GEOM::GeomObjPtr GEOMBase_Helper::getSelected( const QList<TopAbs_ShapeEnum>& types )
1279 QList<GEOM::GeomObjPtr> selected = getSelected( types, 1 );
1280 return selected.count() > 0 ? selected[0] : GEOM::GeomObjPtr();
1283 //================================================================
1284 // Function : getSelected
1285 // Purpose : Get selected object(s) by specified type
1287 // Returns list of selected objects if selection satisfies specifies selection options.
1288 // (no matter global or local selection is activated). If \a type is TopAbs_SHAPE,
1289 // geometrical objects of any valid type are expected.
1291 // The \a type parameter specifies allowed type of the object(s) being selected.
1292 // The \a count parameter specifies exact number of the objects to be retrieved from selection.
1293 // The \a strict parameter specifies policy being applied to the selection.
1294 // If \a count < 0, then any number of the selected objects is valid (including 0).
1295 // In this case, if \a strict is \c true (default), all selected objects should satisfy
1296 // the specified \a type.
1297 // If \a count > 0, only specified number of the objects is retrieved from the selection.
1298 // In this case, if \a strict is \c true (default), function returns empty list if total number of selected
1299 // objects does not correspond to the \a count parameter. Otherwise (if \a strict is \c false),
1300 // function returns valid list of objects if at least \a count objects satisfy specified \a type.
1302 // \param type type of the object(s) to be obtained from selection
1303 // \param count number of items to be retrieved from selection
1304 // \param strict selection policy
1305 // \return list of selected geometrical objects or empty list if selection is not satisfactory
1306 //================================================================
1307 QList<GEOM::GeomObjPtr> GEOMBase_Helper::getSelected( TopAbs_ShapeEnum type, int count, bool strict )
1309 QList<TopAbs_ShapeEnum> types;
1311 return getSelected( types, count, strict );
1314 static bool typeInList( TopAbs_ShapeEnum type, const QList<TopAbs_ShapeEnum>& types )
1317 for ( int i = 0; i < types.count() && !ok; i++ )
1318 ok = types[i] == TopAbs_SHAPE || types[i] == type;
1322 //================================================================
1323 // Function : getSelected
1324 // Purpose : Get selected objects by specified types
1326 // Returns list of selected objects if selection satisfies specifies selection options.
1327 // (no matter global or local selection is activated). If \a types includes TopAbs_SHAPE,
1328 // geometrical objects of any valid type are expected.
1330 // The \a types parameter specifies allowed types of the object(s) being selected.
1331 // The \a count parameter specifies exact number of the objects to be retrieved from selection.
1332 // The \a strict parameter specifies policy being applied to the selection.
1333 // If \a count < 0, then any number of the selected objects is valid (including 0).
1334 // In this case, if \a strict is \c true (default), all selected objects should satisfy
1335 // the specified \a type.
1336 // If \a count > 0, only specified number of the objects is retrieved from the selection.
1337 // In this case, if \a strict is \c true (default), function returns empty list if total number of selected
1338 // objects does not correspond to the \a count parameter. Otherwise (if \a strict is \c false),
1339 // function returns valid list of objects if at least \a count objects satisfy specified \a type.
1341 // \param types list of allowed shape types for the objects to be obtained from selection
1342 // \param count number of items to be retrieved from selection
1343 // \param strict selection policy
1344 // \return list of selected geometrical objects or empty list if selection is not satisfactory
1345 //================================================================
1346 QList<GEOM::GeomObjPtr> GEOMBase_Helper::getSelected( const QList<TopAbs_ShapeEnum>& types, int count, bool strict )
1348 SUIT_Session* session = SUIT_Session::session();
1349 QList<GEOM::GeomObjPtr> result;
1351 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1353 LightApp_SelectionMgr* selMgr = app->selectionMgr();
1355 SALOME_ListIO selected;
1356 selMgr->selectedObjects( selected );
1357 SALOME_ListIteratorOfListIO it( selected );
1358 bool stopped = false;
1359 for ( ; it.More() && !stopped; it.Next() ) {
1360 Handle(SALOME_InteractiveObject) IO = it.Value();
1361 GEOM::GeomObjPtr object = GEOMBase::ConvertIOinGEOMObject( IO );
1363 TColStd_IndexedMapOfInteger subShapes;
1364 selMgr->GetIndexes( IO, subShapes );
1365 int nbSubShapes = subShapes.Extent();
1366 if ( nbSubShapes == 0 ) {
1368 if ( typeInList( (TopAbs_ShapeEnum)(object->GetShapeType()), types ) ) {
1371 if ( strict && result.count() > count ) {
1375 else if ( !strict && result.count() == count )
1379 else if ( strict ) {
1386 for ( int i = 1; i <= nbSubShapes && !stopped; i++ ) {
1387 int idx = subShapes( i );
1388 GEOM::GeomObjPtr subShape = findObjectInFather( object.get(), idx );
1390 // sub-shape is not yet published in the study
1391 GEOM::ShapesOpPtr shapesOp = getGeomEngine()->GetIShapesOperations();
1392 subShape.take( shapesOp->GetSubShape( object.get(), idx ) ); // take ownership!
1394 if ( typeInList( (TopAbs_ShapeEnum)(subShape->GetShapeType()), types ) ) {
1397 if ( strict && result.count() > count ) {
1401 else if ( !strict && result.count() == count )
1405 else if ( strict ) {
1417 //================================================================
1418 // Function : hideSourceObject
1420 //================================================================
1421 void GEOMBase_Helper::hideSourceObjects( QList<GEOM::GeomObjPtr> theObject )
1423 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1424 if ( resMgr->booleanValue( "Geometry", "hide_input_object", true) ) {
1425 GEOM_Displayer* aDisplayer = getDisplayer();
1426 for ( int i = 0; i < theObject.count(); i++ )
1427 aDisplayer->Erase( theObject[i].get() );
1431 //================================================================
1432 // Function : setIsApplyAndClose
1433 // Purpose : Set value of the flag indicating that the dialog is
1434 // accepted by Apply & Close button
1435 //================================================================
1436 void GEOMBase_Helper::setIsApplyAndClose( const bool theFlag )
1438 myIsApplyAndClose = theFlag;
1441 //================================================================
1442 // Function : isApplyAndClose
1443 // Purpose : Get value of the flag indicating that the dialog is
1444 // accepted by Apply & Close button
1445 //================================================================
1446 bool GEOMBase_Helper::isApplyAndClose() const
1448 return myIsApplyAndClose;
1451 //================================================================
1452 // Function : setIsOptimizedBrowsing
1453 // Purpose : Set value of the flag switching to optimized
1454 // browsing mode (to select the first published
1456 //================================================================
1457 void GEOMBase_Helper::setIsOptimizedBrowsing( const bool theFlag )
1459 myIsOptimizedBrowsing = theFlag;
1462 //================================================================
1463 // Function : isOptimizedBrowsing
1464 // Purpose : Get value of the flag switching to optimized
1465 // browsing mode (to select the first published
1467 //================================================================
1468 bool GEOMBase_Helper::isOptimizedBrowsing() const
1470 return myIsOptimizedBrowsing;