1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : GEOMBase_Helper.cxx
25 // Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
27 #include "GEOMBase_Helper.h"
29 #include "GEOM_Operation.h"
31 #include <GeometryGUI.h>
33 #include <SUIT_Desktop.h>
34 #include <SUIT_Session.h>
35 #include <SUIT_ViewManager.h>
36 #include <SUIT_ViewWindow.h>
37 #include <SUIT_ViewModel.h>
38 #include <SUIT_MessageBox.h>
39 #include <SUIT_OverrideCursor.h>
40 #include <SUIT_ResourceMgr.h>
42 #include <SalomeApp_Module.h>
43 #include <SalomeApp_Application.h>
44 #include <SalomeApp_Study.h>
45 #include <LightApp_SelectionMgr.h>
46 #include <LightApp_DataOwner.h>
47 #include <SalomeApp_Tools.h>
48 #include <SALOME_ListIO.hxx>
49 #include "utilities.h"
51 #include <SALOME_Prs.h>
52 #include "utilities.h"
54 #include <OCCViewer_ViewModel.h>
55 #include <SVTK_ViewModel.h>
57 #include <TColStd_MapOfInteger.hxx>
58 #include <TCollection_AsciiString.hxx>
59 #include <TColStd_IndexedMapOfInteger.hxx>
61 //To disable automatic genericobj management, the following line should be commented.
62 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
63 #define WITHGENERICOBJ
65 //================================================================
66 // Function : getActiveView
67 // Purpose : Get active view window, returns 0 if no open study frame
68 //================================================================
69 SUIT_ViewWindow* GEOMBase_Helper::getActiveView()
71 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
73 return SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
79 //================================================================
80 // Function : getGeomEngine
81 // Purpose : Static method
82 //================================================================
83 GEOM::GEOM_Gen_ptr GEOMBase_Helper::getGeomEngine()
85 return GeometryGUI::GetGeomGen();
88 //================================================================
89 // Function : GEOMBase_Helper
91 //================================================================
92 GEOMBase_Helper::GEOMBase_Helper( SUIT_Desktop* desktop )
93 : myDesktop( desktop ), myViewWindow( 0 ), myDisplayer( 0 ), myCommand( 0 ), isPreview( false ),
94 myIsApplyAndClose( false ), myIsOptimizedBrowsing( false ), myIsWaitCursorEnabled( true ),
95 myIsDisableBrowsing(false), myIsDisplayResult(true)
99 //================================================================
100 // Function : ~GEOMBase_Helper
102 //================================================================
103 GEOMBase_Helper::~GEOMBase_Helper()
105 //rnv: Fix for the "IPAL21922 : WinTC5.1.4: incorrect quit salome"
106 if ( !SUIT_Session::session()->activeApplication() || !SUIT_Session::session()->activeApplication()->desktop() )
109 if ( myPreview.size() )
113 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
115 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
117 globalSelection(aGeomGUI->getLocalSelectionMode() , true );
122 if ( !CORBA::is_nil( myOperation ) )
123 myOperation->UnRegister();
126 //================================================================
127 // Function : display
129 //================================================================
130 void GEOMBase_Helper::display( const ObjectList& objList, const bool updateView )
132 ObjectList::const_iterator it;
133 for ( it = objList.begin(); it != objList.end(); it++ ) {
134 display( *it, false );
136 if ( !objList.empty() && updateView )
137 getDisplayer()->UpdateViewer();
140 //================================================================
141 // Function : display
142 // Purpose : Display object.
143 // Important : Object must be already in study
144 //================================================================
145 void GEOMBase_Helper::display( GEOM::GEOM_Object_ptr object, const bool updateView )
147 // Unset color of shape ( this color may be set during preview displaying )
148 // Default color will be used
149 // getDisplayer()->UnsetColor();
150 getDisplayer()->UnsetWidth();
152 MESSAGE("GEOMBase_Helper::display myTexture = "<<getDisplayer()->GetTexture())
154 // Enable activisation of selection
155 getDisplayer()->SetToActivate( true );
158 getDisplayer()->Display( object, updateView );
161 //================================================================
164 //================================================================
165 void GEOMBase_Helper::erase( const ObjectList& objList, const bool updateView )
167 ObjectList::const_iterator it = objList.begin();
168 for ( ; it != objList.end(); it++ ) {
171 if ( !objList.empty() && updateView )
172 getDisplayer()->UpdateViewer();
175 //================================================================
178 //================================================================
179 void GEOMBase_Helper::erase( GEOM::GEOM_Object_ptr object, const bool updateView )
181 if ( !object->_is_nil() ) {
182 QString entry = getEntry( object );
183 getDisplayer()->Erase( new SALOME_InteractiveObject(
184 entry.toLatin1().constData(),
185 "GEOM", strdup( GEOMBase::GetName( object ).toLatin1().constData() ) ), true, updateView );
189 //================================================================
190 // Function : redisplay
192 //================================================================
193 void GEOMBase_Helper::redisplay( const ObjectList& objList,
194 const bool withChildren,
195 const bool updateView )
197 ObjectList::const_iterator it = objList.begin();
198 for ( ; it != objList.end(); it++ ) {
199 redisplay( *it, withChildren, false );
201 if ( !objList.empty() && updateView )
202 getDisplayer()->UpdateViewer();
205 //================================================================
206 // Function : redisplay
208 //================================================================
209 void GEOMBase_Helper::redisplay( GEOM::GEOM_Object_ptr object,
210 const bool withChildren,
211 const bool updateView )
213 if ( !object->_is_nil() ) {
214 // Unset color of shape ( this color may be set during preview displaying )
215 // Default color will be used
216 getDisplayer()->UnsetColor();
217 getDisplayer()->UnsetWidth();
219 // Enable activisation of selection
220 getDisplayer()->SetToActivate( true );
222 QString entry = getEntry( object );
223 getDisplayer()->Redisplay(new SALOME_InteractiveObject
224 (entry.toLatin1().constData(), "GEOM", strdup(GEOMBase::GetName(object).toLatin1().constData())), false);
227 if ( withChildren ) {
228 SalomeApp_Study* aDoc = getStudy();
229 if ( aDoc && aDoc->studyDS() ) {
230 _PTR(Study) aStudy = aDoc->studyDS();
231 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string(object);
232 _PTR(SObject) aSObj (aStudy->FindObjectIOR(std::string(objStr.in())));
234 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
235 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
236 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow
237 (GeometryGUI::ClientSObjectToObject(anIt->Value()));
238 if ( !CORBA::is_nil( aChild ) ) {
239 if ( !aChild->_is_nil() ) {
240 QString entry = getEntry( aChild );
241 getDisplayer()->Redisplay( new SALOME_InteractiveObject(
242 entry.toLatin1().constData(), "GEOM", strdup( GEOMBase::GetName( aChild ).toLatin1().constData() ) ), false );
251 getDisplayer()->UpdateViewer();
254 //================================================================
255 // Function : displayPreview
256 // Purpose : Method for displaying preview based on execute() results
257 //================================================================
258 void GEOMBase_Helper::displayPreview( const bool display,
261 const bool toRemoveFromEngine,
262 const double lineWidth,
263 const int displayMode,
268 erasePreview( update );
274 if ( !isValid( msg ) )
276 erasePreview( update );
282 erasePreview( false );
285 SUIT_OverrideCursor wc;
288 if ( !isWaitCursorEnabled() )
291 if ( !execute( objects ) || !getOperation()->IsDone() ) {
295 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it )
297 GEOM::GEOM_Object_var obj=*it;
298 displayPreview( obj, true, activate, false, lineWidth, displayMode, color );
299 if ( toRemoveFromEngine )
304 catch( const SALOME::SALOME_Exception& e ) {
305 SalomeApp_Tools::QtCatchCorbaException( e );
314 //================================================================
315 // Function : displayPreview
316 // Purpose : Method for displaying preview of resulting shape
317 //================================================================
318 void GEOMBase_Helper::displayPreview( GEOM::GEOM_Object_ptr object,
322 const double lineWidth,
323 const int displayMode,
326 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
328 // Set color for preview shape
329 getDisplayer()->SetColor( color == -1 ? Quantity_NOC_VIOLET : color );
331 // set width of displayed shape
332 getDisplayer()->SetWidth( lineWidth == -1 ? resMgr->integerValue("Geometry", "preview_edge_width", -1) : lineWidth );
334 // set display mode of displayed shape
335 int aPrevDispMode = getDisplayer()->SetDisplayMode( displayMode == -1 ? resMgr->integerValue( "Geometry", "display_mode", 0 ) : displayMode );
337 // Disable activation of selection
338 getDisplayer()->SetToActivate( activate );
340 // Make a reference to GEOM_Object
341 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string( object );
342 getDisplayer()->SetName( objStr.in() );
345 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( object );
346 if ( aPrs == 0 || aPrs->IsNull() )
349 // Make preview not clippable
350 aPrs->SetClippable (false);
353 displayPreview( aPrs, append, update );
355 getDisplayer()->UnsetName();
356 getDisplayer()->UnsetColor();
357 getDisplayer()->SetDisplayMode( aPrevDispMode );
359 // Enable activation of displayed objects
360 getDisplayer()->SetToActivate( true );
363 //================================================================
364 // Function : displayPreview
365 // Purpose : Method for displaying arbitrary preview objects (not limited to shapes)
366 //================================================================
367 void GEOMBase_Helper::displayPreview( const SALOME_Prs* prs,
372 erasePreview( false );
374 // remember current view frame to make correct erase preview later
375 myViewWindow = getActiveView();
377 if ( myViewWindow == 0 )
381 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
382 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
383 aViewManager->getType() == SVTK_Viewer::Type() )
385 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
386 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
388 aView->Display( getDisplayer(), prs );
391 // Add prs to the preview list
392 myPreview.push_back( (SALOME_Prs*)prs );
396 getDisplayer()->UpdateViewer();
399 //================================================================
400 // Function : erasePreview
402 //================================================================
403 void GEOMBase_Helper::erasePreview( const bool update )
405 // check view frame where the preview was displayed
406 bool vfOK = checkViewWindow() && myViewWindow;
407 // Iterate through presentations and delete them
408 for ( PrsList::iterator anIter = myPreview.begin(); anIter != myPreview.end(); ++anIter )
412 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
413 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
414 aViewManager->getType() == SVTK_Viewer::Type() )
416 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
417 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
419 aView->Erase( getDisplayer(), *anIter, true );
431 //================================================================
432 // Function : localSelection
433 // Purpose : Activate selection of objects of a given type
434 // IMPORTANT : Works after localSelection( ... ) method call only
435 //================================================================
436 void GEOMBase_Helper::activate( const int theType )
438 if (!getStudy()) return;
439 _PTR(Study) aStudy = getStudy()->studyDS();
440 _PTR(SComponent) aGeom ( aStudy->FindComponent( "GEOM" ) );
445 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( aGeom ) );
446 for ( ; anIter->More(); anIter->Next() )
448 _PTR(SObject) aSO ( anIter->Value() );
451 _PTR(SObject) aRefSO;
452 if ( !aSO->ReferencedObject( aRefSO ) )
454 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow
455 (GeometryGUI::ClientSObjectToObject(aSO));
456 if ( !anObj->_is_nil() && anObj->GetType() == theType )
457 aList.Append( new SALOME_InteractiveObject( aSO->GetID().c_str(), "GEOM", aSO->GetName().c_str()) );
462 getDisplayer()->LocalSelection( aList, 0 );
465 //================================================================
466 // Function : localSelection
467 // Purpose : Activate selection of sub-shapes in accordance with mode
468 // modes are from TopAbs_ShapeEnum
469 //================================================================
470 void GEOMBase_Helper::localSelection( const ObjectList& theObjs, const std::list<int> modes )
472 SALOME_ListIO aListOfIO;
474 ObjectList::const_iterator anIter = theObjs.begin();
475 for ( ; anIter != theObjs.end(); ++anIter )
477 GEOM::GEOM_Object_ptr anObj = *anIter;
478 if ( anObj->_is_nil() )
480 QString anEntry = getEntry( anObj );
482 aListOfIO.Append( new SALOME_InteractiveObject(
483 anEntry.toLatin1().constData(), "GEOM", strdup( GEOMBase::GetName( anObj ).toLatin1().constData() ) ) );
486 getDisplayer()->LocalSelection( aListOfIO, modes );
489 //================================================================
490 // Function : localSelection
491 // Purpose : Activate selection of sub-shapes in accordance with mode
492 // theMode is from TopAbs_ShapeEnum
493 //================================================================
494 void GEOMBase_Helper::localSelection( const ObjectList& theObjs, const int theMode )
496 std::list<int> modes;
497 modes.push_back( theMode );
498 localSelection( theObjs, modes );
501 //================================================================
502 // Function : localSelection
503 // Purpose : Activate selection of sub-shapes in accordance with mode
504 // modes are from TopAbs_ShapeEnum
505 //================================================================
506 void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const std::list<int> modes )
508 // If object is null local selection for all objects is activated
509 if ( obj->_is_nil() ) {
510 getDisplayer()->LocalSelection( Handle(SALOME_InteractiveObject)(), modes );
515 objList.push_back( obj );
516 localSelection( objList, modes );
519 //================================================================
520 // Function : localSelection
521 // Purpose : Activate selection of sub-shapes in accordance with mode
522 // mode is from TopAbs_ShapeEnum
523 //================================================================
524 void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const int mode )
526 std::list<int> modes;
527 modes.push_back( mode );
528 localSelection( obj, modes );
531 //================================================================
532 // Function : localSelection
533 // Purpose : Activate selection of sub-shapes in accordance with mode
534 // modes are from TopAbs_ShapeEnum
535 //================================================================
536 void GEOMBase_Helper::localSelection( const std::list<int> modes )
538 localSelection( GEOM::GEOM_Object::_nil(), modes );
541 //================================================================
542 // Function : localSelection
543 // Purpose : Activate selection of sub-shapes in accordance with mode
544 // mode is from TopAbs_ShapeEnum
545 //================================================================
546 void GEOMBase_Helper::localSelection( const int mode )
548 std::list<int> modes;
549 modes.push_back( mode );
550 localSelection( modes );
553 //================================================================
554 // Function : globalSelection
555 // Purpose : Activate selection of sub-shapes. Set selection filters
556 // in accordance with mode. theMode is from GEOMImpl_Types
557 //================================================================
558 void GEOMBase_Helper::globalSelection( const int theMode, const bool update )
560 getDisplayer()->GlobalSelection( theMode, update );
563 //================================================================
564 // Function : globalSelection
565 // Purpose : Activate selection of sub-shapes. Set selection filters
566 // in accordance with mode. theMode is from GEOMImpl_Types
567 //================================================================
568 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
571 getDisplayer()->GlobalSelection( theModes, update );
574 //================================================================
575 // Function : globalSelection
576 // Purpose : Activate selection of sub-shapes. Set selection filters
577 // in accordance with mode. theMode is from GEOMImpl_Types
578 //================================================================
579 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
580 const QList<int>& subShapes,
583 getDisplayer()->GlobalSelection( theModes, update, &subShapes );
586 //================================================================
587 // Function : addInStudy
588 // Purpose : Add object in study
589 //================================================================
590 QString GEOMBase_Helper::addInStudy( GEOM::GEOM_Object_ptr theObj, const char* theName )
595 _PTR(Study) aStudy = getStudy()->studyDS();
596 if ( !aStudy || theObj->_is_nil() )
599 SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy(aStudy);
601 GEOM::GEOM_Object_ptr aFatherObj = getFather( theObj );
603 SALOMEDS::SObject_var aSO =
604 getGeomEngine()->AddInStudy(aStudyDS, theObj, theName, aFatherObj);
607 if ( !aSO->_is_nil() ) {
608 CORBA::String_var entry = aSO->GetID();
609 anEntry = entry.in();
611 // Each dialog is responsible for this method implementation,
612 // default implementation does nothing
613 restoreSubShapes(aStudyDS, aSO);
619 //================================================================
620 // Function : restoreSubShapes
621 // Purpose : restore tree of argument's sub-shapes under the resulting shape
622 //================================================================
623 void GEOMBase_Helper::restoreSubShapes (SALOMEDS::Study_ptr /*theStudy*/,
624 SALOMEDS::SObject_ptr /*theSObject*/)
626 // do nothing by default
628 // example of implementation in particular dialog:
629 // GEOM::ListOfGO anArgs;
630 // anArgs.length(0); // empty list means that all arguments should be restored
631 // getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
632 // /*theFindMethod=*/GEOM::FSM_GetInPlace,
633 // /*theInheritFirstArg=*/false);
636 //================================================================
637 // Function : updateObjBrowser
638 // Purpose : Update object browser
639 //================================================================
640 void GEOMBase_Helper::updateObjBrowser() const
642 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
644 CAM_Module* module = app->module( "Geometry" );
645 SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
647 appMod->updateObjBrowser( true );
652 //================================================================
653 // Function : updateViewer
654 // Purpose : Update active 3D view
655 //================================================================
656 void GEOMBase_Helper::updateViewer()
658 getDisplayer()->UpdateViewer();
661 //================================================================
662 // Function : getStudyId
663 // Purpose : Get study Id
664 //================================================================
665 int GEOMBase_Helper::getStudyId() const
669 anId = getStudy()->id();
673 //================================================================
674 // Function : getStudy
675 // Purpose : Returns the active study. It is recommended to use
676 // this method instead of direct desktop->getActiveStudy() calls
677 //================================================================
678 SalomeApp_Study* GEOMBase_Helper::getStudy() const
680 SUIT_Desktop* aDesktop = getDesktop();
684 QList<SUIT_Application*> anAppList = SUIT_Session::session()->applications();
686 SUIT_Application* anApp = 0;
687 QListIterator<SUIT_Application*> it( anAppList );
688 while ( it.hasNext() )
691 if ( anApp && anApp->desktop() == aDesktop )
695 return dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
698 //================================================================
699 // Function : getEntry
701 //================================================================
702 QString GEOMBase_Helper::getEntry( GEOM::GEOM_Object_ptr object ) const
704 SalomeApp_Study* study = getStudy();
706 QString objIOR = GEOMBase::GetIORFromObject( object );
707 if ( objIOR != "" ) {
708 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( objIOR.toLatin1().constData() ) );
710 return QString::fromStdString(SO->GetID());
716 //================================================================
717 // Function : getDisplayer
719 //================================================================
720 GEOM_Displayer* GEOMBase_Helper::getDisplayer()
723 myDisplayer = new GEOM_Displayer( getStudy() );
727 //================================================================
728 // Function : clearShapeBuffer
730 //================================================================
731 void GEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
733 GeometryGUI::ClearShapeBuffer(theObj);
736 //================================================================
737 // Function : openCommand
739 //================================================================
740 bool GEOMBase_Helper::openCommand()
743 if ( !getStudy() || hasCommand() )
745 MESSAGE("Getting out from openCommand()")
749 GEOM::GEOM_IOperations_var anOp = GEOM::GEOM_IOperations::_narrow( getOperation() );
750 if ( !anOp->_is_nil() ) {
751 myCommand = new GEOM_Operation( SUIT_Session::session()->activeApplication(), anOp.in() );
757 MESSAGE("anOp->_is_nil() = true")
763 //================================================================
764 // Function : abortCommand
766 //================================================================
767 bool GEOMBase_Helper::abortCommand()
773 delete myCommand; // I don't know where to delete this object here ?
779 //================================================================
780 // Function : commitCommand
782 //================================================================
783 bool GEOMBase_Helper::commitCommand( const char* )
789 delete myCommand; // I don't know where to delete this object here ?
795 //================================================================
796 // Function : hasCommand
798 //================================================================
799 bool GEOMBase_Helper::hasCommand() const
801 return (bool)myCommand;
804 //================================================================
805 // Function : getOperation
807 //================================================================
808 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::getOperation()
810 if ( myOperation->_is_nil() )
811 myOperation = createOperation();
818 //================================================================
819 // Function : checkViewWindow
821 //================================================================
822 bool GEOMBase_Helper::checkViewWindow()
825 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
826 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
827 while ( it.hasNext() )
829 if ( myViewWindow == it.next() )
837 //================================================================
838 // Function : onAccept
839 // Purpose : This method should be called from dialog's slots onOk() and onApply()
840 // It perfroms user input validation, then it
841 // performs a proper operation and manages transactions, etc.
842 //================================================================
843 bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction, bool erasePreviewFlag )
845 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
848 MESSAGE("appStudy is empty")
851 _PTR(Study) aStudy = appStudy->studyDS();
853 bool aLocked = (_PTR(AttributeStudyProperties) (aStudy->GetProperties()))->IsLocked();
855 MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
856 SUIT_MessageBox::warning ( (QWidget*)SUIT_Session::session()->activeApplication()->desktop(),
857 QObject::tr("WRN_WARNING"),
858 QObject::tr("WRN_STUDY_LOCKED"),
859 QObject::tr("BUT_OK") );
864 if ( !isValid( msg ) ) {
870 erasePreview( false );
875 if ( ( !publish && !useTransaction ) || openCommand() ) {
876 SUIT_OverrideCursor wc;
877 SUIT_Session::session()->activeApplication()->putInfo( "" );
879 if ( !execute( objects ) || !getOperation()->IsDone() ) {
885 QList<GEOM::GeomObjPtr> anObjectList = getSourceObjects( );
886 addSubshapesToStudy(); // add Sub-shapes if local selection
887 const int nbObjs = objects.size();
888 QStringList anEntryList;
889 int currObj = 1, aNumber = 1;
890 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it, currObj++ ) {
891 GEOM::GEOM_Object_var obj=*it;
893 QString aName = getObjectName(obj);
894 if (aName.isEmpty()) {
895 aName = getNewObjectName(currObj);
898 aName = getPrefix(obj);
900 // Try to find a unique name
901 aName = GEOMBase::GetDefaultName(aName, extractPrefix());
903 // Don't check name uniqueness in case of numerous objects
904 aName = aName + "_" + QString::number(aNumber++);
907 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
908 if ( aName.isEmpty() )
909 aName = GEOMBase::GetDefaultName( getPrefix( obj ) );
912 anEntryList << addInStudy( obj, aName.toLatin1().constData() );
914 if( isDisplayResult() )
915 display( obj, false );
916 #ifdef WITHGENERICOBJ
917 // obj has been published in study. Its refcount has been incremented.
918 // It is safe to decrement its refcount
919 // so that it will be destroyed when the entry in study will be removed
924 // asv : fix of PAL6454. If publish==false, then the original shape
925 // was modified, and need to be re-cached in GEOM_Client before redisplay
926 clearShapeBuffer( obj );
927 // withChildren=true, updateView=false
928 if( isDisplayResult() )
929 redisplay( obj, true, false );
936 if( SUIT_Application* anApp = SUIT_Session::session()->activeApplication() ) {
937 LightApp_Application* aLightApp = dynamic_cast<LightApp_Application*>( anApp );
939 QString anOpName( typeid(*this).name() );
940 aLightApp->emitOperationFinished( "Geometry", anOpName, anEntryList );
942 if ( !isDisableBrowsing() )
943 aLightApp->browseObjects( anEntryList, isApplyAndClose(), isOptimizedBrowsing() );
945 anApp->putInfo( QObject::tr("GEOM_PRP_DONE") );
947 if ( anObjectList.count() > 0 )
948 hideSourceObjects( anObjectList );
956 catch( const SALOME::SALOME_Exception& e ) {
957 SalomeApp_Tools::QtCatchCorbaException( e );
959 MESSAGE("Exception catched")
964 MESSAGE("result ="<<result)
969 //================================================================
970 // Function : showError
971 // Purpose : Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
972 //================================================================
973 void GEOMBase_Helper::showError()
976 if ( !getOperation()->_is_nil() )
977 msg = QObject::tr( getOperation()->GetErrorCode() );
980 msg = QObject::tr( "GEOM_PRP_ABORT" );
982 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
983 QObject::tr( "GEOM_ERROR_STATUS" ),
985 QObject::tr( "BUT_OK" ) );
988 //================================================================
989 // Function : showError
990 // Purpose : Shows a error message followed by <msg>
991 //================================================================
992 void GEOMBase_Helper::showError( const QString& msg )
994 QString str( QObject::tr( "GEOM_INCORRECT_INPUT" ) );
995 if ( !msg.isEmpty() )
997 SUIT_MessageBox::critical(SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ), str, QObject::tr( "BUT_OK" ) );
1000 //////////////////////////////////////////////////////////////////
1001 // Virtual methods to be redefined in dialogs
1002 //////////////////////////////////////////////////////////////////
1004 //================================================================
1005 // Function : createOperation
1006 // Purpose : Redefine this method to return proper IOperation reference
1007 //================================================================
1008 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::createOperation()
1010 GEOM::GEOM_IOperations_var aNilOp;
1011 return aNilOp._retn();
1014 //================================================================
1015 // Function : isValid
1016 // Purpose : Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
1017 //================================================================
1018 bool GEOMBase_Helper::isValid( QString& )
1023 //================================================================
1024 // Function : execute
1025 // Purpose : This method is called by onAccept().
1026 // It should perform the required operation and put all new or modified objects into
1027 // <objects> argument.Should return <false> if some error occurs during its execution.
1028 //================================================================
1029 bool GEOMBase_Helper::execute( ObjectList& objects )
1034 //================================================================
1035 // Function : getFather
1036 // Purpose : This method is called by addInStudy(). It should return a father object
1037 // for <theObj> or a nil reference if <theObj> should be published
1038 // as a top-level object.
1039 //================================================================
1040 GEOM::GEOM_Object_ptr GEOMBase_Helper::getFather( GEOM::GEOM_Object_ptr theObj )
1042 return GEOM::GEOM_Object::_nil();
1045 //================================================================
1046 // Function : getObjectName
1047 // Purpose : Redefine this method to return proper name for the given object
1048 //================================================================
1049 QString GEOMBase_Helper::getObjectName(GEOM::GEOM_Object_ptr object) const
1054 //================================================================
1055 // Function : getNewObjectName
1056 // Purpose : Redefine this method to return proper name for a new object
1057 //================================================================
1058 QString GEOMBase_Helper::getNewObjectName (int) const
1063 //================================================================
1064 // Function : extractPrefix
1065 // Purpose : Redefine this method to return \c true if necessary
1066 // to extract prefix when generating new name for the
1067 // object(s) being created
1068 //================================================================
1069 bool GEOMBase_Helper::extractPrefix() const
1074 //================================================================
1075 // Function : getPrefix
1076 // Purpose : Get prefix for name of created object
1077 //================================================================
1078 QString GEOMBase_Helper::getPrefix( GEOM::GEOM_Object_ptr theObj ) const
1080 if ( !myPrefix.isEmpty() || theObj->_is_nil() )
1083 GEOM::shape_type aType = theObj->GetShapeType();
1087 case GEOM::VERTEX : return QObject::tr( "GEOM_VERTEX" );
1088 case GEOM::EDGE : return QObject::tr( "GEOM_EDGE" );
1089 case GEOM::WIRE : return QObject::tr( "GEOM_WIRE" );
1090 case GEOM::FACE : return QObject::tr( "GEOM_FACE" );
1091 case GEOM::SHELL : return QObject::tr( "GEOM_SHELL" );
1092 case GEOM::SOLID : return QObject::tr( "GEOM_SOLID" );
1093 case GEOM::COMPSOLID: return QObject::tr( "GEOM_COMPOUNDSOLID" );
1094 case GEOM::COMPOUND : return QObject::tr( "GEOM_COMPOUND" );
1095 default : return "";
1099 //================================================================
1100 // Function : getDesktop
1101 // Purpose : Returns myDesktop field. Initialized in constructor,
1102 // usually as dynamic_cast<SUIT_Desktop*>(parentWidget())
1103 //================================================================
1104 SUIT_Desktop* GEOMBase_Helper::getDesktop() const
1109 //================================================================
1110 // Function : selectObjects
1111 // Purpose : Selects list of objects
1112 //================================================================
1113 bool GEOMBase_Helper::selectObjects( ObjectList& objects )
1115 SUIT_DataOwnerPtrList aList;
1116 ObjectList::iterator anIter;
1117 for ( anIter = objects.begin(); anIter != objects.end(); ++anIter )
1119 QString anEntry = getEntry( *anIter );
1120 LightApp_DataOwner* anOwher = new LightApp_DataOwner( anEntry );
1121 aList.append( anOwher );
1124 SUIT_Session* session = SUIT_Session::session();
1125 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1129 LightApp_SelectionMgr* aMgr = app->selectionMgr();
1133 aMgr->setSelected( aList, false );
1138 //================================================================
1139 // Function : findObjectInFather
1140 // Purpose : It should return an object if its founded in study or
1141 // return Null object if the object is not founded
1142 //================================================================
1143 GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather (GEOM::GEOM_Object_ptr theFather,
1144 const QString& theName)
1146 SalomeApp_Application* app =
1147 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1148 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1149 _PTR(Study) aDStudy = appStudy->studyDS();
1150 QString IOR = GEOMBase::GetIORFromObject( theFather );
1151 _PTR(SObject) SObj ( aDStudy->FindObjectIOR( IOR.toLatin1().constData() ) );
1153 bool inStudy = false;
1154 GEOM::GEOM_Object_var aReturnObject;
1155 for (_PTR(ChildIterator) iit (aDStudy->NewChildIterator( SObj )); iit->More() && !inStudy; iit->Next()) {
1156 _PTR(SObject) child (iit->Value());
1157 QString aChildName = child->GetName().c_str();
1158 if (aChildName == theName) {
1160 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(iit->Value());
1161 aReturnObject = GEOM::GEOM_Object::_narrow( corbaObj );
1165 return aReturnObject._retn();
1167 return GEOM::GEOM_Object::_nil();
1170 //================================================================
1171 // Function : findObjectInFather
1172 // Purpose : It should return an object if its founded in study or
1173 // return Null object if the object is not founded
1174 //================================================================
1175 GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather( GEOM::GEOM_Object_ptr theFather,
1178 GEOM::GEOM_Object_var object;
1180 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
1182 _PTR(Study) studyDS = study->studyDS();
1183 QString IOR = GEOMBase::GetIORFromObject( theFather );
1184 _PTR(SObject) sobject( studyDS->FindObjectIOR( IOR.toLatin1().constData() ) );
1186 _PTR(ChildIterator) it( studyDS->NewChildIterator( sobject ) );
1187 for ( ; it->More(); it->Next() ) {
1188 GEOM::GEOM_Object_var cobject = GEOM::GEOM_Object::_narrow( GeometryGUI::ClientSObjectToObject( it->Value() ) );
1189 if ( !CORBA::is_nil( cobject ) ) {
1190 GEOM::ListOfLong_var indices = cobject->GetSubShapeIndices();
1191 int length = indices->length();
1192 // VSR 18/03/2014: we need only sub-shapes with single sub-shape index (to exclude groups, etc)
1193 if ( length == 1 && indices[0] == theIndex ) {
1202 return object._retn();
1205 //================================================================
1206 // Function : addSubshapesToStudy
1207 // Purpose : Virtual method to add sub-shapes if needs
1208 //================================================================
1209 void GEOMBase_Helper::addSubshapesToStudy()
1211 //Impemented in Dialogs, called from Accept method
1214 //================================================================
1215 // Function : getSourceObjects
1216 // Purpose : Virtual method to get source objects
1217 //================================================================
1218 QList<GEOM::GeomObjPtr> GEOMBase_Helper::getSourceObjects()
1220 //Impemented in Dialogs, called from Accept method
1221 QList<GEOM::GeomObjPtr> res;
1225 //================================================================
1226 // Function : getSelected
1227 // Purpose : Get selected object by specified type
1229 // Returns valid object if only one object of the specified type is selected
1230 // (no matter global or local selection is activated). If \a type is TopAbs_SHAPE,
1231 // geometrical object of any valid type is expected.
1233 // \param type type of the object to be obtained from selection
1234 // \return selected geometrical object or nil object if selection is not satisfactory
1235 //================================================================
1236 GEOM::GeomObjPtr GEOMBase_Helper::getSelected( TopAbs_ShapeEnum type )
1238 QList<TopAbs_ShapeEnum> types;
1240 return getSelected( types );
1243 //================================================================
1244 // Function : getSelected
1245 // Purpose : Get selected object by specified types
1247 // Returns valid object if only one object of the specified type is selected
1248 // (no matter global or local selection is activated). The list of allowed
1249 // shape types is passed via \a types. If \a types includes TopAbs_SHAPE,
1250 // geometrical object of any valid type is expected.
1252 // \param types list of allowed shape types for the objects to be obtained from selection
1253 // \return selected geometrical object or nil object if selection is not satisfactory
1254 //================================================================
1255 GEOM::GeomObjPtr GEOMBase_Helper::getSelected( const QList<TopAbs_ShapeEnum>& types )
1257 QList<GEOM::GeomObjPtr> selected = getSelected( types, 1 );
1258 return selected.count() > 0 ? selected[0] : GEOM::GeomObjPtr();
1261 //================================================================
1262 // Function : getSelected
1263 // Purpose : Get selected object(s) by specified type
1265 // Returns list of selected objects if selection satisfies specifies selection options.
1266 // (no matter global or local selection is activated). If \a type is TopAbs_SHAPE,
1267 // geometrical objects of any valid type are expected.
1269 // The \a type parameter specifies allowed type of the object(s) being selected.
1270 // The \a count parameter specifies exact number of the objects to be retrieved from selection.
1271 // The \a strict parameter specifies policy being applied to the selection.
1272 // If \a count < 0, then any number of the selected objects is valid (including 0).
1273 // In this case, if \a strict is \c true (default), all selected objects should satisfy
1274 // the specified \a type.
1275 // If \a count > 0, only specified number of the objects is retrieved from the selection.
1276 // In this case, if \a strict is \c true (default), function returns empty list if total number of selected
1277 // objects does not correspond to the \a count parameter. Otherwise (if \a strict is \c false),
1278 // function returns valid list of objects if at least \a count objects satisfy specified \a type.
1280 // \param type type of the object(s) to be obtained from selection
1281 // \param count number of items to be retrieved from selection
1282 // \param strict selection policy
1283 // \return list of selected geometrical objects or empty list if selection is not satisfactory
1284 //================================================================
1285 QList<GEOM::GeomObjPtr> GEOMBase_Helper::getSelected( TopAbs_ShapeEnum type, int count, bool strict )
1287 QList<TopAbs_ShapeEnum> types;
1289 return getSelected( types, count, strict );
1292 static bool typeInList( TopAbs_ShapeEnum type, const QList<TopAbs_ShapeEnum>& types )
1295 for ( int i = 0; i < types.count() && !ok; i++ )
1296 ok = types[i] == TopAbs_SHAPE || types[i] == type;
1300 //================================================================
1301 // Function : getSelected
1302 // Purpose : Get selected objects by specified types
1304 // Returns list of selected objects if selection satisfies specifies selection options.
1305 // (no matter global or local selection is activated). If \a types includes TopAbs_SHAPE,
1306 // geometrical objects of any valid type are expected.
1308 // The \a types parameter specifies allowed types of the object(s) being selected.
1309 // The \a count parameter specifies exact number of the objects to be retrieved from selection.
1310 // The \a strict parameter specifies policy being applied to the selection.
1311 // If \a count < 0, then any number of the selected objects is valid (including 0).
1312 // In this case, if \a strict is \c true (default), all selected objects should satisfy
1313 // the specified \a type.
1314 // If \a count > 0, only specified number of the objects is retrieved from the selection.
1315 // In this case, if \a strict is \c true (default), function returns empty list if total number of selected
1316 // objects does not correspond to the \a count parameter. Otherwise (if \a strict is \c false),
1317 // function returns valid list of objects if at least \a count objects satisfy specified \a type.
1319 // \param types list of allowed shape types for the objects to be obtained from selection
1320 // \param count number of items to be retrieved from selection
1321 // \param strict selection policy
1322 // \return list of selected geometrical objects or empty list if selection is not satisfactory
1323 //================================================================
1324 QList<GEOM::GeomObjPtr> GEOMBase_Helper::getSelected( const QList<TopAbs_ShapeEnum>& types, int count, bool strict )
1326 SUIT_Session* session = SUIT_Session::session();
1327 QList<GEOM::GeomObjPtr> result;
1329 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1331 LightApp_SelectionMgr* selMgr = app->selectionMgr();
1333 SALOME_ListIO selected;
1334 selMgr->selectedObjects( selected );
1335 SALOME_ListIteratorOfListIO it( selected );
1336 bool stopped = false;
1337 for ( ; it.More() && !stopped; it.Next() ) {
1338 Handle(SALOME_InteractiveObject) IO = it.Value();
1339 GEOM::GeomObjPtr object = GEOMBase::ConvertIOinGEOMObject( IO );
1341 TColStd_IndexedMapOfInteger subShapes;
1342 selMgr->GetIndexes( IO, subShapes );
1343 int nbSubShapes = subShapes.Extent();
1344 if ( nbSubShapes == 0 ) {
1346 if ( typeInList( (TopAbs_ShapeEnum)(object->GetShapeType()), types ) ) {
1349 if ( strict && result.count() > count ) {
1353 else if ( !strict && result.count() == count )
1357 else if ( strict ) {
1364 for ( int i = 1; i <= nbSubShapes && !stopped; i++ ) {
1365 int idx = subShapes( i );
1366 GEOM::GeomObjPtr subShape = findObjectInFather( object.get(), idx );
1368 // sub-shape is not yet published in the study
1369 GEOM::ShapesOpPtr shapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
1370 subShape.take( shapesOp->GetSubShape( object.get(), idx ) ); // take ownership!
1372 if ( typeInList( (TopAbs_ShapeEnum)(subShape->GetShapeType()), types ) ) {
1375 if ( strict && result.count() > count ) {
1379 else if ( !strict && result.count() == count )
1383 else if ( strict ) {
1395 //================================================================
1396 // Function : hideSourceObject
1398 //================================================================
1399 void GEOMBase_Helper::hideSourceObjects( QList<GEOM::GeomObjPtr> theObject )
1401 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1402 if ( resMgr->booleanValue( "Geometry", "hide_input_object", true) ) {
1403 GEOM_Displayer* aDisplayer = getDisplayer();
1404 for ( int i = 0; i < theObject.count(); i++ )
1405 aDisplayer->Erase( theObject[i].get() );
1409 //================================================================
1410 // Function : setIsApplyAndClose
1411 // Purpose : Set value of the flag indicating that the dialog is
1412 // accepted by Apply & Close button
1413 //================================================================
1414 void GEOMBase_Helper::setIsApplyAndClose( const bool theFlag )
1416 myIsApplyAndClose = theFlag;
1419 //================================================================
1420 // Function : isApplyAndClose
1421 // Purpose : Get value of the flag indicating that the dialog is
1422 // accepted by Apply & Close button
1423 //================================================================
1424 bool GEOMBase_Helper::isApplyAndClose() const
1426 return myIsApplyAndClose;
1429 //================================================================
1430 // Function : setIsOptimizedBrowsing
1431 // Purpose : Set value of the flag switching to optimized
1432 // browsing mode (to select the first published
1434 //================================================================
1435 void GEOMBase_Helper::setIsOptimizedBrowsing( const bool theFlag )
1437 myIsOptimizedBrowsing = theFlag;
1440 //================================================================
1441 // Function : isOptimizedBrowsing
1442 // Purpose : Get value of the flag switching to optimized
1443 // browsing mode (to select the first published
1445 //================================================================
1446 bool GEOMBase_Helper::isOptimizedBrowsing() const
1448 return myIsOptimizedBrowsing;