1 // Copyright (C) 2007-2010 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>
41 #include <SalomeApp_Module.h>
42 #include <SalomeApp_Application.h>
43 #include <SalomeApp_Study.h>
44 #include <LightApp_SelectionMgr.h>
45 #include <LightApp_DataOwner.h>
46 #include <SalomeApp_Tools.h>
48 #include <SALOME_Prs.h>
50 #include <OCCViewer_ViewModel.h>
51 #include <SVTK_ViewModel.h>
53 #include <TColStd_MapOfInteger.hxx>
54 #include <TCollection_AsciiString.hxx>
56 //To disable automatic genericobj management, the following line should be commented.
57 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
58 #define WITHGENERICOBJ
60 //================================================================
61 // Function : getActiveView
62 // Purpose : Get active view window, returns 0 if no open study frame
63 //================================================================
64 static SUIT_ViewWindow* getActiveView()
66 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
68 return SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
74 //================================================================
75 // Function : getGeomEngine
76 // Purpose : Static method
77 //================================================================
78 GEOM::GEOM_Gen_ptr GEOMBase_Helper::getGeomEngine()
80 return GeometryGUI::GetGeomGen();
83 //================================================================
84 // Function : GEOMBase_Helper
86 //================================================================
87 GEOMBase_Helper::GEOMBase_Helper( SUIT_Desktop* desktop )
88 : myDesktop( desktop ), myViewWindow( 0 ), myDisplayer( 0 ), myCommand( 0 ), isPreview( false )
92 //================================================================
93 // Function : ~GEOMBase_Helper
95 //================================================================
96 GEOMBase_Helper::~GEOMBase_Helper()
98 //rnv: Fix for the "IPAL21922 : WinTC5.1.4: incorrect quit salome"
99 if ( !SUIT_Session::session()->activeApplication() || !SUIT_Session::session()->activeApplication()->desktop() )
102 if ( myPreview.size() )
106 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
108 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
110 globalSelection(aGeomGUI->getLocalSelectionMode() , true );
115 if ( !CORBA::is_nil( myOperation ) )
116 myOperation->Destroy();
119 //================================================================
120 // Function : display
122 //================================================================
123 void GEOMBase_Helper::display( const ObjectList& objList, const bool updateView )
125 ObjectList::const_iterator it;
126 for ( it = objList.begin(); it != objList.end(); it++ ) {
127 display( *it, false );
129 if ( !objList.empty() && updateView )
130 getDisplayer()->UpdateViewer();
133 //================================================================
134 // Function : display
135 // Purpose : Display object.
136 // Important : Object must be already in study
137 //================================================================
138 void GEOMBase_Helper::display( GEOM::GEOM_Object_ptr object, const bool updateView )
140 // Unset color of shape ( this color may be set during preview displaying )
141 // Default color will be used
142 getDisplayer()->UnsetColor();
143 getDisplayer()->UnsetWidth();
145 // Enable activisation of selection
146 getDisplayer()->SetToActivate( true );
149 getDisplayer()->Display( object, updateView );
152 //================================================================
155 //================================================================
156 void GEOMBase_Helper::erase( const ObjectList& objList, const bool updateView )
158 ObjectList::const_iterator it = objList.begin();
159 for ( ; it != objList.end(); it++ ) {
162 if ( !objList.empty() && updateView )
163 getDisplayer()->UpdateViewer();
166 //================================================================
169 //================================================================
170 void GEOMBase_Helper::erase( GEOM::GEOM_Object_ptr object, const bool updateView )
172 if ( !object->_is_nil() ) {
173 QString entry = getEntry( object );
174 getDisplayer()->Erase( new SALOME_InteractiveObject(
175 entry.toLatin1().constData(),
176 "GEOM", strdup( GEOMBase::GetName( object ).toLatin1().constData() ) ), true, updateView );
180 //================================================================
181 // Function : redisplay
183 //================================================================
184 void GEOMBase_Helper::redisplay( const ObjectList& objList,
185 const bool withChildren,
186 const bool updateView )
188 ObjectList::const_iterator it = objList.begin();
189 for ( ; it != objList.end(); it++ ) {
190 redisplay( *it, withChildren, false );
192 if ( !objList.empty() && updateView )
193 getDisplayer()->UpdateViewer();
196 //================================================================
197 // Function : redisplay
199 //================================================================
200 void GEOMBase_Helper::redisplay( GEOM::GEOM_Object_ptr object,
201 const bool withChildren,
202 const bool updateView )
204 if ( !object->_is_nil() ) {
205 // Unset color of shape ( this color may be set during preview displaying )
206 // Default color will be used
207 getDisplayer()->UnsetColor();
208 getDisplayer()->UnsetWidth();
210 // Enable activisation of selection
211 getDisplayer()->SetToActivate( true );
213 QString entry = getEntry( object );
214 getDisplayer()->Redisplay(new SALOME_InteractiveObject
215 (entry.toLatin1().constData(), "GEOM", strdup(GEOMBase::GetName(object).toLatin1().constData())), false);
218 if ( withChildren ) {
219 SalomeApp_Study* aDoc = getStudy();
220 if ( aDoc && aDoc->studyDS() ) {
221 _PTR(Study) aStudy = aDoc->studyDS();
222 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string(object);
223 _PTR(SObject) aSObj (aStudy->FindObjectIOR(std::string(objStr.in())));
225 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
226 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
227 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow
228 (GeometryGUI::ClientSObjectToObject(anIt->Value()));
229 if ( !CORBA::is_nil( aChild ) ) {
230 if ( !aChild->_is_nil() ) {
231 QString entry = getEntry( aChild );
232 getDisplayer()->Redisplay( new SALOME_InteractiveObject(
233 entry.toLatin1().constData(), "GEOM", strdup( GEOMBase::GetName( aChild ).toLatin1().constData() ) ), false );
242 getDisplayer()->UpdateViewer();
245 //================================================================
246 // Function : displayPreview
247 // Purpose : Method for displaying preview based on execute() results
248 //================================================================
249 void GEOMBase_Helper::displayPreview( const bool activate,
251 const bool toRemoveFromEngine,
252 const double lineWidth,
253 const int displayMode,
258 if ( !isValid( msg ) )
260 erasePreview( update );
265 erasePreview( false );
268 SUIT_OverrideCursor wc;
270 if ( !execute( objects ) || !getOperation()->IsDone() ) {
274 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it )
276 GEOM::GEOM_Object_var obj=*it;
277 displayPreview( obj, true, activate, false, lineWidth, displayMode, color );
278 if ( toRemoveFromEngine )
283 catch( const SALOME::SALOME_Exception& e ) {
284 SalomeApp_Tools::QtCatchCorbaException( e );
293 //================================================================
294 // Function : displayPreview
295 // Purpose : Method for displaying preview of resulting shape
296 //================================================================
297 void GEOMBase_Helper::displayPreview( GEOM::GEOM_Object_ptr object,
301 const double lineWidth,
302 const int displayMode,
305 // Set color for preview shape
306 getDisplayer()->SetColor( color == -1 ? Quantity_NOC_VIOLET : color );
308 // set width of displayed shape
309 getDisplayer()->SetWidth( lineWidth );
311 // set display mode of displayed shape
312 int aPrevDispMode = getDisplayer()->SetDisplayMode( displayMode );
314 // Disable activation of selection
315 getDisplayer()->SetToActivate( activate );
317 // Make a reference to GEOM_Object
318 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string( object );
319 getDisplayer()->SetName( objStr.in() );
322 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( object );
323 if ( aPrs == 0 || aPrs->IsNull() )
327 displayPreview( aPrs, append, update );
329 getDisplayer()->UnsetName();
330 getDisplayer()->UnsetColor();
331 getDisplayer()->SetDisplayMode( aPrevDispMode );
333 // Enable activation of displayed objects
334 getDisplayer()->SetToActivate( true );
337 //================================================================
338 // Function : displayPreview
339 // Purpose : Method for displaying arbitrary preview objects (not limited to shapes)
340 //================================================================
341 void GEOMBase_Helper::displayPreview( const SALOME_Prs* prs,
346 erasePreview( false );
348 // remember current view frame to make correct erase preview later
349 myViewWindow = getActiveView();
351 if ( myViewWindow == 0 )
355 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
356 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
357 aViewManager->getType() == SVTK_Viewer::Type() )
359 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
360 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
362 aView->Display( prs );
365 // Add prs to the preview list
366 myPreview.push_back( (SALOME_Prs*)prs );
370 getDisplayer()->UpdateViewer();
373 //================================================================
374 // Function : erasePreview
376 //================================================================
377 void GEOMBase_Helper::erasePreview( const bool update )
379 // check view frame where the preview was displayed
380 bool vfOK = checkViewWindow() && myViewWindow;
381 // Iterate through presentations and delete them
382 for ( PrsList::iterator anIter = myPreview.begin(); anIter != myPreview.end(); ++anIter ) {
385 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
386 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
387 aViewManager->getType() == SVTK_Viewer::Type() )
389 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
390 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
392 aView->Erase( *anIter, true );
404 //================================================================
405 // Function : localSelection
406 // Purpose : Activate selection of objects of a given type
407 // IMPORTANT : Works after localSelection( ... ) method call only
408 //================================================================
409 void GEOMBase_Helper::activate( const int theType )
411 if (!getStudy()) return;
412 _PTR(Study) aStudy = getStudy()->studyDS();
413 _PTR(SComponent) aGeom ( aStudy->FindComponent( "GEOM" ) );
418 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( aGeom ) );
419 for ( ; anIter->More(); anIter->Next() )
421 _PTR(SObject) aSO ( anIter->Value() );
424 _PTR(SObject) aRefSO;
425 if ( !aSO->ReferencedObject( aRefSO ) )
427 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow
428 (GeometryGUI::ClientSObjectToObject(aSO));
429 if ( !anObj->_is_nil() && anObj->GetType() == theType )
430 aList.Append( new SALOME_InteractiveObject( aSO->GetID().c_str(), "GEOM", aSO->GetName().c_str()) );
435 getDisplayer()->LocalSelection( aList, 0 );
438 //================================================================
439 // Function : localSelection
440 // Purpose : Activate selection of subshapes in accordance with mode
441 // theMode is from TopAbs_ShapeEnum
442 //================================================================
443 void GEOMBase_Helper::localSelection( const ObjectList& theObjs, const int theMode )
445 SALOME_ListIO aListOfIO;
447 ObjectList::const_iterator anIter = theObjs.begin();
448 for ( ; anIter != theObjs.end(); ++anIter )
450 GEOM::GEOM_Object_ptr anObj = *anIter;
451 if ( anObj->_is_nil() )
453 QString anEntry = getEntry( anObj );
455 aListOfIO.Append( new SALOME_InteractiveObject(
456 anEntry.toLatin1().constData(), "GEOM", strdup( GEOMBase::GetName( anObj ).toLatin1().constData() ) ) );
459 getDisplayer()->LocalSelection( aListOfIO, theMode );
462 //================================================================
463 // Function : localSelection
464 // Purpose : Activate selection of subshapes in accordance with mode
465 // theMode is from TopAbs_ShapeEnum
466 //================================================================
467 void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const int mode )
469 // If object is null local selection for all objects is activated
470 if ( obj->_is_nil() ) {
471 getDisplayer()->LocalSelection( Handle(SALOME_InteractiveObject)(), mode );
476 objList.push_back( obj );
477 localSelection( objList, mode );
481 //================================================================
482 // Function : globalSelection
483 // Purpose : Activate selection of subshapes. Set selection filters
484 // in accordance with mode. theMode is from GEOMImpl_Types
485 //================================================================
486 void GEOMBase_Helper::globalSelection( const int theMode, const bool update )
488 getDisplayer()->GlobalSelection( theMode, update );
491 //================================================================
492 // Function : globalSelection
493 // Purpose : Activate selection of subshapes. Set selection filters
494 // in accordance with mode. theMode is from GEOMImpl_Types
495 //================================================================
496 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
499 getDisplayer()->GlobalSelection( theModes, update );
502 //================================================================
503 // Function : globalSelection
504 // Purpose : Activate selection of subshapes. Set selection filters
505 // in accordance with mode. theMode is from GEOMImpl_Types
506 //================================================================
507 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
508 const QList<int>& subShapes,
511 getDisplayer()->GlobalSelection( theModes, update, &subShapes );
514 //================================================================
515 // Function : addInStudy
516 // Purpose : Add object in study
517 //================================================================
518 void GEOMBase_Helper::addInStudy( GEOM::GEOM_Object_ptr theObj, const char* theName )
523 _PTR(Study) aStudy = getStudy()->studyDS();
524 if ( !aStudy || theObj->_is_nil() )
527 SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy(aStudy);
529 GEOM::GEOM_Object_ptr aFatherObj = getFather( theObj );
531 SALOMEDS::SObject_var aSO =
532 getGeomEngine()->AddInStudy(aStudyDS, theObj, theName, aFatherObj);
534 // Each dialog is responsible for this method implementation,
535 // default implementation does nothing
536 restoreSubShapes(aStudyDS, aSO);
540 //================================================================
541 // Function : restoreSubShapes
542 // Purpose : restore tree of argument's sub-shapes under the resulting shape
543 //================================================================
544 void GEOMBase_Helper::restoreSubShapes (SALOMEDS::Study_ptr /*theStudy*/,
545 SALOMEDS::SObject_ptr /*theSObject*/)
547 // do nothing by default
549 // example of implementation in particular dialog:
550 // GEOM::ListOfGO anArgs;
551 // anArgs.length(0); // empty list means that all arguments should be restored
552 // getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
553 // /*theFindMethod=*/GEOM::FSM_GetInPlace,
554 // /*theInheritFirstArg=*/false);
557 //================================================================
558 // Function : updateObjBrowser
559 // Purpose : Update object browser
560 //================================================================
561 void GEOMBase_Helper::updateObjBrowser() const
563 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
565 CAM_Module* module = app->module( "Geometry" );
566 SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
568 appMod->updateObjBrowser( true );
573 //================================================================
574 // Function : updateViewer
575 // Purpose : Update active 3D view
576 //================================================================
577 void GEOMBase_Helper::updateViewer()
579 getDisplayer()->UpdateViewer();
582 //================================================================
583 // Function : getStudyId
584 // Purpose : Get study Id
585 //================================================================
586 int GEOMBase_Helper::getStudyId() const
590 anId = getStudy()->id();
594 //================================================================
595 // Function : getStudy
596 // Purpose : Returns the active study. It is recommended to use
597 // this method instead of direct desktop->getActiveStudy() calls
598 //================================================================
599 SalomeApp_Study* GEOMBase_Helper::getStudy() const
601 SUIT_Desktop* aDesktop = getDesktop();
605 QList<SUIT_Application*> anAppList = SUIT_Session::session()->applications();
607 SUIT_Application* anApp = 0;
608 QListIterator<SUIT_Application*> it( anAppList );
609 while ( it.hasNext() )
612 if ( anApp && anApp->desktop() == aDesktop )
616 return dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
619 //================================================================
620 // Function : getEntry
622 //================================================================
623 QString GEOMBase_Helper::getEntry( GEOM::GEOM_Object_ptr object ) const
625 SalomeApp_Study* study = getStudy();
627 QString objIOR = GEOMBase::GetIORFromObject( object );
628 if ( objIOR != "" ) {
629 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( objIOR.toLatin1().constData() ) );
631 return QString::fromStdString(SO->GetID());
637 //================================================================
638 // Function : getDisplayer
640 //================================================================
641 GEOM_Displayer* GEOMBase_Helper::getDisplayer()
644 myDisplayer = new GEOM_Displayer( getStudy() );
648 //================================================================
649 // Function : clearShapeBuffer
651 //================================================================
652 void GEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
654 if ( CORBA::is_nil( theObj ) )
657 CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( theObj );
658 TCollection_AsciiString asciiIOR( (char *)IOR.in() );
659 GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
661 if ( !getStudy() || !getStudy()->studyDS() )
664 _PTR(Study) aStudy = getStudy()->studyDS();
665 _PTR(SObject) aSObj ( aStudy->FindObjectIOR( std::string( IOR ) ) );
669 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
670 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
671 _PTR(GenericAttribute) anAttr;
672 if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
673 _PTR(AttributeIOR) anIOR ( anAttr );
674 TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
675 GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
680 //================================================================
681 // Function : openCommand
683 //================================================================
684 bool GEOMBase_Helper::openCommand()
687 if ( !getStudy() || hasCommand() )
690 GEOM::GEOM_IOperations_var anOp = GEOM::GEOM_IOperations::_narrow( getOperation() );
691 if ( !anOp->_is_nil() ) {
692 myCommand = new GEOM_Operation( SUIT_Session::session()->activeApplication(), anOp.in() );
700 //================================================================
701 // Function : abortCommand
703 //================================================================
704 bool GEOMBase_Helper::abortCommand()
710 delete myCommand; // I don't know where to delete this object here ?
716 //================================================================
717 // Function : commitCommand
719 //================================================================
720 bool GEOMBase_Helper::commitCommand( const char* )
726 delete myCommand; // I don't know where to delete this object here ?
732 //================================================================
733 // Function : hasCommand
735 //================================================================
736 bool GEOMBase_Helper::hasCommand() const
738 return (bool)myCommand;
741 //================================================================
742 // Function : getOperation
744 //================================================================
745 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::getOperation()
747 if ( myOperation->_is_nil() )
748 myOperation = createOperation();
755 //================================================================
756 // Function : checkViewWindow
758 //================================================================
759 bool GEOMBase_Helper::checkViewWindow()
762 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
763 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
764 while ( it.hasNext() )
766 if ( myViewWindow == it.next() )
774 //================================================================
775 // Function : onAccept
776 // Purpose : This method should be called from dialog's slots onOk() and onApply()
777 // It perfroms user input validation, then it
778 // performs a proper operation and manages transactions, etc.
779 //================================================================
780 bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction )
782 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
783 if ( !appStudy ) return false;
784 _PTR(Study) aStudy = appStudy->studyDS();
786 bool aLocked = (_PTR(AttributeStudyProperties) (aStudy->GetProperties()))->IsLocked();
788 MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
789 SUIT_MessageBox::warning ( (QWidget*)SUIT_Session::session()->activeApplication()->desktop(),
790 QObject::tr("WRN_WARNING"),
791 QObject::tr("WRN_STUDY_LOCKED"),
792 QObject::tr("BUT_OK") );
797 if ( !isValid( msg ) ) {
802 erasePreview( false );
807 if ( ( !publish && !useTransaction ) || openCommand() ) {
808 SUIT_OverrideCursor wc;
809 SUIT_Session::session()->activeApplication()->putInfo( "" );
811 if ( !execute( objects ) || !getOperation()->IsDone() ) {
817 addSubshapesToStudy(); // add Subshapes if local selection
818 const int nbObjs = objects.size();
820 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
821 GEOM::GEOM_Object_var obj=*it;
823 QString aName = getNewObjectName();
826 aName = getPrefix(obj);
828 // Try to find a unique name
829 aName = GEOMBase::GetDefaultName(aName, extractPrefix());
831 // Don't check name uniqueness in case of numerous objects
832 aName = aName + "_" + QString::number(aNumber++);
835 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
836 if ( aName.isEmpty() )
837 aName = GEOMBase::GetDefaultName( getPrefix( obj ) );
839 addInStudy( obj, aName.toLatin1().constData() );
841 display( obj, false );
842 #ifdef WITHGENERICOBJ
843 // obj has been published in study. Its refcount has been incremented.
844 // It is safe to decrement its refcount
845 // so that it will be destroyed when the entry in study will be removed
850 // asv : fix of PAL6454. If publish==false, then the original shape
851 // was modified, and need to be re-cached in GEOM_Client before redisplay
852 clearShapeBuffer( obj );
853 // withChildren=true, updateView=false
854 redisplay( obj, true, false );
861 SUIT_Session::session()->activeApplication()->putInfo( QObject::tr("GEOM_PRP_DONE") );
869 catch( const SALOME::SALOME_Exception& e ) {
870 SalomeApp_Tools::QtCatchCorbaException( e );
880 //================================================================
881 // Function : showError
882 // Purpose : Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
883 //================================================================
884 void GEOMBase_Helper::showError()
887 if ( !getOperation()->_is_nil() )
888 msg = QObject::tr( getOperation()->GetErrorCode() );
891 msg = QObject::tr( "GEOM_PRP_ABORT" );
893 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
894 QObject::tr( "GEOM_ERROR_STATUS" ),
896 QObject::tr( "BUT_OK" ) );
899 //================================================================
900 // Function : showError
901 // Purpose : Shows a error message followed by <msg>
902 //================================================================
903 void GEOMBase_Helper::showError( const QString& msg )
905 QString str( QObject::tr( "GEOM_INCORRECT_INPUT" ) );
906 if ( !msg.isEmpty() )
908 SUIT_MessageBox::critical(SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ), str, QObject::tr( "BUT_OK" ) );
911 //////////////////////////////////////////////////////////////////
912 // Virtual methods to be redefined in dialogs
913 //////////////////////////////////////////////////////////////////
915 //================================================================
916 // Function : createOperation
917 // Purpose : Redefine this method to return proper IOperation reference
918 //================================================================
919 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::createOperation()
921 GEOM::GEOM_IOperations_var aNilOp;
922 return aNilOp._retn();
925 //================================================================
926 // Function : isValid
927 // Purpose : Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
928 //================================================================
929 bool GEOMBase_Helper::isValid( QString& )
934 //================================================================
935 // Function : execute
936 // Purpose : This method is called by onAccept().
937 // It should perform the required operation and put all new or modified objects into
938 // <objects> argument.Should return <false> if some error occurs during its execution.
939 //================================================================
940 bool GEOMBase_Helper::execute( ObjectList& objects )
945 //================================================================
946 // Function : getFather
947 // Purpose : This method is called by addInStudy(). It should return a father object
948 // for <theObj> or a nil reference if <theObj> should be published
949 // as a top-level object.
950 //================================================================
951 GEOM::GEOM_Object_ptr GEOMBase_Helper::getFather( GEOM::GEOM_Object_ptr theObj )
953 return GEOM::GEOM_Object::_nil();
956 //================================================================
957 // Function : getNewObjectName
958 // Purpose : Redefine this method to return proper name for a new object
959 //================================================================
960 QString GEOMBase_Helper::getNewObjectName() const
962 return QString::null;
965 //================================================================
966 // Function : extractPrefix
967 // Purpose : Redefine this method to return \c true if necessary
968 // to extract prefix when generating new name for the
969 // object(s) being created
970 //================================================================
971 bool GEOMBase_Helper::extractPrefix() const
976 //================================================================
977 // Function : getPrefix
978 // Purpose : Get prefix for name of created object
979 //================================================================
980 QString GEOMBase_Helper::getPrefix( GEOM::GEOM_Object_ptr theObj ) const
982 if ( !myPrefix.isEmpty() || theObj->_is_nil() )
985 //TopoDS_Shape aShape;
986 //if ( !GEOMBase::GetShape( theObj, aShape ) )
989 //long aType = aShape.ShapeType();
990 GEOM::shape_type aType = theObj->GetShapeType();
994 case GEOM::VERTEX : return QObject::tr( "GEOM_VERTEX" );
995 case GEOM::EDGE : return QObject::tr( "GEOM_EDGE" );
996 case GEOM::WIRE : return QObject::tr( "GEOM_WIRE" );
997 case GEOM::FACE : return QObject::tr( "GEOM_FACE" );
998 case GEOM::SHELL : return QObject::tr( "GEOM_SHELL" );
999 case GEOM::SOLID : return QObject::tr( "GEOM_SOLID" );
1000 case GEOM::COMPSOLID: return QObject::tr( "GEOM_COMPOUNDSOLID" );
1001 case GEOM::COMPOUND : return QObject::tr( "GEOM_COMPOUND" );
1002 default : return "";
1006 //================================================================
1007 // Function : getDesktop
1008 // Purpose : Returns myDesktop field. Initialized in constructor,
1009 // usually as dynamic_cast<SUIT_Desktop*>(parentWidget())
1010 //================================================================
1011 SUIT_Desktop* GEOMBase_Helper::getDesktop() const
1016 //================================================================
1017 // Function : selectObjects
1018 // Purpose : Selects list of objects
1019 //================================================================
1020 bool GEOMBase_Helper::selectObjects( ObjectList& objects )
1022 SUIT_DataOwnerPtrList aList;
1023 ObjectList::iterator anIter;
1024 for ( anIter = objects.begin(); anIter != objects.end(); ++anIter )
1026 QString anEntry = getEntry( *anIter );
1027 LightApp_DataOwner* anOwher = new LightApp_DataOwner( anEntry );
1028 aList.append( anOwher );
1031 SUIT_Session* session = SUIT_Session::session();
1032 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1036 LightApp_SelectionMgr* aMgr = app->selectionMgr();
1040 aMgr->setSelected( aList, false );
1045 //================================================================
1046 // Function : findObjectInFather
1047 // Purpose : It should return an object if its founded in study or
1048 // return Null object if the object is not founded
1049 //================================================================
1050 GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather (GEOM::GEOM_Object_ptr theFather,
1051 const QString& theName)
1053 SalomeApp_Application* app =
1054 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1055 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1056 _PTR(Study) aDStudy = appStudy->studyDS();
1057 QString IOR = GEOMBase::GetIORFromObject( theFather );
1058 _PTR(SObject) SObj ( aDStudy->FindObjectIOR( IOR.toLatin1().constData() ) );
1060 bool inStudy = false;
1061 GEOM::GEOM_Object_var aReturnObject;
1062 for (_PTR(ChildIterator) iit (aDStudy->NewChildIterator( SObj )); iit->More() && !inStudy; iit->Next()) {
1063 _PTR(SObject) child (iit->Value());
1064 QString aChildName = child->GetName().c_str();
1065 if (aChildName == theName) {
1067 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(iit->Value());
1068 aReturnObject = GEOM::GEOM_Object::_narrow( corbaObj );
1072 return aReturnObject._retn();
1074 return GEOM::GEOM_Object::_nil();
1077 //================================================================
1078 // Function : addSubshapesToStudy
1079 // Purpose : Virtual method to add subshapes if needs
1080 //================================================================
1081 void GEOMBase_Helper::addSubshapesToStudy()
1083 //Impemented in Dialogs, called from Accept method
1086 //================================================================
1087 // Function : addSubshapesToFather
1088 // Purpose : Method to add Father Subshapes to Study if it`s not exist
1089 //================================================================
1090 void GEOMBase_Helper::addSubshapesToFather( QMap<QString, GEOM::GEOM_Object_var>& theMap )
1093 SalomeApp_Application* app =
1094 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1095 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1096 _PTR(Study) aDStudy = appStudy->studyDS();
1098 GEOM::GEOM_IGroupOperations_var anOp = getGeomEngine()->GetIGroupOperations( getStudyId() );
1100 for( QMap<QString, GEOM::GEOM_Object_var>::Iterator it = theMap.begin(); it != theMap.end(); it++ ) {
1101 if ( !anOp->_is_nil() ) {
1102 GEOM::GEOM_Object_var aFatherObj = anOp->GetMainShape( it.value() );
1103 if ( !aFatherObj->_is_nil() ) {
1104 QString aFatherEntry = getEntry( aFatherObj );
1105 if ( aFatherEntry != "") { // additional checking that object is valid 0020598 EDF 1191
1106 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aFatherObj, it.key().toLatin1().data() );
1107 //Add Object to study if its not exist
1108 if ( aFindedObject->_is_nil() )
1109 GeometryGUI::GetGeomGen()->AddInStudy(GeometryGUI::ClientStudyToStudy(aDStudy),
1110 it.value(), it.key().toLatin1().data(), aFatherObj );
1114 //cout << " anOperations is NULL! " << endl;