1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : GEOMBase_Helper.cxx
25 // Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
27 #include "GEOMBase_Helper.h"
29 #include "GEOM_Operation.h"
31 #include <GeometryGUI.h>
33 #include <SUIT_Desktop.h>
34 #include <SUIT_Session.h>
35 #include <SUIT_ViewManager.h>
36 #include <SUIT_ViewWindow.h>
37 #include <SUIT_ViewModel.h>
38 #include <SUIT_MessageBox.h>
39 #include <SUIT_OverrideCursor.h>
40 #include <SUIT_ResourceMgr.h>
42 #include <SalomeApp_Module.h>
43 #include <SalomeApp_Application.h>
44 #include <SalomeApp_Study.h>
45 #include <LightApp_SelectionMgr.h>
46 #include <LightApp_DataOwner.h>
47 #include <SalomeApp_Tools.h>
48 #include <SALOME_ListIO.hxx>
49 #include "utilities.h"
51 #include <SALOME_Prs.h>
52 #include "utilities.h"
54 #include <OCCViewer_ViewModel.h>
55 #include <SVTK_ViewModel.h>
57 #include <TCollection_AsciiString.hxx>
58 #include <TColStd_IndexedMapOfInteger.hxx>
60 //To disable automatic genericobj management, the following line should be commented.
61 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
62 #define WITHGENERICOBJ
64 //================================================================
65 // Function : getActiveView
66 // Purpose : Get active view window, returns 0 if no open study frame
67 //================================================================
68 SUIT_ViewWindow* GEOMBase_Helper::getActiveView()
70 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
72 return SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
78 //================================================================
79 // Function : getGeomEngine
80 // Purpose : Static method
81 //================================================================
82 GEOM::GEOM_Gen_ptr GEOMBase_Helper::getGeomEngine()
84 return GeometryGUI::GetGeomGen();
87 //================================================================
88 // Function : GEOMBase_Helper
90 //================================================================
91 GEOMBase_Helper::GEOMBase_Helper( SUIT_Desktop* desktop )
92 : myDisplayer( 0 ), myCommand( 0 ), myViewWindow( 0 ), isPreview( false ), myDesktop( desktop ),
93 myIsApplyAndClose( false ), myIsOptimizedBrowsing( false ), myIsWaitCursorEnabled( true ),
94 myIsDisableBrowsing(false), myIsDisplayResult(true)
98 //================================================================
99 // Function : ~GEOMBase_Helper
101 //================================================================
102 GEOMBase_Helper::~GEOMBase_Helper()
104 //rnv: Fix for the "IPAL21922 : WinTC5.1.4: incorrect quit salome"
105 if ( !SUIT_Session::session()->activeApplication() || !SUIT_Session::session()->activeApplication()->desktop() )
108 if ( myPreview.size() )
112 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
114 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
116 globalSelection(aGeomGUI->getLocalSelectionMode() , true );
121 if ( !CORBA::is_nil( myOperation ) )
122 myOperation->UnRegister();
125 //================================================================
126 // Function : display
128 //================================================================
129 void GEOMBase_Helper::display( const ObjectList& objList, const bool updateView )
131 ObjectList::const_iterator it;
132 for ( it = objList.begin(); it != objList.end(); it++ ) {
133 display( *it, false );
135 if ( !objList.empty() && updateView )
136 getDisplayer()->UpdateViewer();
139 //================================================================
140 // Function : display
141 // Purpose : Display object.
142 // Important : Object must be already in study
143 //================================================================
144 void GEOMBase_Helper::display( GEOM::GEOM_Object_ptr object, const bool updateView )
146 // Unset color of shape ( this color may be set during preview displaying )
147 // Default color will be used
148 // getDisplayer()->UnsetColor();
149 getDisplayer()->UnsetWidth();
151 MESSAGE("GEOMBase_Helper::display myTexture = "<<getDisplayer()->GetTexture())
153 // Enable activisation of selection
154 getDisplayer()->SetToActivate( true );
157 getDisplayer()->Display( object, updateView );
160 //================================================================
163 //================================================================
164 void GEOMBase_Helper::erase( const ObjectList& objList, const bool updateView )
166 ObjectList::const_iterator it = objList.begin();
167 for ( ; it != objList.end(); it++ ) {
170 if ( !objList.empty() && updateView )
171 getDisplayer()->UpdateViewer();
174 //================================================================
177 //================================================================
178 void GEOMBase_Helper::erase( GEOM::GEOM_Object_ptr object, const bool updateView )
180 if ( !object->_is_nil() ) {
181 QString entry = getEntry( object );
182 getDisplayer()->Erase( new SALOME_InteractiveObject(
183 entry.toLatin1().constData(),
184 "GEOM", strdup( GEOMBase::GetName( object ).toLatin1().constData() ) ), true, updateView );
188 //================================================================
189 // Function : redisplay
191 //================================================================
192 void GEOMBase_Helper::redisplay( const ObjectList& objList,
193 const bool withChildren,
194 const bool updateView )
196 ObjectList::const_iterator it = objList.begin();
197 for ( ; it != objList.end(); it++ ) {
198 redisplay( *it, withChildren, false );
200 if ( !objList.empty() && updateView )
201 getDisplayer()->UpdateViewer();
204 //================================================================
205 // Function : redisplay
207 //================================================================
208 void GEOMBase_Helper::redisplay( GEOM::GEOM_Object_ptr object,
209 const bool withChildren,
210 const bool updateView )
212 if ( !object->_is_nil() ) {
213 // Unset color of shape ( this color may be set during preview displaying )
214 // Default color will be used
215 getDisplayer()->UnsetColor();
216 getDisplayer()->UnsetWidth();
218 // Enable activisation of selection
219 getDisplayer()->SetToActivate( true );
221 QString entry = getEntry( object );
222 getDisplayer()->Redisplay(new SALOME_InteractiveObject
223 (entry.toLatin1().constData(), "GEOM", strdup(GEOMBase::GetName(object).toLatin1().constData())), false);
226 if ( withChildren ) {
227 SalomeApp_Study* aDoc = getStudy();
228 if ( aDoc && aDoc->studyDS() ) {
229 _PTR(Study) aStudy = aDoc->studyDS();
230 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string(object);
231 _PTR(SObject) aSObj (aStudy->FindObjectIOR(std::string(objStr.in())));
233 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
234 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
235 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow
236 (GeometryGUI::ClientSObjectToObject(anIt->Value()));
237 if ( !CORBA::is_nil( aChild ) ) {
238 if ( !aChild->_is_nil() ) {
239 QString entry = getEntry( aChild );
240 getDisplayer()->Redisplay( new SALOME_InteractiveObject(
241 entry.toLatin1().constData(), "GEOM", strdup( GEOMBase::GetName( aChild ).toLatin1().constData() ) ), false );
250 getDisplayer()->UpdateViewer();
253 //================================================================
254 // Function : displayPreview
255 // Purpose : Method for displaying preview based on execute() results
256 //================================================================
257 void GEOMBase_Helper::displayPreview( const bool display,
260 const bool toRemoveFromEngine,
261 const double lineWidth,
262 const int displayMode,
267 erasePreview( update );
273 if ( !isValid( msg ) )
275 erasePreview( update );
281 erasePreview( false );
284 SUIT_OverrideCursor wc;
287 if ( !isWaitCursorEnabled() )
290 if ( !execute( objects ) || !getOperation()->IsDone() ) {
294 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it )
296 GEOM::GEOM_Object_var obj=*it;
297 displayPreview( obj, true, activate, false, lineWidth, displayMode, color );
298 if ( toRemoveFromEngine )
303 catch( const SALOME::SALOME_Exception& e ) {
304 SalomeApp_Tools::QtCatchCorbaException( e );
313 //================================================================
314 // Function : displayPreview
315 // Purpose : Method for displaying preview of resulting shape
316 //================================================================
317 void GEOMBase_Helper::displayPreview( GEOM::GEOM_Object_ptr object,
321 const double lineWidth,
322 const int displayMode,
325 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
327 // Set color for preview shape
328 getDisplayer()->SetColor( color == -1 ? Quantity_NOC_VIOLET : color );
330 // set width of displayed shape
331 getDisplayer()->SetWidth( lineWidth == -1 ? resMgr->integerValue("Geometry", "preview_edge_width", -1) : lineWidth );
333 // set display mode of displayed shape
334 int aPrevDispMode = getDisplayer()->SetDisplayMode( displayMode == -1 ? resMgr->integerValue( "Geometry", "display_mode", 0 ) : displayMode );
336 // Disable activation of selection
337 getDisplayer()->SetToActivate( activate );
339 // Make a reference to GEOM_Object
340 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string( object );
341 getDisplayer()->SetName( objStr.in() );
344 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( object );
345 if ( aPrs == 0 || aPrs->IsNull() )
348 // Make preview not clippable
349 aPrs->SetClippable (false);
352 displayPreview( aPrs, append, update );
354 getDisplayer()->UnsetName();
355 getDisplayer()->UnsetColor();
356 getDisplayer()->SetDisplayMode( aPrevDispMode );
358 // Enable activation of displayed objects
359 getDisplayer()->SetToActivate( true );
362 //================================================================
363 // Function : displayPreview
364 // Purpose : Method for displaying arbitrary preview objects (not limited to shapes)
365 //================================================================
366 void GEOMBase_Helper::displayPreview( const SALOME_Prs* prs,
371 erasePreview( false );
373 // remember current view frame to make correct erase preview later
374 myViewWindow = getActiveView();
376 if ( myViewWindow == 0 )
380 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
381 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
382 aViewManager->getType() == SVTK_Viewer::Type() )
384 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
385 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
387 aView->Display( getDisplayer(), prs );
390 // Add prs to the preview list
391 myPreview.push_back( (SALOME_Prs*)prs );
395 getDisplayer()->UpdateViewer();
398 //================================================================
399 // Function : erasePreview
401 //================================================================
402 void GEOMBase_Helper::erasePreview( const bool update )
404 // check view frame where the preview was displayed
405 bool vfOK = checkViewWindow() && myViewWindow;
406 // Iterate through presentations and delete them
407 for ( PrsList::iterator anIter = myPreview.begin(); anIter != myPreview.end(); ++anIter )
411 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
412 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
413 aViewManager->getType() == SVTK_Viewer::Type() )
415 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
416 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
418 aView->Erase( getDisplayer(), *anIter, true );
430 //================================================================
431 // Function : localSelection
432 // Purpose : Activate selection of objects of a given type
433 // IMPORTANT : Works after localSelection( ... ) method call only
434 //================================================================
435 void GEOMBase_Helper::activate( const int theType )
437 if (!getStudy()) return;
438 _PTR(Study) aStudy = getStudy()->studyDS();
439 _PTR(SComponent) aGeom ( aStudy->FindComponent( "GEOM" ) );
444 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( aGeom ) );
445 for ( ; anIter->More(); anIter->Next() )
447 _PTR(SObject) aSO ( anIter->Value() );
450 _PTR(SObject) aRefSO;
451 if ( !aSO->ReferencedObject( aRefSO ) )
453 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow
454 (GeometryGUI::ClientSObjectToObject(aSO));
455 if ( !anObj->_is_nil() && anObj->GetType() == theType )
456 aList.Append( new SALOME_InteractiveObject( aSO->GetID().c_str(), "GEOM", aSO->GetName().c_str()) );
461 getDisplayer()->LocalSelection( aList, 0 );
464 //================================================================
465 // Function : localSelection
466 // Purpose : Activate selection of sub-shapes in accordance with mode
467 // modes are from TopAbs_ShapeEnum
468 //================================================================
469 void GEOMBase_Helper::localSelection( const ObjectList& theObjs, const std::list<int> modes )
471 SALOME_ListIO aListOfIO;
473 ObjectList::const_iterator anIter = theObjs.begin();
474 for ( ; anIter != theObjs.end(); ++anIter )
476 GEOM::GEOM_Object_ptr anObj = *anIter;
477 if ( anObj->_is_nil() )
479 QString anEntry = getEntry( anObj );
481 aListOfIO.Append( new SALOME_InteractiveObject(
482 anEntry.toLatin1().constData(), "GEOM", strdup( GEOMBase::GetName( anObj ).toLatin1().constData() ) ) );
485 getDisplayer()->LocalSelection( aListOfIO, modes );
488 //================================================================
489 // Function : localSelection
490 // Purpose : Activate selection of sub-shapes in accordance with mode
491 // theMode is from TopAbs_ShapeEnum
492 //================================================================
493 void GEOMBase_Helper::localSelection( const ObjectList& theObjs, const int theMode )
495 std::list<int> modes;
496 modes.push_back( theMode );
497 localSelection( theObjs, modes );
500 //================================================================
501 // Function : localSelection
502 // Purpose : Activate selection of sub-shapes in accordance with mode
503 // modes are from TopAbs_ShapeEnum
504 //================================================================
505 void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const std::list<int> modes )
507 // If object is null local selection for all objects is activated
508 if ( obj->_is_nil() ) {
509 getDisplayer()->LocalSelection( Handle(SALOME_InteractiveObject)(), modes );
514 objList.push_back( obj );
515 localSelection( objList, modes );
518 //================================================================
519 // Function : localSelection
520 // Purpose : Activate selection of sub-shapes in accordance with mode
521 // mode is from TopAbs_ShapeEnum
522 //================================================================
523 void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const int mode )
525 std::list<int> modes;
526 modes.push_back( mode );
527 localSelection( obj, modes );
530 //================================================================
531 // Function : localSelection
532 // Purpose : Activate selection of sub-shapes in accordance with mode
533 // modes are from TopAbs_ShapeEnum
534 //================================================================
535 void GEOMBase_Helper::localSelection( const std::list<int> modes )
537 localSelection( GEOM::GEOM_Object::_nil(), modes );
540 //================================================================
541 // Function : localSelection
542 // Purpose : Activate selection of sub-shapes in accordance with mode
543 // mode is from TopAbs_ShapeEnum
544 //================================================================
545 void GEOMBase_Helper::localSelection( const int mode )
547 std::list<int> modes;
548 modes.push_back( mode );
549 localSelection( modes );
552 //================================================================
553 // Function : globalSelection
554 // Purpose : Activate selection of sub-shapes. Set selection filters
555 // in accordance with mode. theMode is from GEOMImpl_Types
556 //================================================================
557 void GEOMBase_Helper::globalSelection( const int theMode, const bool update )
559 getDisplayer()->GlobalSelection( theMode, update );
562 //================================================================
563 // Function : globalSelection
564 // Purpose : Activate selection of sub-shapes. Set selection filters
565 // in accordance with mode. theMode is from GEOMImpl_Types
566 //================================================================
567 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
570 getDisplayer()->GlobalSelection( theModes, update );
573 //================================================================
574 // Function : globalSelection
575 // Purpose : Activate selection of sub-shapes. Set selection filters
576 // in accordance with mode. theMode is from GEOMImpl_Types
577 //================================================================
578 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
579 const QList<int>& subShapes,
582 getDisplayer()->GlobalSelection( theModes, update, &subShapes );
585 //================================================================
586 // Function : addInStudy
587 // Purpose : Add object in study
588 //================================================================
589 QString GEOMBase_Helper::addInStudy( GEOM::GEOM_Object_ptr theObj, const char* theName )
594 _PTR(Study) aStudy = getStudy()->studyDS();
595 if ( !aStudy || theObj->_is_nil() )
598 GEOM::GEOM_Object_ptr aFatherObj = getFather( theObj );
600 SALOMEDS::SObject_var aSO =
601 getGeomEngine()->AddInStudy(theObj, theName, aFatherObj);
604 if ( !aSO->_is_nil() ) {
605 CORBA::String_var entry = aSO->GetID();
606 anEntry = entry.in();
608 // Each dialog is responsible for this method implementation,
609 // default implementation does nothing
610 restoreSubShapes(aSO);
616 //================================================================
617 // Function : restoreSubShapes
618 // Purpose : restore tree of argument's sub-shapes under the resulting shape
619 //================================================================
620 void GEOMBase_Helper::restoreSubShapes (SALOMEDS::SObject_ptr /*theSObject*/)
622 // do nothing by default
624 // example of implementation in particular dialog:
625 // GEOM::ListOfGO anArgs;
626 // anArgs.length(0); // empty list means that all arguments should be restored
627 // getGeomEngine()->RestoreSubShapesSO(theSObject, anArgs,
628 // /*theFindMethod=*/GEOM::FSM_GetInPlace,
629 // /*theInheritFirstArg=*/false);
632 //================================================================
633 // Function : updateObjBrowser
634 // Purpose : Update object browser
635 //================================================================
636 void GEOMBase_Helper::updateObjBrowser() const
638 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
640 CAM_Module* module = app->module( "Geometry" );
641 SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
643 appMod->updateObjBrowser();
648 //================================================================
649 // Function : updateViewer
650 // Purpose : Update active 3D view
651 //================================================================
652 void GEOMBase_Helper::updateViewer()
654 getDisplayer()->UpdateViewer();
657 //================================================================
658 // Function : getStudy
659 // Purpose : Returns the active study. It is recommended to use
660 // this method instead of direct desktop->getActiveStudy() calls
661 //================================================================
662 SalomeApp_Study* GEOMBase_Helper::getStudy() const
664 SUIT_Desktop* aDesktop = getDesktop();
668 QList<SUIT_Application*> anAppList = SUIT_Session::session()->applications();
670 SUIT_Application* anApp = 0;
671 QListIterator<SUIT_Application*> it( anAppList );
672 while ( it.hasNext() )
675 if ( anApp && anApp->desktop() == aDesktop )
679 return dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
682 //================================================================
683 // Function : getEntry
685 //================================================================
686 QString GEOMBase_Helper::getEntry( GEOM::GEOM_Object_ptr object ) const
688 SalomeApp_Study* study = getStudy();
690 QString objIOR = GEOMBase::GetIORFromObject( object );
691 if ( objIOR != "" ) {
692 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( objIOR.toLatin1().constData() ) );
694 return QString::fromStdString(SO->GetID());
700 //================================================================
701 // Function : getDisplayer
703 //================================================================
704 GEOM_Displayer* GEOMBase_Helper::getDisplayer()
707 myDisplayer = new GEOM_Displayer();
711 //================================================================
712 // Function : clearShapeBuffer
714 //================================================================
715 void GEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
717 GeometryGUI::ClearShapeBuffer(theObj);
720 //================================================================
721 // Function : openCommand
723 //================================================================
724 bool GEOMBase_Helper::openCommand()
727 if ( !getStudy() || hasCommand() )
729 MESSAGE("Getting out from openCommand()")
733 GEOM::GEOM_IOperations_var anOp = GEOM::GEOM_IOperations::_narrow( getOperation() );
734 if ( !anOp->_is_nil() ) {
735 myCommand = new GEOM_Operation( SUIT_Session::session()->activeApplication(), anOp.in() );
741 MESSAGE("anOp->_is_nil() = true")
747 //================================================================
748 // Function : abortCommand
750 //================================================================
751 bool GEOMBase_Helper::abortCommand()
757 delete myCommand; // I don't know where to delete this object here ?
763 //================================================================
764 // Function : commitCommand
766 //================================================================
767 bool GEOMBase_Helper::commitCommand( const char* )
773 delete myCommand; // I don't know where to delete this object here ?
779 //================================================================
780 // Function : hasCommand
782 //================================================================
783 bool GEOMBase_Helper::hasCommand() const
785 return (bool)myCommand;
788 //================================================================
789 // Function : getOperation
791 //================================================================
792 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::getOperation()
794 if ( myOperation->_is_nil() )
795 myOperation = createOperation();
802 //================================================================
803 // Function : checkViewWindow
805 //================================================================
806 bool GEOMBase_Helper::checkViewWindow()
809 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
810 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
811 while ( it.hasNext() )
813 if ( myViewWindow == it.next() )
821 //================================================================
822 // Function : onAccept
823 // Purpose : This method should be called from dialog's slots onOk() and onApply()
824 // It perfroms user input validation, then it
825 // performs a proper operation and manages transactions, etc.
826 //================================================================
827 bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction, bool erasePreviewFlag )
829 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
832 MESSAGE("appStudy is empty")
835 _PTR(Study) aStudy = appStudy->studyDS();
837 bool aLocked = (_PTR(AttributeStudyProperties) (aStudy->GetProperties()))->IsLocked();
839 MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
840 SUIT_MessageBox::warning ( (QWidget*)SUIT_Session::session()->activeApplication()->desktop(),
841 QObject::tr("WRN_WARNING"),
842 QObject::tr("WRN_STUDY_LOCKED"),
843 QObject::tr("BUT_OK") );
848 if ( !isValid( msg ) ) {
854 erasePreview( false );
859 if ( ( !publish && !useTransaction ) || openCommand() ) {
860 SUIT_OverrideCursor wc;
861 SUIT_Session::session()->activeApplication()->putInfo( "" );
863 if ( !execute( objects ) || !getOperation()->IsDone() ) {
869 QList<GEOM::GeomObjPtr> anObjectList = getSourceObjects( );
870 addSubshapesToStudy(); // add Sub-shapes if local selection
871 const int nbObjs = objects.size();
872 QStringList anEntryList;
873 int currObj = 1, aNumber = 1;
874 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it, currObj++ ) {
875 GEOM::GEOM_Object_var obj=*it;
877 QString aName = getObjectName(obj);
878 if (aName.isEmpty()) {
879 aName = getNewObjectName(currObj);
882 aName = getPrefix(obj);
884 // Try to find a unique name
885 aName = GEOMBase::GetDefaultName(aName, extractPrefix());
887 // Don't check name uniqueness in case of numerous objects
888 aName = aName + "_" + QString::number(aNumber++);
891 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
892 if ( aName.isEmpty() )
893 aName = GEOMBase::GetDefaultName( getPrefix( obj ) );
896 anEntryList << addInStudy( obj, aName.toLatin1().constData() );
898 if( isDisplayResult() )
899 display( obj, false );
900 #ifdef WITHGENERICOBJ
901 // obj has been published in study. Its refcount has been incremented.
902 // It is safe to decrement its refcount
903 // so that it will be destroyed when the entry in study will be removed
908 // asv : fix of PAL6454. If publish==false, then the original shape
909 // was modified, and need to be re-cached in GEOM_Client before redisplay
910 clearShapeBuffer( obj );
911 // withChildren=true, updateView=false
912 if( isDisplayResult() )
913 redisplay( obj, true, false );
920 if( SUIT_Application* anApp = SUIT_Session::session()->activeApplication() ) {
921 LightApp_Application* aLightApp = dynamic_cast<LightApp_Application*>( anApp );
923 QString anOpName( typeid(*this).name() );
924 aLightApp->emitOperationFinished( "Geometry", anOpName, anEntryList );
926 if ( !isDisableBrowsing() )
927 aLightApp->browseObjects( anEntryList, isApplyAndClose(), isOptimizedBrowsing() );
929 anApp->putInfo( QObject::tr("GEOM_PRP_DONE") );
931 if ( anObjectList.count() > 0 )
932 hideSourceObjects( anObjectList );
940 catch( const SALOME::SALOME_Exception& e ) {
941 SalomeApp_Tools::QtCatchCorbaException( e );
943 MESSAGE("Exception catched")
948 MESSAGE("result ="<<result)
953 //================================================================
954 // Function : showError
955 // Purpose : Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
956 //================================================================
957 void GEOMBase_Helper::showError()
960 if ( !getOperation()->_is_nil() )
961 msg = QObject::tr( getOperation()->GetErrorCode() );
964 msg = QObject::tr( "GEOM_PRP_ABORT" );
966 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
967 QObject::tr( "GEOM_ERROR_STATUS" ),
969 QObject::tr( "BUT_OK" ) );
972 //================================================================
973 // Function : showError
974 // Purpose : Shows a error message followed by <msg>
975 //================================================================
976 void GEOMBase_Helper::showError( const QString& msg )
978 QString str( QObject::tr( "GEOM_INCORRECT_INPUT" ) );
979 if ( !msg.isEmpty() )
981 SUIT_MessageBox::critical(SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ), str, QObject::tr( "BUT_OK" ) );
984 //////////////////////////////////////////////////////////////////
985 // Virtual methods to be redefined in dialogs
986 //////////////////////////////////////////////////////////////////
988 //================================================================
989 // Function : createOperation
990 // Purpose : Redefine this method to return proper IOperation reference
991 //================================================================
992 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::createOperation()
994 GEOM::GEOM_IOperations_var aNilOp;
995 return aNilOp._retn();
998 //================================================================
999 // Function : isValid
1000 // Purpose : Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
1001 //================================================================
1002 bool GEOMBase_Helper::isValid( QString& )
1007 //================================================================
1008 // Function : execute
1009 // Purpose : This method is called by onAccept().
1010 // It should perform the required operation and put all new or modified objects into
1011 // <objects> argument.Should return <false> if some error occurs during its execution.
1012 //================================================================
1013 bool GEOMBase_Helper::execute( ObjectList& objects )
1018 //================================================================
1019 // Function : getFather
1020 // Purpose : This method is called by addInStudy(). It should return a father object
1021 // for <theObj> or a nil reference if <theObj> should be published
1022 // as a top-level object.
1023 //================================================================
1024 GEOM::GEOM_Object_ptr GEOMBase_Helper::getFather( GEOM::GEOM_Object_ptr theObj )
1026 return GEOM::GEOM_Object::_nil();
1029 //================================================================
1030 // Function : getObjectName
1031 // Purpose : Redefine this method to return proper name for the given object
1032 //================================================================
1033 QString GEOMBase_Helper::getObjectName(GEOM::GEOM_Object_ptr object) const
1038 //================================================================
1039 // Function : getNewObjectName
1040 // Purpose : Redefine this method to return proper name for a new object
1041 //================================================================
1042 QString GEOMBase_Helper::getNewObjectName (int) const
1047 //================================================================
1048 // Function : extractPrefix
1049 // Purpose : Redefine this method to return \c true if necessary
1050 // to extract prefix when generating new name for the
1051 // object(s) being created
1052 //================================================================
1053 bool GEOMBase_Helper::extractPrefix() const
1058 //================================================================
1059 // Function : getPrefix
1060 // Purpose : Get prefix for name of created object
1061 //================================================================
1062 QString GEOMBase_Helper::getPrefix( GEOM::GEOM_Object_ptr theObj ) const
1064 if ( !myPrefix.isEmpty() || theObj->_is_nil() )
1067 GEOM::shape_type aType = theObj->GetShapeType();
1071 case GEOM::VERTEX : return QObject::tr( "GEOM_VERTEX" );
1072 case GEOM::EDGE : return QObject::tr( "GEOM_EDGE" );
1073 case GEOM::WIRE : return QObject::tr( "GEOM_WIRE" );
1074 case GEOM::FACE : return QObject::tr( "GEOM_FACE" );
1075 case GEOM::SHELL : return QObject::tr( "GEOM_SHELL" );
1076 case GEOM::SOLID : return QObject::tr( "GEOM_SOLID" );
1077 case GEOM::COMPSOLID: return QObject::tr( "GEOM_COMPOUNDSOLID" );
1078 case GEOM::COMPOUND : return QObject::tr( "GEOM_COMPOUND" );
1079 default : return "";
1083 //================================================================
1084 // Function : getDesktop
1085 // Purpose : Returns myDesktop field. Initialized in constructor,
1086 // usually as dynamic_cast<SUIT_Desktop*>(parentWidget())
1087 //================================================================
1088 SUIT_Desktop* GEOMBase_Helper::getDesktop() const
1093 //================================================================
1094 // Function : selectObjects
1095 // Purpose : Selects list of objects
1096 //================================================================
1097 bool GEOMBase_Helper::selectObjects( ObjectList& objects )
1099 SUIT_DataOwnerPtrList aList;
1100 ObjectList::iterator anIter;
1101 for ( anIter = objects.begin(); anIter != objects.end(); ++anIter )
1103 QString anEntry = getEntry( *anIter );
1104 LightApp_DataOwner* anOwher = new LightApp_DataOwner( anEntry );
1105 aList.append( anOwher );
1108 SUIT_Session* session = SUIT_Session::session();
1109 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1113 LightApp_SelectionMgr* aMgr = app->selectionMgr();
1117 aMgr->setSelected( aList, false );
1122 //================================================================
1123 // Function : findObjectInFather
1124 // Purpose : It should return an object if its founded in study or
1125 // return Null object if the object is not founded
1126 //================================================================
1127 GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather (GEOM::GEOM_Object_ptr theFather,
1128 const QString& theName)
1130 SalomeApp_Application* app =
1131 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1132 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1133 _PTR(Study) aDStudy = appStudy->studyDS();
1134 QString IOR = GEOMBase::GetIORFromObject( theFather );
1135 _PTR(SObject) SObj ( aDStudy->FindObjectIOR( IOR.toLatin1().constData() ) );
1137 bool inStudy = false;
1138 GEOM::GEOM_Object_var aReturnObject;
1139 for (_PTR(ChildIterator) iit (aDStudy->NewChildIterator( SObj )); iit->More() && !inStudy; iit->Next()) {
1140 _PTR(SObject) child (iit->Value());
1141 QString aChildName = child->GetName().c_str();
1142 if (aChildName == theName) {
1144 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(iit->Value());
1145 aReturnObject = GEOM::GEOM_Object::_narrow( corbaObj );
1149 return aReturnObject._retn();
1151 return GEOM::GEOM_Object::_nil();
1154 //================================================================
1155 // Function : findObjectInFather
1156 // Purpose : It should return an object if its founded in study or
1157 // return Null object if the object is not founded
1158 //================================================================
1159 GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather( GEOM::GEOM_Object_ptr theFather,
1162 GEOM::GEOM_Object_var object;
1164 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
1166 _PTR(Study) studyDS = study->studyDS();
1167 QString IOR = GEOMBase::GetIORFromObject( theFather );
1168 _PTR(SObject) sobject( studyDS->FindObjectIOR( IOR.toLatin1().constData() ) );
1170 _PTR(ChildIterator) it( studyDS->NewChildIterator( sobject ) );
1171 for ( ; it->More(); it->Next() ) {
1172 GEOM::GEOM_Object_var cobject = GEOM::GEOM_Object::_narrow( GeometryGUI::ClientSObjectToObject( it->Value() ) );
1173 if ( !CORBA::is_nil( cobject ) ) {
1174 GEOM::ListOfLong_var indices = cobject->GetSubShapeIndices();
1175 int length = indices->length();
1176 // VSR 18/03/2014: we need only sub-shapes with single sub-shape index (to exclude groups, etc)
1177 if ( length == 1 && indices[0] == theIndex ) {
1186 return object._retn();
1189 //================================================================
1190 // Function : addSubshapesToStudy
1191 // Purpose : Virtual method to add sub-shapes if needs
1192 //================================================================
1193 void GEOMBase_Helper::addSubshapesToStudy()
1195 //Impemented in Dialogs, called from Accept method
1198 //================================================================
1199 // Function : getSourceObjects
1200 // Purpose : Virtual method to get source objects
1201 //================================================================
1202 QList<GEOM::GeomObjPtr> GEOMBase_Helper::getSourceObjects()
1204 //Impemented in Dialogs, called from Accept method
1205 QList<GEOM::GeomObjPtr> res;
1209 //================================================================
1210 // Function : getSelected
1211 // Purpose : Get selected object by specified type
1213 // Returns valid object if only one object of the specified type is selected
1214 // (no matter global or local selection is activated). If \a type is TopAbs_SHAPE,
1215 // geometrical object of any valid type is expected.
1217 // \param type type of the object to be obtained from selection
1218 // \return selected geometrical object or nil object if selection is not satisfactory
1219 //================================================================
1220 GEOM::GeomObjPtr GEOMBase_Helper::getSelected( TopAbs_ShapeEnum type )
1222 QList<TopAbs_ShapeEnum> types;
1224 return getSelected( types );
1227 //================================================================
1228 // Function : getSelected
1229 // Purpose : Get selected object by specified types
1231 // Returns valid object if only one object of the specified type is selected
1232 // (no matter global or local selection is activated). The list of allowed
1233 // shape types is passed via \a types. If \a types includes TopAbs_SHAPE,
1234 // geometrical object of any valid type is expected.
1236 // \param types list of allowed shape types for the objects to be obtained from selection
1237 // \return selected geometrical object or nil object if selection is not satisfactory
1238 //================================================================
1239 GEOM::GeomObjPtr GEOMBase_Helper::getSelected( const QList<TopAbs_ShapeEnum>& types )
1241 QList<GEOM::GeomObjPtr> selected = getSelected( types, 1 );
1242 return selected.count() > 0 ? selected[0] : GEOM::GeomObjPtr();
1245 //================================================================
1246 // Function : getSelected
1247 // Purpose : Get selected object(s) by specified type
1249 // Returns list of selected objects if selection satisfies specifies selection options.
1250 // (no matter global or local selection is activated). If \a type is TopAbs_SHAPE,
1251 // geometrical objects of any valid type are expected.
1253 // The \a type parameter specifies allowed type of the object(s) being selected.
1254 // The \a count parameter specifies exact number of the objects to be retrieved from selection.
1255 // The \a strict parameter specifies policy being applied to the selection.
1256 // If \a count < 0, then any number of the selected objects is valid (including 0).
1257 // In this case, if \a strict is \c true (default), all selected objects should satisfy
1258 // the specified \a type.
1259 // If \a count > 0, only specified number of the objects is retrieved from the selection.
1260 // In this case, if \a strict is \c true (default), function returns empty list if total number of selected
1261 // objects does not correspond to the \a count parameter. Otherwise (if \a strict is \c false),
1262 // function returns valid list of objects if at least \a count objects satisfy specified \a type.
1264 // \param type type of the object(s) to be obtained from selection
1265 // \param count number of items to be retrieved from selection
1266 // \param strict selection policy
1267 // \return list of selected geometrical objects or empty list if selection is not satisfactory
1268 //================================================================
1269 QList<GEOM::GeomObjPtr> GEOMBase_Helper::getSelected( TopAbs_ShapeEnum type, int count, bool strict )
1271 QList<TopAbs_ShapeEnum> types;
1273 return getSelected( types, count, strict );
1276 static bool typeInList( TopAbs_ShapeEnum type, const QList<TopAbs_ShapeEnum>& types )
1279 for ( int i = 0; i < types.count() && !ok; i++ )
1280 ok = types[i] == TopAbs_SHAPE || types[i] == type;
1284 //================================================================
1285 // Function : getSelected
1286 // Purpose : Get selected objects by specified types
1288 // Returns list of selected objects if selection satisfies specifies selection options.
1289 // (no matter global or local selection is activated). If \a types includes TopAbs_SHAPE,
1290 // geometrical objects of any valid type are expected.
1292 // The \a types parameter specifies allowed types of the object(s) being selected.
1293 // The \a count parameter specifies exact number of the objects to be retrieved from selection.
1294 // The \a strict parameter specifies policy being applied to the selection.
1295 // If \a count < 0, then any number of the selected objects is valid (including 0).
1296 // In this case, if \a strict is \c true (default), all selected objects should satisfy
1297 // the specified \a type.
1298 // If \a count > 0, only specified number of the objects is retrieved from the selection.
1299 // In this case, if \a strict is \c true (default), function returns empty list if total number of selected
1300 // objects does not correspond to the \a count parameter. Otherwise (if \a strict is \c false),
1301 // function returns valid list of objects if at least \a count objects satisfy specified \a type.
1303 // \param types list of allowed shape types for the objects to be obtained from selection
1304 // \param count number of items to be retrieved from selection
1305 // \param strict selection policy
1306 // \return list of selected geometrical objects or empty list if selection is not satisfactory
1307 //================================================================
1308 QList<GEOM::GeomObjPtr> GEOMBase_Helper::getSelected( const QList<TopAbs_ShapeEnum>& types, int count, bool strict )
1310 SUIT_Session* session = SUIT_Session::session();
1311 QList<GEOM::GeomObjPtr> result;
1313 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1315 LightApp_SelectionMgr* selMgr = app->selectionMgr();
1317 SALOME_ListIO selected;
1318 selMgr->selectedObjects( selected );
1319 SALOME_ListIteratorOfListIO it( selected );
1320 bool stopped = false;
1321 for ( ; it.More() && !stopped; it.Next() ) {
1322 Handle(SALOME_InteractiveObject) IO = it.Value();
1323 GEOM::GeomObjPtr object = GEOMBase::ConvertIOinGEOMObject( IO );
1325 TColStd_IndexedMapOfInteger subShapes;
1326 selMgr->GetIndexes( IO, subShapes );
1327 int nbSubShapes = subShapes.Extent();
1328 if ( nbSubShapes == 0 ) {
1330 if ( typeInList( (TopAbs_ShapeEnum)(object->GetShapeType()), types ) ) {
1333 if ( strict && result.count() > count ) {
1337 else if ( !strict && result.count() == count )
1341 else if ( strict ) {
1348 for ( int i = 1; i <= nbSubShapes && !stopped; i++ ) {
1349 int idx = subShapes( i );
1350 GEOM::GeomObjPtr subShape = findObjectInFather( object.get(), idx );
1352 // sub-shape is not yet published in the study
1353 GEOM::ShapesOpPtr shapesOp = getGeomEngine()->GetIShapesOperations();
1354 subShape.take( shapesOp->GetSubShape( object.get(), idx ) ); // take ownership!
1356 if ( typeInList( (TopAbs_ShapeEnum)(subShape->GetShapeType()), types ) ) {
1359 if ( strict && result.count() > count ) {
1363 else if ( !strict && result.count() == count )
1367 else if ( strict ) {
1379 //================================================================
1380 // Function : hideSourceObject
1382 //================================================================
1383 void GEOMBase_Helper::hideSourceObjects( QList<GEOM::GeomObjPtr> theObject )
1385 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1386 if ( resMgr->booleanValue( "Geometry", "hide_input_object", true) ) {
1387 GEOM_Displayer* aDisplayer = getDisplayer();
1388 for ( int i = 0; i < theObject.count(); i++ )
1389 aDisplayer->Erase( theObject[i].get() );
1393 //================================================================
1394 // Function : setIsApplyAndClose
1395 // Purpose : Set value of the flag indicating that the dialog is
1396 // accepted by Apply & Close button
1397 //================================================================
1398 void GEOMBase_Helper::setIsApplyAndClose( const bool theFlag )
1400 myIsApplyAndClose = theFlag;
1403 //================================================================
1404 // Function : isApplyAndClose
1405 // Purpose : Get value of the flag indicating that the dialog is
1406 // accepted by Apply & Close button
1407 //================================================================
1408 bool GEOMBase_Helper::isApplyAndClose() const
1410 return myIsApplyAndClose;
1413 //================================================================
1414 // Function : setIsOptimizedBrowsing
1415 // Purpose : Set value of the flag switching to optimized
1416 // browsing mode (to select the first published
1418 //================================================================
1419 void GEOMBase_Helper::setIsOptimizedBrowsing( const bool theFlag )
1421 myIsOptimizedBrowsing = theFlag;
1424 //================================================================
1425 // Function : isOptimizedBrowsing
1426 // Purpose : Get value of the flag switching to optimized
1427 // browsing mode (to select the first published
1429 //================================================================
1430 bool GEOMBase_Helper::isOptimizedBrowsing() const
1432 return myIsOptimizedBrowsing;