1 // SALOME SALOMEGUI : implementation of desktop and GUI kernel
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : QAD_Study.cxx
25 // Author : Nicolas REJNERI
31 \class QAD_Study QAD_Study.h
32 \brief Study for QAD-based application.
36 #include "QAD_Tools.h"
37 #include "QAD_Desktop.h"
38 #include "QAD_Study.h"
39 #include "QAD_RightFrame.h"
40 #include "QAD_LeftFrame.h"
41 #include "QAD_MessageBox.h"
42 #include "QAD_Application.h"
43 #include "QAD_ObjectBrowser.h"
44 #include "QAD_PyInterp.h"
45 #include "QAD_Config.h"
47 #include "utilities.h"
49 #include "SALOME_Selection.h"
50 #include "SALOME_TypeFilter.hxx"
51 #include "SALOME_InteractiveObject.hxx"
52 #include "SALOME_ListIteratorOfListIO.hxx"
54 #include <SALOMEconfig.h>
55 #include CORBA_SERVER_HEADER(SALOMEDS)
57 // OPEN CASCADE Include
58 #include <Standard_Failure.hxx>
61 #include <qapplication.h>
67 QAD_Study::QAD_Study(QAD_Application* app,
68 SALOMEDS::Study_var aStudy,
69 const QString& path ) :
70 myOperationState( Undef ),
72 myActiveStudyFrame( 0 ),
73 myStudyFrameCount( 0 ),
78 myTitle = QAD_Tools::getFileNameFromPath( path, false );
85 myStudyFrames.clear();
88 myStudyFrames.setAutoDelete( true );
89 myOperations.setAutoDelete( true );
90 myChildWidgets.setAutoDelete( true );
92 /* create python interpreter */
93 _interp = new QAD_PyInterp();
96 /* create default selection */
97 //NRI Selection( "Salome" );
98 Selection( QAD_Application::getDesktop()->getComponentUserName( "KERNEL" ) );
100 /* create study frame */
102 createStudyFrame( getNextStudyFrameName() );
104 /* set default Undo/Redo limit */
105 QAD_ASSERT_DEBUG_ONLY( !myStudy->_is_nil() );
106 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
107 SB->UndoLimit( MAX_UNDO );
113 QAD_Study::~QAD_Study ()
116 //SRN: added - clear selection in case the study will be loaded again so the title will coincide
117 SALOME_Selection::RemoveSelection( QString(myTitle + "_" + mySelection) );
121 Returns TRUE if Study is created correctly. Returns FALSE otherwise.
123 bool QAD_Study::getResult()
129 //=======================================================================//
130 // StudyFrames management //
131 //=======================================================================//
135 void QAD_Study::addStudyFrame(QAD_StudyFrame* sf )
137 myStudyFrames.append( sf );
139 sf->getRightFrame()->getViewFrame()->setPopupServer( myApp );
140 // Provide the same common popup menu commands for both the Object Browser and 3D viewer
141 sf->getLeftFrame()->getObjectBrowser()->setPopupServer( myApp );
143 /* icon of Study Frame */
144 const QPixmap& icon = myApp->getApplicationIcon();
145 if ( !icon.isNull() )
146 sf->setIcon ( icon );
149 QAD_ASSERT ( connect( sf, SIGNAL(sfStudyFrameActivated(QAD_StudyFrame*) ),
150 SLOT(onStudyFrameActivated(QAD_StudyFrame*))) );
153 QAD_ASSERT ( connect( sf,
154 SIGNAL(sfStudyFrameClosing(QAD_StudyFrame*) ),
156 SLOT(onLastStudyFrameClosing(QAD_StudyFrame*))) );
159 myActiveStudyFrame = sf;
163 Removes studyframe from the list
165 void QAD_Study::removeStudyFrame( QAD_StudyFrame* sf )
168 if (!myStudy->IsEmpty()) {
169 SALOMEDS::SObject_var fatherSF = myStudy->FindObjectID(sf->entry());
170 if (!fatherSF->_is_nil()) {
171 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
172 aStudyBuilder->RemoveObject(fatherSF);
175 updateObjBrowser( true );
177 myStudyFrames.removeRef( sf );
182 Returns number of study frames
184 int QAD_Study::getStudyFramesCount() const
186 return myStudyFrames.count();
190 Returns study frame by its index in list
192 QAD_StudyFrame* QAD_Study::getStudyFrame( unsigned i )
194 return myStudyFrames.at(i);
198 Returns study frame by its name or null if not found
200 QAD_StudyFrame* QAD_Study::getStudyFrameByName ( const QString& name )
202 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() )
204 if ( sf->title().compare(name) == 0 ) {
212 Returns first study frame in the list
214 QAD_StudyFrame* QAD_Study::getFirstStudyFrame()
216 return myStudyFrames.first();
220 Returns last study frame in the list
222 QAD_StudyFrame* QAD_Study::getLastStudyFrame()
224 return myStudyFrames.last();
228 Returns the vector of studyframes
230 const QList<QAD_StudyFrame>& QAD_Study::getStudyFrames() const
232 return myStudyFrames;
236 Returns the active study frame
238 QAD_StudyFrame* QAD_Study::getActiveStudyFrame() const
240 return myActiveStudyFrame;
243 //=======================================================================//
244 // Study properties //
245 //=======================================================================//
247 Returns reference to supporting application
249 QAD_Application* QAD_Study::getApp() const
255 Returns the name of document ( filename without path and extension )
257 const QString& QAD_Study::getTitle() const
263 Returns the absolute file path of this document
265 const QString& QAD_Study::getPath() const
271 Changes the name of document
273 void QAD_Study::setTitle( const QString& path )
277 QString title = QAD_Tools::getFileNameFromPath( path, false );
278 QAD_ASSERT_DEBUG_ONLY ( !title.isNull() );
280 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf ; sf = myStudyFrames.next() )
282 QString oldName = sf->title();
283 int k = oldName.find( myTitle, 0, false );
284 QString restName = ( oldName.length() > myTitle.length() + k) ?
285 oldName.right(oldName.length() - (myTitle.length() + k) + 1) :
292 int l = restName.find( "#", 0, false );
293 int ll = restName.length();
294 newName = title + restName.mid( l, ll-l );
296 newName = oldName.mid(0, k);
297 newName = newName + title + restName;
299 sf->setTitle( newName );
304 Selection( QAD_Application::getDesktop()->getActiveComponent() );
308 Returns whether the document is active
310 bool QAD_Study::isActive() const
316 Returns whether the document is read only
318 bool QAD_Study::isReadOnly() const
324 Sets read-only property
326 void QAD_Study::setReadOnly(bool state)
328 myIsReadOnly = state;
331 //=======================================================================//
332 // Study operations //
333 //=======================================================================//
335 Performs specific study frame related actions when it is activated.
336 By default resumes all suspended operations.
338 void QAD_Study::onStudyFrameActivated( QAD_StudyFrame* activeStudyFrame )
340 static int IS_FIRST_STUDY = 1;
341 if(IS_FIRST_STUDY){ //for normally initialize "salome.py and ..."
342 _interp->run(""); IS_FIRST_STUDY = 0;
344 // bool found = false;
345 for ( QAD_StudyFrame* studyframe = myStudyFrames.first(); studyframe; studyframe = myStudyFrames.next() ) {
346 if ( studyframe == activeStudyFrame) { /* one of my study frames */
348 // if ( !myActiveStudyFrame || myActiveStudyFrame != activeStudyFrame ) {
349 myActiveStudyFrame = activeStudyFrame;
350 //NRI if ( !myIsActive ) {
352 resumeAllOperations();
353 /* activate application */
354 myApp->onStudyActivated( this );
361 // myActiveStudyFrame = 0;
366 Performs specific study related actions when it is deactivated.
367 By default suspends all performing operations.
369 void QAD_Study::onStudyDeactivated()
371 // MESSAGE ("QAD_Study::onStudyDeactivated init. ");
373 suspendAllOperations();
374 // MESSAGE ("QAD_Study::onStudyDeactivated done. ");
378 Closes all study frames of the study and performs other specific study
379 related actions needed for proper closing of the study
381 void QAD_Study::close()
383 if ( !myStudy->_is_nil() )
384 abortAllOperations();
385 /* clear each study frame */
386 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.first() ) {
389 qApp->processEvents();
390 qApp->processEvents();
391 removeStudyFrame(sf);
394 /* delete all studyframes */
395 myStudyFrames.clear();
396 myOperations.clear();
397 myChildWidgets.clear();
399 // QWorkspace* ws = QAD_Application::getDesktop()->getMainFrame();
400 // if (/* !ws->activeWindow() && */ws->windowList().count() > 0 )
401 // ws->activateWindow(ws->windowList().last());
404 //=======================================================================//
405 // Operations management //
406 //=======================================================================//
408 Returns number of completed operations
410 int QAD_Study::getOperationsCount() const
412 return myOperations.count();
416 Returns the state of the last operation
418 OperationState QAD_Study::getOperationState() const
420 return myOperationState;
424 Returns operation by its index in list
426 QAD_Operation* QAD_Study::getOperation( unsigned i)
428 return ( myOperations.isEmpty() ? 0 : myOperations.at(i) );
432 Returns performing operation launched first
434 QAD_Operation* QAD_Study::getFirstOperation()
436 return ( myOperations.isEmpty() ? 0 : myOperations.first() );
440 Returns performing operation launched last
442 QAD_Operation* QAD_Study::getLastOperation()
444 return ( myOperations.isEmpty() ? 0 : myOperations.last() );
448 Aborts all performing operations
450 void QAD_Study::abortAllOperations()
452 for ( QAD_Operation* op = myOperations.last(); op;
453 op = myOperations.prev() )
458 Resumes all performing operations
460 void QAD_Study::resumeAllOperations()
462 for ( QAD_Operation* op = myOperations.first(); op;
463 op = myOperations.next() )
468 Suspendes all performing operations
470 void QAD_Study::suspendAllOperations()
472 // MESSAGE ( " QAD_Study::suspendAllOperations init. " )
473 for ( QAD_Operation* op = myOperations.last(); op;
474 op = myOperations.prev() )
479 Initializes the operation and checks its compatibility
480 with another operation in process if any.
481 Returns 'true' if init'ed OK, 'false' otherwise.
483 bool QAD_Study::initOperation( QAD_Operation* op )
486 { /* can't start a non-const operation */
487 if ( op->changesData() )
489 QAD_MessageBox::error1( QAD_Application::getDesktop(), tr("ERR_ERROR"),
490 tr("ERR_DOC_READONLY"), tr("BUT_OK") );
495 /* Add the new operation
497 if ( myOperations.isEmpty() )
498 myOperations.append( op );
501 /* Check compatibility of new operation with the existing operations.
502 Since each operations is checked in that way, it's enough to check
503 the last operation only */
504 if ( !getLastOperation()->compatibleWith( op ) )
506 if ( QAD_MessageBox::warn2( QAD_Application::getDesktop(), tr("WRN_WARNING"),
507 tr("QUE_ABORTCURRENTOPERATION"), tr("BUT_YES"),
508 tr("BUT_NO"), QAD_YES, QAD_NO, QAD_NO )
511 getLastOperation()->abort();
513 myOperations.append( op );
519 Called when operation was finished.
520 Removes appointed operation from the list and aborted all operations
523 void QAD_Study::clearOperation( QAD_Operation* op)
525 if ( myOperations.contains( op ) )
527 /* abort all the operations launched after 'op' */
528 for ( QAD_Operation* cur = myOperations.last(); cur;
529 cur = myOperations.prev() )
531 if ( cur == op ) break;
534 myOperations.remove( op );
541 QAD_StudyFrame* QAD_Study::createStudyFrame( const QString& title, ViewType theViewType)
543 QAD_Desktop* parent = QAD_Application::getDesktop();
544 //srn: Forbid appending Interface Applicative and its children to UseCase
545 myStudy->EnableUseCaseAutoFilling(false);
547 SALOMEDS::SComponent_var father = myStudy->FindComponent("Interface Applicative");
548 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
549 SALOMEDS::GenericAttribute_var anAttr;
550 SALOMEDS::AttributeName_var aName;
551 SALOMEDS::AttributeComment_var aComment;
552 SALOMEDS::AttributeSelectable_var aSelAttr;
554 // mpv : where is "NewCommand" call?
555 // aStudyBuilder->CommitCommand();
557 // mpv : is study is locked, then next code will raise exception. So, temporary unlock study
558 int aLocked = myStudy->GetProperties()->IsLocked();
559 if (aLocked) myStudy->GetProperties()->SetLocked(false);
561 if ( father->_is_nil() ) {
562 father = aStudyBuilder->NewComponent("Interface Applicative");
563 anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributeName");
564 aName = SALOMEDS::AttributeName::_narrow(anAttr);
565 aName->SetValue("Interface Applicative");
567 anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributeSelectable");
568 aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
569 aSelAttr->SetSelectable(false);
572 //VRV: T2.5 - add default viewer
573 if(theViewType == VIEW_TYPE_MAX) {
574 QString viewerValue = QAD_CONFIG->getSetting( "Viewer:DefaultViewer" );
576 theViewType = (ViewType)viewerValue.toInt( &ok, 10 );
577 if (!ok || theViewType < VIEW_OCC || theViewType >= VIEW_TYPE_MAX)
578 theViewType = VIEW_VTK;
580 //QApplication::restoreOverrideCursor();
581 QAD_StudyFrame* sf = NULL;
582 SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(father);
583 if ( theViewType == VIEW_OCC) {
584 // MESSAGE ("Create Study Frame for OCC viewer");
585 sf = new QAD_StudyFrame ( this, parent->getMainFrame(),
586 title, _interp, VIEW_OCC );
588 Standard_CString name = strdup(sf->title().latin1());
589 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
590 aName = SALOMEDS::AttributeName::_narrow(anAttr);
591 aName->SetValue(name);
592 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeComment");
593 aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
594 aComment->SetValue("OCC");
596 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeSelectable");
597 aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
598 aSelAttr->SetSelectable(false);
600 else if ( theViewType == VIEW_VTK) {
601 // MESSAGE ("Create Study Frame for VTK viewer");
602 sf = new QAD_StudyFrame ( this, parent->getMainFrame(),
603 title, _interp, VIEW_VTK );
604 Standard_CString name = strdup(sf->title().latin1());
605 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
606 aName = SALOMEDS::AttributeName::_narrow(anAttr);
607 aName->SetValue(name);
608 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeComment");
609 aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
610 aComment->SetValue("VTK");
612 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeSelectable");
613 aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
614 aSelAttr->SetSelectable(false);
616 else if ( theViewType == VIEW_GRAPHSUPERV) {
617 //MESSAGE ("Create Study Frame for SUPER`VISOR Graph");
618 sf = new QAD_StudyFrame ( this, parent->getMainFrame(),
619 title, _interp, VIEW_GRAPHSUPERV );
620 Standard_CString name = strdup(sf->title().latin1());
621 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
622 aName = SALOMEDS::AttributeName::_narrow(anAttr);
623 aName->SetValue(name);
624 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeComment");
625 aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
626 aComment->SetValue("GRAPH");
628 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeSelectable");
629 aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
630 aSelAttr->SetSelectable(false);
632 else if ( theViewType == VIEW_PLOT2D ) {
633 sf = new QAD_StudyFrame ( this, parent->getMainFrame(),
634 title, _interp, VIEW_PLOT2D );
635 Standard_CString name = strdup(sf->title().latin1());
636 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
637 aName = SALOMEDS::AttributeName::_narrow(anAttr);
638 aName->SetValue(name);
639 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeComment");
640 aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
641 aComment->SetValue("PLOT2D");
643 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeSelectable");
644 aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
645 aSelAttr->SetSelectable(false);
647 //VRV: T2.5 - add default viewer
649 sf->resize( int (0.8*parent->getMainFrame()->width()),
650 int (0.8*parent->getMainFrame()->height() ));
652 sf->setEntry(newObj->GetID());
656 updateObjBrowser( true );
658 parent->setSettings();
662 if (aLocked) myStudy->GetProperties()->SetLocked(true);
664 // T2.12 - add the word "locked" to study frame captions if this study is locked
667 myStudy->EnableUseCaseAutoFilling(true);
673 Updates study frame captions according to IsLocked study flag
675 void QAD_Study::updateCaptions()
677 QString appendix("");
679 if (!myStudy->_is_nil()) {
680 SALOMEDS::AttributeStudyProperties_var propAttr = myStudy->GetProperties();
682 if (!propAttr->_is_nil() ) {
683 if ( propAttr->IsModified() )
684 appendix += " (" + tr("PRP_STUDY_MODIFIED") + ")";
686 appendix += " (" + tr("PRP_STUDY_SAVED") + ")";
690 if (!propAttr->_is_nil() && propAttr->IsLocked()) {
691 appendix += " (" + tr("PRP_STUDY_LOCKED") + ")";
695 for (myStudyFrames.first(); myStudyFrames.current(); myStudyFrames.next()) {
696 myStudyFrames.current()->setCaption(myStudyFrames.current()->title() + appendix);
702 Shows the active study frame.
703 Called by Desktop after 'new' and 'open' commands.
705 void QAD_Study::show()
707 for (myStudyFrames.first(); myStudyFrames.current(); myStudyFrames.next()) {
708 myStudyFrames.current()->show();
712 //=======================================================================//
713 // Study properties (CAF related) //
714 //=======================================================================//
717 Returns connected SALOMEDS_Study object
719 SALOMEDS::Study_var QAD_Study::getStudyDocument()
725 Returns whether the document was saved in file
727 bool QAD_Study::isSaved() const
729 return myStudy->IsSaved();
733 Returns whether the document is modified
735 bool QAD_Study::isModified() const
737 // return myStudy->IsModified(); // VSR:05/12/02 - USE PROPERTY : MODIFIED FLAG
738 if ( !myStudy->_is_nil() ) {
739 SALOMEDS::AttributeStudyProperties_var propAttr = myStudy->GetProperties();
740 if ( !propAttr->_is_nil() )
741 return propAttr->IsModified();
746 bool QAD_Study::undo()
749 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
752 /* Update Object Browser */
753 updateObjBrowser( true );
755 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
757 sf->getRightFrame()->getViewFrame()->undo( myStudy, sf->entry() );
761 // mpv 07.03.2003 SAL1805: clear selection must be called after study structure changed
762 SALOME_Selection* Sel = SALOME_Selection::Selection( getSelection() );
763 Sel->ClearIObjects();
765 // mpv : undo command can raise exception, if study is locked
766 catch ( SALOMEDS::StudyBuilder::LockProtection& ) {
767 QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
768 QObject::tr("WRN_WARNING"),
769 QObject::tr("WRN_STUDY_LOCKED"),
770 QObject::tr("BUT_OK"));
773 catch ( Standard_Failure ) {
781 bool QAD_Study::redo()
784 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
787 /* Update Object Browser */
788 updateObjBrowser( true );
791 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
792 sf->getRightFrame()->getViewFrame()->redo( myStudy, sf->entry() );
796 // mpv 07.03.2003 SAL1805: clear selection must be called after study structure changed
797 SALOME_Selection* Sel = SALOME_Selection::Selection( getSelection() );
798 Sel->ClearIObjects();
800 // mpv : redo command can raise exception, if study is locked
801 catch ( SALOMEDS::StudyBuilder::LockProtection& ) {
802 QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
803 QObject::tr("WRN_WARNING"),
804 QObject::tr("WRN_STUDY_LOCKED"),
805 QObject::tr("BUT_OK"));
808 catch ( Standard_Failure ) {
814 Check if possible to perform 'undo' command
816 bool QAD_Study::canUndo() const
818 if ( myStudy->_is_nil() )
821 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
822 return (SB->GetAvailableUndos() > 0 );
826 Check if possible to perform 'redo' command
828 bool QAD_Study::canRedo() const
830 if ( myStudy->_is_nil() )
833 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
834 return (SB->GetAvailableRedos() > 0 );
838 Called when operation is started
839 Returns 'true' if started OK, 'false' otherwise.
841 bool QAD_Study::onOperationStarted( QAD_Operation* op )
843 if ( !initOperation( op ) )
847 { /* start a new transaction */
848 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
851 catch ( Standard_Failure )
853 /* May be, a transaction is already open,
854 it's not a problem */
856 myOperationState = Started;
861 Called when operation is finished
863 void QAD_Study::onOperationFinished( QAD_Operation* op )
866 /* transaction is completed OK */
867 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
870 catch ( SALOMEDS::StudyBuilder::LockProtection& ) {
871 QApplication::restoreOverrideCursor();
872 QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
873 QObject::tr("WRN_WARNING"),
874 QObject::tr("WRN_STUDY_LOCKED"),
875 QObject::tr("BUT_OK"));
876 onOperationAborted(op);
877 updateObjBrowser( true );
880 catch ( Standard_Failure ) {
882 myOperationState = Finished;
883 emit docOperationTerminated( true ); /* terminated successfully */
886 // mpv: any operation must call this method, otherwise study may not be saved
887 updateObjBrowser( true );
889 clearOperation( op ); /* we don't need the operation anymore */
890 QAD_Application::getDesktop()->putInfo ( tr("INF_DOC_OPERATIONFINISHED") );
894 Called when operation is suspended
896 void QAD_Study::onOperationSuspended( QAD_Operation* op )
898 myOperationState = Suspended;
902 Called when operation is resumed
904 void QAD_Study::onOperationResumed( QAD_Operation* op )
906 myOperationState = Resumed;
910 Called when operation is aborted
912 void QAD_Study::onOperationAborted(QAD_Operation* op)
915 /* abort transaction */
916 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
919 catch ( Standard_Failure )
922 myOperationState = Aborted;
923 emit docOperationTerminated( false ); /* aborted */
928 QAD_Application::getDesktop()->putInfo ( tr("INF_DOC_OPERATIONABORTED") );
932 Call when the last study frame is closing
934 void QAD_Study::onLastStudyFrameClosing( QAD_StudyFrame* sf )
936 if ( myStudyFrames.count() == 1 ) {
937 emit docClosing( this );
939 removeStudyFrame( sf );
941 // QWorkspace* ws = QAD_Application::getDesktop()->getMainFrame();
942 // if ( !ws->activeWindow() && ws->windowList().count() > 0 )
943 // ws->activatePreviousWindow();
947 Call when created a new window3d
949 QAD_StudyFrame* QAD_Study::newWindow3d(QString name, ViewType theViewType, bool toShow)
951 if(name == "") name = getNextStudyFrameName();
952 QAD_StudyFrame* sf = createStudyFrame( name, theViewType );
954 if (toShow) showFrame(sf);
955 // sf->compressLeft(); /* compress LeftFrame */
956 sf->getRightFrame()->compressBottom(); /* compress BottomFrame */
962 void QAD_Study::showFrame(QAD_StudyFrame* theFrame){
963 theFrame->resize( (int)(0.64*QAD_Application::getDesktop()->getMainFrame()->width()),
964 (int)(0.64*QAD_Application::getDesktop()->getMainFrame()->height()));
972 Call when setted a message
974 void QAD_Study::setMessage(const char* message)
976 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
977 sf->getRightFrame()->getMessage()->setMessage(message);
982 Call when updated object browser
984 void QAD_Study::updateObjBrowser( bool updateSelection )
986 QAD_Desktop* parent = QAD_Application::getDesktop();
987 SALOME_ModuleCatalog::ModuleCatalog_var Catalog = parent->getCatalogue();
989 QString ActiveComp = parent->getActiveComponent();
991 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
992 sf->getLeftFrame()->getObjectBrowser()->Update();
995 /* update selection */
996 if ( updateSelection && (myStudyFrames.count() > 0) ) {
997 SALOME_Selection* Sel = SALOME_Selection::Selection( getSelection() );
998 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
999 for(;It.More();It.Next()) {
1000 if ( Sel->AddIObject( It.Value() ) == 0 ) {
1001 highlight( It.Value(), true, false );
1005 /* update viewers */
1010 Updates only Use Case Browser
1012 void QAD_Study::updateUseCaseBrowser( bool updateSelection )
1014 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
1015 sf->getLeftFrame()->getObjectBrowser()->UpdateUseCaseBrowser();
1017 /* update selection */
1018 if ( updateSelection && (myStudyFrames.count() > 0) ) {
1019 SALOME_Selection* Sel = SALOME_Selection::Selection( getSelection() );
1020 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1021 for(;It.More();It.Next()) {
1022 if ( Sel->AddIObject( It.Value() ) == 0 ) {
1023 highlight( It.Value(), true, false );
1026 /* update viewers */
1032 unHighlight All Interactive Objects in All Devices
1034 void QAD_Study::unHighlightAll()
1036 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
1037 /* Device = Viewers */
1038 sf->getRightFrame()->getViewFrame()->unHighlightAll();
1040 /* Device = ObjectBrowser */
1041 sf->getLeftFrame()->getObjectBrowser()->unHighlightAll();
1046 Returns type of Interactive Object
1048 int QAD_Study::typeIObject( const Handle(SALOME_InteractiveObject)& IObject )
1050 bool IsStudyObject = isInStudy( IObject );
1051 bool IsGraphicalObject = isInViewer( IObject );
1053 // MESSAGE ( "IsStudyObject : " << IsStudyObject )
1054 // MESSAGE ( "IsGraphicalObject : " << IsGraphicalObject )
1056 if ( IsStudyObject ) {
1057 if ( IsGraphicalObject )
1058 return 1; /* StudyObject and GraphicalObject */
1060 return 2; /* only StudyObject */
1062 if ( IsGraphicalObject )
1063 return 3; /* only GraphicalObject */
1065 return 4; /* may be a component */
1072 Renames the Interactive Object in All Devices
1074 void QAD_Study::renameIObject( const Handle(SALOME_InteractiveObject)& IObject, QString newName )
1076 if (myStudy->GetProperties()->IsLocked()) {
1077 QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
1078 QObject::tr("WRN_WARNING"),
1079 QObject::tr("WRN_STUDY_LOCKED"),
1080 QObject::tr("BUT_OK"));
1084 highlight( IObject, false );
1086 int nbFrames = myStudyFrames.count();
1087 for ( int i = 0; i < nbFrames; i++ ) {
1088 QAD_StudyFrame* sf = myStudyFrames.at( i );
1089 switch ( typeIObject(IObject) ) {
1092 /* Device = Viewers */
1093 sf->getRightFrame()->getViewFrame()->rename(IObject, newName);
1094 /* Device = ObjectBrowser */
1095 sf->getLeftFrame()->getObjectBrowser()->rename(IObject, newName);
1100 /* Device = ObjectBrowser */
1101 sf->getLeftFrame()->getObjectBrowser()->rename(IObject, newName);
1106 /* Device = Viewers */
1107 sf->getRightFrame()->getViewFrame()->rename(IObject, newName);
1112 QString ActiveComp = QAD_Application::getDesktop()->getActiveComponent();
1113 if ( !ActiveComp.isEmpty() ) {
1114 sf->getLeftFrame()->getObjectBrowser()->rename(IObject,newName);
1122 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
1123 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IObject->getEntry() );
1124 if ( !obj->_is_nil() ) {
1125 SALOMEDS::GenericAttribute_var anAttr;
1126 SALOMEDS::AttributeName_var aName;
1127 anAttr = aStudyBuilder->FindOrCreateAttribute(obj, "AttributeName");
1128 aName = SALOMEDS::AttributeName::_narrow(anAttr);
1129 aName->SetValue(strdup(newName.latin1()));
1132 // VSR 13/03/03 - rename Interactive object
1133 IObject->setName( ( char* )newName.latin1() );
1135 updateObjBrowser( true );
1139 Selects the Interactive Object in All Devices
1141 void QAD_Study::highlight( const Handle(SALOME_InteractiveObject)& IObject, bool highlight,bool immediatly )
1143 // MESSAGE ( " QAD_Study::highlight : " << highlight )
1144 int typeIO = typeIObject( IObject );
1146 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
1150 /* Device = Viewer */
1151 if (sf->getTypeView() >= 0 ) { /* Device = Viewers */
1152 sf->getRightFrame()->getViewFrame()->highlight(IObject, highlight, immediatly);
1154 /* Device = ObjectBrowser */
1155 sf->getLeftFrame()->getObjectBrowser()->highlight(IObject, highlight);
1160 /* Device = ObjectBrowser */
1161 sf->getLeftFrame()->getObjectBrowser()->highlight(IObject, highlight);
1166 /* Device = Viewer */
1167 if (sf->getTypeView() >= 0) { /* Device = Viewers */
1168 sf->getRightFrame()->getViewFrame()->highlight(IObject, highlight, immediatly);
1174 QString ActiveComp = QAD_Application::getDesktop()->getActiveComponent();
1175 if ( !ActiveComp.isEmpty() ) {
1176 sf->getLeftFrame()->getObjectBrowser()->highlight(IObject,highlight);
1185 Returns TRUE if the IObject is a Study Object. Returns FALSE otherwise.
1187 bool QAD_Study::isInStudy( const Handle(SALOME_InteractiveObject)& IObject )
1189 return IObject->hasEntry();
1193 Returns true if the IObject has a Graphical Object. Returns FALSE otherwise.
1195 bool QAD_Study::isInViewer( const Handle(SALOME_InteractiveObject)& IObject )
1198 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
1199 found = sf->getRightFrame()->getViewFrame()->isInViewer(IObject);
1207 Returns true if the IObject has a Graphical Object into studyframe. Returns FALSE otherwise.
1209 bool QAD_Study::isInViewer(const char* anEntry, const char* StudyFrameEntry)
1211 SALOMEDS::SObject_var RefSO;
1212 SALOMEDS::SObject_var SO = myStudy->FindObjectID(StudyFrameEntry);
1213 SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(SO);
1214 for (; it->More();it->Next()){
1215 SALOMEDS::SObject_var CSO= it->Value();
1216 if (CSO->ReferencedObject(RefSO))
1217 if ( strcmp( anEntry, RefSO->GetID() ) == 0 )
1225 Returns title for the new studyframe window
1227 QString QAD_Study::getNextStudyFrameName()
1229 QString numStudyFrame;
1230 numStudyFrame.sprintf("%s%d", "#", ++myStudyFrameCount );
1231 return myTitle + numStudyFrame; /* return unique name ( title + unique number) */
1236 Returns the Python interpreter that belongs to this study
1238 QAD_PyInterp* QAD_Study::get_PyInterp(void)
1244 Sets current selection.
1246 void QAD_Study::Selection( QString aSelection )
1248 if ( !SALOME_Selection::FindSelection( QString(myTitle + "_" + aSelection) ) )
1249 SALOME_Selection::CreateSelection( QString(myTitle + "_" + aSelection) );
1251 SALOME_Selection* Sel = SALOME_Selection::Selection( QString(myTitle + "_" + aSelection) );
1253 mySelection = aSelection;
1257 Returns the name of current selection
1259 QString QAD_Study::getSelection()
1261 return QString (myTitle + "_" + mySelection);
1265 Returns the study Id.
1267 int QAD_Study::getStudyId()
1269 return myStudy->StudyId();
1272 void QAD_Study::update3dViewers()
1274 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
1275 sf->getRightFrame()->getViewFrame()->Repaint();
1279 /* Adds new child window */
1280 void QAD_Study::addChildWidget( QWidget* child )
1282 if ( myChildWidgets.findRef( child ) < 0 ) {
1283 myChildWidgets.append( child );
1284 child->installEventFilter( this );
1289 Removes child window from the list ( and deletes it )
1291 void QAD_Study::removeChildWidget( QWidget* child )
1293 myChildWidgets.removeRef( child );
1297 bool QAD_Study::eventFilter( QObject* o, QEvent* e)
1299 int index = myChildWidgets.findRef( ( QWidget* )o );
1300 if ( index >= 0 && e->type() == QEvent::Close ) {
1301 myChildWidgets.at( index )->removeEventFilter( this );
1302 myChildWidgets.remove( ( QWidget* )o );
1305 return QObject::eventFilter( o, e );