2 // File : QAD_Study.cxx
3 // Created : UI team, 05.09.00
4 // Descr : Study for QAD-based application
6 // Modified : Mon Dec 03 14:20:05 2001
7 // Author : Nicolas REJNERI
10 // Copyright : Open CASCADE 2001
14 \class QAD_Study QAD_Study.h
15 \brief Study for QAD-based application.
19 #include "QAD_Tools.h"
20 #include "QAD_Desktop.h"
21 #include "QAD_Study.h"
22 #include "QAD_RightFrame.h"
23 #include "QAD_LeftFrame.h"
24 #include "QAD_MessageBox.h"
25 #include "QAD_Application.h"
26 #include "QAD_ObjectBrowser.h"
27 #include "QAD_PyInterp.h"
28 #include "QAD_Config.h"
30 #include "utilities.h"
32 #include "SALOME_Selection.h"
33 #include "SALOME_TypeFilter.hxx"
34 #include "SALOME_InteractiveObject.hxx"
35 #include "SALOME_ListIteratorOfListIO.hxx"
37 #include <SALOMEconfig.h>
38 #include CORBA_SERVER_HEADER(SALOMEDS)
40 // OPEN CASCADE Include
41 #include <Standard_Failure.hxx>
44 #include <qapplication.h>
50 QAD_Study::QAD_Study(QAD_Application* app,
51 SALOMEDS::Study_var aStudy,
52 const QString& path ) :
53 myOperationState( Undef ),
55 myActiveStudyFrame( 0 ),
56 myStudyFrameCount( 0 ),
61 myTitle = QAD_Tools::getFileNameFromPath( path, false );
68 myStudyFrames.clear();
71 myStudyFrames.setAutoDelete( true );
72 myOperations.setAutoDelete( true );
73 myChildWidgets.setAutoDelete( true );
75 /* create python interpreter */
76 _interp = new QAD_PyInterp();
79 /* create default selection */
80 //NRI Selection( "Salome" );
81 Selection( QAD_Application::getDesktop()->getComponentUserName( "KERNEL" ) );
83 /* create study frame */
85 createStudyFrame( getNextStudyFrameName() );
87 /* set default Undo/Redo limit */
88 QAD_ASSERT_DEBUG_ONLY( !myStudy->_is_nil() );
89 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
90 SB->UndoLimit( MAX_UNDO );
96 QAD_Study::~QAD_Study ()
99 //SRN: added - clear selection in case the study will be loaded again so the title will coincide
100 SALOME_Selection::RemoveSelection( QString(myTitle + "_" + mySelection) );
105 Returns TRUE if Study is created correctly. Returns FALSE otherwise.
107 bool QAD_Study::getResult()
113 //=======================================================================//
114 // StudyFrames management //
115 //=======================================================================//
119 void QAD_Study::addStudyFrame(QAD_StudyFrame* sf )
121 myStudyFrames.append( sf );
123 sf->getRightFrame()->getViewFrame()->setPopupServer( myApp );
124 // Provide the same common popup menu commands for both the Object Browser and 3D viewer
125 sf->getLeftFrame()->getObjectBrowser()->setPopupServer( myApp );
127 /* icon of Study Frame */
128 const QPixmap& icon = myApp->getApplicationIcon();
129 if ( !icon.isNull() )
130 sf->setIcon ( icon );
133 QAD_ASSERT ( connect( sf, SIGNAL(sfStudyFrameActivated(QAD_StudyFrame*) ),
134 SLOT(onStudyFrameActivated(QAD_StudyFrame*))) );
137 QAD_ASSERT ( connect( sf,
138 SIGNAL(sfStudyFrameClosing(QAD_StudyFrame*) ),
140 SLOT(onLastStudyFrameClosing(QAD_StudyFrame*))) );
143 myActiveStudyFrame = sf;
147 Removes studyframe from the list
149 void QAD_Study::removeStudyFrame( QAD_StudyFrame* sf )
152 if (!myStudy->IsEmpty()) {
153 SALOMEDS::SObject_var fatherSF = myStudy->FindObjectID(sf->entry());
154 if (!fatherSF->_is_nil()) {
155 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
156 aStudyBuilder->RemoveObject(fatherSF);
159 updateObjBrowser( true );
161 myStudyFrames.removeRef( sf );
166 Returns number of study frames
168 int QAD_Study::getStudyFramesCount() const
170 return myStudyFrames.count();
174 Returns study frame by its index in list
176 QAD_StudyFrame* QAD_Study::getStudyFrame( unsigned i )
178 return myStudyFrames.at(i);
182 Returns study frame by its name or null if not found
184 QAD_StudyFrame* QAD_Study::getStudyFrameByName ( const QString& name )
186 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() )
188 if ( sf->title().compare(name) == 0 ) {
196 Returns first study frame in the list
198 QAD_StudyFrame* QAD_Study::getFirstStudyFrame()
200 return myStudyFrames.first();
204 Returns last study frame in the list
206 QAD_StudyFrame* QAD_Study::getLastStudyFrame()
208 return myStudyFrames.last();
212 Returns the vector of studyframes
214 const QList<QAD_StudyFrame>& QAD_Study::getStudyFrames() const
216 return myStudyFrames;
220 Returns the active study frame
222 QAD_StudyFrame* QAD_Study::getActiveStudyFrame() const
224 return myActiveStudyFrame;
227 //=======================================================================//
228 // Study properties //
229 //=======================================================================//
231 Returns reference to supporting application
233 QAD_Application* QAD_Study::getApp() const
239 Returns the name of document ( filename without path and extension )
241 const QString& QAD_Study::getTitle() const
247 Returns the absolute file path of this document
249 const QString& QAD_Study::getPath() const
255 Changes the name of document
257 void QAD_Study::setTitle( const QString& path )
261 QString title = QAD_Tools::getFileNameFromPath( path, false );
262 QAD_ASSERT_DEBUG_ONLY ( !title.isNull() );
264 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf ; sf = myStudyFrames.next() )
266 QString oldName = sf->title();
267 int k = oldName.find( myTitle, 0, false );
268 QString restName = ( oldName.length() > myTitle.length() + k) ?
269 oldName.right(oldName.length() - (myTitle.length() + k) + 1) :
276 int l = restName.find( "#", 0, false );
277 int ll = restName.length();
278 newName = title + restName.mid( l, ll-l );
280 newName = oldName.mid(0, k);
281 newName = newName + title + restName;
283 sf->setTitle( newName );
288 Selection( QAD_Application::getDesktop()->getActiveComponent() );
292 Returns whether the document is active
294 bool QAD_Study::isActive() const
300 Returns whether the document is read only
302 bool QAD_Study::isReadOnly() const
308 Sets read-only property
310 void QAD_Study::setReadOnly(bool state)
312 myIsReadOnly = state;
315 //=======================================================================//
316 // Study operations //
317 //=======================================================================//
319 Performs specific study frame related actions when it is activated.
320 By default resumes all suspended operations.
322 void QAD_Study::onStudyFrameActivated( QAD_StudyFrame* activeStudyFrame )
324 static int IS_FIRST_STUDY = 1;
325 if(IS_FIRST_STUDY){ //for normally initialize "salome.py and ..."
326 _interp->run(""); IS_FIRST_STUDY = 0;
328 // bool found = false;
329 for ( QAD_StudyFrame* studyframe = myStudyFrames.first(); studyframe; studyframe = myStudyFrames.next() ) {
330 if ( studyframe == activeStudyFrame) { /* one of my study frames */
332 // if ( !myActiveStudyFrame || myActiveStudyFrame != activeStudyFrame ) {
333 myActiveStudyFrame = activeStudyFrame;
334 //NRI if ( !myIsActive ) {
336 resumeAllOperations();
337 /* activate application */
338 myApp->onStudyActivated( this );
345 // myActiveStudyFrame = 0;
350 Performs specific study related actions when it is deactivated.
351 By default suspends all performing operations.
353 void QAD_Study::onStudyDeactivated()
355 // MESSAGE ("QAD_Study::onStudyDeactivated init. ");
357 suspendAllOperations();
358 // MESSAGE ("QAD_Study::onStudyDeactivated done. ");
362 Closes all study frames of the study and performs other specific study
363 related actions needed for proper closing of the study
365 void QAD_Study::close()
367 if ( !myStudy->_is_nil() )
368 abortAllOperations();
369 /* clear each study frame */
370 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.first() ) {
373 qApp->processEvents();
374 qApp->processEvents();
375 removeStudyFrame(sf);
378 /* delete all studyframes */
379 myStudyFrames.clear();
380 myOperations.clear();
381 myChildWidgets.clear();
383 // QWorkspace* ws = QAD_Application::getDesktop()->getMainFrame();
384 // if (/* !ws->activeWindow() && */ws->windowList().count() > 0 )
385 // ws->activateWindow(ws->windowList().last());
388 //=======================================================================//
389 // Operations management //
390 //=======================================================================//
392 Returns number of completed operations
394 int QAD_Study::getOperationsCount() const
396 return myOperations.count();
400 Returns the state of the last operation
402 OperationState QAD_Study::getOperationState() const
404 return myOperationState;
408 Returns operation by its index in list
410 QAD_Operation* QAD_Study::getOperation( unsigned i)
412 return ( myOperations.isEmpty() ? 0 : myOperations.at(i) );
416 Returns performing operation launched first
418 QAD_Operation* QAD_Study::getFirstOperation()
420 return ( myOperations.isEmpty() ? 0 : myOperations.first() );
424 Returns performing operation launched last
426 QAD_Operation* QAD_Study::getLastOperation()
428 return ( myOperations.isEmpty() ? 0 : myOperations.last() );
432 Aborts all performing operations
434 void QAD_Study::abortAllOperations()
436 for ( QAD_Operation* op = myOperations.last(); op;
437 op = myOperations.prev() )
442 Resumes all performing operations
444 void QAD_Study::resumeAllOperations()
446 for ( QAD_Operation* op = myOperations.first(); op;
447 op = myOperations.next() )
452 Suspendes all performing operations
454 void QAD_Study::suspendAllOperations()
456 // MESSAGE ( " QAD_Study::suspendAllOperations init. " )
457 for ( QAD_Operation* op = myOperations.last(); op;
458 op = myOperations.prev() )
463 Initializes the operation and checks its compatibility
464 with another operation in process if any.
465 Returns 'true' if init'ed OK, 'false' otherwise.
467 bool QAD_Study::initOperation( QAD_Operation* op )
470 { /* can't start a non-const operation */
471 if ( op->changesData() )
473 QAD_MessageBox::error1( QAD_Application::getDesktop(), tr("ERR_ERROR"),
474 tr("ERR_DOC_READONLY"), tr("BUT_OK") );
479 /* Add the new operation
481 if ( myOperations.isEmpty() )
482 myOperations.append( op );
485 /* Check compatibility of new operation with the existing operations.
486 Since each operations is checked in that way, it's enough to check
487 the last operation only */
488 if ( !getLastOperation()->compatibleWith( op ) )
490 if ( QAD_MessageBox::warn2( QAD_Application::getDesktop(), tr("WRN_WARNING"),
491 tr("QUE_ABORTCURRENTOPERATION"), tr("BUT_YES"),
492 tr("BUT_NO"), QAD_YES, QAD_NO, QAD_NO )
495 getLastOperation()->abort();
497 myOperations.append( op );
503 Called when operation was finished.
504 Removes appointed operation from the list and aborted all operations
507 void QAD_Study::clearOperation( QAD_Operation* op)
509 if ( myOperations.contains( op ) )
511 /* abort all the operations launched after 'op' */
512 for ( QAD_Operation* cur = myOperations.last(); cur;
513 cur = myOperations.prev() )
515 if ( cur == op ) break;
518 myOperations.remove( op );
525 QAD_StudyFrame* QAD_Study::createStudyFrame( const QString& title, ViewType theViewType)
527 QAD_Desktop* parent = QAD_Application::getDesktop();
528 //srn: Forbid appending Interface Applicative and its children to UseCase
529 myStudy->EnableUseCaseAutoFilling(false);
531 SALOMEDS::SComponent_var father = myStudy->FindComponent("Interface Applicative");
532 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
533 SALOMEDS::GenericAttribute_var anAttr;
534 SALOMEDS::AttributeName_var aName;
535 SALOMEDS::AttributeComment_var aComment;
536 SALOMEDS::AttributeSelectable_var aSelAttr;
538 // mpv : where is "NewCommand" call?
539 // aStudyBuilder->CommitCommand();
541 // mpv : is study is locked, then next code will raise exception. So, temporary unlock study
542 int aLocked = myStudy->GetProperties()->IsLocked();
543 if (aLocked) myStudy->GetProperties()->SetLocked(false);
545 if ( father->_is_nil() ) {
546 father = aStudyBuilder->NewComponent("Interface Applicative");
547 anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributeName");
548 aName = SALOMEDS::AttributeName::_narrow(anAttr);
549 aName->SetValue("Interface Applicative");
551 anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributeSelectable");
552 aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
553 aSelAttr->SetSelectable(false);
556 //VRV: T2.5 - add default viewer
557 if(theViewType == VIEW_TYPE_MAX) {
558 QString viewerValue = QAD_CONFIG->getSetting( "Viewer:DefaultViewer" );
560 theViewType = (ViewType)viewerValue.toInt( &ok, 10 );
561 if (!ok || theViewType < VIEW_OCC || theViewType >= VIEW_TYPE_MAX)
562 theViewType = VIEW_VTK;
564 //QApplication::restoreOverrideCursor();
565 QAD_StudyFrame* sf = NULL;
566 SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(father);
567 if ( theViewType == VIEW_OCC) {
568 // MESSAGE ("Create Study Frame for OCC viewer");
569 sf = new QAD_StudyFrame ( this, parent->getMainFrame(),
570 title, _interp, VIEW_OCC );
572 Standard_CString name = strdup(sf->title().latin1());
573 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
574 aName = SALOMEDS::AttributeName::_narrow(anAttr);
575 aName->SetValue(name);
576 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeComment");
577 aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
578 aComment->SetValue("OCC");
580 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeSelectable");
581 aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
582 aSelAttr->SetSelectable(false);
584 else if ( theViewType == VIEW_VTK) {
585 // MESSAGE ("Create Study Frame for VTK viewer");
586 sf = new QAD_StudyFrame ( this, parent->getMainFrame(),
587 title, _interp, VIEW_VTK );
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("VTK");
596 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeSelectable");
597 aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
598 aSelAttr->SetSelectable(false);
600 else if ( theViewType == VIEW_GRAPHSUPERV) {
601 //MESSAGE ("Create Study Frame for SUPER`VISOR Graph");
602 sf = new QAD_StudyFrame ( this, parent->getMainFrame(),
603 title, _interp, VIEW_GRAPHSUPERV );
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("GRAPH");
612 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeSelectable");
613 aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
614 aSelAttr->SetSelectable(false);
616 else if ( theViewType == VIEW_PLOT2D ) {
617 sf = new QAD_StudyFrame ( this, parent->getMainFrame(),
618 title, _interp, VIEW_PLOT2D );
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("PLOT2D");
627 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeSelectable");
628 aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
629 aSelAttr->SetSelectable(false);
631 //VRV: T2.5 - add default viewer
633 sf->resize( int (0.8*parent->getMainFrame()->width()),
634 int (0.8*parent->getMainFrame()->height() ));
636 sf->setEntry(newObj->GetID());
640 updateObjBrowser( true );
642 parent->setSettings();
646 if (aLocked) myStudy->GetProperties()->SetLocked(true);
648 // T2.12 - add the word "locked" to study frame captions if this study is locked
651 myStudy->EnableUseCaseAutoFilling(true);
657 Updates study frame captions according to IsLocked study flag
659 void QAD_Study::updateCaptions()
661 QString appendix("");
663 if (!myStudy->_is_nil()) {
664 SALOMEDS::AttributeStudyProperties_var propAttr = myStudy->GetProperties();
666 if (!propAttr->_is_nil() ) {
667 if ( propAttr->IsModified() )
668 appendix += " (" + tr("PRP_STUDY_MODIFIED") + ")";
670 appendix += " (" + tr("PRP_STUDY_SAVED") + ")";
674 if (!propAttr->_is_nil() && propAttr->IsLocked()) {
675 appendix += " (" + tr("PRP_STUDY_LOCKED") + ")";
679 for (myStudyFrames.first(); myStudyFrames.current(); myStudyFrames.next()) {
680 myStudyFrames.current()->setCaption(myStudyFrames.current()->title() + appendix);
686 Shows the active study frame.
687 Called by Desktop after 'new' and 'open' commands.
689 void QAD_Study::show()
691 for (myStudyFrames.first(); myStudyFrames.current(); myStudyFrames.next()) {
692 myStudyFrames.current()->show();
696 //=======================================================================//
697 // Study properties (CAF related) //
698 //=======================================================================//
701 Returns connected SALOMEDS_Study object
703 SALOMEDS::Study_var QAD_Study::getStudyDocument()
709 Returns whether the document was saved in file
711 bool QAD_Study::isSaved() const
713 return myStudy->IsSaved();
717 Returns whether the document is modified
719 bool QAD_Study::isModified() const
721 // return myStudy->IsModified(); // VSR:05/12/02 - USE PROPERTY : MODIFIED FLAG
722 if ( !myStudy->_is_nil() ) {
723 SALOMEDS::AttributeStudyProperties_var propAttr = myStudy->GetProperties();
724 if ( !propAttr->_is_nil() )
725 return propAttr->IsModified();
730 bool QAD_Study::undo()
733 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
736 /* Update Object Browser */
737 updateObjBrowser( true );
739 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
741 sf->getRightFrame()->getViewFrame()->undo( myStudy, sf->entry() );
745 // mpv 07.03.2003 SAL1805: clear selection must be called after study structure changed
746 SALOME_Selection* Sel = SALOME_Selection::Selection( getSelection() );
747 Sel->ClearIObjects();
749 // mpv : undo command can raise exception, if study is locked
750 catch ( SALOMEDS::StudyBuilder::LockProtection& ) {
751 QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
752 QObject::tr("WRN_WARNING"),
753 QObject::tr("WRN_STUDY_LOCKED"),
754 QObject::tr("BUT_OK"));
757 catch ( Standard_Failure ) {
765 bool QAD_Study::redo()
768 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
771 /* Update Object Browser */
772 updateObjBrowser( true );
775 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
776 sf->getRightFrame()->getViewFrame()->redo( myStudy, sf->entry() );
780 // mpv 07.03.2003 SAL1805: clear selection must be called after study structure changed
781 SALOME_Selection* Sel = SALOME_Selection::Selection( getSelection() );
782 Sel->ClearIObjects();
784 // mpv : redo command can raise exception, if study is locked
785 catch ( SALOMEDS::StudyBuilder::LockProtection& ) {
786 QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
787 QObject::tr("WRN_WARNING"),
788 QObject::tr("WRN_STUDY_LOCKED"),
789 QObject::tr("BUT_OK"));
792 catch ( Standard_Failure ) {
798 Check if possible to perform 'undo' command
800 bool QAD_Study::canUndo() const
802 if ( myStudy->_is_nil() )
805 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
806 return (SB->GetAvailableUndos() > 0 );
810 Check if possible to perform 'redo' command
812 bool QAD_Study::canRedo() const
814 if ( myStudy->_is_nil() )
817 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
818 return (SB->GetAvailableRedos() > 0 );
822 Called when operation is started
823 Returns 'true' if started OK, 'false' otherwise.
825 bool QAD_Study::onOperationStarted( QAD_Operation* op )
827 if ( !initOperation( op ) )
831 { /* start a new transaction */
832 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
835 catch ( Standard_Failure )
837 /* May be, a transaction is already open,
838 it's not a problem */
840 myOperationState = Started;
845 Called when operation is finished
847 void QAD_Study::onOperationFinished( QAD_Operation* op )
850 /* transaction is completed OK */
851 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
854 catch ( SALOMEDS::StudyBuilder::LockProtection& ) {
855 QApplication::restoreOverrideCursor();
856 QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
857 QObject::tr("WRN_WARNING"),
858 QObject::tr("WRN_STUDY_LOCKED"),
859 QObject::tr("BUT_OK"));
860 onOperationAborted(op);
861 updateObjBrowser( true );
864 catch ( Standard_Failure ) {
866 myOperationState = Finished;
867 emit docOperationTerminated( true ); /* terminated successfully */
870 // mpv: any operation must call this method, otherwise study may not be saved
871 updateObjBrowser( true );
873 clearOperation( op ); /* we don't need the operation anymore */
874 QAD_Application::getDesktop()->putInfo ( tr("INF_DOC_OPERATIONFINISHED") );
878 Called when operation is suspended
880 void QAD_Study::onOperationSuspended( QAD_Operation* op )
882 myOperationState = Suspended;
886 Called when operation is resumed
888 void QAD_Study::onOperationResumed( QAD_Operation* op )
890 myOperationState = Resumed;
894 Called when operation is aborted
896 void QAD_Study::onOperationAborted(QAD_Operation* op)
899 /* abort transaction */
900 SALOMEDS::StudyBuilder_var SB = myStudy->NewBuilder();
903 catch ( Standard_Failure )
906 myOperationState = Aborted;
907 emit docOperationTerminated( false ); /* aborted */
912 QAD_Application::getDesktop()->putInfo ( tr("INF_DOC_OPERATIONABORTED") );
916 Call when the last study frame is closing
918 void QAD_Study::onLastStudyFrameClosing( QAD_StudyFrame* sf )
920 if ( myStudyFrames.count() == 1 ) {
921 emit docClosing( this );
923 removeStudyFrame( sf );
925 // QWorkspace* ws = QAD_Application::getDesktop()->getMainFrame();
926 // if ( !ws->activeWindow() && ws->windowList().count() > 0 )
927 // ws->activatePreviousWindow();
931 Call when created a new window3d
933 QAD_StudyFrame* QAD_Study::newWindow3d(QString name, ViewType theViewType, bool toShow)
935 if(name == "") name = getNextStudyFrameName();
936 QAD_StudyFrame* sf = createStudyFrame( name, theViewType );
938 if (toShow) showFrame(sf);
939 // sf->compressLeft(); /* compress LeftFrame */
940 sf->getRightFrame()->compressBottom(); /* compress BottomFrame */
946 void QAD_Study::showFrame(QAD_StudyFrame* theFrame){
947 theFrame->resize(0.64*QAD_Application::getDesktop()->getMainFrame()->width(),
948 0.64*QAD_Application::getDesktop()->getMainFrame()->height());
956 Call when setted a message
958 void QAD_Study::setMessage(const char* message)
960 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
961 sf->getRightFrame()->getMessage()->setMessage(message);
966 Call when updated object browser
968 void QAD_Study::updateObjBrowser( bool updateSelection )
970 QAD_Desktop* parent = QAD_Application::getDesktop();
971 SALOME_ModuleCatalog::ModuleCatalog_var Catalog = parent->getCatalogue();
973 QString ActiveComp = parent->getActiveComponent();
975 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
976 sf->getLeftFrame()->getObjectBrowser()->Update();
979 /* update selection */
980 if ( updateSelection && (myStudyFrames.count() > 0) ) {
981 SALOME_Selection* Sel = SALOME_Selection::Selection( getSelection() );
982 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
983 for(;It.More();It.Next()) {
984 if ( Sel->AddIObject( It.Value() ) == 0 ) {
985 highlight( It.Value(), true, false );
994 Updates only Use Case Browser
996 void QAD_Study::updateUseCaseBrowser( bool updateSelection )
998 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
999 sf->getLeftFrame()->getObjectBrowser()->UpdateUseCaseBrowser();
1001 /* update selection */
1002 if ( updateSelection && (myStudyFrames.count() > 0) ) {
1003 SALOME_Selection* Sel = SALOME_Selection::Selection( getSelection() );
1004 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1005 for(;It.More();It.Next()) {
1006 if ( Sel->AddIObject( It.Value() ) == 0 ) {
1007 highlight( It.Value(), true, false );
1010 /* update viewers */
1016 unHighlight All Interactive Objects in All Devices
1018 void QAD_Study::unHighlightAll()
1020 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
1021 /* Device = Viewers */
1022 sf->getRightFrame()->getViewFrame()->unHighlightAll();
1024 /* Device = ObjectBrowser */
1025 sf->getLeftFrame()->getObjectBrowser()->unHighlightAll();
1030 Returns type of Interactive Object
1032 int QAD_Study::typeIObject( const Handle(SALOME_InteractiveObject)& IObject )
1034 bool IsStudyObject = isInStudy( IObject );
1035 bool IsGraphicalObject = isInViewer( IObject );
1037 // MESSAGE ( "IsStudyObject : " << IsStudyObject )
1038 // MESSAGE ( "IsGraphicalObject : " << IsGraphicalObject )
1040 if ( IsStudyObject ) {
1041 if ( IsGraphicalObject )
1042 return 1; /* StudyObject and GraphicalObject */
1044 return 2; /* only StudyObject */
1046 if ( IsGraphicalObject )
1047 return 3; /* only GraphicalObject */
1049 return 4; /* may be a component */
1056 Renames the Interactive Object in All Devices
1058 void QAD_Study::renameIObject( const Handle(SALOME_InteractiveObject)& IObject, QString newName )
1060 if (myStudy->GetProperties()->IsLocked()) {
1061 QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
1062 QObject::tr("WRN_WARNING"),
1063 QObject::tr("WRN_STUDY_LOCKED"),
1064 QObject::tr("BUT_OK"));
1068 highlight( IObject, false );
1070 int nbFrames = myStudyFrames.count();
1071 for ( int i = 0; i < nbFrames; i++ ) {
1072 QAD_StudyFrame* sf = myStudyFrames.at( i );
1073 switch ( typeIObject(IObject) ) {
1076 /* Device = Viewers */
1077 sf->getRightFrame()->getViewFrame()->rename(IObject, newName);
1078 /* Device = ObjectBrowser */
1079 sf->getLeftFrame()->getObjectBrowser()->rename(IObject, newName);
1084 /* Device = ObjectBrowser */
1085 sf->getLeftFrame()->getObjectBrowser()->rename(IObject, newName);
1090 /* Device = Viewers */
1091 sf->getRightFrame()->getViewFrame()->rename(IObject, newName);
1096 QString ActiveComp = QAD_Application::getDesktop()->getActiveComponent();
1097 if ( !ActiveComp.isEmpty() ) {
1098 sf->getLeftFrame()->getObjectBrowser()->rename(IObject,newName);
1106 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
1107 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IObject->getEntry() );
1108 if ( !obj->_is_nil() ) {
1109 SALOMEDS::GenericAttribute_var anAttr;
1110 SALOMEDS::AttributeName_var aName;
1111 anAttr = aStudyBuilder->FindOrCreateAttribute(obj, "AttributeName");
1112 aName = SALOMEDS::AttributeName::_narrow(anAttr);
1113 aName->SetValue(strdup(newName.latin1()));
1116 // VSR 13/03/03 - rename Interactive object
1117 IObject->setName( ( char* )newName.latin1() );
1119 updateObjBrowser( true );
1123 Selects the Interactive Object in All Devices
1125 void QAD_Study::highlight( const Handle(SALOME_InteractiveObject)& IObject, bool highlight,bool immediatly )
1127 // MESSAGE ( " QAD_Study::highlight : " << highlight )
1128 int typeIO = typeIObject( IObject );
1130 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
1134 /* Device = Viewer */
1135 if (sf->getTypeView() >= 0 ) { /* Device = Viewers */
1136 sf->getRightFrame()->getViewFrame()->highlight(IObject, highlight, immediatly);
1138 /* Device = ObjectBrowser */
1139 sf->getLeftFrame()->getObjectBrowser()->highlight(IObject, highlight);
1144 /* Device = ObjectBrowser */
1145 sf->getLeftFrame()->getObjectBrowser()->highlight(IObject, highlight);
1150 /* Device = Viewer */
1151 if (sf->getTypeView() >= 0) { /* Device = Viewers */
1152 sf->getRightFrame()->getViewFrame()->highlight(IObject, highlight, immediatly);
1158 QString ActiveComp = QAD_Application::getDesktop()->getActiveComponent();
1159 if ( !ActiveComp.isEmpty() ) {
1160 sf->getLeftFrame()->getObjectBrowser()->highlight(IObject,highlight);
1169 Returns TRUE if the IObject is a Study Object. Returns FALSE otherwise.
1171 bool QAD_Study::isInStudy( const Handle(SALOME_InteractiveObject)& IObject )
1173 return IObject->hasEntry();
1177 Returns true if the IObject has a Graphical Object. Returns FALSE otherwise.
1179 bool QAD_Study::isInViewer( const Handle(SALOME_InteractiveObject)& IObject )
1182 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
1183 found = sf->getRightFrame()->getViewFrame()->isInViewer(IObject);
1191 Returns true if the IObject has a Graphical Object into studyframe. Returns FALSE otherwise.
1193 bool QAD_Study::isInViewer(const char* anEntry, const char* StudyFrameEntry)
1195 SALOMEDS::SObject_var RefSO;
1196 SALOMEDS::SObject_var SO = myStudy->FindObjectID(StudyFrameEntry);
1197 SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(SO);
1198 for (; it->More();it->Next()){
1199 SALOMEDS::SObject_var CSO= it->Value();
1200 if (CSO->ReferencedObject(RefSO))
1201 if ( strcmp( anEntry, RefSO->GetID() ) == 0 )
1209 Returns title for the new studyframe window
1211 QString QAD_Study::getNextStudyFrameName()
1213 QString numStudyFrame;
1214 numStudyFrame.sprintf("%s%d", "#", ++myStudyFrameCount );
1215 return myTitle + numStudyFrame; /* return unique name ( title + unique number) */
1220 Returns the Python interpreter that belongs to this study
1222 QAD_PyInterp* QAD_Study::get_PyInterp(void)
1228 Sets current selection.
1230 void QAD_Study::Selection( QString aSelection )
1232 if ( !SALOME_Selection::FindSelection( QString(myTitle + "_" + aSelection) ) )
1233 SALOME_Selection::CreateSelection( QString(myTitle + "_" + aSelection) );
1235 SALOME_Selection* Sel = SALOME_Selection::Selection( QString(myTitle + "_" + aSelection) );
1237 mySelection = aSelection;
1241 Returns the name of current selection
1243 QString QAD_Study::getSelection()
1245 return QString (myTitle + "_" + mySelection);
1249 Returns the study Id.
1251 int QAD_Study::getStudyId()
1253 return myStudy->StudyId();
1256 void QAD_Study::update3dViewers()
1258 for ( QAD_StudyFrame* sf = myStudyFrames.first(); sf; sf = myStudyFrames.next() ) {
1259 sf->getRightFrame()->getViewFrame()->Repaint();
1263 /* Adds new child window */
1264 void QAD_Study::addChildWidget( QWidget* child )
1266 if ( myChildWidgets.findRef( child ) < 0 ) {
1267 myChildWidgets.append( child );
1268 child->installEventFilter( this );
1273 Removes child window from the list ( and deletes it )
1275 void QAD_Study::removeChildWidget( QWidget* child )
1277 myChildWidgets.removeRef( child );
1281 bool QAD_Study::eventFilter( QObject* o, QEvent* e)
1283 int index = myChildWidgets.findRef( ( QWidget* )o );
1284 if ( index >= 0 && e->type() == QEvent::Close ) {
1285 myChildWidgets.at( index )->removeEventFilter( this );
1286 myChildWidgets.remove( ( QWidget* )o );
1289 return QObject::eventFilter( o, e );