1 // Copyright (C) 2007-2008 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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : GEOMBase_Helper.cxx
24 // Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
26 #include "GEOMBase_Helper.h"
28 #include "GEOM_Operation.h"
30 #include <GeometryGUI.h>
32 #include <SUIT_Desktop.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ViewManager.h>
35 #include <SUIT_ViewWindow.h>
36 #include <SUIT_ViewModel.h>
37 #include <SUIT_MessageBox.h>
38 #include <SUIT_OverrideCursor.h>
40 #include <SalomeApp_Module.h>
41 #include <SalomeApp_Application.h>
42 #include <SalomeApp_Study.h>
43 #include <SalomeApp_Notebook.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 ), myNoteBook( 0 ), isPreview( false )
90 if( SalomeApp_Application* app = (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )
91 if( SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) )
92 myNoteBook = new SalomeApp_Notebook( appStudy );
95 //================================================================
96 // Function : ~GEOMBase_Helper
98 //================================================================
99 GEOMBase_Helper::~GEOMBase_Helper()
101 if ( !SUIT_Session::session()->activeApplication()->desktop() )
104 if ( myPreview.size() )
108 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
110 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
112 globalSelection(aGeomGUI->getLocalSelectionMode() , true );
117 if ( !CORBA::is_nil( myOperation ) )
118 myOperation->Destroy();
127 //================================================================
128 // Function : display
130 //================================================================
131 void GEOMBase_Helper::display( const ObjectList& objList, const bool updateView )
133 ObjectList::const_iterator it;
134 for ( it = objList.begin(); it != objList.end(); it++ ) {
135 display( *it, false );
137 if ( !objList.empty() && updateView )
138 getDisplayer()->UpdateViewer();
141 //================================================================
142 // Function : display
143 // Purpose : Display object.
144 // Important : Object must be already in study
145 //================================================================
146 void GEOMBase_Helper::display( GEOM::GEOM_Object_ptr object, const bool updateView )
148 // Unset color of shape ( this color may be set during preview displaying )
149 // Default color will be used
150 getDisplayer()->UnsetColor();
151 getDisplayer()->UnsetWidth();
153 // 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 std::string entry = getEntry( object );
182 getDisplayer()->Erase( new SALOME_InteractiveObject(
183 entry.c_str(), "GEOM", strdup( GEOMBase::GetName( object ).toLatin1().constData() ) ), true, updateView );
187 //================================================================
188 // Function : redisplay
190 //================================================================
191 void GEOMBase_Helper::redisplay( const ObjectList& objList,
192 const bool withChildren,
193 const bool updateView )
195 ObjectList::const_iterator it = objList.begin();
196 for ( ; it != objList.end(); it++ ) {
197 redisplay( *it, withChildren, false );
199 if ( !objList.empty() && updateView )
200 getDisplayer()->UpdateViewer();
203 //================================================================
204 // Function : redisplay
206 //================================================================
207 void GEOMBase_Helper::redisplay( GEOM::GEOM_Object_ptr object,
208 const bool withChildren,
209 const bool updateView )
211 if ( !object->_is_nil() ) {
212 // Unset color of shape ( this color may be set during preview displaying )
213 // Default color will be used
214 getDisplayer()->UnsetColor();
215 getDisplayer()->UnsetWidth();
217 // Enable activisation of selection
218 getDisplayer()->SetToActivate( true );
220 std::string entry = getEntry( object );
221 getDisplayer()->Redisplay(new SALOME_InteractiveObject
222 (entry.c_str(), "GEOM", strdup(GEOMBase::GetName(object).toLatin1().constData())), false);
225 if ( withChildren ) {
226 SalomeApp_Study* aDoc = getStudy();
227 if ( aDoc && aDoc->studyDS() ) {
228 _PTR(Study) aStudy = aDoc->studyDS();
229 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string(object);
230 _PTR(SObject) aSObj (aStudy->FindObjectIOR(std::string(objStr.in())));
232 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
233 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
234 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow
235 (GeometryGUI::ClientSObjectToObject(anIt->Value()));
236 if ( !CORBA::is_nil( aChild ) ) {
237 if ( !aChild->_is_nil() ) {
238 std::string entry = getEntry( aChild );
239 getDisplayer()->Redisplay( new SALOME_InteractiveObject(
240 entry.c_str(), "GEOM", strdup( GEOMBase::GetName( aChild ).toLatin1().constData() ) ), false );
249 getDisplayer()->UpdateViewer();
252 //================================================================
253 // Function : displayPreview
254 // Purpose : Method for displaying preview based on execute() results
255 //================================================================
256 void GEOMBase_Helper::displayPreview( const bool activate,
258 const bool toRemoveFromEngine,
259 const double lineWidth,
260 const int displayMode,
265 if ( !isValid( msg ) )
267 erasePreview( update );
272 erasePreview( false );
275 SUIT_OverrideCursor wc;
277 if ( !execute( objects ) || !getOperation()->IsDone() ) {
281 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it )
283 GEOM::GEOM_Object_var obj=*it;
284 displayPreview( obj, true, activate, false, lineWidth, displayMode, color );
285 if ( toRemoveFromEngine )
290 catch( const SALOME::SALOME_Exception& e ) {
291 SalomeApp_Tools::QtCatchCorbaException( e );
300 //================================================================
301 // Function : displayPreview
302 // Purpose : Method for displaying preview of resulting shape
303 //================================================================
304 void GEOMBase_Helper::displayPreview( GEOM::GEOM_Object_ptr object,
308 const double lineWidth,
309 const int displayMode,
312 // Set color for preview shape
313 getDisplayer()->SetColor( color == -1 ? Quantity_NOC_VIOLET : color );
315 // set width of displayed shape
316 getDisplayer()->SetWidth( lineWidth );
318 // set display mode of displayed shape
319 int aPrevDispMode = getDisplayer()->SetDisplayMode( displayMode );
321 // Disable activation of selection
322 getDisplayer()->SetToActivate( activate );
324 // Make a reference to GEOM_Object
325 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string( object );
326 getDisplayer()->SetName( objStr.in() );
329 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( object );
330 if ( aPrs == 0 || aPrs->IsNull() )
334 displayPreview( aPrs, append, update );
336 getDisplayer()->UnsetName();
337 getDisplayer()->UnsetColor();
338 getDisplayer()->SetDisplayMode( aPrevDispMode );
340 // Enable activation of displayed objects
341 getDisplayer()->SetToActivate( true );
344 //================================================================
345 // Function : displayPreview
346 // Purpose : Method for displaying arbitrary preview objects (not limited to shapes)
347 //================================================================
348 void GEOMBase_Helper::displayPreview( const SALOME_Prs* prs,
353 erasePreview( false );
355 // remember current view frame to make correct erase preview later
356 myViewWindow = getActiveView();
358 if ( myViewWindow == 0 )
362 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
363 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
364 aViewManager->getType() == SVTK_Viewer::Type() )
366 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
367 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
369 aView->Display( prs );
372 // Add prs to the preview list
373 myPreview.push_back( (SALOME_Prs*)prs );
377 getDisplayer()->UpdateViewer();
380 //================================================================
381 // Function : erasePreview
383 //================================================================
384 void GEOMBase_Helper::erasePreview( const bool update )
386 // check view frame where the preview was displayed
387 bool vfOK = checkViewWindow() && myViewWindow;
388 // Iterate through presentations and delete them
389 for ( PrsList::iterator anIter = myPreview.begin(); anIter != myPreview.end(); ++anIter ) {
392 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
393 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
394 aViewManager->getType() == SVTK_Viewer::Type() )
396 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
397 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
399 aView->Erase( *anIter, true );
411 //================================================================
412 // Function : localSelection
413 // Purpose : Activate selection of objects of a given type
414 // IMPORTANT : Works after localSelection( ... ) method call only
415 //================================================================
416 void GEOMBase_Helper::activate( const int theType )
418 if (!getStudy()) return;
419 _PTR(Study) aStudy = getStudy()->studyDS();
420 _PTR(SComponent) aGeom ( aStudy->FindComponent( "GEOM" ) );
425 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( aGeom ) );
426 for ( ; anIter->More(); anIter->Next() )
428 _PTR(SObject) aSO ( anIter->Value() );
431 _PTR(SObject) aRefSO;
432 if ( !aSO->ReferencedObject( aRefSO ) )
434 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow
435 (GeometryGUI::ClientSObjectToObject(aSO));
436 if ( !anObj->_is_nil() && anObj->GetType() == theType )
437 aList.Append( new SALOME_InteractiveObject( aSO->GetID().c_str(), "GEOM", aSO->GetName().c_str()) );
442 getDisplayer()->LocalSelection( aList, 0 );
445 //================================================================
446 // Function : localSelection
447 // Purpose : Activate selection of subshapes in accordance with mode
448 // theMode is from TopAbs_ShapeEnum
449 //================================================================
450 void GEOMBase_Helper::localSelection( const ObjectList& theObjs, const int theMode )
452 SALOME_ListIO aListOfIO;
454 ObjectList::const_iterator anIter = theObjs.begin();
455 for ( ; anIter != theObjs.end(); ++anIter )
457 GEOM::GEOM_Object_ptr anObj = *anIter;
458 if ( anObj->_is_nil() )
460 std::string aEntry = getEntry( anObj );
462 aListOfIO.Append( new SALOME_InteractiveObject(
463 aEntry.c_str(), "GEOM", strdup( GEOMBase::GetName( anObj ).toLatin1().constData() ) ) );
466 getDisplayer()->LocalSelection( aListOfIO, theMode );
469 //================================================================
470 // Function : localSelection
471 // Purpose : Activate selection of subshapes in accordance with mode
472 // theMode is from TopAbs_ShapeEnum
473 //================================================================
474 void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const int mode )
476 // If object is null local selection for all objects is activated
477 if ( obj->_is_nil() ) {
478 getDisplayer()->LocalSelection( Handle(SALOME_InteractiveObject)(), mode );
483 objList.push_back( obj );
484 localSelection( objList, mode );
488 //================================================================
489 // Function : globalSelection
490 // Purpose : Activate selection of subshapes. Set selection filters
491 // in accordance with mode. theMode is from GEOMImpl_Types
492 //================================================================
493 void GEOMBase_Helper::globalSelection( const int theMode, const bool update )
495 getDisplayer()->GlobalSelection( theMode, update );
498 //================================================================
499 // Function : globalSelection
500 // Purpose : Activate selection of subshapes. Set selection filters
501 // in accordance with mode. theMode is from GEOMImpl_Types
502 //================================================================
503 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
506 getDisplayer()->GlobalSelection( theModes, update );
509 //================================================================
510 // Function : globalSelection
511 // Purpose : Activate selection of subshapes. Set selection filters
512 // in accordance with mode. theMode is from GEOMImpl_Types
513 //================================================================
514 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
515 const QList<int>& subShapes,
518 getDisplayer()->GlobalSelection( theModes, update, &subShapes );
521 //================================================================
522 // Function : addInStudy
523 // Purpose : Add object in study
524 //================================================================
525 void GEOMBase_Helper::addInStudy( GEOM::GEOM_Object_ptr theObj, const char* theName )
530 _PTR(Study) aStudy = getStudy()->studyDS();
531 if ( !aStudy || theObj->_is_nil() )
534 SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy(aStudy);
536 GEOM::GEOM_Object_ptr aFatherObj = getFather( theObj );
538 SALOMEDS::SObject_var aSO =
539 getGeomEngine()->AddInStudy(aStudyDS, theObj, theName, aFatherObj);
541 // Each dialog is responsible for this method implementation,
542 // default implementation does nothing
543 restoreSubShapes(aStudyDS, aSO);
547 //================================================================
548 // Function : restoreSubShapes
549 // Purpose : restore tree of argument's sub-shapes under the resulting shape
550 //================================================================
551 void GEOMBase_Helper::restoreSubShapes (SALOMEDS::Study_ptr /*theStudy*/,
552 SALOMEDS::SObject_ptr /*theSObject*/)
554 // do nothing by default
556 // example of implementation in particular dialog:
557 // GEOM::ListOfGO anArgs;
558 // anArgs.length(0); // empty list means that all arguments should be restored
559 // getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
560 // /*theFindMethod=*/GEOM::FSM_GetInPlace,
561 // /*theInheritFirstArg=*/false);
564 //================================================================
565 // Function : updateObjBrowser
566 // Purpose : Update object browser
567 //================================================================
568 void GEOMBase_Helper::updateObjBrowser() const
570 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
572 CAM_Module* module = app->module( "Geometry" );
573 SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
575 appMod->updateObjBrowser( true );
580 //================================================================
581 // Function : updateViewer
582 // Purpose : Update active 3D view
583 //================================================================
584 void GEOMBase_Helper::updateViewer()
586 getDisplayer()->UpdateViewer();
589 //================================================================
590 // Function : getStudyId
591 // Purpose : Get study Id
592 //================================================================
593 int GEOMBase_Helper::getStudyId() const
597 anId = getStudy()->id();
601 //================================================================
602 // Function : getStudy
603 // Purpose : Returns the active study. It is recommended to use
604 // this method instead of direct desktop->getActiveStudy() calls
605 //================================================================
606 SalomeApp_Study* GEOMBase_Helper::getStudy() const
608 SUIT_Desktop* aDesktop = getDesktop();
612 QList<SUIT_Application*> anAppList = SUIT_Session::session()->applications();
614 SUIT_Application* anApp = 0;
615 QListIterator<SUIT_Application*> it( anAppList );
616 while ( it.hasNext() )
619 if ( anApp && anApp->desktop() == aDesktop )
623 return dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
626 //================================================================
627 // Function : getEntry
629 //================================================================
630 char* GEOMBase_Helper::getEntry( GEOM::GEOM_Object_ptr object ) const
632 SalomeApp_Study* study = getStudy();
634 char * objIOR = GEOMBase::GetIORFromObject( object );
635 std::string IOR( objIOR );
638 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
640 return (char*) TCollection_AsciiString((char*)SO->GetID().c_str()).ToCString();
647 //================================================================
648 // Function : getDisplayer
650 //================================================================
651 GEOM_Displayer* GEOMBase_Helper::getDisplayer()
654 myDisplayer = new GEOM_Displayer( getStudy() );
658 //================================================================
659 // Function : clearShapeBuffer
661 //================================================================
662 void GEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
664 if ( CORBA::is_nil( theObj ) )
667 CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( theObj );
668 TCollection_AsciiString asciiIOR( (char *)IOR.in() );
669 GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
671 if ( !getStudy() || !getStudy()->studyDS() )
674 _PTR(Study) aStudy = getStudy()->studyDS();
675 _PTR(SObject) aSObj ( aStudy->FindObjectIOR( std::string( IOR ) ) );
679 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
680 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
681 _PTR(GenericAttribute) anAttr;
682 if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
683 _PTR(AttributeIOR) anIOR ( anAttr );
684 TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
685 GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
690 //================================================================
691 // Function : openCommand
693 //================================================================
694 bool GEOMBase_Helper::openCommand()
697 if ( !getStudy() || hasCommand() )
700 GEOM::GEOM_IOperations_var anOp = GEOM::GEOM_IOperations::_narrow( getOperation() );
701 if ( !anOp->_is_nil() ) {
702 myCommand = new GEOM_Operation( SUIT_Session::session()->activeApplication(), anOp.in() );
710 //================================================================
711 // Function : abortCommand
713 //================================================================
714 bool GEOMBase_Helper::abortCommand()
720 delete myCommand; // I don't know where to delete this object here ?
726 //================================================================
727 // Function : commitCommand
729 //================================================================
730 bool GEOMBase_Helper::commitCommand( const char* )
736 delete myCommand; // I don't know where to delete this object here ?
742 //================================================================
743 // Function : hasCommand
745 //================================================================
746 bool GEOMBase_Helper::hasCommand() const
748 return (bool)myCommand;
751 //================================================================
752 // Function : getOperation
754 //================================================================
755 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::getOperation()
757 if ( myOperation->_is_nil() )
758 myOperation = createOperation();
765 //================================================================
766 // Function : checkViewWindow
768 //================================================================
769 bool GEOMBase_Helper::checkViewWindow()
772 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
773 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
774 while ( it.hasNext() )
776 if ( myViewWindow == it.next() )
784 //================================================================
785 // Function : onAccept
786 // Purpose : This method should be called from dialog's slots onOk() and onApply()
787 // It perfroms user input validation, then it
788 // performs a proper operation and manages transactions, etc.
789 //================================================================
790 bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction )
792 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
793 if ( !appStudy ) return false;
794 _PTR(Study) aStudy = appStudy->studyDS();
796 bool aLocked = (_PTR(AttributeStudyProperties) (aStudy->GetProperties()))->IsLocked();
798 MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
799 SUIT_MessageBox::warning ( (QWidget*)SUIT_Session::session()->activeApplication()->desktop(),
800 QObject::tr("WRN_WARNING"),
801 QObject::tr("WRN_STUDY_LOCKED"),
802 QObject::tr("BUT_OK") );
807 if ( !isValid( msg ) ) {
812 erasePreview( false );
815 if ( ( !publish && !useTransaction ) || openCommand() ) {
816 SUIT_OverrideCursor wc;
817 SUIT_Session::session()->activeApplication()->putInfo( "" );
819 if ( !execute( objects ) || !getOperation()->IsDone() ) {
825 addSubshapesToStudy(); // add Subshapes if local selection
826 const int nbObjs = objects.size();
828 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
829 GEOM::GEOM_Object_var obj=*it;
831 QString aName = getNewObjectName();
834 aName = getPrefix(obj);
836 // Try to find a unique name
837 aName = GEOMBase::GetDefaultName(aName);
839 // Don't check name uniqueness in case of numerous objects
840 aName = aName + "_" + QString::number(aNumber++);
843 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
844 if ( aName.isEmpty() )
845 aName = GEOMBase::GetDefaultName( getPrefix( obj ) );
847 addInStudy( obj, aName.toLatin1().constData() );
849 display( obj, false );
850 #ifdef WITHGENERICOBJ
851 // obj has been published in study. Its refcount has been incremented.
852 // It is safe to decrement its refcount
853 // so that it will be destroyed when the entry in study will be removed
858 // asv : fix of PAL6454. If publish==false, then the original shape
859 // was modified, and need to be re-cached in GEOM_Client before redisplay
860 clearShapeBuffer( obj );
861 // withChildren=true, updateView=false
862 redisplay( obj, true, false );
869 SUIT_Session::session()->activeApplication()->putInfo( QObject::tr("GEOM_PRP_DONE") );
876 catch( const SALOME::SALOME_Exception& e ) {
877 SalomeApp_Tools::QtCatchCorbaException( e );
887 //================================================================
888 // Function : showError
889 // Purpose : Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
890 //================================================================
891 void GEOMBase_Helper::showError()
894 if ( !getOperation()->_is_nil() )
895 msg = QObject::tr( getOperation()->GetErrorCode() );
898 msg = QObject::tr( "GEOM_PRP_ABORT" );
900 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
901 QObject::tr( "GEOM_ERROR_STATUS" ),
903 QObject::tr( "BUT_OK" ) );
906 //================================================================
907 // Function : showError
908 // Purpose : Shows a error message followed by <msg>
909 //================================================================
910 void GEOMBase_Helper::showError( const QString& msg )
912 QString str( QObject::tr( "GEOM_INCORRECT_INPUT" ) );
913 if ( !msg.isEmpty() )
915 SUIT_MessageBox::critical(SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ), str, QObject::tr( "BUT_OK" ) );
918 //////////////////////////////////////////////////////////////////
919 // Virtual methods to be redefined in dialogs
920 //////////////////////////////////////////////////////////////////
922 //================================================================
923 // Function : createOperation
924 // Purpose : Redefine this method to return proper IOperation reference
925 //================================================================
926 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::createOperation()
928 GEOM::GEOM_IOperations_var aNilOp;
929 return aNilOp._retn();
932 //================================================================
933 // Function : isValid
934 // Purpose : Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
935 //================================================================
936 bool GEOMBase_Helper::isValid( QString& )
941 //================================================================
942 // Function : execute
943 // Purpose : This method is called by onAccept().
944 // It should perform the required operation and put all new or modified objects into
945 // <objects> argument.Should return <false> if some error occurs during its execution.
946 //================================================================
947 bool GEOMBase_Helper::execute( ObjectList& objects )
952 //================================================================
953 // Function : getFather
954 // Purpose : This method is called by addInStudy(). It should return a father object
955 // for <theObj> or a nil reference if <theObj> should be published
956 // as a top-level object.
957 //================================================================
958 GEOM::GEOM_Object_ptr GEOMBase_Helper::getFather( GEOM::GEOM_Object_ptr theObj )
960 return GEOM::GEOM_Object::_nil();
963 //================================================================
964 // Function : getNewObjectName
965 // Purpose : Redefine this method to return proper name for a new object
966 //================================================================
967 QString GEOMBase_Helper::getNewObjectName() const
969 return QString::null;
972 //================================================================
973 // Function : getPrefix
974 // Purpose : Get prefix for name of created object
975 //================================================================
976 QString GEOMBase_Helper::getPrefix( GEOM::GEOM_Object_ptr theObj ) const
978 if ( !myPrefix.isEmpty() || theObj->_is_nil() )
981 //TopoDS_Shape aShape;
982 //if ( !GEOMBase::GetShape( theObj, aShape ) )
985 //long aType = aShape.ShapeType();
986 GEOM::shape_type aType = theObj->GetShapeType();
990 case GEOM::VERTEX : return QObject::tr( "GEOM_VERTEX" );
991 case GEOM::EDGE : return QObject::tr( "GEOM_EDGE" );
992 case GEOM::WIRE : return QObject::tr( "GEOM_WIRE" );
993 case GEOM::FACE : return QObject::tr( "GEOM_FACE" );
994 case GEOM::SHELL : return QObject::tr( "GEOM_SHELL" );
995 case GEOM::SOLID : return QObject::tr( "GEOM_SOLID" );
996 case GEOM::COMPSOLID: return QObject::tr( "GEOM_COMPOUNDSOLID" );
997 case GEOM::COMPOUND : return QObject::tr( "GEOM_COMPOUND" );
1002 //================================================================
1003 // Function : getDesktop
1004 // Purpose : Returns myDesktop field. Initialized in constructor,
1005 // usually as dynamic_cast<SUIT_Desktop*>(parentWidget())
1006 //================================================================
1007 SUIT_Desktop* GEOMBase_Helper::getDesktop() const
1012 //================================================================
1013 // Function : selectObjects
1014 // Purpose : Selects list of objects
1015 //================================================================
1016 bool GEOMBase_Helper::selectObjects( ObjectList& objects )
1018 SUIT_DataOwnerPtrList aList;
1019 ObjectList::iterator anIter;
1020 for ( anIter = objects.begin(); anIter != objects.end(); ++anIter )
1022 std::string entry = getEntry( *anIter );
1023 QString aEntry( entry.c_str() );
1024 LightApp_DataOwner* anOwher = new LightApp_DataOwner( aEntry );
1025 aList.append( anOwher );
1028 SUIT_Session* session = SUIT_Session::session();
1029 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1033 LightApp_SelectionMgr* aMgr = app->selectionMgr();
1037 aMgr->setSelected( aList, false );
1042 //================================================================
1043 // Function : findObjectInFather
1044 // Purpose : It should return an object if its founded in study or
1045 // return Null object if the object is not founded
1046 //================================================================
1047 GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather (GEOM::GEOM_Object_ptr theFather,
1048 const QString& theName)
1050 SalomeApp_Application* app =
1051 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1052 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1053 _PTR(Study) aDStudy = appStudy->studyDS();
1054 std::string IOR = GEOMBase::GetIORFromObject( theFather );
1055 _PTR(SObject) SObj ( aDStudy->FindObjectIOR( IOR ) );
1057 bool inStudy = false;
1058 GEOM::GEOM_Object_var aReturnObject;
1059 for (_PTR(ChildIterator) iit (aDStudy->NewChildIterator( SObj )); iit->More() && !inStudy; iit->Next()) {
1060 _PTR(SObject) child (iit->Value());
1061 QString aChildName = child->GetName().c_str();
1062 if (aChildName == theName) {
1064 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(iit->Value());
1065 aReturnObject = GEOM::GEOM_Object::_narrow( corbaObj );
1069 return aReturnObject._retn();
1071 return GEOM::GEOM_Object::_nil();
1074 //================================================================
1075 // Function : addSubshapesToStudy
1076 // Purpose : Virtual method to add subshapes if needs
1077 //================================================================
1078 void GEOMBase_Helper::addSubshapesToStudy()
1080 //Impemented in Dialogs, called from Accept method
1083 //================================================================
1084 // Function : addSubshapesToFather
1085 // Purpose : Method to add Father Subshapes to Study if it`s not exist
1086 //================================================================
1087 void GEOMBase_Helper::addSubshapesToFather( QMap<QString, GEOM::GEOM_Object_var>& theMap )
1090 SalomeApp_Application* app =
1091 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1092 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1093 _PTR(Study) aDStudy = appStudy->studyDS();
1095 GEOM::GEOM_IGroupOperations_var anOp = getGeomEngine()->GetIGroupOperations( getStudyId() );
1097 for( QMap<QString, GEOM::GEOM_Object_var>::Iterator it = theMap.begin(); it != theMap.end(); it++ )
1099 if ( !anOp->_is_nil() ) {
1100 GEOM::GEOM_Object_var aFatherObj = anOp->GetMainShape( it.value() );
1101 if ( !aFatherObj->_is_nil() ) {
1102 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aFatherObj, it.key().toLatin1().data() );
1104 //Add Object to study if its not exist
1105 if ( aFindedObject == GEOM::GEOM_Object::_nil() )
1106 GeometryGUI::GetGeomGen()->AddInStudy(GeometryGUI::ClientStudyToStudy(aDStudy),
1107 it.value(), it.key().toLatin1().data(), aFatherObj );
1111 //cout << " anOperations is NULL! " << endl;