1 #include "SalomeApp_Study.h"
3 #include "SalomeApp_Module.h"
4 #include "SalomeApp_DataModel.h"
5 #include "SalomeApp_RootObject.h"
6 #include "SalomeApp_DataObject.h"
7 #include "SalomeApp_Application.h"
9 #include <OB_Browser.h>
11 #include <SUIT_ResourceMgr.h>
13 #include "utilities.h"
18 SalomeApp_Study::SalomeApp_Study( SUIT_Application* app )
26 SalomeApp_Study::~SalomeApp_Study()
33 int SalomeApp_Study::id() const
37 id = studyDS()->StudyId();
44 _PTR(Study) SalomeApp_Study::studyDS() const
52 void SalomeApp_Study::createDocument()
54 MESSAGE( "openDocument" );
56 // initialize myStudyDS, read HDF file
57 QString aName = newStudyName();
58 _PTR(Study) study ( SalomeApp_Application::studyMgr()->NewStudy( aName.latin1() ) );
63 setStudyName( aName );
66 setRoot( new SalomeApp_RootObject( this ) );
68 CAM_Study::createDocument();
73 //=======================================================================
74 // name : openDocument
75 /*! Purpose : Open document*/
76 //=======================================================================
77 bool SalomeApp_Study::openDocument( const QString& theFileName )
79 MESSAGE( "openDocument" );
81 // initialize myStudyDS, read HDF file
82 _PTR(Study) study ( SalomeApp_Application::studyMgr()->Open( (char*) theFileName.latin1() ) );
88 setRoot( new SalomeApp_RootObject( this ) ); // create myRoot
90 // update loaded data models: call open() and update() on them.
93 for ( ModelListIterator it( dm_s ); it.current(); ++it )
94 openDataModel( studyName(), it.current() );
96 // this will build a SUIT_DataObject-s tree under myRoot member field
97 // passing "false" in order NOT to rebuild existing data models' trees - it was done in previous step
98 // but tree that corresponds to not-loaded data models will be updated any way.
99 ((SalomeApp_Application*)application())->updateObjectBrowser( false );
101 bool res = CAM_Study::openDocument( theFileName );
107 //=======================================================================
108 // name : loadDocument
109 /*! Purpose : Connects GUI study to SALOMEDS one already loaded into StudyManager*/
110 //=======================================================================
111 bool SalomeApp_Study::loadDocument( const QString& theStudyName )
113 MESSAGE( "loadDocument" );
115 // obtain myStudyDS from StudyManager
116 _PTR(Study) study ( SalomeApp_Application::studyMgr()->GetStudyByName( (char*) theStudyName.latin1() ) );
122 setRoot( new SalomeApp_RootObject( this ) ); // create myRoot
124 //SRN: BugID IPAL9021, put there the same code as in a method openDocument
126 // update loaded data models: call open() and update() on them.
129 for ( ModelListIterator it( dm_s ); it.current(); ++it )
130 openDataModel( studyName(), it.current() );
132 // this will build a SUIT_DataObject-s tree under myRoot member field
133 // passing "false" in order NOT to rebuild existing data models' trees - it was done in previous step
134 // but tree that corresponds to not-loaded data models will be updated any way.
135 ((SalomeApp_Application*)application())->updateObjectBrowser( false );
137 bool res = CAM_Study::openDocument( theStudyName );
140 //SRN: BugID IPAL9021: End
145 //=======================================================================
146 // name : saveDocumentAs
147 /*! Purpose : Save document */
148 //=======================================================================
149 bool SalomeApp_Study::saveDocumentAs( const QString& theFileName )
151 ModelList list; dataModels( list );
153 SalomeApp_DataModel* aModel = (SalomeApp_DataModel*)list.first();
154 for ( ; aModel; aModel = (SalomeApp_DataModel*)list.next() )
155 aModel->saveAs( theFileName, this );
157 // save SALOMEDS document
158 SUIT_ResourceMgr* resMgr = application()->resourceMgr();
162 bool isMultiFile = resMgr->booleanValue( "Study", "multi_file", false ),
163 isAscii = resMgr->booleanValue( "Study", "ascii_file", true );
164 isAscii ? SalomeApp_Application::studyMgr()->SaveAsASCII( theFileName.latin1(), studyDS(), isMultiFile ) :
165 SalomeApp_Application::studyMgr()->SaveAs ( theFileName.latin1(), studyDS(), isMultiFile );
167 bool res = CAM_Study::saveDocumentAs( theFileName ); //SRN: BugID IPAL9377, removed usage of uninitialized variable <res>
175 //=======================================================================
176 // name : saveDocument
177 /*! Purpose : Save document */
178 //=======================================================================
179 void SalomeApp_Study::saveDocument()
181 ModelList list; dataModels( list );
183 SalomeApp_DataModel* aModel = (SalomeApp_DataModel*)list.first();
184 for ( ; aModel; aModel = (SalomeApp_DataModel*)list.next() )
187 CAM_Study::saveDocument();
189 // save SALOMEDS document
190 SUIT_ResourceMgr* resMgr = application()->resourceMgr();
194 bool isMultiFile = resMgr->booleanValue( "Study", "multi_file", false ),
195 isAscii = resMgr->booleanValue( "Study", "ascii_file", true );
196 isAscii ? SalomeApp_Application::studyMgr()->SaveASCII( studyDS(), isMultiFile ) :
197 SalomeApp_Application::studyMgr()->Save ( studyDS(), isMultiFile );
202 //================================================================
203 // Function : closeDocument
204 /*! Purpose : Close document */
205 //================================================================
206 void SalomeApp_Study::closeDocument(bool permanently)
208 // Inform everybody that this study is going to close when it's most safe to,
209 // i.e. in the very beginning
212 // close SALOMEDS document
213 _PTR(Study) studyPtr = studyDS();
216 if(permanently) SalomeApp_Application::studyMgr()->Close( studyPtr );
217 SALOMEDSClient_Study* aStudy = 0;
218 setStudyDS( _PTR(Study)(aStudy) );
221 CAM_Study::closeDocument(permanently);
224 //================================================================
225 // Function : isModified
226 /*! Purpose : Check data model on modifications.*/
227 //================================================================
228 bool SalomeApp_Study::isModified() const
230 bool isAnyChanged = studyDS() && studyDS()->IsModified();
231 ModelList list; dataModels( list );
233 SalomeApp_DataModel* aModel = 0;
234 for ( QPtrListIterator<CAM_DataModel> it( list ); it.current() && !isAnyChanged; ++it ){
235 aModel = dynamic_cast<SalomeApp_DataModel*>( it.current() );
237 isAnyChanged = aModel->isModified();
242 //================================================================
243 // Function : isSaved
244 /*! Purpose : Check: data model is saved?*/
245 //================================================================
246 bool SalomeApp_Study::isSaved() const
248 bool isAllSaved = studyDS() && studyDS()->GetPersistentReference().size();
249 ModelList list; dataModels( list );
251 SalomeApp_DataModel* aModel = 0;
252 for ( QPtrListIterator<CAM_DataModel> it( list ); it.current() && isAllSaved; ++it ){
253 aModel = dynamic_cast<SalomeApp_DataModel*>( it.current() );
255 isAllSaved = aModel->isSaved();
263 void SalomeApp_Study::setStudyDS( const _PTR(Study)& s )
271 void SalomeApp_Study::dataModelInserted (const CAM_DataModel* dm)
273 MESSAGE("SalomeApp_Study::dataModelInserted() : module name() = " << dm->module()->name());
275 CAM_Study::dataModelInserted(dm);
277 // Create SComponent for module, using default engine (CORBAless)
278 SalomeApp_Module* aModule = (SalomeApp_Module*)(dm->module());
280 QString anEngineIOR = aModule->engineIOR();
281 if (anEngineIOR.isEmpty()) { // CORBAless module
282 // Check SComponent existance
283 _PTR(SComponent) aComp = studyDS()->FindComponent(dm->module()->name());
286 _PTR(StudyBuilder) aBuilder = studyDS()->NewBuilder();
287 aComp = aBuilder->NewComponent(dm->module()->name());
289 // Set default engine IOR
290 aBuilder->DefineComponentInstance(aComp, SalomeApp_Application::defaultEngineIOR().latin1());
299 bool SalomeApp_Study::openDataModel( const QString& studyName, CAM_DataModel* dm )
304 SalomeApp_DataModel* aDM = (SalomeApp_DataModel*)(dm);
305 if (aDM && aDM->open(studyName, this)) {
306 // Something has been read -> create data model tree
307 aDM->update(NULL, this);
315 Create new study name.
317 QString SalomeApp_Study::newStudyName() const
319 std::vector<std::string> studies = SalomeApp_Application::studyMgr()->GetOpenStudies();
320 QString prefix( "Study%1" ), newName, curName;
321 int i = 1, j, n = studies.size();
322 while ( newName.isEmpty() ){
323 curName = prefix.arg( i );
324 for ( j = 0 ; j < n; j++ ){
325 if ( !strcmp( studies[j].c_str(), curName.latin1() ) )
336 void SalomeApp_Study::deleteReferencesTo( _PTR( SObject ) obj )
338 _PTR(StudyBuilder) sb = studyDS()->NewBuilder();
339 std::vector<_PTR(SObject)> aRefs = studyDS()->FindDependances( obj );
340 for( int i=0, n=aRefs.size(); i<n; i++ )
342 _PTR( SObject ) o = aRefs[i];
343 if( o->GetFatherComponent()->ComponentDataType()==obj->GetFatherComponent()->ComponentDataType() )
345 sb->RemoveReference( o );
346 sb->RemoveObjectWithChildren( o );