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 Selection( "Salome" );
99 /* create study frame */
101 createStudyFrame( getNextStudyFrameName() );
103 /* set default Undo/Redo limit */
104 QAD_ASSERT_DEBUG_ONLY( !myStudy->_is_nil() );
105 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
106 SB->UndoLimit( MAX_UNDO );
112 QAD_Study::~QAD_Study ()
115 //SRN: added - clear selection in case the study will be loaded again so the title will coincide
116 SALOME_Selection::RemoveSelection( QString(myTitle + "_" + mySelection) );
120 Returns TRUE if Study is created correctly. Returns FALSE otherwise.
122 bool QAD_Study::getResult()
128 //=======================================================================//
129 // StudyFrames management //
130 //=======================================================================//
134 void QAD_Study::addStudyFrame(QAD_StudyFrame* sf )
136 myStudyFrames.append( sf );
138 sf->getRightFrame()->getViewFrame()->setPopupServer( myApp );
139 // Provide the same common popup menu commands for both the Object Browser and 3D viewer
140 sf->getLeftFrame()->getObjectBrowser()->setPopupServer( myApp );
142 /* icon of Study Frame */
143 const QPixmap& icon = myApp->getApplicationIcon();
144 if ( !icon.isNull() )
145 sf->setIcon ( icon );
148 QAD_ASSERT ( connect( sf, SIGNAL(sfStudyFrameActivated(QAD_StudyFrame*) ),
149 SLOT(onStudyFrameActivated(QAD_StudyFrame*))) );
152 QAD_ASSERT ( connect( sf,
153 SIGNAL(sfStudyFrameClosing(QAD_StudyFrame*) ),
155 SLOT(onLastStudyFrameClosing(QAD_StudyFrame*))) );
158 myActiveStudyFrame = sf;
162 Removes studyframe from the list
164 void QAD_Study::removeStudyFrame( QAD_StudyFrame* sf )
167 if (!myStudy->IsEmpty()) {
168 SALOMEDS::SObject_var fatherSF = myStudy->FindObjectID(sf->entry());
169 if (!fatherSF->_is_nil()) {
170 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
171 aStudyBuilder->RemoveObject(fatherSF);
174 updateObjBrowser( true );
176 myStudyFrames.removeRef( sf );
181 Returns number of study frames
183 int QAD_Study::getStudyFramesCount() const
185 return myStudyFrames.count();
189 Returns study frame by its index in list
191 QAD_StudyFrame* QAD_Study::getStudyFrame( unsigned i )
193 return myStudyFrames.at(i);
197 Returns study frame by its name or null if not found
199 QAD_StudyFrame* QAD_Study::getStudyFrameByName ( const QString& name )
201 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() )
203 if ( sf->title().compare(name) == 0 ) {
211 Returns first study frame in the list
213 QAD_StudyFrame* QAD_Study::getFirstStudyFrame()
215 return myStudyFrames.first();
219 Returns last study frame in the list
221 QAD_StudyFrame* QAD_Study::getLastStudyFrame()
223 return myStudyFrames.last();
227 Returns the vector of studyframes
229 const QList<QAD_StudyFrame>& QAD_Study::getStudyFrames() const
231 return myStudyFrames;
235 Returns the active study frame
237 QAD_StudyFrame* QAD_Study::getActiveStudyFrame() const
239 return myActiveStudyFrame;
242 //=======================================================================//
243 // Study properties //
244 //=======================================================================//
246 Returns reference to supporting application
248 QAD_Application* QAD_Study::getApp() const
254 Returns the name of document ( filename without path and extension )
256 const QString& QAD_Study::getTitle() const
262 Returns the absolute file path of this document
264 const QString& QAD_Study::getPath() const
270 Changes the name of document
272 void QAD_Study::setTitle( const QString& path )
276 QString title = QAD_Tools::getFileNameFromPath( path, false );
277 QAD_ASSERT_DEBUG_ONLY ( !title.isNull() );
279 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf ; sf = myStudyFrames.next() )
281 QString oldName = sf->title();
282 int k = oldName.find( myTitle, 0, false );
283 QString restName = ( oldName.length() > myTitle.length() + k) ?
284 oldName.right(oldName.length() - (myTitle.length() + k) + 1) :
291 int l = restName.find( "#", 0, false );
292 int ll = restName.length();
293 newName = title + restName.mid( l, ll-l );
295 newName = oldName.mid(0, k);
296 newName = newName + title + restName;
298 sf->setTitle( newName );
303 Selection( QAD_Application::getDesktop()->getActiveComponent() );
307 Returns whether the document is active
309 bool QAD_Study::isActive() const
315 Returns whether the document is read only
317 bool QAD_Study::isReadOnly() const
323 Sets read-only property
325 void QAD_Study::setReadOnly(bool state)
327 myIsReadOnly = state;
330 //=======================================================================//
331 // Study operations //
332 //=======================================================================//
334 Performs specific study frame related actions when it is activated.
335 By default resumes all suspended operations.
337 void QAD_Study::onStudyFrameActivated( QAD_StudyFrame* activeStudyFrame )
339 static int IS_FIRST_STUDY = 1;
340 if(IS_FIRST_STUDY){ //for normally initialize "salome.py and ..."
341 _interp->run(""); IS_FIRST_STUDY = 0;
343 // bool found = false;
344 for ( QAD_StudyFrame* studyframe = myStudyFrames.first(); studyframe; studyframe = myStudyFrames.next() ) {
345 if ( studyframe == activeStudyFrame) { /* one of my study frames */
347 // if ( !myActiveStudyFrame || myActiveStudyFrame != activeStudyFrame ) {
348 myActiveStudyFrame = activeStudyFrame;
349 //NRI if ( !myIsActive ) {
351 resumeAllOperations();
352 /* activate application */
353 myApp->onStudyActivated( this );
360 // myActiveStudyFrame = 0;
365 Performs specific study related actions when it is deactivated.
366 By default suspends all performing operations.
368 void QAD_Study::onStudyDeactivated()
370 // MESSAGE ("QAD_Study::onStudyDeactivated init. ");
372 suspendAllOperations();
373 // MESSAGE ("QAD_Study::onStudyDeactivated done. ");
377 Closes all study frames of the study and performs other specific study
378 related actions needed for proper closing of the study
380 void QAD_Study::close()
382 if ( !myStudy->_is_nil() )
383 abortAllOperations();
384 /* clear each study frame */
385 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.first() ) {
388 qApp->processEvents();
389 qApp->processEvents();
390 removeStudyFrame(sf);
393 /* delete all studyframes */
394 myStudyFrames.clear();
395 myOperations.clear();
396 myChildWidgets.clear();
398 // QWorkspace* ws = QAD_Application::getDesktop()->getMainFrame();
399 // if (/* !ws->activeWindow() && */ws->windowList().count() > 0 )
400 // ws->activateWindow(ws->windowList().last());
403 //=======================================================================//
404 // Operations management //
405 //=======================================================================//
407 Returns number of completed operations
409 int QAD_Study::getOperationsCount() const
411 return myOperations.count();
415 Returns the state of the last operation
417 OperationState QAD_Study::getOperationState() const
419 return myOperationState;
423 Returns operation by its index in list
425 QAD_Operation* QAD_Study::getOperation( unsigned i)
427 return ( myOperations.isEmpty() ? 0 : myOperations.at(i) );
431 Returns performing operation launched first
433 QAD_Operation* QAD_Study::getFirstOperation()
435 return ( myOperations.isEmpty() ? 0 : myOperations.first() );
439 Returns performing operation launched last
441 QAD_Operation* QAD_Study::getLastOperation()
443 return ( myOperations.isEmpty() ? 0 : myOperations.last() );
447 Aborts all performing operations
449 void QAD_Study::abortAllOperations()
451 for ( QAD_Operation* op = myOperations.last(); op;
452 op = myOperations.prev() )
457 Resumes all performing operations
459 void QAD_Study::resumeAllOperations()
461 for ( QAD_Operation* op = myOperations.first(); op;
462 op = myOperations.next() )
467 Suspendes all performing operations
469 void QAD_Study::suspendAllOperations()
471 // MESSAGE ( " QAD_Study::suspendAllOperations init. " )
472 for ( QAD_Operation* op = myOperations.last(); op;
473 op = myOperations.prev() )
478 Initializes the operation and checks its compatibility
479 with another operation in process if any.
480 Returns 'true' if init'ed OK, 'false' otherwise.
482 bool QAD_Study::initOperation( QAD_Operation* op )
485 { /* can't start a non-const operation */
486 if ( op->changesData() )
488 QAD_MessageBox::error1( QAD_Application::getDesktop(), tr("ERR_ERROR"),
489 tr("ERR_DOC_READONLY"), tr("BUT_OK") );
494 /* Add the new operation
496 if ( myOperations.isEmpty() )
497 myOperations.append( op );
500 /* Check compatibility of new operation with the existing operations.
501 Since each operations is checked in that way, it's enough to check
502 the last operation only */
503 if ( !getLastOperation()->compatibleWith( op ) )
505 if ( QAD_MessageBox::warn2( QAD_Application::getDesktop(), tr("WRN_WARNING"),
506 tr("QUE_ABORTCURRENTOPERATION"), tr("BUT_YES"),
507 tr("BUT_NO"), QAD_YES, QAD_NO, QAD_NO )
510 getLastOperation()->abort();
512 myOperations.append( op );
518 Called when operation was finished.
519 Removes appointed operation from the list and aborted all operations
522 void QAD_Study::clearOperation( QAD_Operation* op)
524 if ( myOperations.contains( op ) )
526 /* abort all the operations launched after 'op' */
527 for ( QAD_Operation* cur = myOperations.last(); cur;
528 cur = myOperations.prev() )
530 if ( cur == op ) break;
533 myOperations.remove( op );
540 QAD_StudyFrame* QAD_Study::createStudyFrame( const QString& title, ViewType theViewType)
542 QAD_Desktop* parent = QAD_Application::getDesktop();
543 //srn: Forbid appending Interface Applicative and its children to UseCase
544 myStudy->EnableUseCaseAutoFilling(false);
546 SALOMEDS::SComponent_var father = myStudy->FindComponent("Interface Applicative");
547 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
548 SALOMEDS::GenericAttribute_var anAttr;
549 SALOMEDS::AttributeName_var aName;
550 SALOMEDS::AttributeComment_var aComment;
551 SALOMEDS::AttributeSelectable_var aSelAttr;
553 // mpv : where is "NewCommand" call?
554 // aStudyBuilder->CommitCommand();
556 // mpv : is study is locked, then next code will raise exception. So, temporary unlock study
557 int aLocked = myStudy->GetProperties()->IsLocked();
558 if (aLocked) myStudy->GetProperties()->SetLocked(false);
560 if ( father->_is_nil() ) {
561 father = aStudyBuilder->NewComponent("Interface Applicative");
562 anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributeName");
563 aName = SALOMEDS::AttributeName::_narrow(anAttr);
564 aName->SetValue("Interface Applicative");
566 anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributeSelectable");
567 aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
568 aSelAttr->SetSelectable(false);
571 //VRV: T2.5 - add default viewer
572 if(theViewType == VIEW_TYPE_MAX) {
573 QString viewerValue = QAD_CONFIG->getSetting( "Viewer:DefaultViewer" );
575 theViewType = (ViewType)viewerValue.toInt( &ok, 10 );
576 if (!ok || theViewType < VIEW_OCC || theViewType >= VIEW_TYPE_MAX)
577 theViewType = VIEW_VTK;
579 //QApplication::restoreOverrideCursor();
580 QAD_StudyFrame* sf = NULL;
581 SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(father);
582 if ( theViewType == VIEW_OCC) {
583 // MESSAGE ("Create Study Frame for OCC viewer");
584 sf = new QAD_StudyFrame ( this, parent->getMainFrame(),
585 title, _interp, VIEW_OCC );
587 Standard_CString name = strdup(sf->title().latin1());
588 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
589 aName = SALOMEDS::AttributeName::_narrow(anAttr);
590 aName->SetValue(name);
591 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeComment");
592 aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
593 aComment->SetValue("OCC");
595 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeSelectable");
596 aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
597 aSelAttr->SetSelectable(false);
599 else if ( theViewType == VIEW_VTK) {
600 // MESSAGE ("Create Study Frame for VTK viewer");
601 sf = new QAD_StudyFrame ( this, parent->getMainFrame(),
602 title, _interp, VIEW_VTK );
603 Standard_CString name = strdup(sf->title().latin1());
604 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
605 aName = SALOMEDS::AttributeName::_narrow(anAttr);
606 aName->SetValue(name);
607 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeComment");
608 aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
609 aComment->SetValue("VTK");
611 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeSelectable");
612 aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
613 aSelAttr->SetSelectable(false);
615 else if ( theViewType == VIEW_GRAPHSUPERV) {
616 //MESSAGE ("Create Study Frame for SUPER`VISOR Graph");
617 sf = new QAD_StudyFrame ( this, parent->getMainFrame(),
618 title, _interp, VIEW_GRAPHSUPERV );
619 Standard_CString name = strdup(sf->title().latin1());
620 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
621 aName = SALOMEDS::AttributeName::_narrow(anAttr);
622 aName->SetValue(name);
623 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeComment");
624 aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
625 aComment->SetValue("GRAPH");
627 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeSelectable");
628 aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
629 aSelAttr->SetSelectable(false);
631 else if ( theViewType == VIEW_PLOT2D ) {
632 sf = new QAD_StudyFrame ( this, parent->getMainFrame(),
633 title, _interp, VIEW_PLOT2D );
634 Standard_CString name = strdup(sf->title().latin1());
635 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
636 aName = SALOMEDS::AttributeName::_narrow(anAttr);
637 aName->SetValue(name);
638 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeComment");
639 aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
640 aComment->SetValue("PLOT2D");
642 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeSelectable");
643 aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
644 aSelAttr->SetSelectable(false);
646 //VRV: T2.5 - add default viewer
648 sf->resize( int (0.8*parent->getMainFrame()->width()),
649 int (0.8*parent->getMainFrame()->height() ));
651 sf->setEntry(newObj->GetID());
655 updateObjBrowser( true );
657 parent->setSettings();
661 if (aLocked) myStudy->GetProperties()->SetLocked(true);
663 // T2.12 - add the word "locked" to study frame captions if this study is locked
666 myStudy->EnableUseCaseAutoFilling(true);
672 Updates study frame captions according to IsLocked study flag
674 void QAD_Study::updateCaptions()
676 QString appendix("");
678 if (!myStudy->_is_nil()) {
679 SALOMEDS::AttributeStudyProperties_var propAttr = myStudy->GetProperties();
681 if (!propAttr->_is_nil() ) {
682 if ( propAttr->IsModified() )
683 appendix += " (" + tr("PRP_STUDY_MODIFIED") + ")";
685 appendix += " (" + tr("PRP_STUDY_SAVED") + ")";
689 if (!propAttr->_is_nil() && propAttr->IsLocked()) {
690 appendix += " (" + tr("PRP_STUDY_LOCKED") + ")";
694 for (myStudyFrames.first(); myStudyFrames.current(); myStudyFrames.next()) {
695 myStudyFrames.current()->setCaption(myStudyFrames.current()->title() + appendix);
701 Shows the active study frame.
702 Called by Desktop after 'new' and 'open' commands.
704 void QAD_Study::show()
706 for (myStudyFrames.first(); myStudyFrames.current(); myStudyFrames.next()) {
707 myStudyFrames.current()->show();
711 //=======================================================================//
712 // Study properties (CAF related) //
713 //=======================================================================//
716 Returns connected SALOMEDS_Study object
718 SALOMEDS::Study_var QAD_Study::getStudyDocument()
724 Returns whether the document was saved in file
726 bool QAD_Study::isSaved() const
728 return myStudy->IsSaved();
732 Returns whether the document is modified
734 bool QAD_Study::isModified() const
736 // return myStudy->IsModified(); // VSR:05/12/02 - USE PROPERTY : MODIFIED FLAG
737 if ( !myStudy->_is_nil() ) {
738 SALOMEDS::AttributeStudyProperties_var propAttr = myStudy->GetProperties();
739 if ( !propAttr->_is_nil() )
740 return propAttr->IsModified();
745 bool QAD_Study::undo()
748 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
751 /* Update Object Browser */
752 updateObjBrowser( true );
754 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
756 sf->getRightFrame()->getViewFrame()->undo( myStudy, sf->entry() );
760 // mpv 07.03.2003 SAL1805: clear selection must be called after study structure changed
761 SALOME_Selection* Sel = SALOME_Selection::Selection( getSelection() );
762 Sel->ClearIObjects();
764 // mpv : undo command can raise exception, if study is locked
765 catch ( SALOMEDS::StudyBuilder::LockProtection& ) {
766 QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
767 QObject::tr("WRN_WARNING"),
768 QObject::tr("WRN_STUDY_LOCKED"),
769 QObject::tr("BUT_OK"));
772 catch ( Standard_Failure ) {
780 bool QAD_Study::redo()
783 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
786 /* Update Object Browser */
787 updateObjBrowser( true );
790 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
791 sf->getRightFrame()->getViewFrame()->redo( myStudy, sf->entry() );
795 // mpv 07.03.2003 SAL1805: clear selection must be called after study structure changed
796 SALOME_Selection* Sel = SALOME_Selection::Selection( getSelection() );
797 Sel->ClearIObjects();
799 // mpv : redo command can raise exception, if study is locked
800 catch ( SALOMEDS::StudyBuilder::LockProtection& ) {
801 QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
802 QObject::tr("WRN_WARNING"),
803 QObject::tr("WRN_STUDY_LOCKED"),
804 QObject::tr("BUT_OK"));
807 catch ( Standard_Failure ) {
813 Check if possible to perform 'undo' command
815 bool QAD_Study::canUndo() const
817 if ( myStudy->_is_nil() )
820 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
821 return (SB->GetAvailableUndos() > 0 );
825 Check if possible to perform 'redo' command
827 bool QAD_Study::canRedo() const
829 if ( myStudy->_is_nil() )
832 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
833 return (SB->GetAvailableRedos() > 0 );
837 Called when operation is started
838 Returns 'true' if started OK, 'false' otherwise.
840 bool QAD_Study::onOperationStarted( QAD_Operation* op )
842 if ( !initOperation( op ) )
846 { /* start a new transaction */
847 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
850 catch ( Standard_Failure )
852 /* May be, a transaction is already open,
853 it's not a problem */
855 myOperationState = Started;
860 Called when operation is finished
862 void QAD_Study::onOperationFinished( QAD_Operation* op )
865 /* transaction is completed OK */
866 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
869 catch ( SALOMEDS::StudyBuilder::LockProtection& ) {
870 QApplication::restoreOverrideCursor();
871 QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
872 QObject::tr("WRN_WARNING"),
873 QObject::tr("WRN_STUDY_LOCKED"),
874 QObject::tr("BUT_OK"));
875 onOperationAborted(op);
876 updateObjBrowser( true );
879 catch ( Standard_Failure ) {
881 myOperationState = Finished;
882 emit docOperationTerminated( true ); /* terminated successfully */
885 // mpv: any operation must call this method, otherwise study may not be saved
886 updateObjBrowser( true );
888 clearOperation( op ); /* we don't need the operation anymore */
889 QAD_Application::getDesktop()->putInfo ( tr("INF_DOC_OPERATIONFINISHED") );
893 Called when operation is suspended
895 void QAD_Study::onOperationSuspended( QAD_Operation* op )
897 myOperationState = Suspended;
901 Called when operation is resumed
903 void QAD_Study::onOperationResumed( QAD_Operation* op )
905 myOperationState = Resumed;
909 Called when operation is aborted
911 void QAD_Study::onOperationAborted(QAD_Operation* op)
914 /* abort transaction */
915 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
918 catch ( Standard_Failure )
921 myOperationState = Aborted;
922 emit docOperationTerminated( false ); /* aborted */
927 QAD_Application::getDesktop()->putInfo ( tr("INF_DOC_OPERATIONABORTED") );
931 Call when the last study frame is closing
933 void QAD_Study::onLastStudyFrameClosing( QAD_StudyFrame* sf )
935 if ( myStudyFrames.count() == 1 ) {
936 emit docClosing( this );
938 removeStudyFrame( sf );
940 // QWorkspace* ws = QAD_Application::getDesktop()->getMainFrame();
941 // if ( !ws->activeWindow() && ws->windowList().count() > 0 )
942 // ws->activatePreviousWindow();
946 Call when created a new window3d
948 QAD_StudyFrame* QAD_Study::newWindow3d(QString name, ViewType theViewType, bool toShow)
950 if(name == "") name = getNextStudyFrameName();
951 QAD_StudyFrame* sf = createStudyFrame( name, theViewType );
953 if (toShow) showFrame(sf);
954 // sf->compressLeft(); /* compress LeftFrame */
955 sf->getRightFrame()->compressBottom(); /* compress BottomFrame */
961 void QAD_Study::showFrame(QAD_StudyFrame* theFrame){
962 theFrame->resize( (int)(0.64*QAD_Application::getDesktop()->getMainFrame()->width()),
963 (int)(0.64*QAD_Application::getDesktop()->getMainFrame()->height()));
971 Call when setted a message
973 void QAD_Study::setMessage(const char* message)
975 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
976 sf->getRightFrame()->getMessage()->setMessage(message);
981 Call when updated object browser
983 void QAD_Study::updateObjBrowser( bool updateSelection )
985 QAD_Desktop* parent = QAD_Application::getDesktop();
986 SALOME_ModuleCatalog::ModuleCatalog_var Catalog = parent->getCatalogue();
988 QString ActiveComp = parent->getActiveComponent();
990 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
991 sf->getLeftFrame()->getObjectBrowser()->Update();
994 /* update selection */
995 if ( updateSelection && (myStudyFrames.count() > 0) ) {
996 SALOME_Selection* Sel = SALOME_Selection::Selection( getSelection() );
997 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
998 for(;It.More();It.Next()) {
999 if ( Sel->AddIObject( It.Value() ) == 0 ) {
1000 highlight( It.Value(), true, false );
1004 /* update viewers */
1009 Updates only Use Case Browser
1011 void QAD_Study::updateUseCaseBrowser( bool updateSelection )
1013 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
1014 sf->getLeftFrame()->getObjectBrowser()->UpdateUseCaseBrowser();
1016 /* update selection */
1017 if ( updateSelection && (myStudyFrames.count() > 0) ) {
1018 SALOME_Selection* Sel = SALOME_Selection::Selection( getSelection() );
1019 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1020 for(;It.More();It.Next()) {
1021 if ( Sel->AddIObject( It.Value() ) == 0 ) {
1022 highlight( It.Value(), true, false );
1025 /* update viewers */
1031 unHighlight All Interactive Objects in All Devices
1033 void QAD_Study::unHighlightAll()
1035 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
1036 /* Device = Viewers */
1037 sf->getRightFrame()->getViewFrame()->unHighlightAll();
1039 /* Device = ObjectBrowser */
1040 sf->getLeftFrame()->getObjectBrowser()->unHighlightAll();
1045 Returns type of Interactive Object
1047 int QAD_Study::typeIObject( const Handle(SALOME_InteractiveObject)& IObject )
1049 bool IsStudyObject = isInStudy( IObject );
1050 bool IsGraphicalObject = isInViewer( IObject );
1052 // MESSAGE ( "IsStudyObject : " << IsStudyObject )
1053 // MESSAGE ( "IsGraphicalObject : " << IsGraphicalObject )
1055 if ( IsStudyObject ) {
1056 if ( IsGraphicalObject )
1057 return 1; /* StudyObject and GraphicalObject */
1059 return 2; /* only StudyObject */
1061 if ( IsGraphicalObject )
1062 return 3; /* only GraphicalObject */
1064 return 4; /* may be a component */
1071 Renames the Interactive Object in All Devices
1073 void QAD_Study::renameIObject( const Handle(SALOME_InteractiveObject)& IObject, QString newName )
1075 if (myStudy->GetProperties()->IsLocked()) {
1076 QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
1077 QObject::tr("WRN_WARNING"),
1078 QObject::tr("WRN_STUDY_LOCKED"),
1079 QObject::tr("BUT_OK"));
1083 highlight( IObject, false );
1085 int nbFrames = myStudyFrames.count();
1086 for ( int i = 0; i < nbFrames; i++ ) {
1087 QAD_StudyFrame* sf = myStudyFrames.at( i );
1088 switch ( typeIObject(IObject) ) {
1091 /* Device = Viewers */
1092 sf->getRightFrame()->getViewFrame()->rename(IObject, newName);
1093 /* Device = ObjectBrowser */
1094 sf->getLeftFrame()->getObjectBrowser()->rename(IObject, newName);
1099 /* Device = ObjectBrowser */
1100 sf->getLeftFrame()->getObjectBrowser()->rename(IObject, newName);
1105 /* Device = Viewers */
1106 sf->getRightFrame()->getViewFrame()->rename(IObject, newName);
1111 QString ActiveComp = QAD_Application::getDesktop()->getActiveComponent();
1112 if ( !ActiveComp.isEmpty() ) {
1113 sf->getLeftFrame()->getObjectBrowser()->rename(IObject,newName);
1121 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
1122 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IObject->getEntry() );
1123 if ( !obj->_is_nil() ) {
1124 SALOMEDS::GenericAttribute_var anAttr;
1125 SALOMEDS::AttributeName_var aName;
1126 anAttr = aStudyBuilder->FindOrCreateAttribute(obj, "AttributeName");
1127 aName = SALOMEDS::AttributeName::_narrow(anAttr);
1128 aName->SetValue(strdup(newName.latin1()));
1131 // VSR 13/03/03 - rename Interactive object
1132 IObject->setName( ( char* )newName.latin1() );
1134 updateObjBrowser( true );
1138 Selects the Interactive Object in All Devices
1140 void QAD_Study::highlight( const Handle(SALOME_InteractiveObject)& IObject, bool highlight,bool immediatly )
1142 // MESSAGE ( " QAD_Study::highlight : " << highlight )
1143 int typeIO = typeIObject( IObject );
1145 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
1149 /* Device = Viewer */
1150 if (sf->getTypeView() >= 0 ) { /* Device = Viewers */
1151 sf->getRightFrame()->getViewFrame()->highlight(IObject, highlight, immediatly);
1153 /* Device = ObjectBrowser */
1154 sf->getLeftFrame()->getObjectBrowser()->highlight(IObject, highlight);
1159 /* Device = ObjectBrowser */
1160 sf->getLeftFrame()->getObjectBrowser()->highlight(IObject, highlight);
1165 /* Device = Viewer */
1166 if (sf->getTypeView() >= 0) { /* Device = Viewers */
1167 sf->getRightFrame()->getViewFrame()->highlight(IObject, highlight, immediatly);
1173 QString ActiveComp = QAD_Application::getDesktop()->getActiveComponent();
1174 if ( !ActiveComp.isEmpty() ) {
1175 sf->getLeftFrame()->getObjectBrowser()->highlight(IObject,highlight);
1184 Returns TRUE if the IObject is a Study Object. Returns FALSE otherwise.
1186 bool QAD_Study::isInStudy( const Handle(SALOME_InteractiveObject)& IObject )
1188 return IObject->hasEntry();
1192 Returns true if the IObject has a Graphical Object. Returns FALSE otherwise.
1194 bool QAD_Study::isInViewer( const Handle(SALOME_InteractiveObject)& IObject )
1197 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
1198 found = sf->getRightFrame()->getViewFrame()->isInViewer(IObject);
1206 Returns true if the IObject has a Graphical Object into studyframe. Returns FALSE otherwise.
1208 bool QAD_Study::isInViewer(const char* anEntry, const char* StudyFrameEntry)
1210 SALOMEDS::SObject_var RefSO;
1211 SALOMEDS::SObject_var SO = myStudy->FindObjectID(StudyFrameEntry);
1212 SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(SO);
1213 for (; it->More();it->Next()){
1214 SALOMEDS::SObject_var CSO= it->Value();
1215 if (CSO->ReferencedObject(RefSO))
1216 if ( strcmp( anEntry, RefSO->GetID() ) == 0 )
1224 Returns title for the new studyframe window
1226 QString QAD_Study::getNextStudyFrameName()
1228 QString numStudyFrame;
1229 numStudyFrame.sprintf("%s%d", "#", ++myStudyFrameCount );
1230 return myTitle + numStudyFrame; /* return unique name ( title + unique number) */
1235 Returns the Python interpreter that belongs to this study
1237 QAD_PyInterp* QAD_Study::get_PyInterp(void)
1243 Sets current selection.
1245 void QAD_Study::Selection( QString aSelection )
1247 if ( !SALOME_Selection::FindSelection( QString(myTitle + "_" + aSelection) ) )
1248 SALOME_Selection::CreateSelection( QString(myTitle + "_" + aSelection) );
1250 SALOME_Selection* Sel = SALOME_Selection::Selection( QString(myTitle + "_" + aSelection) );
1252 mySelection = aSelection;
1256 Returns the name of current selection
1258 QString QAD_Study::getSelection()
1260 return QString (myTitle + "_" + mySelection);
1264 Returns the study Id.
1266 int QAD_Study::getStudyId()
1268 return myStudy->StudyId();
1271 void QAD_Study::update3dViewers()
1273 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
1274 sf->getRightFrame()->getViewFrame()->Repaint();
1278 /* Adds new child window */
1279 void QAD_Study::addChildWidget( QWidget* child )
1281 if ( myChildWidgets.findRef( child ) < 0 ) {
1282 myChildWidgets.append( child );
1283 child->installEventFilter( this );
1288 Removes child window from the list ( and deletes it )
1290 void QAD_Study::removeChildWidget( QWidget* child )
1292 myChildWidgets.removeRef( child );
1296 bool QAD_Study::eventFilter( QObject* o, QEvent* e)
1298 int index = myChildWidgets.findRef( ( QWidget* )o );
1299 if ( index >= 0 && e->type() == QEvent::Close ) {
1300 myChildWidgets.at( index )->removeEventFilter( this );
1301 myChildWidgets.remove( ( QWidget* )o );
1304 return QObject::eventFilter( o, e );