1 // Copyright (C) 2007-2011 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.
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_ListIteratorOfListIO.hxx>
50 #include <SALOME_Prs.h>
52 #include <OCCViewer_ViewModel.h>
53 #include <SVTK_ViewModel.h>
55 #include <TColStd_MapOfInteger.hxx>
56 #include <TCollection_AsciiString.hxx>
57 #include <TColStd_IndexedMapOfInteger.hxx>
59 //To disable automatic genericobj management, the following line should be commented.
60 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
61 #define WITHGENERICOBJ
63 //================================================================
64 // Function : getActiveView
65 // Purpose : Get active view window, returns 0 if no open study frame
66 //================================================================
67 static SUIT_ViewWindow* getActiveView()
69 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
71 return SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
77 //================================================================
78 // Function : getGeomEngine
79 // Purpose : Static method
80 //================================================================
81 GEOM::GEOM_Gen_ptr GEOMBase_Helper::getGeomEngine()
83 return GeometryGUI::GetGeomGen();
86 //================================================================
87 // Function : GEOMBase_Helper
89 //================================================================
90 GEOMBase_Helper::GEOMBase_Helper( SUIT_Desktop* desktop )
91 : myDesktop( desktop ), myViewWindow( 0 ), myDisplayer( 0 ), myCommand( 0 ), isPreview( false ),
92 myIsApplyAndClose( false ), myIsOptimizedBrowsing( false ), myIsWaitCursorEnabled( true )
96 //================================================================
97 // Function : ~GEOMBase_Helper
99 //================================================================
100 GEOMBase_Helper::~GEOMBase_Helper()
102 //rnv: Fix for the "IPAL21922 : WinTC5.1.4: incorrect quit salome"
103 if ( !SUIT_Session::session()->activeApplication() || !SUIT_Session::session()->activeApplication()->desktop() )
106 if ( myPreview.size() )
110 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
112 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
114 globalSelection(aGeomGUI->getLocalSelectionMode() , true );
119 if ( !CORBA::is_nil( myOperation ) )
120 myOperation->UnRegister();
123 //================================================================
124 // Function : display
126 //================================================================
127 void GEOMBase_Helper::display( const ObjectList& objList, const bool updateView )
129 ObjectList::const_iterator it;
130 for ( it = objList.begin(); it != objList.end(); it++ ) {
131 display( *it, false );
133 if ( !objList.empty() && updateView )
134 getDisplayer()->UpdateViewer();
137 //================================================================
138 // Function : display
139 // Purpose : Display object.
140 // Important : Object must be already in study
141 //================================================================
142 void GEOMBase_Helper::display( GEOM::GEOM_Object_ptr object, const bool updateView )
144 // Unset color of shape ( this color may be set during preview displaying )
145 // Default color will be used
146 // getDisplayer()->UnsetColor();
147 getDisplayer()->UnsetWidth();
149 MESSAGE("GEOMBase_Helper::display myTexture = "<<getDisplayer()->GetTexture())
151 // Enable activisation of selection
152 getDisplayer()->SetToActivate( true );
155 getDisplayer()->Display( object, updateView );
158 //================================================================
161 //================================================================
162 void GEOMBase_Helper::erase( const ObjectList& objList, const bool updateView )
164 ObjectList::const_iterator it = objList.begin();
165 for ( ; it != objList.end(); it++ ) {
168 if ( !objList.empty() && updateView )
169 getDisplayer()->UpdateViewer();
172 //================================================================
175 //================================================================
176 void GEOMBase_Helper::erase( GEOM::GEOM_Object_ptr object, const bool updateView )
178 if ( !object->_is_nil() ) {
179 QString entry = getEntry( object );
180 getDisplayer()->Erase( new SALOME_InteractiveObject(
181 entry.toLatin1().constData(),
182 "GEOM", strdup( GEOMBase::GetName( object ).toLatin1().constData() ) ), true, updateView );
186 //================================================================
187 // Function : redisplay
189 //================================================================
190 void GEOMBase_Helper::redisplay( const ObjectList& objList,
191 const bool withChildren,
192 const bool updateView )
194 ObjectList::const_iterator it = objList.begin();
195 for ( ; it != objList.end(); it++ ) {
196 redisplay( *it, withChildren, false );
198 if ( !objList.empty() && updateView )
199 getDisplayer()->UpdateViewer();
202 //================================================================
203 // Function : redisplay
205 //================================================================
206 void GEOMBase_Helper::redisplay( GEOM::GEOM_Object_ptr object,
207 const bool withChildren,
208 const bool updateView )
210 if ( !object->_is_nil() ) {
211 // Unset color of shape ( this color may be set during preview displaying )
212 // Default color will be used
213 getDisplayer()->UnsetColor();
214 getDisplayer()->UnsetWidth();
216 // Enable activisation of selection
217 getDisplayer()->SetToActivate( true );
219 QString entry = getEntry( object );
220 getDisplayer()->Redisplay(new SALOME_InteractiveObject
221 (entry.toLatin1().constData(), "GEOM", strdup(GEOMBase::GetName(object).toLatin1().constData())), false);
224 if ( withChildren ) {
225 SalomeApp_Study* aDoc = getStudy();
226 if ( aDoc && aDoc->studyDS() ) {
227 _PTR(Study) aStudy = aDoc->studyDS();
228 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string(object);
229 _PTR(SObject) aSObj (aStudy->FindObjectIOR(std::string(objStr.in())));
231 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
232 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
233 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow
234 (GeometryGUI::ClientSObjectToObject(anIt->Value()));
235 if ( !CORBA::is_nil( aChild ) ) {
236 if ( !aChild->_is_nil() ) {
237 QString entry = getEntry( aChild );
238 getDisplayer()->Redisplay( new SALOME_InteractiveObject(
239 entry.toLatin1().constData(), "GEOM", strdup( GEOMBase::GetName( aChild ).toLatin1().constData() ) ), false );
248 getDisplayer()->UpdateViewer();
251 //================================================================
252 // Function : displayPreview
253 // Purpose : Method for displaying preview based on execute() results
254 //================================================================
255 void GEOMBase_Helper::displayPreview( const bool display,
258 const bool toRemoveFromEngine,
259 const double lineWidth,
260 const int displayMode,
264 erasePreview( update );
270 if ( !isValid( msg ) )
272 erasePreview( update );
277 erasePreview( false );
280 SUIT_OverrideCursor wc;
283 if ( !isWaitCursorEnabled() )
286 if ( !execute( objects ) || !getOperation()->IsDone() ) {
290 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it )
292 GEOM::GEOM_Object_var obj=*it;
293 displayPreview( obj, true, activate, false, lineWidth, displayMode, color );
294 if ( toRemoveFromEngine )
299 catch( const SALOME::SALOME_Exception& e ) {
300 SalomeApp_Tools::QtCatchCorbaException( e );
309 //================================================================
310 // Function : displayPreview
311 // Purpose : Method for displaying preview of resulting shape
312 //================================================================
313 void GEOMBase_Helper::displayPreview( GEOM::GEOM_Object_ptr object,
317 const double lineWidth,
318 const int displayMode,
321 // Set color for preview shape
322 getDisplayer()->SetColor( color == -1 ? Quantity_NOC_VIOLET : color );
324 // set width of displayed shape
327 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
328 lw = resMgr->integerValue("Geometry", "preview_edge_width", -1);
330 getDisplayer()->SetWidth( lw );
332 // set display mode of displayed shape
333 int aPrevDispMode = getDisplayer()->SetDisplayMode( displayMode );
335 // Disable activation of selection
336 getDisplayer()->SetToActivate( activate );
338 // Make a reference to GEOM_Object
339 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string( object );
340 getDisplayer()->SetName( objStr.in() );
343 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( object );
344 if ( aPrs == 0 || aPrs->IsNull() )
348 displayPreview( aPrs, append, update );
350 getDisplayer()->UnsetName();
351 getDisplayer()->UnsetColor();
352 getDisplayer()->SetDisplayMode( aPrevDispMode );
354 // Enable activation of displayed objects
355 getDisplayer()->SetToActivate( true );
358 //================================================================
359 // Function : displayPreview
360 // Purpose : Method for displaying arbitrary preview objects (not limited to shapes)
361 //================================================================
362 void GEOMBase_Helper::displayPreview( const SALOME_Prs* prs,
367 erasePreview( false );
369 // remember current view frame to make correct erase preview later
370 myViewWindow = getActiveView();
372 if ( myViewWindow == 0 )
376 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
377 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
378 aViewManager->getType() == SVTK_Viewer::Type() )
380 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
381 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
383 aView->Display( prs );
386 // Add prs to the preview list
387 myPreview.push_back( (SALOME_Prs*)prs );
391 getDisplayer()->UpdateViewer();
394 //================================================================
395 // Function : erasePreview
397 //================================================================
398 void GEOMBase_Helper::erasePreview( const bool update )
400 // check view frame where the preview was displayed
401 bool vfOK = checkViewWindow() && myViewWindow;
402 // Iterate through presentations and delete them
403 for ( PrsList::iterator anIter = myPreview.begin(); anIter != myPreview.end(); ++anIter ) {
406 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
407 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
408 aViewManager->getType() == SVTK_Viewer::Type() )
410 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
411 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
413 aView->Erase( *anIter, true );
425 //================================================================
426 // Function : localSelection
427 // Purpose : Activate selection of objects of a given type
428 // IMPORTANT : Works after localSelection( ... ) method call only
429 //================================================================
430 void GEOMBase_Helper::activate( const int theType )
432 if (!getStudy()) return;
433 _PTR(Study) aStudy = getStudy()->studyDS();
434 _PTR(SComponent) aGeom ( aStudy->FindComponent( "GEOM" ) );
439 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( aGeom ) );
440 for ( ; anIter->More(); anIter->Next() )
442 _PTR(SObject) aSO ( anIter->Value() );
445 _PTR(SObject) aRefSO;
446 if ( !aSO->ReferencedObject( aRefSO ) )
448 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow
449 (GeometryGUI::ClientSObjectToObject(aSO));
450 if ( !anObj->_is_nil() && anObj->GetType() == theType )
451 aList.Append( new SALOME_InteractiveObject( aSO->GetID().c_str(), "GEOM", aSO->GetName().c_str()) );
456 getDisplayer()->LocalSelection( aList, 0 );
459 //================================================================
460 // Function : localSelection
461 // Purpose : Activate selection of sub-shapes in accordance with mode
462 // theMode is from TopAbs_ShapeEnum
463 //================================================================
464 void GEOMBase_Helper::localSelection( const ObjectList& theObjs, const int theMode )
466 SALOME_ListIO aListOfIO;
468 ObjectList::const_iterator anIter = theObjs.begin();
469 for ( ; anIter != theObjs.end(); ++anIter )
471 GEOM::GEOM_Object_ptr anObj = *anIter;
472 if ( anObj->_is_nil() )
474 QString anEntry = getEntry( anObj );
476 aListOfIO.Append( new SALOME_InteractiveObject(
477 anEntry.toLatin1().constData(), "GEOM", strdup( GEOMBase::GetName( anObj ).toLatin1().constData() ) ) );
480 getDisplayer()->LocalSelection( aListOfIO, theMode );
483 //================================================================
484 // Function : localSelection
485 // Purpose : Activate selection of sub-shapes in accordance with mode
486 // theMode is from TopAbs_ShapeEnum
487 //================================================================
488 void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const int mode )
490 // If object is null local selection for all objects is activated
491 if ( obj->_is_nil() ) {
492 getDisplayer()->LocalSelection( Handle(SALOME_InteractiveObject)(), mode );
497 objList.push_back( obj );
498 localSelection( objList, mode );
502 //================================================================
503 // Function : globalSelection
504 // Purpose : Activate selection of sub-shapes. Set selection filters
505 // in accordance with mode. theMode is from GEOMImpl_Types
506 //================================================================
507 void GEOMBase_Helper::globalSelection( const int theMode, const bool update )
509 getDisplayer()->GlobalSelection( theMode, update );
512 //================================================================
513 // Function : globalSelection
514 // Purpose : Activate selection of sub-shapes. Set selection filters
515 // in accordance with mode. theMode is from GEOMImpl_Types
516 //================================================================
517 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
520 getDisplayer()->GlobalSelection( theModes, update );
523 //================================================================
524 // Function : globalSelection
525 // Purpose : Activate selection of sub-shapes. Set selection filters
526 // in accordance with mode. theMode is from GEOMImpl_Types
527 //================================================================
528 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
529 const QList<int>& subShapes,
532 getDisplayer()->GlobalSelection( theModes, update, &subShapes );
535 //================================================================
536 // Function : addInStudy
537 // Purpose : Add object in study
538 //================================================================
539 QString GEOMBase_Helper::addInStudy( GEOM::GEOM_Object_ptr theObj, const char* theName )
544 _PTR(Study) aStudy = getStudy()->studyDS();
545 if ( !aStudy || theObj->_is_nil() )
548 SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy(aStudy);
550 GEOM::GEOM_Object_ptr aFatherObj = getFather( theObj );
552 SALOMEDS::SObject_var aSO =
553 getGeomEngine()->AddInStudy(aStudyDS, theObj, theName, aFatherObj);
556 if ( !aSO->_is_nil() )
557 anEntry = aSO->GetID();
559 // Each dialog is responsible for this method implementation,
560 // default implementation does nothing
561 restoreSubShapes(aStudyDS, aSO);
567 //================================================================
568 // Function : restoreSubShapes
569 // Purpose : restore tree of argument's sub-shapes under the resulting shape
570 //================================================================
571 void GEOMBase_Helper::restoreSubShapes (SALOMEDS::Study_ptr /*theStudy*/,
572 SALOMEDS::SObject_ptr /*theSObject*/)
574 // do nothing by default
576 // example of implementation in particular dialog:
577 // GEOM::ListOfGO anArgs;
578 // anArgs.length(0); // empty list means that all arguments should be restored
579 // getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
580 // /*theFindMethod=*/GEOM::FSM_GetInPlace,
581 // /*theInheritFirstArg=*/false);
584 //================================================================
585 // Function : updateObjBrowser
586 // Purpose : Update object browser
587 //================================================================
588 void GEOMBase_Helper::updateObjBrowser() const
590 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
592 CAM_Module* module = app->module( "Geometry" );
593 SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
595 appMod->updateObjBrowser( true );
600 //================================================================
601 // Function : updateViewer
602 // Purpose : Update active 3D view
603 //================================================================
604 void GEOMBase_Helper::updateViewer()
606 getDisplayer()->UpdateViewer();
609 //================================================================
610 // Function : getStudyId
611 // Purpose : Get study Id
612 //================================================================
613 int GEOMBase_Helper::getStudyId() const
617 anId = getStudy()->id();
621 //================================================================
622 // Function : getStudy
623 // Purpose : Returns the active study. It is recommended to use
624 // this method instead of direct desktop->getActiveStudy() calls
625 //================================================================
626 SalomeApp_Study* GEOMBase_Helper::getStudy() const
628 SUIT_Desktop* aDesktop = getDesktop();
632 QList<SUIT_Application*> anAppList = SUIT_Session::session()->applications();
634 SUIT_Application* anApp = 0;
635 QListIterator<SUIT_Application*> it( anAppList );
636 while ( it.hasNext() )
639 if ( anApp && anApp->desktop() == aDesktop )
643 return dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
646 //================================================================
647 // Function : getEntry
649 //================================================================
650 QString GEOMBase_Helper::getEntry( GEOM::GEOM_Object_ptr object ) const
652 SalomeApp_Study* study = getStudy();
654 QString objIOR = GEOMBase::GetIORFromObject( object );
655 if ( objIOR != "" ) {
656 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( objIOR.toLatin1().constData() ) );
658 return QString::fromStdString(SO->GetID());
664 //================================================================
665 // Function : getDisplayer
667 //================================================================
668 GEOM_Displayer* GEOMBase_Helper::getDisplayer()
671 myDisplayer = new GEOM_Displayer( getStudy() );
675 //================================================================
676 // Function : clearShapeBuffer
678 //================================================================
679 void GEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
681 if ( CORBA::is_nil( theObj ) )
684 CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( theObj );
685 TCollection_AsciiString asciiIOR( (char *)IOR.in() );
686 GEOM_Client::get_client().RemoveShapeFromBuffer( asciiIOR );
688 if ( !getStudy() || !getStudy()->studyDS() )
691 _PTR(Study) aStudy = getStudy()->studyDS();
692 _PTR(SObject) aSObj ( aStudy->FindObjectIOR( std::string( IOR ) ) );
696 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
697 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
698 _PTR(GenericAttribute) anAttr;
699 if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
700 _PTR(AttributeIOR) anIOR ( anAttr );
701 TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
702 GEOM_Client::get_client().RemoveShapeFromBuffer( asciiIOR );
707 //================================================================
708 // Function : openCommand
710 //================================================================
711 bool GEOMBase_Helper::openCommand()
714 if ( !getStudy() || hasCommand() )
716 MESSAGE("Getting out from openCommand()")
720 GEOM::GEOM_IOperations_var anOp = GEOM::GEOM_IOperations::_narrow( getOperation() );
721 if ( !anOp->_is_nil() ) {
722 myCommand = new GEOM_Operation( SUIT_Session::session()->activeApplication(), anOp.in() );
728 MESSAGE("anOp->_is_nil() = true")
734 //================================================================
735 // Function : abortCommand
737 //================================================================
738 bool GEOMBase_Helper::abortCommand()
744 delete myCommand; // I don't know where to delete this object here ?
750 //================================================================
751 // Function : commitCommand
753 //================================================================
754 bool GEOMBase_Helper::commitCommand( const char* )
760 delete myCommand; // I don't know where to delete this object here ?
766 //================================================================
767 // Function : hasCommand
769 //================================================================
770 bool GEOMBase_Helper::hasCommand() const
772 bool res = (bool) myCommand;
773 return (bool)myCommand;
776 //================================================================
777 // Function : getOperation
779 //================================================================
780 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::getOperation()
782 if ( myOperation->_is_nil() )
783 myOperation = createOperation();
790 //================================================================
791 // Function : checkViewWindow
793 //================================================================
794 bool GEOMBase_Helper::checkViewWindow()
797 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
798 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
799 while ( it.hasNext() )
801 if ( myViewWindow == it.next() )
809 //================================================================
810 // Function : onAccept
811 // Purpose : This method should be called from dialog's slots onOk() and onApply()
812 // It perfroms user input validation, then it
813 // performs a proper operation and manages transactions, etc.
814 //================================================================
815 bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction )
817 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
820 MESSAGE("appStudy is empty")
823 _PTR(Study) aStudy = appStudy->studyDS();
825 bool aLocked = (_PTR(AttributeStudyProperties) (aStudy->GetProperties()))->IsLocked();
827 MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
828 SUIT_MessageBox::warning ( (QWidget*)SUIT_Session::session()->activeApplication()->desktop(),
829 QObject::tr("WRN_WARNING"),
830 QObject::tr("WRN_STUDY_LOCKED"),
831 QObject::tr("BUT_OK") );
836 if ( !isValid( msg ) ) {
841 erasePreview( false );
846 if ( ( !publish && !useTransaction ) || openCommand() ) {
847 SUIT_OverrideCursor wc;
848 SUIT_Session::session()->activeApplication()->putInfo( "" );
850 if ( !execute( objects ) || !getOperation()->IsDone() ) {
856 addSubshapesToStudy(); // add Sub-shapes if local selection
857 const int nbObjs = objects.size();
858 QStringList anEntryList;
860 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
861 GEOM::GEOM_Object_var obj=*it;
863 QString aName = getNewObjectName();
866 aName = getPrefix(obj);
868 // Try to find a unique name
869 aName = GEOMBase::GetDefaultName(aName, extractPrefix());
871 // Don't check name uniqueness in case of numerous objects
872 aName = aName + "_" + QString::number(aNumber++);
875 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
876 if ( aName.isEmpty() )
877 aName = GEOMBase::GetDefaultName( getPrefix( obj ) );
879 anEntryList << addInStudy( obj, aName.toLatin1().constData() );
881 display( obj, false );
882 #ifdef WITHGENERICOBJ
883 // obj has been published in study. Its refcount has been incremented.
884 // It is safe to decrement its refcount
885 // so that it will be destroyed when the entry in study will be removed
890 // asv : fix of PAL6454. If publish==false, then the original shape
891 // was modified, and need to be re-cached in GEOM_Client before redisplay
892 clearShapeBuffer( obj );
893 // withChildren=true, updateView=false
894 redisplay( obj, true, false );
901 if( SUIT_Application* anApp = SUIT_Session::session()->activeApplication() ) {
902 if( LightApp_Application* aLightApp = dynamic_cast<LightApp_Application*>( anApp ) )
903 aLightApp->browseObjects( anEntryList, isApplyAndClose(), isOptimizedBrowsing() );
904 anApp->putInfo( QObject::tr("GEOM_PRP_DONE") );
913 catch( const SALOME::SALOME_Exception& e ) {
914 SalomeApp_Tools::QtCatchCorbaException( e );
916 MESSAGE("Exception catched")
921 MESSAGE("result ="<<result)
926 //================================================================
927 // Function : showError
928 // Purpose : Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
929 //================================================================
930 void GEOMBase_Helper::showError()
933 if ( !getOperation()->_is_nil() )
934 msg = QObject::tr( getOperation()->GetErrorCode() );
937 msg = QObject::tr( "GEOM_PRP_ABORT" );
939 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
940 QObject::tr( "GEOM_ERROR_STATUS" ),
942 QObject::tr( "BUT_OK" ) );
945 //================================================================
946 // Function : showError
947 // Purpose : Shows a error message followed by <msg>
948 //================================================================
949 void GEOMBase_Helper::showError( const QString& msg )
951 QString str( QObject::tr( "GEOM_INCORRECT_INPUT" ) );
952 if ( !msg.isEmpty() )
954 SUIT_MessageBox::critical(SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ), str, QObject::tr( "BUT_OK" ) );
957 //////////////////////////////////////////////////////////////////
958 // Virtual methods to be redefined in dialogs
959 //////////////////////////////////////////////////////////////////
961 //================================================================
962 // Function : createOperation
963 // Purpose : Redefine this method to return proper IOperation reference
964 //================================================================
965 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::createOperation()
967 GEOM::GEOM_IOperations_var aNilOp;
968 return aNilOp._retn();
971 //================================================================
972 // Function : isValid
973 // Purpose : Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
974 //================================================================
975 bool GEOMBase_Helper::isValid( QString& )
980 //================================================================
981 // Function : execute
982 // Purpose : This method is called by onAccept().
983 // It should perform the required operation and put all new or modified objects into
984 // <objects> argument.Should return <false> if some error occurs during its execution.
985 //================================================================
986 bool GEOMBase_Helper::execute( ObjectList& objects )
991 //================================================================
992 // Function : getFather
993 // Purpose : This method is called by addInStudy(). It should return a father object
994 // for <theObj> or a nil reference if <theObj> should be published
995 // as a top-level object.
996 //================================================================
997 GEOM::GEOM_Object_ptr GEOMBase_Helper::getFather( GEOM::GEOM_Object_ptr theObj )
999 return GEOM::GEOM_Object::_nil();
1002 //================================================================
1003 // Function : getNewObjectName
1004 // Purpose : Redefine this method to return proper name for a new object
1005 //================================================================
1006 QString GEOMBase_Helper::getNewObjectName() const
1008 return QString::null;
1011 //================================================================
1012 // Function : extractPrefix
1013 // Purpose : Redefine this method to return \c true if necessary
1014 // to extract prefix when generating new name for the
1015 // object(s) being created
1016 //================================================================
1017 bool GEOMBase_Helper::extractPrefix() const
1022 //================================================================
1023 // Function : getPrefix
1024 // Purpose : Get prefix for name of created object
1025 //================================================================
1026 QString GEOMBase_Helper::getPrefix( GEOM::GEOM_Object_ptr theObj ) const
1028 if ( !myPrefix.isEmpty() || theObj->_is_nil() )
1031 GEOM::shape_type aType = theObj->GetShapeType();
1035 case GEOM::VERTEX : return QObject::tr( "GEOM_VERTEX" );
1036 case GEOM::EDGE : return QObject::tr( "GEOM_EDGE" );
1037 case GEOM::WIRE : return QObject::tr( "GEOM_WIRE" );
1038 case GEOM::FACE : return QObject::tr( "GEOM_FACE" );
1039 case GEOM::SHELL : return QObject::tr( "GEOM_SHELL" );
1040 case GEOM::SOLID : return QObject::tr( "GEOM_SOLID" );
1041 case GEOM::COMPSOLID: return QObject::tr( "GEOM_COMPOUNDSOLID" );
1042 case GEOM::COMPOUND : return QObject::tr( "GEOM_COMPOUND" );
1043 default : return "";
1047 //================================================================
1048 // Function : getDesktop
1049 // Purpose : Returns myDesktop field. Initialized in constructor,
1050 // usually as dynamic_cast<SUIT_Desktop*>(parentWidget())
1051 //================================================================
1052 SUIT_Desktop* GEOMBase_Helper::getDesktop() const
1057 //================================================================
1058 // Function : selectObjects
1059 // Purpose : Selects list of objects
1060 //================================================================
1061 bool GEOMBase_Helper::selectObjects( ObjectList& objects )
1063 SUIT_DataOwnerPtrList aList;
1064 ObjectList::iterator anIter;
1065 for ( anIter = objects.begin(); anIter != objects.end(); ++anIter )
1067 QString anEntry = getEntry( *anIter );
1068 LightApp_DataOwner* anOwher = new LightApp_DataOwner( anEntry );
1069 aList.append( anOwher );
1072 SUIT_Session* session = SUIT_Session::session();
1073 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1077 LightApp_SelectionMgr* aMgr = app->selectionMgr();
1081 aMgr->setSelected( aList, false );
1086 //================================================================
1087 // Function : findObjectInFather
1088 // Purpose : It should return an object if its founded in study or
1089 // return Null object if the object is not founded
1090 //================================================================
1091 GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather (GEOM::GEOM_Object_ptr theFather,
1092 const QString& theName)
1094 SalomeApp_Application* app =
1095 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1096 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1097 _PTR(Study) aDStudy = appStudy->studyDS();
1098 QString IOR = GEOMBase::GetIORFromObject( theFather );
1099 _PTR(SObject) SObj ( aDStudy->FindObjectIOR( IOR.toLatin1().constData() ) );
1101 bool inStudy = false;
1102 GEOM::GEOM_Object_var aReturnObject;
1103 for (_PTR(ChildIterator) iit (aDStudy->NewChildIterator( SObj )); iit->More() && !inStudy; iit->Next()) {
1104 _PTR(SObject) child (iit->Value());
1105 QString aChildName = child->GetName().c_str();
1106 if (aChildName == theName) {
1108 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(iit->Value());
1109 aReturnObject = GEOM::GEOM_Object::_narrow( corbaObj );
1113 return aReturnObject._retn();
1115 return GEOM::GEOM_Object::_nil();
1118 //================================================================
1119 // Function : findObjectInFather
1120 // Purpose : It should return an object if its founded in study or
1121 // return Null object if the object is not founded
1122 //================================================================
1123 GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather( GEOM::GEOM_Object_ptr theFather,
1126 GEOM::GEOM_Object_var object;
1129 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
1131 _PTR(Study) studyDS = study->studyDS();
1132 QString IOR = GEOMBase::GetIORFromObject( theFather );
1133 _PTR(SObject) sobject( studyDS->FindObjectIOR( IOR.toLatin1().constData() ) );
1135 _PTR(ChildIterator) it( studyDS->NewChildIterator( sobject ) );
1136 for ( ; it->More() && !found; it->Next() ) {
1137 GEOM::GEOM_Object_var cobject = GEOM::GEOM_Object::_narrow( GeometryGUI::ClientSObjectToObject( it->Value() ) );
1138 if ( !CORBA::is_nil( cobject ) ) {
1139 GEOM::ListOfLong_var indices = cobject->GetSubShapeIndices();
1140 int length = indices->length();
1141 for ( int i = 0; i < length && !found; i++ ) {
1142 if ( indices[i] == theIndex ) {
1152 return object._retn();
1155 //================================================================
1156 // Function : addSubshapesToStudy
1157 // Purpose : Virtual method to add sub-shapes if needs
1158 //================================================================
1159 void GEOMBase_Helper::addSubshapesToStudy()
1161 //Impemented in Dialogs, called from Accept method
1164 //================================================================
1165 // Function : getSelected
1166 // Purpose : Get selected object by specified type
1168 // Returns valid object if only one object of the specified type is selected
1169 // (no matter global or local selection is activated). If \a type is TopAbs_SHAPE,
1170 // geometrical object of any valid type is expected.
1172 // \param type type of the object to be obtained from selection
1173 // \return selected geometrical object or nil object if selection is not satisfactory
1174 //================================================================
1175 GEOM::GeomObjPtr GEOMBase_Helper::getSelected( TopAbs_ShapeEnum type )
1177 QList<TopAbs_ShapeEnum> types;
1179 return getSelected( types );
1182 //================================================================
1183 // Function : getSelected
1184 // Purpose : Get selected object by specified types
1186 // Returns valid object if only one object of the specified type is selected
1187 // (no matter global or local selection is activated). The list of allowed
1188 // shape types is passed via \a types. If \a types includes TopAbs_SHAPE,
1189 // geometrical object of any valid type is expected.
1191 // \param types list of allowed shape types for the objects to be obtained from selection
1192 // \return selected geometrical object or nil object if selection is not satisfactory
1193 //================================================================
1194 GEOM::GeomObjPtr GEOMBase_Helper::getSelected( const QList<TopAbs_ShapeEnum>& types )
1196 QList<GEOM::GeomObjPtr> selected = getSelected( types, 1 );
1197 return selected.count() > 0 ? selected[0] : GEOM::GeomObjPtr();
1200 //================================================================
1201 // Function : getSelected
1202 // Purpose : Get selected object(s) by specified type
1204 // Returns list of selected objects if selection satisfies specifies selection options.
1205 // (no matter global or local selection is activated). If \a type is TopAbs_SHAPE,
1206 // geometrical objects of any valid type are expected.
1208 // The \a type parameter specifies allowed type of the object(s) being selected.
1209 // The \a count parameter specifies exact number of the objects to be retrieved from selection.
1210 // The \a strict parameter specifies policy being applied to the selection.
1211 // If \a count < 0, then any number of the selected objects is valid (including 0).
1212 // In this case, if \a strict is \c true (default), all selected objects should satisfy
1213 // the specified \a type.
1214 // If \a count > 0, only specified number of the objects is retrieved from the selection.
1215 // In this case, if \a strict is \c true (default), function returns empty list if total number of selected
1216 // objects does not correspond to the \a count parameter. Otherwise (if \a strict is \c false),
1217 // function returns valid list of objects if at least \a count objects satisfy specified \a type.
1219 // \param type type of the object(s) to be obtained from selection
1220 // \param count number of items to be retrieved from selection
1221 // \param strict selection policy
1222 // \return list of selected geometrical objects or empty list if selection is not satisfactory
1223 //================================================================
1224 QList<GEOM::GeomObjPtr> GEOMBase_Helper::getSelected( TopAbs_ShapeEnum type, int count, bool strict )
1226 QList<TopAbs_ShapeEnum> types;
1228 return getSelected( types, count, strict );
1231 static bool typeInList( TopAbs_ShapeEnum type, const QList<TopAbs_ShapeEnum>& types )
1234 for ( int i = 0; i < types.count() && !ok; i++ )
1235 ok = types[i] == TopAbs_SHAPE || types[i] == type;
1239 //================================================================
1240 // Function : getSelected
1241 // Purpose : Get selected objects by specified types
1243 // Returns list of selected objects if selection satisfies specifies selection options.
1244 // (no matter global or local selection is activated). If \a types includes TopAbs_SHAPE,
1245 // geometrical objects of any valid type are expected.
1247 // The \a types parameter specifies allowed types of the object(s) being selected.
1248 // The \a count parameter specifies exact number of the objects to be retrieved from selection.
1249 // The \a strict parameter specifies policy being applied to the selection.
1250 // If \a count < 0, then any number of the selected objects is valid (including 0).
1251 // In this case, if \a strict is \c true (default), all selected objects should satisfy
1252 // the specified \a type.
1253 // If \a count > 0, only specified number of the objects is retrieved from the selection.
1254 // In this case, if \a strict is \c true (default), function returns empty list if total number of selected
1255 // objects does not correspond to the \a count parameter. Otherwise (if \a strict is \c false),
1256 // function returns valid list of objects if at least \a count objects satisfy specified \a type.
1258 // \param types list of allowed shape types for the objects to be obtained from selection
1259 // \param count number of items to be retrieved from selection
1260 // \param strict selection policy
1261 // \return list of selected geometrical objects or empty list if selection is not satisfactory
1262 //================================================================
1263 QList<GEOM::GeomObjPtr> GEOMBase_Helper::getSelected( const QList<TopAbs_ShapeEnum>& types, int count, bool strict )
1265 SUIT_Session* session = SUIT_Session::session();
1266 QList<GEOM::GeomObjPtr> result;
1268 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1270 LightApp_SelectionMgr* selMgr = app->selectionMgr();
1272 SALOME_ListIO selected;
1273 selMgr->selectedObjects( selected );
1274 SALOME_ListIteratorOfListIO it( selected );
1275 bool stopped = false;
1276 for ( ; it.More() && !stopped; it.Next() ) {
1277 Handle(SALOME_InteractiveObject) IO = it.Value();
1278 GEOM::GeomObjPtr object = GEOMBase::ConvertIOinGEOMObject( IO );
1280 TColStd_IndexedMapOfInteger subShapes;
1281 selMgr->GetIndexes( IO, subShapes );
1282 int nbSubShapes = subShapes.Extent();
1283 if ( nbSubShapes == 0 ) {
1285 if ( typeInList( (TopAbs_ShapeEnum)(object->GetShapeType()), types ) ) {
1288 if ( strict && result.count() > count ) {
1292 else if ( !strict && result.count() == count )
1296 else if ( strict ) {
1303 for ( int i = 1; i <= nbSubShapes && !stopped; i++ ) {
1304 int idx = subShapes( i );
1305 GEOM::GeomObjPtr subShape = findObjectInFather( object.get(), idx );
1307 // sub-shape is not yet published in the study
1308 GEOM::ShapesOpPtr shapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
1309 subShape.take( shapesOp->GetSubShape( object.get(), idx ) ); // take ownership!
1311 if ( typeInList( (TopAbs_ShapeEnum)(subShape->GetShapeType()), types ) ) {
1314 if ( strict && result.count() > count ) {
1318 else if ( !strict && result.count() == count )
1322 else if ( strict ) {
1335 //================================================================
1336 // Function : setIsApplyAndClose
1337 // Purpose : Set value of the flag indicating that the dialog is
1338 // accepted by Apply & Close button
1339 //================================================================
1340 void GEOMBase_Helper::setIsApplyAndClose( const bool theFlag )
1342 myIsApplyAndClose = theFlag;
1345 //================================================================
1346 // Function : isApplyAndClose
1347 // Purpose : Get value of the flag indicating that the dialog is
1348 // accepted by Apply & Close button
1349 //================================================================
1350 bool GEOMBase_Helper::isApplyAndClose() const
1352 return myIsApplyAndClose;
1355 //================================================================
1356 // Function : setIsOptimizedBrowsing
1357 // Purpose : Set value of the flag switching to optimized
1358 // browsing mode (to select the first published
1360 //================================================================
1361 void GEOMBase_Helper::setIsOptimizedBrowsing( const bool theFlag )
1363 myIsOptimizedBrowsing = theFlag;
1366 //================================================================
1367 // Function : isOptimizedBrowsing
1368 // Purpose : Get value of the flag switching to optimized
1369 // browsing mode (to select the first published
1371 //================================================================
1372 bool GEOMBase_Helper::isOptimizedBrowsing() const
1374 return myIsOptimizedBrowsing;