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 if ( !SUIT_Session::session()->activeApplication()->desktop() )
101 if ( myPreview.size() )
105 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
107 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
109 globalSelection(aGeomGUI->getLocalSelectionMode() , true );
114 if ( !CORBA::is_nil( myOperation ) )
115 myOperation->Destroy();
118 //================================================================
119 // Function : display
121 //================================================================
122 void GEOMBase_Helper::display( const ObjectList& objList, const bool updateView )
124 ObjectList::const_iterator it;
125 for ( it = objList.begin(); it != objList.end(); it++ ) {
126 display( *it, false );
128 if ( !objList.empty() && updateView )
129 getDisplayer()->UpdateViewer();
132 //================================================================
133 // Function : display
134 // Purpose : Display object.
135 // Important : Object must be already in study
136 //================================================================
137 void GEOMBase_Helper::display( GEOM::GEOM_Object_ptr object, const bool updateView )
139 // Unset color of shape ( this color may be set during preview displaying )
140 // Default color will be used
141 getDisplayer()->UnsetColor();
142 getDisplayer()->UnsetWidth();
144 // Enable activisation of selection
145 getDisplayer()->SetToActivate( true );
148 getDisplayer()->Display( object, updateView );
151 //================================================================
154 //================================================================
155 void GEOMBase_Helper::erase( const ObjectList& objList, const bool updateView )
157 ObjectList::const_iterator it = objList.begin();
158 for ( ; it != objList.end(); it++ ) {
161 if ( !objList.empty() && updateView )
162 getDisplayer()->UpdateViewer();
165 //================================================================
168 //================================================================
169 void GEOMBase_Helper::erase( GEOM::GEOM_Object_ptr object, const bool updateView )
171 if ( !object->_is_nil() ) {
172 std::string entry = getEntry( object );
173 getDisplayer()->Erase( new SALOME_InteractiveObject(
174 entry.c_str(), "GEOM", strdup( GEOMBase::GetName( object ).toLatin1().constData() ) ), true, updateView );
178 //================================================================
179 // Function : redisplay
181 //================================================================
182 void GEOMBase_Helper::redisplay( const ObjectList& objList,
183 const bool withChildren,
184 const bool updateView )
186 ObjectList::const_iterator it = objList.begin();
187 for ( ; it != objList.end(); it++ ) {
188 redisplay( *it, withChildren, false );
190 if ( !objList.empty() && updateView )
191 getDisplayer()->UpdateViewer();
194 //================================================================
195 // Function : redisplay
197 //================================================================
198 void GEOMBase_Helper::redisplay( GEOM::GEOM_Object_ptr object,
199 const bool withChildren,
200 const bool updateView )
202 if ( !object->_is_nil() ) {
203 // Unset color of shape ( this color may be set during preview displaying )
204 // Default color will be used
205 getDisplayer()->UnsetColor();
206 getDisplayer()->UnsetWidth();
208 // Enable activisation of selection
209 getDisplayer()->SetToActivate( true );
211 std::string entry = getEntry( object );
212 getDisplayer()->Redisplay(new SALOME_InteractiveObject
213 (entry.c_str(), "GEOM", strdup(GEOMBase::GetName(object).toLatin1().constData())), false);
216 if ( withChildren ) {
217 SalomeApp_Study* aDoc = getStudy();
218 if ( aDoc && aDoc->studyDS() ) {
219 _PTR(Study) aStudy = aDoc->studyDS();
220 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string(object);
221 _PTR(SObject) aSObj (aStudy->FindObjectIOR(std::string(objStr.in())));
223 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
224 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
225 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow
226 (GeometryGUI::ClientSObjectToObject(anIt->Value()));
227 if ( !CORBA::is_nil( aChild ) ) {
228 if ( !aChild->_is_nil() ) {
229 std::string entry = getEntry( aChild );
230 getDisplayer()->Redisplay( new SALOME_InteractiveObject(
231 entry.c_str(), "GEOM", strdup( GEOMBase::GetName( aChild ).toLatin1().constData() ) ), false );
240 getDisplayer()->UpdateViewer();
243 //================================================================
244 // Function : displayPreview
245 // Purpose : Method for displaying preview based on execute() results
246 //================================================================
247 void GEOMBase_Helper::displayPreview( const bool activate,
249 const bool toRemoveFromEngine,
250 const double lineWidth,
251 const int displayMode,
256 if ( !isValid( msg ) )
258 erasePreview( update );
263 erasePreview( false );
266 SUIT_OverrideCursor wc;
268 if ( !execute( objects ) || !getOperation()->IsDone() ) {
272 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it )
274 GEOM::GEOM_Object_var obj=*it;
275 displayPreview( obj, true, activate, false, lineWidth, displayMode, color );
276 if ( toRemoveFromEngine )
281 catch( const SALOME::SALOME_Exception& e ) {
282 SalomeApp_Tools::QtCatchCorbaException( e );
291 //================================================================
292 // Function : displayPreview
293 // Purpose : Method for displaying preview of resulting shape
294 //================================================================
295 void GEOMBase_Helper::displayPreview( GEOM::GEOM_Object_ptr object,
299 const double lineWidth,
300 const int displayMode,
303 // Set color for preview shape
304 getDisplayer()->SetColor( color == -1 ? Quantity_NOC_VIOLET : color );
306 // set width of displayed shape
307 getDisplayer()->SetWidth( lineWidth );
309 // set display mode of displayed shape
310 int aPrevDispMode = getDisplayer()->SetDisplayMode( displayMode );
312 // Disable activation of selection
313 getDisplayer()->SetToActivate( activate );
315 // Make a reference to GEOM_Object
316 CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string( object );
317 getDisplayer()->SetName( objStr.in() );
320 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( object );
321 if ( aPrs == 0 || aPrs->IsNull() )
325 displayPreview( aPrs, append, update );
327 getDisplayer()->UnsetName();
328 getDisplayer()->UnsetColor();
329 getDisplayer()->SetDisplayMode( aPrevDispMode );
331 // Enable activation of displayed objects
332 getDisplayer()->SetToActivate( true );
335 //================================================================
336 // Function : displayPreview
337 // Purpose : Method for displaying arbitrary preview objects (not limited to shapes)
338 //================================================================
339 void GEOMBase_Helper::displayPreview( const SALOME_Prs* prs,
344 erasePreview( false );
346 // remember current view frame to make correct erase preview later
347 myViewWindow = getActiveView();
349 if ( myViewWindow == 0 )
353 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
354 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
355 aViewManager->getType() == SVTK_Viewer::Type() )
357 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
358 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
360 aView->Display( prs );
363 // Add prs to the preview list
364 myPreview.push_back( (SALOME_Prs*)prs );
368 getDisplayer()->UpdateViewer();
371 //================================================================
372 // Function : erasePreview
374 //================================================================
375 void GEOMBase_Helper::erasePreview( const bool update )
377 // check view frame where the preview was displayed
378 bool vfOK = checkViewWindow() && myViewWindow;
379 // Iterate through presentations and delete them
380 for ( PrsList::iterator anIter = myPreview.begin(); anIter != myPreview.end(); ++anIter ) {
383 SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
384 if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
385 aViewManager->getType() == SVTK_Viewer::Type() )
387 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
388 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
390 aView->Erase( *anIter, true );
402 //================================================================
403 // Function : localSelection
404 // Purpose : Activate selection of objects of a given type
405 // IMPORTANT : Works after localSelection( ... ) method call only
406 //================================================================
407 void GEOMBase_Helper::activate( const int theType )
409 if (!getStudy()) return;
410 _PTR(Study) aStudy = getStudy()->studyDS();
411 _PTR(SComponent) aGeom ( aStudy->FindComponent( "GEOM" ) );
416 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( aGeom ) );
417 for ( ; anIter->More(); anIter->Next() )
419 _PTR(SObject) aSO ( anIter->Value() );
422 _PTR(SObject) aRefSO;
423 if ( !aSO->ReferencedObject( aRefSO ) )
425 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow
426 (GeometryGUI::ClientSObjectToObject(aSO));
427 if ( !anObj->_is_nil() && anObj->GetType() == theType )
428 aList.Append( new SALOME_InteractiveObject( aSO->GetID().c_str(), "GEOM", aSO->GetName().c_str()) );
433 getDisplayer()->LocalSelection( aList, 0 );
436 //================================================================
437 // Function : localSelection
438 // Purpose : Activate selection of subshapes in accordance with mode
439 // theMode is from TopAbs_ShapeEnum
440 //================================================================
441 void GEOMBase_Helper::localSelection( const ObjectList& theObjs, const int theMode )
443 SALOME_ListIO aListOfIO;
445 ObjectList::const_iterator anIter = theObjs.begin();
446 for ( ; anIter != theObjs.end(); ++anIter )
448 GEOM::GEOM_Object_ptr anObj = *anIter;
449 if ( anObj->_is_nil() )
451 std::string aEntry = getEntry( anObj );
453 aListOfIO.Append( new SALOME_InteractiveObject(
454 aEntry.c_str(), "GEOM", strdup( GEOMBase::GetName( anObj ).toLatin1().constData() ) ) );
457 getDisplayer()->LocalSelection( aListOfIO, theMode );
460 //================================================================
461 // Function : localSelection
462 // Purpose : Activate selection of subshapes in accordance with mode
463 // theMode is from TopAbs_ShapeEnum
464 //================================================================
465 void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const int mode )
467 // If object is null local selection for all objects is activated
468 if ( obj->_is_nil() ) {
469 getDisplayer()->LocalSelection( Handle(SALOME_InteractiveObject)(), mode );
474 objList.push_back( obj );
475 localSelection( objList, mode );
479 //================================================================
480 // Function : globalSelection
481 // Purpose : Activate selection of subshapes. Set selection filters
482 // in accordance with mode. theMode is from GEOMImpl_Types
483 //================================================================
484 void GEOMBase_Helper::globalSelection( const int theMode, const bool update )
486 getDisplayer()->GlobalSelection( theMode, update );
489 //================================================================
490 // Function : globalSelection
491 // Purpose : Activate selection of subshapes. Set selection filters
492 // in accordance with mode. theMode is from GEOMImpl_Types
493 //================================================================
494 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
497 getDisplayer()->GlobalSelection( theModes, update );
500 //================================================================
501 // Function : globalSelection
502 // Purpose : Activate selection of subshapes. Set selection filters
503 // in accordance with mode. theMode is from GEOMImpl_Types
504 //================================================================
505 void GEOMBase_Helper::globalSelection( const TColStd_MapOfInteger& theModes,
506 const QList<int>& subShapes,
509 getDisplayer()->GlobalSelection( theModes, update, &subShapes );
512 //================================================================
513 // Function : addInStudy
514 // Purpose : Add object in study
515 //================================================================
516 void GEOMBase_Helper::addInStudy( GEOM::GEOM_Object_ptr theObj, const char* theName )
521 _PTR(Study) aStudy = getStudy()->studyDS();
522 if ( !aStudy || theObj->_is_nil() )
525 SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy(aStudy);
527 GEOM::GEOM_Object_ptr aFatherObj = getFather( theObj );
529 SALOMEDS::SObject_var aSO =
530 getGeomEngine()->AddInStudy(aStudyDS, theObj, theName, aFatherObj);
532 // Each dialog is responsible for this method implementation,
533 // default implementation does nothing
534 restoreSubShapes(aStudyDS, aSO);
538 //================================================================
539 // Function : restoreSubShapes
540 // Purpose : restore tree of argument's sub-shapes under the resulting shape
541 //================================================================
542 void GEOMBase_Helper::restoreSubShapes (SALOMEDS::Study_ptr /*theStudy*/,
543 SALOMEDS::SObject_ptr /*theSObject*/)
545 // do nothing by default
547 // example of implementation in particular dialog:
548 // GEOM::ListOfGO anArgs;
549 // anArgs.length(0); // empty list means that all arguments should be restored
550 // getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
551 // /*theFindMethod=*/GEOM::FSM_GetInPlace,
552 // /*theInheritFirstArg=*/false);
555 //================================================================
556 // Function : updateObjBrowser
557 // Purpose : Update object browser
558 //================================================================
559 void GEOMBase_Helper::updateObjBrowser() const
561 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
563 CAM_Module* module = app->module( "Geometry" );
564 SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>( module );
566 appMod->updateObjBrowser( true );
571 //================================================================
572 // Function : updateViewer
573 // Purpose : Update active 3D view
574 //================================================================
575 void GEOMBase_Helper::updateViewer()
577 getDisplayer()->UpdateViewer();
580 //================================================================
581 // Function : getStudyId
582 // Purpose : Get study Id
583 //================================================================
584 int GEOMBase_Helper::getStudyId() const
588 anId = getStudy()->id();
592 //================================================================
593 // Function : getStudy
594 // Purpose : Returns the active study. It is recommended to use
595 // this method instead of direct desktop->getActiveStudy() calls
596 //================================================================
597 SalomeApp_Study* GEOMBase_Helper::getStudy() const
599 SUIT_Desktop* aDesktop = getDesktop();
603 QList<SUIT_Application*> anAppList = SUIT_Session::session()->applications();
605 SUIT_Application* anApp = 0;
606 QListIterator<SUIT_Application*> it( anAppList );
607 while ( it.hasNext() )
610 if ( anApp && anApp->desktop() == aDesktop )
614 return dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
617 //================================================================
618 // Function : getEntry
620 //================================================================
621 char* GEOMBase_Helper::getEntry( GEOM::GEOM_Object_ptr object ) const
623 SalomeApp_Study* study = getStudy();
625 char * objIOR = GEOMBase::GetIORFromObject( object );
626 std::string IOR( objIOR );
629 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
631 return (char*) TCollection_AsciiString((char*)SO->GetID().c_str()).ToCString();
638 //================================================================
639 // Function : getDisplayer
641 //================================================================
642 GEOM_Displayer* GEOMBase_Helper::getDisplayer()
645 myDisplayer = new GEOM_Displayer( getStudy() );
649 //================================================================
650 // Function : clearShapeBuffer
652 //================================================================
653 void GEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
655 if ( CORBA::is_nil( theObj ) )
658 CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( theObj );
659 TCollection_AsciiString asciiIOR( (char *)IOR.in() );
660 GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
662 if ( !getStudy() || !getStudy()->studyDS() )
665 _PTR(Study) aStudy = getStudy()->studyDS();
666 _PTR(SObject) aSObj ( aStudy->FindObjectIOR( std::string( IOR ) ) );
670 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
671 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
672 _PTR(GenericAttribute) anAttr;
673 if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
674 _PTR(AttributeIOR) anIOR ( anAttr );
675 TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
676 GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
681 //================================================================
682 // Function : openCommand
684 //================================================================
685 bool GEOMBase_Helper::openCommand()
688 if ( !getStudy() || hasCommand() )
691 GEOM::GEOM_IOperations_var anOp = GEOM::GEOM_IOperations::_narrow( getOperation() );
692 if ( !anOp->_is_nil() ) {
693 myCommand = new GEOM_Operation( SUIT_Session::session()->activeApplication(), anOp.in() );
701 //================================================================
702 // Function : abortCommand
704 //================================================================
705 bool GEOMBase_Helper::abortCommand()
711 delete myCommand; // I don't know where to delete this object here ?
717 //================================================================
718 // Function : commitCommand
720 //================================================================
721 bool GEOMBase_Helper::commitCommand( const char* )
727 delete myCommand; // I don't know where to delete this object here ?
733 //================================================================
734 // Function : hasCommand
736 //================================================================
737 bool GEOMBase_Helper::hasCommand() const
739 return (bool)myCommand;
742 //================================================================
743 // Function : getOperation
745 //================================================================
746 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::getOperation()
748 if ( myOperation->_is_nil() )
749 myOperation = createOperation();
756 //================================================================
757 // Function : checkViewWindow
759 //================================================================
760 bool GEOMBase_Helper::checkViewWindow()
763 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
764 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
765 while ( it.hasNext() )
767 if ( myViewWindow == it.next() )
775 //================================================================
776 // Function : onAccept
777 // Purpose : This method should be called from dialog's slots onOk() and onApply()
778 // It perfroms user input validation, then it
779 // performs a proper operation and manages transactions, etc.
780 //================================================================
781 bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction )
783 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
784 if ( !appStudy ) return false;
785 _PTR(Study) aStudy = appStudy->studyDS();
787 bool aLocked = (_PTR(AttributeStudyProperties) (aStudy->GetProperties()))->IsLocked();
789 MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
790 SUIT_MessageBox::warning ( (QWidget*)SUIT_Session::session()->activeApplication()->desktop(),
791 QObject::tr("WRN_WARNING"),
792 QObject::tr("WRN_STUDY_LOCKED"),
793 QObject::tr("BUT_OK") );
798 if ( !isValid( msg ) ) {
803 erasePreview( false );
808 if ( ( !publish && !useTransaction ) || openCommand() ) {
809 SUIT_OverrideCursor wc;
810 SUIT_Session::session()->activeApplication()->putInfo( "" );
812 if ( !execute( objects ) || !getOperation()->IsDone() ) {
818 addSubshapesToStudy(); // add Subshapes if local selection
819 const int nbObjs = objects.size();
821 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
822 GEOM::GEOM_Object_var obj=*it;
824 QString aName = getNewObjectName();
827 aName = getPrefix(obj);
829 // Try to find a unique name
830 aName = GEOMBase::GetDefaultName(aName, extractPrefix());
832 // Don't check name uniqueness in case of numerous objects
833 aName = aName + "_" + QString::number(aNumber++);
836 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
837 if ( aName.isEmpty() )
838 aName = GEOMBase::GetDefaultName( getPrefix( obj ) );
840 addInStudy( obj, aName.toLatin1().constData() );
842 display( obj, false );
843 #ifdef WITHGENERICOBJ
844 // obj has been published in study. Its refcount has been incremented.
845 // It is safe to decrement its refcount
846 // so that it will be destroyed when the entry in study will be removed
851 // asv : fix of PAL6454. If publish==false, then the original shape
852 // was modified, and need to be re-cached in GEOM_Client before redisplay
853 clearShapeBuffer( obj );
854 // withChildren=true, updateView=false
855 redisplay( obj, true, false );
862 SUIT_Session::session()->activeApplication()->putInfo( QObject::tr("GEOM_PRP_DONE") );
870 catch( const SALOME::SALOME_Exception& e ) {
871 SalomeApp_Tools::QtCatchCorbaException( e );
881 //================================================================
882 // Function : showError
883 // Purpose : Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
884 //================================================================
885 void GEOMBase_Helper::showError()
888 if ( !getOperation()->_is_nil() )
889 msg = QObject::tr( getOperation()->GetErrorCode() );
892 msg = QObject::tr( "GEOM_PRP_ABORT" );
894 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
895 QObject::tr( "GEOM_ERROR_STATUS" ),
897 QObject::tr( "BUT_OK" ) );
900 //================================================================
901 // Function : showError
902 // Purpose : Shows a error message followed by <msg>
903 //================================================================
904 void GEOMBase_Helper::showError( const QString& msg )
906 QString str( QObject::tr( "GEOM_INCORRECT_INPUT" ) );
907 if ( !msg.isEmpty() )
909 SUIT_MessageBox::critical(SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ), str, QObject::tr( "BUT_OK" ) );
912 //////////////////////////////////////////////////////////////////
913 // Virtual methods to be redefined in dialogs
914 //////////////////////////////////////////////////////////////////
916 //================================================================
917 // Function : createOperation
918 // Purpose : Redefine this method to return proper IOperation reference
919 //================================================================
920 GEOM::GEOM_IOperations_ptr GEOMBase_Helper::createOperation()
922 GEOM::GEOM_IOperations_var aNilOp;
923 return aNilOp._retn();
926 //================================================================
927 // Function : isValid
928 // Purpose : Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
929 //================================================================
930 bool GEOMBase_Helper::isValid( QString& )
935 //================================================================
936 // Function : execute
937 // Purpose : This method is called by onAccept().
938 // It should perform the required operation and put all new or modified objects into
939 // <objects> argument.Should return <false> if some error occurs during its execution.
940 //================================================================
941 bool GEOMBase_Helper::execute( ObjectList& objects )
946 //================================================================
947 // Function : getFather
948 // Purpose : This method is called by addInStudy(). It should return a father object
949 // for <theObj> or a nil reference if <theObj> should be published
950 // as a top-level object.
951 //================================================================
952 GEOM::GEOM_Object_ptr GEOMBase_Helper::getFather( GEOM::GEOM_Object_ptr theObj )
954 return GEOM::GEOM_Object::_nil();
957 //================================================================
958 // Function : getNewObjectName
959 // Purpose : Redefine this method to return proper name for a new object
960 //================================================================
961 QString GEOMBase_Helper::getNewObjectName() const
963 return QString::null;
966 //================================================================
967 // Function : extractPrefix
968 // Purpose : Redefine this method to return \c true if necessary
969 // to extract prefix when generating new name for the
970 // object(s) being created
971 //================================================================
972 bool GEOMBase_Helper::extractPrefix() const
977 //================================================================
978 // Function : getPrefix
979 // Purpose : Get prefix for name of created object
980 //================================================================
981 QString GEOMBase_Helper::getPrefix( GEOM::GEOM_Object_ptr theObj ) const
983 if ( !myPrefix.isEmpty() || theObj->_is_nil() )
986 //TopoDS_Shape aShape;
987 //if ( !GEOMBase::GetShape( theObj, aShape ) )
990 //long aType = aShape.ShapeType();
991 GEOM::shape_type aType = theObj->GetShapeType();
995 case GEOM::VERTEX : return QObject::tr( "GEOM_VERTEX" );
996 case GEOM::EDGE : return QObject::tr( "GEOM_EDGE" );
997 case GEOM::WIRE : return QObject::tr( "GEOM_WIRE" );
998 case GEOM::FACE : return QObject::tr( "GEOM_FACE" );
999 case GEOM::SHELL : return QObject::tr( "GEOM_SHELL" );
1000 case GEOM::SOLID : return QObject::tr( "GEOM_SOLID" );
1001 case GEOM::COMPSOLID: return QObject::tr( "GEOM_COMPOUNDSOLID" );
1002 case GEOM::COMPOUND : return QObject::tr( "GEOM_COMPOUND" );
1003 default : return "";
1007 //================================================================
1008 // Function : getDesktop
1009 // Purpose : Returns myDesktop field. Initialized in constructor,
1010 // usually as dynamic_cast<SUIT_Desktop*>(parentWidget())
1011 //================================================================
1012 SUIT_Desktop* GEOMBase_Helper::getDesktop() const
1017 //================================================================
1018 // Function : selectObjects
1019 // Purpose : Selects list of objects
1020 //================================================================
1021 bool GEOMBase_Helper::selectObjects( ObjectList& objects )
1023 SUIT_DataOwnerPtrList aList;
1024 ObjectList::iterator anIter;
1025 for ( anIter = objects.begin(); anIter != objects.end(); ++anIter )
1027 std::string entry = getEntry( *anIter );
1028 QString aEntry( entry.c_str() );
1029 LightApp_DataOwner* anOwher = new LightApp_DataOwner( aEntry );
1030 aList.append( anOwher );
1033 SUIT_Session* session = SUIT_Session::session();
1034 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1038 LightApp_SelectionMgr* aMgr = app->selectionMgr();
1042 aMgr->setSelected( aList, false );
1047 //================================================================
1048 // Function : findObjectInFather
1049 // Purpose : It should return an object if its founded in study or
1050 // return Null object if the object is not founded
1051 //================================================================
1052 GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather (GEOM::GEOM_Object_ptr theFather,
1053 const QString& theName)
1055 SalomeApp_Application* app =
1056 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1057 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1058 _PTR(Study) aDStudy = appStudy->studyDS();
1059 std::string IOR = GEOMBase::GetIORFromObject( theFather );
1060 _PTR(SObject) SObj ( aDStudy->FindObjectIOR( IOR ) );
1062 bool inStudy = false;
1063 GEOM::GEOM_Object_var aReturnObject;
1064 for (_PTR(ChildIterator) iit (aDStudy->NewChildIterator( SObj )); iit->More() && !inStudy; iit->Next()) {
1065 _PTR(SObject) child (iit->Value());
1066 QString aChildName = child->GetName().c_str();
1067 if (aChildName == theName) {
1069 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(iit->Value());
1070 aReturnObject = GEOM::GEOM_Object::_narrow( corbaObj );
1074 return aReturnObject._retn();
1076 return GEOM::GEOM_Object::_nil();
1079 //================================================================
1080 // Function : addSubshapesToStudy
1081 // Purpose : Virtual method to add subshapes if needs
1082 //================================================================
1083 void GEOMBase_Helper::addSubshapesToStudy()
1085 //Impemented in Dialogs, called from Accept method
1088 //================================================================
1089 // Function : addSubshapesToFather
1090 // Purpose : Method to add Father Subshapes to Study if it`s not exist
1091 //================================================================
1092 void GEOMBase_Helper::addSubshapesToFather( QMap<QString, GEOM::GEOM_Object_var>& theMap )
1095 SalomeApp_Application* app =
1096 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
1097 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1098 _PTR(Study) aDStudy = appStudy->studyDS();
1100 GEOM::GEOM_IGroupOperations_var anOp = getGeomEngine()->GetIGroupOperations( getStudyId() );
1102 for( QMap<QString, GEOM::GEOM_Object_var>::Iterator it = theMap.begin(); it != theMap.end(); it++ ) {
1103 if ( !anOp->_is_nil() ) {
1104 GEOM::GEOM_Object_var aFatherObj = anOp->GetMainShape( it.value() );
1105 if ( !aFatherObj->_is_nil() ) {
1106 std::string aFatherEntry = getEntry( aFatherObj );
1107 if ( aFatherEntry != "") { // additional checking that object is valid 0020598 EDF 1191
1108 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aFatherObj, it.key().toLatin1().data() );
1109 //Add Object to study if its not exist
1110 if ( aFindedObject == GEOM::GEOM_Object::_nil() )
1111 GeometryGUI::GetGeomGen()->AddInStudy(GeometryGUI::ClientStudyToStudy(aDStudy),
1112 it.value(), it.key().toLatin1().data(), aFatherObj );
1116 //cout << " anOperations is NULL! " << endl;