1 // VISU OBJECT : interactive object for VISU entities implementation
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
23 // File : VISU_Result_i.cc
24 // Author : Alexey PETROV
27 #include "VISU_Result_i.hh"
28 #include "VISU_Convertor_impl.hxx"
29 #include "VISU_CorbaMedConvertor.hxx"
30 #include "VISU_PipeLine.hxx"
32 #include "QAD_Config.h"
33 #include "SALOMEDS_Tool.hxx"
34 #include "HDFascii.hxx"
37 #include <qfileinfo.h>
42 #include <vtkUnstructuredGridReader.h>
43 #include <vtkUnstructuredGridWriter.h>
49 static int MYDEBUG = 0;
51 static int MYDEBUG = 0;
54 VISU::Result_var VISU::FindResult(SALOMEDS::SObject_ptr theSObject){
55 SALOMEDS::SComponent_var aSComponent = theSObject->GetFatherComponent();
56 SALOMEDS::SObject_var aFather = theSObject->GetFather();
57 CORBA::String_var aComponentID(aSComponent->GetID());
58 CORBA::String_var aFatherID(aFather->GetID());
59 VISU::Result_var aResult;
60 while(strcmp(aComponentID,aFatherID) != 0){
61 CORBA::Object_var anObject = VISU::SObjectToObject(aFather);
62 if(!CORBA::is_nil(anObject)){
63 aResult = VISU::Result::_narrow(anObject);
64 if(!aResult->_is_nil()) return aResult;
66 aFather = aFather->GetFather();
71 void VISU::RemoveFromStudy(SALOMEDS::SObject_ptr theSObject, int theIsAttrOnly){
72 if(!theSObject->_is_nil()){
73 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
74 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
76 aStudyBuilder->RemoveAttribute(theSObject,"AttributeIOR");
78 aStudyBuilder->RemoveObjectWithChildren(theSObject);
82 QString GenerateName(const char* theName){
83 typedef map<string,int> TNameMap;
85 TNameMap::const_iterator i = aMap.find(theName);
91 tmp = VISU::GenerateName(theName,++aMap[theName]);
93 if(MYDEBUG) MESSAGE("GenerateName - "<<tmp<<" from - "<<theName<<"; " <<aMap[theName]);
97 QString GenerateFieldName(const string& theName, const string& theUnits){
99 const string tmp(theUnits.size(),' ');
100 if(theUnits == "" || theUnits == tmp)
101 aName.sprintf("%s, -",theName.c_str());
103 aName.sprintf("%s, %s",theName.c_str(),theUnits.c_str());
104 aName = aName.simplifyWhiteSpace();
105 return aName.latin1();
108 void CreateReference(SALOMEDS::Study_ptr theStudyDocument,
109 const string& theFatherEntry, const string& theRefEntry)
111 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
112 SALOMEDS::SObject_var aFather = theStudyDocument->FindObjectID(theFatherEntry.c_str());
113 SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(aFather);
114 SALOMEDS::SObject_var aRefSObj = theStudyDocument->FindObjectID(theRefEntry.c_str());
115 aStudyBuilder->Addreference(newObj,aRefSObj);
118 string GetComponentDataType(SALOMEDS::SObject_ptr theSObject){
119 SALOMEDS::SComponent_var aCompRefSObj = theSObject->GetFatherComponent();
120 CORBA::String_var aDataType = aCompRefSObj->ComponentDataType();
121 return aDataType.in();
124 //==============================================================================
126 const string VISU::Result_i::myComment = "RESULT";
127 const char* VISU::Result_i::GetComment() const { return myComment.c_str();}
129 VISU::Result_i::Result_i(SALOMEDS::Study_ptr theStudy, const TSourceId& aSourceId) {
130 myStudyDocument = SALOMEDS::Study::_duplicate(theStudy);
131 mySourceId = aSourceId;
134 CORBA::String_var aName = theStudy->Name();
135 MESSAGE("Result_i::Result_i - this = "<<this<<"; StudyId = "<<
136 theStudy->StudyId()<<"; Name = '"<<aName.in()<<"'");
140 void VISU::Result_i::RemoveFromStudy(){
141 VISU::RemoveFromStudy(mySObject,false);
145 int VISU::Result_i::IsPossible(){
147 float aSize = myInput->GetSize();
148 bool aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
149 MESSAGE("Result_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<float(aResult));
151 }catch(std::exception& exc){
152 INFOS("Follow exception was occured :\n"<<exc.what());
154 INFOS("Unknown exception was occured!");
160 CORBA::Boolean VISU::Result_i::BuildAll(){
161 if(MYDEBUG) MESSAGE("Result_i::Build - myIsDone = "<<myIsDone);
162 if(myIsDone) return 1;
163 if(!IsPossible()) return 0;
165 const VISU::TMeshMap& aMeshMap = myInput->GetMeshMap();
166 VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
167 for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
168 const string& aMeshName = aMeshMapIter->first;
169 const VISU::PMesh aMesh = aMeshMapIter->second;
170 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
171 VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter;
173 aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
174 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
175 const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
176 const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
177 const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
178 VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
179 for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){
180 const string& aFieldName = aFieldMapIter->first;
181 const VISU::PField aField = aFieldMapIter->second;
182 const VISU::TValField& aValField = aField->myValField;
183 VISU::TValField::const_iterator aValFieldIter = aValField.begin();
184 for(; aValFieldIter != aValField.end(); aValFieldIter++){
185 int aTimeStamp = aValFieldIter->first;
187 myInput->GetTimeStampOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp);
188 }catch(std::exception& exc){
189 INFOS("Follow exception was occured :\n"<<exc.what());
191 INFOS("Unknown exception was occured!!!");
196 const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
197 VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin();
198 for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){
199 const string& aGroupName = aGroupMapIter->first;
201 myInput->GetMeshOnGroup(aMeshName,aGroupName);
202 }catch(std::exception& exc){
203 INFOS("Follow exception was occured :\n"<<exc.what());
205 INFOS("Unknown exception was occured!!!");
209 const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
210 VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
211 for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
212 const string& aFamilyName = aFamilyMapIter->first;
214 myInput->GetMeshOnEntity(aMeshName,anEntity,aFamilyName);
215 }catch(std::exception& exc){
216 INFOS("Follow exception was occured :\n"<<exc.what());
218 INFOS("Unknown exception was occured!!!");
221 //Import mesh on entity
223 myInput->GetMeshOnEntity(aMeshName,anEntity);
224 }catch(std::exception& exc){
225 INFOS("Follow exception was occured :\n"<<exc.what());
227 INFOS("Unknown exception was occured!!!");
232 }catch(std::exception& exc){
233 INFOS("Follow exception was occured :\n"<<exc.what());
235 INFOS("Unknown exception was occured!!!");
240 VISU::Storable* VISU::Result_i::Build(SALOMEDS::SObject_ptr theSObject)
242 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
243 aStudyBuilder->NewCommand(); // There is a transaction
244 if(MYDEBUG) MESSAGE("Result_i::Build");
246 const TMeshMap& aMeshMap = myInput->GetMeshMap();
248 throw std::runtime_error("Build - There is no any mesh information in the file !!!");
249 mySComponent = FindOrCreateVisuComponent(myStudyDocument);
250 CORBA::String_var aSComponentEntry = mySComponent->GetID(), anIOR(GetID());
251 string aRefFatherEntry = GetRefFatherEntry();
253 aComment.sprintf("myComment=%s;myType=%d;myFileName=%s;myInitFileName=%s",
256 myFileInfo.filePath().latin1(),
257 myInitFileName.c_str()); // Restoring of Python dump
258 string aResultEntry =
259 CreateAttributes(myStudyDocument,
261 aRefFatherEntry.c_str(),
267 mySObject = myStudyDocument->FindObjectID(aResultEntry.c_str());
268 if(mySObject->_is_nil()) throw std::runtime_error("Build - There is no SObject for the Result !!!");
269 if(!CORBA::is_nil(theSObject)){
270 CORBA::String_var aString = theSObject->GetID();
271 CreateReference(myStudyDocument,aResultEntry,aString.in());
273 TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
274 for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
275 const string& aMeshName = aMeshMapIter->first;
276 const VISU::PMesh aMesh = aMeshMapIter->second;
277 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
278 VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter;
279 aComment.sprintf("myComment=MESH;myName=%s;myDim=%d",
280 aMeshName.c_str(),aMesh->myDim);
281 string aMeshEntry = CreateAttributes(myStudyDocument,aResultEntry.c_str(),aRefFatherEntry.c_str(),
282 "",aMeshName.c_str(),"",aComment.latin1(),true);
283 if(aMeshOnEntityMap.empty()) continue;
284 aComment.sprintf("myComment=FAMILIES;myMeshName=%s",aMeshName.c_str());
285 string aSubMeshesEntry = CreateAttributes(myStudyDocument,aMeshEntry.c_str(),aRefFatherEntry.c_str(),
286 "","Families","",aComment.latin1(),true);
287 //Import entities and according families
288 aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
289 typedef std::map<std::string,std::string> TComment2EntryMap;
290 TComment2EntryMap aComment2EntryMap;
291 typedef std::map<VISU::TEntity,std::string> TEntity2EntryMap;
292 TEntity2EntryMap aEntity2EntryMap;
293 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
294 const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
295 aComment.sprintf("myComment=ENTITY;myType=%d;myMeshName=%s;myId=%d",
301 case VISU::NODE_ENTITY : anEntityName = "onNodes"; break;
302 case VISU::EDGE_ENTITY : anEntityName = "onEdges"; break;
303 case VISU::FACE_ENTITY : anEntityName = "onFaces"; break;
304 case VISU::CELL_ENTITY : anEntityName = "onCells"; break;
306 throw std::runtime_error("Build >> Value of entity is incorrect!");
308 aEntity2EntryMap[anEntity] = CreateAttributes(myStudyDocument,aSubMeshesEntry.c_str(),aRefFatherEntry.c_str(),
309 "",anEntityName.c_str(),"",aComment.latin1(),true);
310 const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
311 const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
312 VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
313 for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
314 const string& aFamilyName = aFamilyMapIter->first;
315 aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s",
319 aFamilyName.c_str());
320 aComment2EntryMap[aComment.latin1()] =
321 CreateAttributes(myStudyDocument,
322 aEntity2EntryMap[anEntity].c_str(),
323 aRefFatherEntry.c_str(),
332 const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
333 if(aGroupMap.size() > 0){
334 aComment.sprintf("myComment=GROUPS;myMeshName=%s",
336 string aGroupsEntry =
337 CreateAttributes(myStudyDocument,
339 aRefFatherEntry.c_str(),
345 VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin();
346 for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){
347 const string& aGroupName = aGroupMapIter->first;
348 aComment.sprintf("myComment=GROUP;myType=%d;myMeshName=%s;myName=%s",
349 VISU::TGROUP,aMeshName.c_str(),aGroupName.c_str());
350 string aGroupEntry = CreateAttributes(myStudyDocument,aGroupsEntry.c_str(),aRefFatherEntry.c_str(),
351 "",aGroupName.c_str(),"",aComment.latin1(),true);
352 const VISU::PGroup aGroup = aGroupMapIter->second;
353 const VISU::TFamilyAndEntitySet& aFamilyAndEntitySet = aGroup->myFamilyAndEntitySet;
354 VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = aFamilyAndEntitySet.begin();
355 for(; aFamilyAndEntitySetIter != aFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){
356 const VISU::TFamilyAndEntity& aFamilyAndEntity = *aFamilyAndEntitySetIter;
357 const string& aFamilyName = aFamilyAndEntity.first;
358 const VISU::TEntity& anEntity = aFamilyAndEntity.second;
359 aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s",
363 aFamilyName.c_str());
364 CreateReference(myStudyDocument,aGroupEntry,aComment2EntryMap[aComment.latin1()]);
370 bool isFieldEntryCreated = 0;
371 aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
372 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
373 const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
374 const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
375 const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
376 VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
377 for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){
378 if(!isFieldEntryCreated){
379 aComment.sprintf("myComment=FIELDS;myMeshName=%s",
382 CreateAttributes(myStudyDocument,
384 aRefFatherEntry.c_str(),
390 isFieldEntryCreated = true;
392 const string& aFieldName = aFieldMapIter->first;
393 const VISU::PField aField = aFieldMapIter->second;
394 const VISU::TValField& aValField = aField->myValField;
395 QString aFieldNameWithUnit = ::GenerateFieldName(aFieldName,aField->myUnitNames[0]);
396 aComment.sprintf("myComment=FIELD;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s;myNbTimeStamps=%d;myNumComponent=%d",
397 VISU::TFIELD,aMeshName.c_str(),anEntity,aFieldName.c_str(),aValField.size(),aField->myNbComp);
398 string aFieldEntry = CreateAttributes(myStudyDocument,aFieldsEntry.c_str(),aRefFatherEntry.c_str(),
399 "",aFieldNameWithUnit.latin1(),"",aComment.latin1(),true);
400 CreateReference(myStudyDocument,aFieldEntry,aEntity2EntryMap[anEntity]);
401 VISU::TValField::const_iterator aValFieldIter = aValField.begin();
402 for(; aValFieldIter != aValField.end(); aValFieldIter++){
403 int aTimeStamp = aValFieldIter->first;
404 const VISU::PValForTime aValForTime = aValFieldIter->second;
405 aComment.sprintf("myComment=TIMESTAMP;myType=%d;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d",
406 VISU::TTIMESTAMP,aMeshName.c_str(),anEntity,aFieldName.c_str(),aTimeStamp,aField->myNbComp);
407 string aTimeStampId = VISU_Convertor::GenerateName(aValForTime->myTime);
408 CreateAttributes(myStudyDocument,aFieldEntry.c_str(),aRefFatherEntry.c_str(),
409 "",aTimeStampId.c_str(),"",aComment.latin1(),true);
414 QString aIsBuild = QAD_CONFIG->getSetting("Visu:BuildResult");
415 bool isBuildAll = aIsBuild.isEmpty()? 0 : aIsBuild.toInt();
416 if(isBuildAll) BuildAll();
417 }catch(std::exception& exc){
418 INFOS("Follow exception was occured :\n"<<exc.what());
421 INFOS("Unknown exception was occured!!!");
424 aStudyBuilder->CommitCommand();
428 VISU::Storable* VISU::Result_i::Create(const char* theFileName){
430 myFileInfo.setFile(theFileName);
431 myInitFileName = myFileInfo.filePath().latin1();
432 myName = ::GenerateName(myFileInfo.fileName()).latin1();
433 if(GetSourceId() == eRestoredFile){
434 auto_ptr<char> aTmpDir((char*)SALOMEDS_Tool::GetTmpDir().c_str());
435 static QString aCommand;
436 aCommand.sprintf("cp %s %s",myFileInfo.absFilePath().latin1(),aTmpDir.get());
437 if(system(aCommand) == -1){
438 MESSAGE("Create - Can't execute the command :"<<aCommand);
441 if(MYDEBUG) MESSAGE("Result_i::Create - aCommand = "<<aCommand);
442 myFileInfo.setFile(QString(aTmpDir.get()) + myFileInfo.fileName());
444 myInput = CreateConvertor(myFileInfo.absFilePath().latin1());
446 throw std::runtime_error("Create - Cannot create a Convertor for this file!!!"); return Build();
447 }catch(std::exception& exc){
448 INFOS("Follow exception was occured :\n"<<exc.what());
450 INFOS("Unknown exception was occured!!!");
455 VISU::Storable* VISU::Result_i::Create(SALOMEDS::SObject_ptr theMedSObject){
456 if(MYDEBUG) MESSAGE("Result_i::Create MedObject from SALOMEDS::SObject_ptr");
458 myInput = CreateMEDConvertor(theMedSObject);
459 if(myInput == NULL) return NULL;
460 mySourceId = eComponent;
461 string aCompDataType = GetComponentDataType(theMedSObject);
462 myFileInfo.setFile(aCompDataType.c_str());
463 myName = ::GenerateName("aResult").latin1();
464 VISU::Storable* aStorable = Build(theMedSObject);
466 }catch(std::exception& exc){
467 INFOS("Follow exception was occured :\n"<<exc.what());
469 INFOS("Unknown exception was occured!!!");
474 VISU::Storable* VISU::Result_i::Create(SALOME_MED::FIELD_ptr theField){
475 if(MYDEBUG) MESSAGE("Result_i::Create MedObject from SALOME_MED::FIELD_ptr");
477 myInput = CreateMEDFieldConvertor(theField);
478 if(myInput == NULL) return NULL;
479 mySourceId = eComponent;
480 string aCompDataType = "MED";
481 myFileInfo.setFile(aCompDataType.c_str());
482 myInitFileName = aCompDataType;
483 myName = ::GenerateName("aResult").latin1();
484 CORBA::String_var anIOR = myStudyDocument->ConvertObjectToIOR(theField);
485 SALOMEDS::SObject_var aFieldSObject = myStudyDocument->FindObjectIOR(anIOR);
486 VISU::Storable* aStorable = Build(aFieldSObject);
488 }catch(std::exception& exc){
489 INFOS("Follow exception was occured :\n"<<exc.what());
491 INFOS("Unknown exception was occured!!!");
496 VISU::Storable* VISU::Result_i::Restore(SALOMEDS::SObject_ptr theSObject,
497 const Storable::TRestoringMap& theMap, const string& thePrefix)
499 if(MYDEBUG) MESSAGE("Result_i::Restore - "<<thePrefix);
501 mySObject = SALOMEDS::SObject::_duplicate(theSObject);
502 myStudyDocument = mySObject->GetStudy();
503 mySComponent = mySObject->GetFatherComponent();
504 myName = VISU::Storable::FindValue(theMap,"myName").latin1();
505 myInitFileName = VISU::Storable::FindValue(theMap,"myInitFileName").latin1();
506 SALOMEDS::SObject_var aRefSObj, aTargetRefSObj;
507 if(mySObject->FindSubObject(1,aRefSObj) && aRefSObj->ReferencedObject(aTargetRefSObj)){
508 mySourceId = eRestoredComponent;
509 if(MYDEBUG) MESSAGE("Result_i::GetInput - There is some reference.");
510 SALOMEDS::SComponent_var aCompRefSObj = aTargetRefSObj->GetFatherComponent();
511 CORBA::String_var aDataType = aCompRefSObj->ComponentDataType();
512 myFileInfo.setFile(aDataType.in());
513 if(MYDEBUG) MESSAGE("Result_i::GetInput - aDataType = "<<aDataType);
514 Engines::Component_var aEngComp = Base_i::myEnginesLifeCycle->FindOrLoad_Component("FactoryServer", aDataType.in());
515 if (CORBA::is_nil(aEngComp))
516 throw std::runtime_error("Restore - There is no aEngComp for the aDataType !!!");
517 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
518 SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(aEngComp);
519 aStudyBuilder->LoadWith(aCompRefSObj,aDriver);
520 if(strcmp(aDataType,"MED") == 0)
521 myInput = CreateMEDConvertor(aTargetRefSObj);
523 throw std::runtime_error("GetInput - There is no convertor for the aDataType !!!");
525 myFileInfo.setFile(thePrefix.c_str());
527 string aStudyPrefix("");
528 if (IsMultifile()) aStudyPrefix = (SALOMEDS_Tool::GetNameFromPath(myStudyDocument->URL()));
529 if(!myFileInfo.isFile()){
530 string aFileName = thePrefix + aStudyPrefix + "_" + myName;
531 myFileInfo.setFile(aFileName.c_str());
534 MESSAGE("Result_i::Restore - aFileName = "<<myFileInfo.filePath()<<"; "<<myFileInfo.isFile());
536 if (HDFascii::isASCII(myFileInfo.filePath().latin1())) {
537 char* aResultPath = HDFascii::ConvertFromASCIIToHDF(myFileInfo.filePath().latin1());
538 char* aHDFFileName = new char[strlen(aResultPath) + 19];
539 sprintf(aHDFFileName, "%shdf_from_ascii.hdf", aResultPath);
541 if (IsMultifile()) { // set this file as new - temporary
542 static QString aCommand;
543 aCommand.sprintf("mv %s %s%s",aHDFFileName, aResultPath, myFileInfo.baseName().latin1());
544 if(system(aCommand) == -1){
545 if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - Can't execute the command :"<<aCommand);
547 } else if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - "<<aCommand);
548 myFileInfo.setFile(QString(aResultPath)+QString(myFileInfo.baseName().latin1()));
549 } else { // change current temporary file to the new: with hdf-format
550 static QString aCommand;
551 aCommand.sprintf("mv %s %s\0",aHDFFileName, myFileInfo.filePath().latin1());
552 if(system(aCommand.latin1()) == -1) {
553 if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - Can't execute the command :"<<aCommand);
555 } else if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - "<<aCommand);
556 SALOMEDS::ListOfFileNames_var anEmptyList = new SALOMEDS::ListOfFileNames;
557 SALOMEDS_Tool::RemoveTemporaryFiles(aResultPath, anEmptyList.in(), true);
559 mySourceId = eRestoredFile;
561 delete(aHDFFileName);
562 } else if (!IsMultifile())
563 mySourceId = eRestoredFile;
566 if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - mySourceId = "<<mySourceId);
567 myInput = CreateConvertor(myFileInfo.filePath().latin1());
569 aComment.sprintf("myComment=%s;myType=%d;myFileName=%s;myInitFileName=%s",
570 GetComment(),VISU::TRESULT,myFileInfo.filePath().latin1(),
571 myInitFileName.c_str()); // Restoring of Python dump
572 SALOMEDS::GenericAttribute_var anAttr;
573 if(!theSObject->FindAttribute(anAttr, "AttributeComment"))
574 throw std::runtime_error("Build - There is no AttributeComment for the SObject !!!");
575 SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr);
576 aCmnt->SetValue(aComment.latin1());
578 QString aIsBuild = QAD_CONFIG->getSetting("Visu:BuildResult");
579 if(aIsBuild.isEmpty()? 0 : aIsBuild.toInt())
582 }catch(std::exception& exc){
583 INFOS("Follow exception was occured :\n"<<exc.what());
585 INFOS("Unknown exception was occured!!!");
590 VISU::Result_i::TInput* VISU::Result_i::GetInput() {
594 void VISU::Result_i::ToStream(std::ostringstream& theStr){
595 if(MYDEBUG) MESSAGE(GetComment());
596 Storable::DataToStream(theStr,"myName",myName.c_str());
597 Storable::DataToStream(theStr,"myInitFileName",myInitFileName.c_str());
600 VISU::Storable* VISU::Result_i::Restore(SALOMEDS::SObject_ptr theSObject,
601 const string& thePrefix, const Storable::TRestoringMap& theMap)
603 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
604 VISU::Result_i* pResult = new VISU::Result_i(aStudy);
605 if(pResult == NULL) return NULL;
606 return pResult->Restore(theSObject,theMap,thePrefix);
609 string VISU::Result_i::GetRefFatherEntry() {
610 //return QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry();
614 string VISU::Result_i::GetEntry(){
615 CORBA::String_var anEntry = mySObject->GetID();
616 return string(anEntry);
619 const SALOMEDS::SObject_var& VISU::Result_i::GetSObject() const { return mySObject;}
620 const SALOMEDS::Study_var& VISU::Result_i::GetStudyDocument() const { return myStudyDocument;}
621 const SALOMEDS::SComponent_var& VISU::Result_i::GetSComponent() const { return mySComponent;}
622 std::string VISU::Result_i::GetEntry(const std::string& theComment)
624 return FindEntryWithComment(myStudyDocument,GetEntry().c_str(),theComment.c_str());
627 VISU::Result_i::~Result_i() {
628 MESSAGE("Result_i::~Result_i() - this = "<<this);
629 if(GetSourceId() == eRestoredFile){
630 static QString aCommand;
631 aCommand.sprintf("rm %s",myFileInfo.filePath().latin1());
632 MESSAGE("Result_i::~Result_i - system("<<aCommand<<") = "<<system(aCommand));
633 aCommand.sprintf("rmdir --ignore-fail-on-non-empty %s",myFileInfo.dirPath().latin1());
634 MESSAGE("Result_i::~Result_i - system("<<aCommand<<") = "<<system(aCommand));
636 if(myInput) delete myInput;