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 );
104 study->IsSaved(true);
108 //=======================================================================
109 // name : loadDocument
110 /*! Purpose : Connects GUI study to SALOMEDS one already loaded into StudyManager*/
111 //=======================================================================
112 bool SalomeApp_Study::loadDocument( const QString& theStudyName )
114 MESSAGE( "loadDocument" );
116 // obtain myStudyDS from StudyManager
117 _PTR(Study) study ( SalomeApp_Application::studyMgr()->GetStudyByName( (char*) theStudyName.latin1() ) );
123 setRoot( new SalomeApp_RootObject( this ) ); // create myRoot
125 //SRN: BugID IPAL9021, put there the same code as in a method openDocument
127 // update loaded data models: call open() and update() on them.
130 for ( ModelListIterator it( dm_s ); it.current(); ++it )
131 openDataModel( studyName(), it.current() );
133 // this will build a SUIT_DataObject-s tree under myRoot member field
134 // passing "false" in order NOT to rebuild existing data models' trees - it was done in previous step
135 // but tree that corresponds to not-loaded data models will be updated any way.
136 ((SalomeApp_Application*)application())->updateObjectBrowser( false );
138 bool res = CAM_Study::openDocument( theStudyName );
141 //SRN: BugID IPAL9021: End
146 //=======================================================================
147 // name : saveDocumentAs
148 /*! Purpose : Save document */
149 //=======================================================================
150 bool SalomeApp_Study::saveDocumentAs( const QString& theFileName )
152 ModelList list; dataModels( list );
154 SalomeApp_DataModel* aModel = (SalomeApp_DataModel*)list.first();
155 for ( ; aModel; aModel = (SalomeApp_DataModel*)list.next() )
156 aModel->saveAs( theFileName, this );
158 // save SALOMEDS document
159 SUIT_ResourceMgr* resMgr = application()->resourceMgr();
163 bool isMultiFile = resMgr->booleanValue( "Study", "multi_file", false ),
164 isAscii = resMgr->booleanValue( "Study", "ascii_file", true );
165 isAscii ? SalomeApp_Application::studyMgr()->SaveAsASCII( theFileName.latin1(), studyDS(), isMultiFile ) :
166 SalomeApp_Application::studyMgr()->SaveAs ( theFileName.latin1(), studyDS(), isMultiFile );
168 bool res = CAM_Study::saveDocumentAs( theFileName ); //SRN: BugID IPAL9377, removed usage of uninitialized variable <res>
176 //=======================================================================
177 // name : saveDocument
178 /*! Purpose : Save document */
179 //=======================================================================
180 void SalomeApp_Study::saveDocument()
182 ModelList list; dataModels( list );
184 SalomeApp_DataModel* aModel = (SalomeApp_DataModel*)list.first();
185 for ( ; aModel; aModel = (SalomeApp_DataModel*)list.next() )
188 CAM_Study::saveDocument();
190 // save SALOMEDS document
191 SUIT_ResourceMgr* resMgr = application()->resourceMgr();
195 bool isMultiFile = resMgr->booleanValue( "Study", "multi_file", false ),
196 isAscii = resMgr->booleanValue( "Study", "ascii_file", true );
197 isAscii ? SalomeApp_Application::studyMgr()->SaveASCII( studyDS(), isMultiFile ) :
198 SalomeApp_Application::studyMgr()->Save ( studyDS(), isMultiFile );
203 //================================================================
204 // Function : closeDocument
205 /*! Purpose : Close document */
206 //================================================================
207 void SalomeApp_Study::closeDocument(bool permanently)
209 // Inform everybody that this study is going to close when it's most safe to,
210 // i.e. in the very beginning
213 // close SALOMEDS document
214 _PTR(Study) studyPtr = studyDS();
217 if(permanently) SalomeApp_Application::studyMgr()->Close( studyPtr );
218 SALOMEDSClient_Study* aStudy = 0;
219 setStudyDS( _PTR(Study)(aStudy) );
222 CAM_Study::closeDocument(permanently);
225 //================================================================
226 // Function : isModified
227 /*! Purpose : Check data model on modifications.*/
228 //================================================================
229 bool SalomeApp_Study::isModified() const
231 bool isAnyChanged = studyDS() && studyDS()->IsModified();
232 ModelList list; dataModels( list );
234 SalomeApp_DataModel* aModel = 0;
235 for ( QPtrListIterator<CAM_DataModel> it( list ); it.current() && !isAnyChanged; ++it ){
236 aModel = dynamic_cast<SalomeApp_DataModel*>( it.current() );
238 isAnyChanged = aModel->isModified();
243 //================================================================
244 // Function : isSaved
245 /*! Purpose : Check: data model is saved?*/
246 //================================================================
247 bool SalomeApp_Study::isSaved() const
249 bool isAllSaved = studyDS() && studyDS()->GetPersistentReference().size();
250 ModelList list; dataModels( list );
252 SalomeApp_DataModel* aModel = 0;
253 for ( QPtrListIterator<CAM_DataModel> it( list ); it.current() && isAllSaved; ++it ){
254 aModel = dynamic_cast<SalomeApp_DataModel*>( it.current() );
256 isAllSaved = aModel->isSaved();
264 void SalomeApp_Study::setStudyDS( const _PTR(Study)& s )
272 void SalomeApp_Study::dataModelInserted (const CAM_DataModel* dm)
274 MESSAGE("SalomeApp_Study::dataModelInserted() : module name() = " << dm->module()->name());
276 CAM_Study::dataModelInserted(dm);
278 // Create SComponent for module, using default engine (CORBAless)
279 SalomeApp_Module* aModule = (SalomeApp_Module*)(dm->module());
281 QString anEngineIOR = aModule->engineIOR();
282 if (anEngineIOR.isEmpty()) { // CORBAless module
283 // Check SComponent existance
284 _PTR(SComponent) aComp = studyDS()->FindComponent(dm->module()->name());
287 _PTR(StudyBuilder) aBuilder = studyDS()->NewBuilder();
288 aComp = aBuilder->NewComponent(dm->module()->name());
290 // Set default engine IOR
291 aBuilder->DefineComponentInstance(aComp, SalomeApp_Application::defaultEngineIOR().latin1());
300 bool SalomeApp_Study::openDataModel( const QString& studyName, CAM_DataModel* dm )
305 SalomeApp_DataModel* aDM = (SalomeApp_DataModel*)(dm);
306 if (aDM && aDM->open(studyName, this)) {
307 // Something has been read -> create data model tree
308 aDM->update(NULL, this);
316 Create new study name.
318 QString SalomeApp_Study::newStudyName() const
320 std::vector<std::string> studies = SalomeApp_Application::studyMgr()->GetOpenStudies();
321 QString prefix( "Study%1" ), newName, curName;
322 int i = 1, j, n = studies.size();
323 while ( newName.isEmpty() ){
324 curName = prefix.arg( i );
325 for ( j = 0 ; j < n; j++ ){
326 if ( !strcmp( studies[j].c_str(), curName.latin1() ) )
337 void SalomeApp_Study::deleteReferencesTo( _PTR( SObject ) obj )
339 _PTR(StudyBuilder) sb = studyDS()->NewBuilder();
340 std::vector<_PTR(SObject)> aRefs = studyDS()->FindDependances( obj );
341 for( int i=0, n=aRefs.size(); i<n; i++ )
343 _PTR( SObject ) o = aRefs[i];
344 if( o->GetFatherComponent()->ComponentDataType()==obj->GetFatherComponent()->ComponentDataType() )
346 sb->RemoveReference( o );
347 sb->RemoveObjectWithChildren( o );