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
30 \class QAD_Study QAD_Study.h
31 \brief Study for QAD-based application.
35 #include "QAD_Tools.h"
36 #include "QAD_Desktop.h"
37 #include "QAD_Study.h"
38 #include "QAD_RightFrame.h"
39 #include "QAD_LeftFrame.h"
40 #include "QAD_MessageBox.h"
41 #include "QAD_Application.h"
42 #include "QAD_ObjectBrowser.h"
43 #include "QAD_PyInterp.h"
44 #include "QAD_Config.h"
46 #include "utilities.h"
48 #include "SALOME_Selection.h"
49 #include "SALOME_TypeFilter.hxx"
50 #include "SALOME_InteractiveObject.hxx"
51 #include "SALOME_ListIteratorOfListIO.hxx"
53 #include <SALOMEconfig.h>
54 #include CORBA_SERVER_HEADER(SALOMEDS)
56 // OPEN CASCADE Include
57 #include <Standard_Failure.hxx>
60 #include <qapplication.h>
66 QAD_Study::QAD_Study(QAD_Application* app,
67 SALOMEDS::Study_var aStudy,
68 const QString& path ) :
69 myOperationState( Undef ),
71 myActiveStudyFrame( 0 ),
72 myStudyFrameCount( 0 ),
77 myTitle = QAD_Tools::getFileNameFromPath( path, true );
84 myStudyFrames.clear();
87 myStudyFrames.setAutoDelete( true );
88 myOperations.setAutoDelete( true );
89 myChildWidgets.setAutoDelete( true );
91 /* create python interpreter */
92 _interp = new QAD_PyInterp();
95 /* create default selection */
96 //NRI Selection( "Salome" );
97 Selection( QAD_Application::getDesktop()->getComponentUserName( "KERNEL" ) );
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();
107 int aLocked = myStudy->GetProperties()->IsLocked();
108 if (aLocked) myStudy->GetProperties()->SetLocked(false);
109 SB->UndoLimit(QAD_Desktop::getUndoLevel());
110 if (aLocked) myStudy->GetProperties()->SetLocked(true);
117 QAD_Study::~QAD_Study ()
120 //SRN: added - clear selection in case the study will be loaded again so the title will coincide
121 SALOME_Selection::RemoveSelection( QString(myTitle + "_" + mySelection) );
125 Returns TRUE if Study is created correctly. Returns FALSE otherwise.
127 bool QAD_Study::getResult()
133 //=======================================================================//
134 // StudyFrames management //
135 //=======================================================================//
139 void QAD_Study::addStudyFrame(QAD_StudyFrame* sf )
141 myStudyFrames.append( sf );
143 sf->getRightFrame()->getViewFrame()->setPopupServer( myApp );
144 // Provide the same common popup menu commands for both the Object Browser and 3D viewer
145 sf->getLeftFrame()->getObjectBrowser()->setPopupServer( myApp );
147 /* icon of Study Frame */
148 const QPixmap& icon = myApp->getApplicationIcon();
149 if ( !icon.isNull() )
150 sf->setIcon ( icon );
153 QAD_ASSERT ( connect( sf, SIGNAL(sfStudyFrameActivated(QAD_StudyFrame*) ),
154 SLOT(onStudyFrameActivated(QAD_StudyFrame*))) );
157 QAD_ASSERT ( connect( sf,
158 SIGNAL(sfStudyFrameClosing(QAD_StudyFrame*) ),
160 SLOT(onLastStudyFrameClosing(QAD_StudyFrame*))) );
163 myActiveStudyFrame = sf;
167 Removes studyframe from the list
169 void QAD_Study::removeStudyFrame( QAD_StudyFrame* sf )
172 if (!myStudy->IsEmpty()) {
173 SALOMEDS::SObject_var fatherSF = myStudy->FindObjectID(sf->entry());
174 if (!fatherSF->_is_nil()) {
175 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
176 int aLocked = myStudy->GetProperties()->IsLocked();
177 if (aLocked) myStudy->GetProperties()->SetLocked(false);
178 aStudyBuilder->RemoveObject(fatherSF);
179 if (aLocked) myStudy->GetProperties()->SetLocked(true);
182 updateObjBrowser( true );
184 myStudyFrames.removeRef( sf );
189 Returns number of study frames
191 int QAD_Study::getStudyFramesCount() const
193 return myStudyFrames.count();
197 Returns study frame by its index in list
199 QAD_StudyFrame* QAD_Study::getStudyFrame( unsigned i )
201 return myStudyFrames.at(i);
205 Returns study frame by its name or null if not found
207 QAD_StudyFrame* QAD_Study::getStudyFrameByName ( const QString& name )
209 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() )
211 if ( sf->title().compare(name) == 0 ) {
219 Returns first study frame in the list
221 QAD_StudyFrame* QAD_Study::getFirstStudyFrame()
223 return myStudyFrames.first();
227 Returns last study frame in the list
229 QAD_StudyFrame* QAD_Study::getLastStudyFrame()
231 return myStudyFrames.last();
235 Returns the vector of studyframes
237 const QList<QAD_StudyFrame>& QAD_Study::getStudyFrames() const
239 return myStudyFrames;
243 Returns the active study frame
245 QAD_StudyFrame* QAD_Study::getActiveStudyFrame() const
247 return myActiveStudyFrame;
250 //=======================================================================//
251 // Study properties //
252 //=======================================================================//
254 Returns reference to supporting application
256 QAD_Application* QAD_Study::getApp() const
262 Returns the name of document ( filename without path and extension )
264 const QString& QAD_Study::getTitle() const
270 Returns the absolute file path of this document
272 const QString& QAD_Study::getPath() const
278 Changes the name of document
280 void QAD_Study::setTitle( const QString& path )
284 QString title = QAD_Tools::getFileNameFromPath( path, true );
285 QAD_ASSERT_DEBUG_ONLY ( !title.isNull() );
287 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf ; sf = myStudyFrames.next() )
289 QString oldName = sf->title();
290 int k = oldName.find( myTitle, 0, false );
291 QString restName = ( oldName.length() > myTitle.length() + k) ?
292 oldName.right(oldName.length() - (myTitle.length() + k) + 1) :
299 int l = restName.find( "#", 0, false );
300 int ll = restName.length();
301 newName = title + restName.mid( l, ll-l );
303 newName = oldName.mid(0, k);
304 newName = newName + title + restName;
306 sf->setTitle( newName );
311 Selection( QAD_Application::getDesktop()->getActiveComponent() );
315 Returns whether the document is active
317 bool QAD_Study::isActive() const
323 Returns whether the document is read only
325 bool QAD_Study::isReadOnly() const
331 Sets read-only property
333 void QAD_Study::setReadOnly(bool state)
335 myIsReadOnly = state;
338 //=======================================================================//
339 // Study operations //
340 //=======================================================================//
342 Performs specific study frame related actions when it is activated.
343 By default resumes all suspended operations.
345 void QAD_Study::onStudyFrameActivated( QAD_StudyFrame* activeStudyFrame )
347 static int IS_FIRST_STUDY = 1;
348 if(IS_FIRST_STUDY){ //for normally initialize "salome.py and ..."
349 _interp->run(""); IS_FIRST_STUDY = 0;
351 // bool found = false;
352 for ( QAD_StudyFrame* studyframe = myStudyFrames.first(); studyframe; studyframe = myStudyFrames.next() ) {
353 if ( studyframe == activeStudyFrame) { /* one of my study frames */
355 // if ( !myActiveStudyFrame || myActiveStudyFrame != activeStudyFrame ) {
356 myActiveStudyFrame = activeStudyFrame;
357 //NRI if ( !myIsActive ) {
359 resumeAllOperations();
360 /* activate application */
361 myApp->onStudyActivated( this );
368 // myActiveStudyFrame = 0;
373 Performs specific study related actions when it is deactivated.
374 By default suspends all performing operations.
376 void QAD_Study::onStudyDeactivated()
378 // MESSAGE ("QAD_Study::onStudyDeactivated init. ");
380 suspendAllOperations();
381 // MESSAGE ("QAD_Study::onStudyDeactivated done. ");
385 Closes all study frames of the study and performs other specific study
386 related actions needed for proper closing of the study
388 void QAD_Study::close()
391 if ( !myStudy->_is_nil() )
392 abortAllOperations();
393 /* clear each study frame */
394 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.first() ) {
397 qApp->processEvents();
398 qApp->processEvents();
399 removeStudyFrame(sf);
402 /* delete all studyframes */
403 myStudyFrames.clear();
404 myOperations.clear();
405 myChildWidgets.clear();
407 // QWorkspace* ws = QAD_Application::getDesktop()->getMainFrame();
408 // if (/* !ws->activeWindow() && */ws->windowList().count() > 0 )
409 // ws->activateWindow(ws->windowList().last());
412 //=======================================================================//
413 // Operations management //
414 //=======================================================================//
416 Returns number of completed operations
418 int QAD_Study::getOperationsCount() const
420 return myOperations.count();
424 Returns the state of the last operation
426 OperationState QAD_Study::getOperationState() const
428 return myOperationState;
432 Returns operation by its index in list
434 QAD_Operation* QAD_Study::getOperation( unsigned i)
436 return ( myOperations.isEmpty() ? 0 : myOperations.at(i) );
440 Returns performing operation launched first
442 QAD_Operation* QAD_Study::getFirstOperation()
444 return ( myOperations.isEmpty() ? 0 : myOperations.first() );
448 Returns performing operation launched last
450 QAD_Operation* QAD_Study::getLastOperation()
452 return ( myOperations.isEmpty() ? 0 : myOperations.last() );
456 Aborts all performing operations
458 void QAD_Study::abortAllOperations()
460 for ( QAD_Operation* op = myOperations.last(); op;
461 op = myOperations.prev() )
466 Resumes all performing operations
468 void QAD_Study::resumeAllOperations()
470 for ( QAD_Operation* op = myOperations.first(); op;
471 op = myOperations.next() )
476 Suspendes all performing operations
478 void QAD_Study::suspendAllOperations()
480 // MESSAGE ( " QAD_Study::suspendAllOperations init. " )
481 for ( QAD_Operation* op = myOperations.last(); op;
482 op = myOperations.prev() )
487 Initializes the operation and checks its compatibility
488 with another operation in process if any.
489 Returns 'true' if init'ed OK, 'false' otherwise.
491 bool QAD_Study::initOperation( QAD_Operation* op )
494 { /* can't start a non-const operation */
495 if ( op->changesData() )
497 QAD_MessageBox::error1( QAD_Application::getDesktop(), tr("ERR_ERROR"),
498 tr("ERR_DOC_READONLY"), tr("BUT_OK") );
503 /* Add the new operation
505 if ( myOperations.isEmpty() )
506 myOperations.append( op );
509 /* Check compatibility of new operation with the existing operations.
510 Since each operations is checked in that way, it's enough to check
511 the last operation only */
512 if ( !getLastOperation()->compatibleWith( op ) )
514 if ( QAD_MessageBox::warn2( QAD_Application::getDesktop(), tr("WRN_WARNING"),
515 tr("QUE_ABORTCURRENTOPERATION"), tr("BUT_YES"),
516 tr("BUT_NO"), QAD_YES, QAD_NO, QAD_NO )
519 getLastOperation()->abort();
521 myOperations.append( op );
527 Called when operation was finished.
528 Removes appointed operation from the list and aborted all operations
531 void QAD_Study::clearOperation( QAD_Operation* op)
533 if ( myOperations.contains( op ) )
535 /* abort all the operations launched after 'op' */
536 for ( QAD_Operation* cur = myOperations.last(); cur;
537 cur = myOperations.prev() )
539 if ( cur == op ) break;
542 myOperations.remove( op );
549 QAD_StudyFrame* QAD_Study::createStudyFrame( const QString& title, ViewType theViewType)
551 QAD_Desktop* parent = QAD_Application::getDesktop();
552 //srn: Forbid appending Interface Applicative and its children to UseCase
553 myStudy->EnableUseCaseAutoFilling(false);
555 SALOMEDS::SComponent_var father = myStudy->FindComponent("Interface Applicative");
556 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
557 SALOMEDS::GenericAttribute_var anAttr;
558 SALOMEDS::AttributeName_var aName;
559 SALOMEDS::AttributeComment_var aComment;
560 SALOMEDS::AttributeSelectable_var aSelAttr;
562 // mpv : where is "NewCommand" call?
563 // aStudyBuilder->CommitCommand();
565 // mpv : is study is locked, then next code will raise exception. So, temporary unlock study
566 int aLocked = myStudy->GetProperties()->IsLocked();
567 if (aLocked) myStudy->GetProperties()->SetLocked(false);
569 if ( father->_is_nil() ) {
570 father = aStudyBuilder->NewComponent("Interface Applicative");
571 anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributeName");
572 aName = SALOMEDS::AttributeName::_narrow(anAttr);
573 aName->SetValue("Interface Applicative");
575 anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributeSelectable");
576 aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
577 aSelAttr->SetSelectable(false);
580 //VRV: T2.5 - add default viewer
581 if(theViewType == VIEW_TYPE_MAX) {
582 QString viewerValue = QAD_CONFIG->getSetting( "Viewer:DefaultViewer" );
584 theViewType = (ViewType)viewerValue.toInt( &ok, 10 );
585 if (!ok || theViewType < VIEW_OCC || theViewType >= VIEW_TYPE_MAX)
586 theViewType = VIEW_VTK;
588 //QApplication::restoreOverrideCursor();
589 QAD_StudyFrame* sf = NULL;
590 SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(father);
591 if ( theViewType == VIEW_OCC) {
592 // MESSAGE ("Create Study Frame for OCC viewer");
593 sf = new QAD_StudyFrame ( this, parent->getMainFrame(),
594 title, _interp, VIEW_OCC );
596 Standard_CString name = strdup(sf->title().latin1());
597 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
598 aName = SALOMEDS::AttributeName::_narrow(anAttr);
599 aName->SetValue(name);
600 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeComment");
601 aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
602 aComment->SetValue("OCC");
604 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeSelectable");
605 aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
606 aSelAttr->SetSelectable(false);
608 else if ( theViewType == VIEW_VTK) {
609 // MESSAGE ("Create Study Frame for VTK viewer");
610 sf = new QAD_StudyFrame ( this, parent->getMainFrame(),
611 title, _interp, VIEW_VTK );
612 Standard_CString name = strdup(sf->title().latin1());
613 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
614 aName = SALOMEDS::AttributeName::_narrow(anAttr);
615 aName->SetValue(name);
616 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeComment");
617 aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
618 aComment->SetValue("VTK");
620 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeSelectable");
621 aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
622 aSelAttr->SetSelectable(false);
624 else if ( theViewType == VIEW_GRAPHSUPERV) {
625 //MESSAGE ("Create Study Frame for SUPER`VISOR Graph");
626 sf = new QAD_StudyFrame ( this, parent->getMainFrame(),
627 title, _interp, VIEW_GRAPHSUPERV );
628 Standard_CString name = strdup(sf->title().latin1());
629 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
630 aName = SALOMEDS::AttributeName::_narrow(anAttr);
631 aName->SetValue(name);
632 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeComment");
633 aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
634 aComment->SetValue("GRAPH");
636 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeSelectable");
637 aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
638 aSelAttr->SetSelectable(false);
640 else if ( theViewType == VIEW_PLOT2D ) {
641 sf = new QAD_StudyFrame ( this, parent->getMainFrame(),
642 title, _interp, VIEW_PLOT2D );
643 Standard_CString name = strdup(sf->title().latin1());
644 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
645 aName = SALOMEDS::AttributeName::_narrow(anAttr);
646 aName->SetValue(name);
647 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeComment");
648 aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
649 aComment->SetValue("PLOT2D");
651 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeSelectable");
652 aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
653 aSelAttr->SetSelectable(false);
655 //VRV: T2.5 - add default viewer
657 sf->resize( int (0.8*parent->getMainFrame()->width()),
658 int (0.8*parent->getMainFrame()->height() ));
660 sf->setEntry(newObj->GetID());
664 updateObjBrowser( true );
666 parent->setSettings();
670 if (aLocked) myStudy->GetProperties()->SetLocked(true);
672 // T2.12 - add the word "locked" to study frame captions if this study is locked
675 myStudy->EnableUseCaseAutoFilling(true);
681 Updates study frame captions according to IsLocked study flag
683 void QAD_Study::updateCaptions()
685 QString appendix("");
687 if (!myStudy->_is_nil()) {
688 SALOMEDS::AttributeStudyProperties_var propAttr = myStudy->GetProperties();
690 if (!propAttr->_is_nil() ) {
691 if ( propAttr->IsModified() )
692 appendix += " (" + tr("PRP_STUDY_MODIFIED") + ")";
694 appendix += " (" + tr("PRP_STUDY_SAVED") + ")";
698 if (!propAttr->_is_nil() && propAttr->IsLocked()) {
699 appendix += " (" + tr("PRP_STUDY_LOCKED") + ")";
703 for (myStudyFrames.first(); myStudyFrames.current(); myStudyFrames.next()) {
704 myStudyFrames.current()->setCaption(myStudyFrames.current()->title() + appendix);
710 Shows the active study frame.
711 Called by Desktop after 'new' and 'open' commands.
713 void QAD_Study::show()
715 for (myStudyFrames.first(); myStudyFrames.current(); myStudyFrames.next()) {
716 myStudyFrames.current()->show();
720 //=======================================================================//
721 // Study properties (CAF related) //
722 //=======================================================================//
725 Returns connected SALOMEDS_Study object
727 SALOMEDS::Study_var QAD_Study::getStudyDocument()
733 Returns whether the document was saved in file
735 bool QAD_Study::isSaved() const
737 return myStudy->IsSaved();
741 Returns whether the document is modified
743 bool QAD_Study::isModified() const
745 // return myStudy->IsModified(); // VSR:05/12/02 - USE PROPERTY : MODIFIED FLAG
746 if ( !myStudy->_is_nil() ) {
747 SALOMEDS::AttributeStudyProperties_var propAttr = myStudy->GetProperties();
748 if ( !propAttr->_is_nil() )
749 return propAttr->IsModified();
754 bool QAD_Study::undo()
757 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
760 /* Update Object Browser */
761 updateObjBrowser( true );
763 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
765 sf->getRightFrame()->getViewFrame()->undo( myStudy, sf->entry() );
769 // mpv 07.03.2003 SAL1805: clear selection must be called after study structure changed
770 SALOME_Selection* Sel = SALOME_Selection::Selection( getSelection() );
771 Sel->ClearIObjects();
773 // mpv : undo command can raise exception, if study is locked
774 catch ( SALOMEDS::StudyBuilder::LockProtection& ) {
775 QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
776 QObject::tr("WRN_WARNING"),
777 QObject::tr("WRN_STUDY_LOCKED"),
778 QObject::tr("BUT_OK"));
781 catch ( Standard_Failure ) {
789 bool QAD_Study::redo()
792 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
795 /* Update Object Browser */
796 updateObjBrowser( true );
799 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
800 sf->getRightFrame()->getViewFrame()->redo( myStudy, sf->entry() );
804 // mpv 07.03.2003 SAL1805: clear selection must be called after study structure changed
805 SALOME_Selection* Sel = SALOME_Selection::Selection( getSelection() );
806 Sel->ClearIObjects();
808 // mpv : redo command can raise exception, if study is locked
809 catch ( SALOMEDS::StudyBuilder::LockProtection& ) {
810 QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
811 QObject::tr("WRN_WARNING"),
812 QObject::tr("WRN_STUDY_LOCKED"),
813 QObject::tr("BUT_OK"));
816 catch ( Standard_Failure ) {
822 Check if possible to perform 'undo' command
824 bool QAD_Study::canUndo() const
826 if ( myStudy->_is_nil() )
829 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
830 return (SB->GetAvailableUndos() > 0 );
834 Check if possible to perform 'redo' command
836 bool QAD_Study::canRedo() const
838 if ( myStudy->_is_nil() )
841 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
842 return (SB->GetAvailableRedos() > 0 );
846 Called when operation is started
847 Returns 'true' if started OK, 'false' otherwise.
849 bool QAD_Study::onOperationStarted( QAD_Operation* op )
851 if ( !initOperation( op ) )
855 { /* start a new transaction */
856 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
859 catch ( Standard_Failure )
861 /* May be, a transaction is already open,
862 it's not a problem */
864 myOperationState = Started;
869 Called when operation is finished
871 void QAD_Study::onOperationFinished( QAD_Operation* op )
874 /* transaction is completed OK */
875 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
878 catch ( SALOMEDS::StudyBuilder::LockProtection& ) {
879 QApplication::restoreOverrideCursor();
880 QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
881 QObject::tr("WRN_WARNING"),
882 QObject::tr("WRN_STUDY_LOCKED"),
883 QObject::tr("BUT_OK"));
884 onOperationAborted(op);
885 updateObjBrowser( true );
888 catch ( Standard_Failure ) {
890 myOperationState = Finished;
891 emit docOperationTerminated( true ); /* terminated successfully */
894 // mpv: any operation must call this method, otherwise study may not be saved
895 updateObjBrowser( true );
897 clearOperation( op ); /* we don't need the operation anymore */
898 QAD_Application::getDesktop()->putInfo ( tr("INF_DOC_OPERATIONFINISHED") );
902 Called when operation is suspended
904 void QAD_Study::onOperationSuspended( QAD_Operation* op )
906 myOperationState = Suspended;
910 Called when operation is resumed
912 void QAD_Study::onOperationResumed( QAD_Operation* op )
914 myOperationState = Resumed;
918 Called when operation is aborted
920 void QAD_Study::onOperationAborted(QAD_Operation* op)
923 /* abort transaction */
924 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
927 catch ( Standard_Failure )
930 myOperationState = Aborted;
931 emit docOperationTerminated( false ); /* aborted */
936 QAD_Application::getDesktop()->putInfo ( tr("INF_DOC_OPERATIONABORTED") );
940 Call when the last study frame is closing
942 void QAD_Study::onLastStudyFrameClosing( QAD_StudyFrame* sf )
944 if ( myStudyFrames.count() == 1 ) {
945 emit docClosing( this );
947 removeStudyFrame( sf );
949 // QWorkspace* ws = QAD_Application::getDesktop()->getMainFrame();
950 // if ( !ws->activeWindow() && ws->windowList().count() > 0 )
951 // ws->activatePreviousWindow();
955 Call when created a new window3d
957 QAD_StudyFrame* QAD_Study::newWindow3d(QString name, ViewType theViewType, bool toShow)
959 if(name == "") name = getNextStudyFrameName();
960 QAD_StudyFrame* sf = createStudyFrame( name, theViewType );
962 if (toShow) showFrame(sf);
963 // sf->compressLeft(); /* compress LeftFrame */
964 sf->getRightFrame()->compressBottom(); /* compress BottomFrame */
970 void QAD_Study::showFrame(QAD_StudyFrame* theFrame){
971 theFrame->resize( (int)(0.64*QAD_Application::getDesktop()->getMainFrame()->width()),
972 (int)(0.64*QAD_Application::getDesktop()->getMainFrame()->height()));
980 Call when setted a message
982 void QAD_Study::setMessage(const char* message)
984 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
985 sf->getRightFrame()->getMessage()->setMessage(message);
990 Call when updated object browser
992 void QAD_Study::updateObjBrowser( bool updateSelection )
994 QAD_Desktop* parent = QAD_Application::getDesktop();
995 SALOME_ModuleCatalog::ModuleCatalog_var Catalog = parent->getCatalogue();
997 QString ActiveComp = parent->getActiveComponent();
999 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
1000 sf->getLeftFrame()->getObjectBrowser()->Update();
1003 /* update selection */
1004 if ( updateSelection && (myStudyFrames.count() > 0) ) {
1005 SALOME_Selection* Sel = SALOME_Selection::Selection( getSelection() );
1006 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1007 for(;It.More();It.Next()) {
1008 if ( Sel->AddIObject( It.Value() ) == 0 ) {
1009 highlight( It.Value(), true, false );
1013 /* update viewers */
1018 Updates only Use Case Browser
1020 void QAD_Study::updateUseCaseBrowser( bool updateSelection )
1022 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
1023 sf->getLeftFrame()->getObjectBrowser()->UpdateUseCaseBrowser();
1025 /* update selection */
1026 if ( updateSelection && (myStudyFrames.count() > 0) ) {
1027 SALOME_Selection* Sel = SALOME_Selection::Selection( getSelection() );
1028 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1029 for(;It.More();It.Next()) {
1030 if ( Sel->AddIObject( It.Value() ) == 0 ) {
1031 highlight( It.Value(), true, false );
1034 /* update viewers */
1040 unHighlight All Interactive Objects in All Devices
1042 void QAD_Study::unHighlightAll()
1044 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
1045 /* Device = Viewers */
1046 sf->getRightFrame()->getViewFrame()->unHighlightAll();
1048 /* Device = ObjectBrowser */
1049 sf->getLeftFrame()->getObjectBrowser()->unHighlightAll();
1054 Returns type of Interactive Object
1056 int QAD_Study::typeIObject( const Handle(SALOME_InteractiveObject)& IObject )
1058 bool IsStudyObject = isInStudy( IObject );
1059 bool IsGraphicalObject = isInViewer( IObject );
1061 // MESSAGE ( "IsStudyObject : " << IsStudyObject )
1062 // MESSAGE ( "IsGraphicalObject : " << IsGraphicalObject )
1064 if ( IsStudyObject ) {
1065 if ( IsGraphicalObject )
1066 return 1; /* StudyObject and GraphicalObject */
1068 return 2; /* only StudyObject */
1070 if ( IsGraphicalObject )
1071 return 3; /* only GraphicalObject */
1073 return 4; /* may be a component */
1080 Renames the Interactive Object in All Devices
1082 void QAD_Study::renameIObject( const Handle(SALOME_InteractiveObject)& IObject, QString newName )
1084 if (myStudy->GetProperties()->IsLocked()) {
1085 QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
1086 QObject::tr("WRN_WARNING"),
1087 QObject::tr("WRN_STUDY_LOCKED"),
1088 QObject::tr("BUT_OK"));
1092 highlight( IObject, false );
1094 int nbFrames = myStudyFrames.count();
1095 for ( int i = 0; i < nbFrames; i++ ) {
1096 QAD_StudyFrame* sf = myStudyFrames.at( i );
1097 switch ( typeIObject(IObject) ) {
1100 /* Device = Viewers */
1101 sf->getRightFrame()->getViewFrame()->rename(IObject, newName);
1102 /* Device = ObjectBrowser */
1103 sf->getLeftFrame()->getObjectBrowser()->rename(IObject, newName);
1108 /* Device = ObjectBrowser */
1109 sf->getLeftFrame()->getObjectBrowser()->rename(IObject, newName);
1114 /* Device = Viewers */
1115 sf->getRightFrame()->getViewFrame()->rename(IObject, newName);
1120 QString ActiveComp = QAD_Application::getDesktop()->getActiveComponent();
1121 if ( !ActiveComp.isEmpty() ) {
1122 sf->getLeftFrame()->getObjectBrowser()->rename(IObject,newName);
1130 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
1131 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IObject->getEntry() );
1132 if ( !obj->_is_nil() ) {
1133 SALOMEDS::GenericAttribute_var anAttr;
1134 SALOMEDS::AttributeName_var aName;
1135 anAttr = aStudyBuilder->FindOrCreateAttribute(obj, "AttributeName");
1136 aName = SALOMEDS::AttributeName::_narrow(anAttr);
1137 aName->SetValue(strdup(newName.latin1()));
1140 // VSR 13/03/03 - rename Interactive object
1141 IObject->setName( ( char* )newName.latin1() );
1143 updateObjBrowser( true );
1147 Selects the Interactive Object in All Devices
1149 void QAD_Study::highlight( const Handle(SALOME_InteractiveObject)& IObject, bool highlight,bool immediatly )
1151 // MESSAGE ( " QAD_Study::highlight : " << highlight )
1152 int typeIO = typeIObject( IObject );
1154 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
1158 /* Device = Viewer */
1159 if (sf->getTypeView() >= 0 ) { /* Device = Viewers */
1160 sf->getRightFrame()->getViewFrame()->highlight(IObject, highlight, immediatly);
1162 /* Device = ObjectBrowser */
1163 sf->getLeftFrame()->getObjectBrowser()->highlight(IObject, highlight);
1168 /* Device = ObjectBrowser */
1169 sf->getLeftFrame()->getObjectBrowser()->highlight(IObject, highlight);
1174 /* Device = Viewer */
1175 if (sf->getTypeView() >= 0) { /* Device = Viewers */
1176 sf->getRightFrame()->getViewFrame()->highlight(IObject, highlight, immediatly);
1182 QString ActiveComp = QAD_Application::getDesktop()->getActiveComponent();
1183 if ( !ActiveComp.isEmpty() ) {
1184 sf->getLeftFrame()->getObjectBrowser()->highlight(IObject,highlight);
1193 Returns TRUE if the IObject is a Study Object. Returns FALSE otherwise.
1195 bool QAD_Study::isInStudy( const Handle(SALOME_InteractiveObject)& IObject )
1197 return IObject->hasEntry();
1201 Returns true if the IObject has a Graphical Object. Returns FALSE otherwise.
1203 bool QAD_Study::isInViewer( const Handle(SALOME_InteractiveObject)& IObject )
1206 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
1207 found = sf->getRightFrame()->getViewFrame()->isInViewer(IObject);
1215 Returns true if the IObject has a Graphical Object into studyframe. Returns FALSE otherwise.
1217 bool QAD_Study::isInViewer(const char* anEntry, const char* StudyFrameEntry)
1219 SALOMEDS::SObject_var RefSO;
1220 SALOMEDS::SObject_var SO = myStudy->FindObjectID(StudyFrameEntry);
1221 SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(SO);
1222 for (; it->More();it->Next()){
1223 SALOMEDS::SObject_var CSO= it->Value();
1224 if (CSO->ReferencedObject(RefSO))
1225 if ( strcmp( anEntry, RefSO->GetID() ) == 0 )
1233 Returns title for the new studyframe window
1235 QString QAD_Study::getNextStudyFrameName()
1237 QString numStudyFrame;
1238 numStudyFrame.sprintf("%s%d", "#", ++myStudyFrameCount );
1239 return myTitle + numStudyFrame; /* return unique name ( title + unique number) */
1244 Returns the Python interpreter that belongs to this study
1246 QAD_PyInterp* QAD_Study::get_PyInterp(void)
1252 Sets current selection.
1254 void QAD_Study::Selection( QString aSelection )
1256 if ( !SALOME_Selection::FindSelection( QString(myTitle + "_" + aSelection) ) )
1257 SALOME_Selection::CreateSelection( QString(myTitle + "_" + aSelection) );
1259 SALOME_Selection* Sel = SALOME_Selection::Selection( QString(myTitle + "_" + aSelection) );
1261 mySelection = aSelection;
1265 Returns the name of current selection
1267 QString QAD_Study::getSelection()
1269 return QString (myTitle + "_" + mySelection);
1273 Returns the study Id.
1275 int QAD_Study::getStudyId()
1277 return myStudy->StudyId();
1280 void QAD_Study::update3dViewers()
1282 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
1283 sf->getRightFrame()->getViewFrame()->Repaint();
1287 /* Adds new child window */
1288 void QAD_Study::addChildWidget( QWidget* child )
1290 if ( myChildWidgets.findRef( child ) < 0 ) {
1291 myChildWidgets.append( child );
1292 child->installEventFilter( this );
1297 Removes child window from the list ( and deletes it )
1299 void QAD_Study::removeChildWidget( QWidget* child )
1301 myChildWidgets.removeRef( child );
1305 bool QAD_Study::eventFilter( QObject* o, QEvent* e)
1307 int index = myChildWidgets.findRef( ( QWidget* )o );
1308 if ( index >= 0 && e->type() == QEvent::Close ) {
1309 myChildWidgets.at( index )->removeEventFilter( this );
1310 myChildWidgets.remove( ( QWidget* )o );
1313 return QObject::eventFilter( o, e );