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 "SUIT_ResourceMgr.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)
120 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
121 SALOMEDS::SComponent_var aCompRefSObj = theSObject->GetFatherComponent();
122 CORBA::String_var aDataType = aCompRefSObj->ComponentDataType();
123 return aDataType.in();
126 //==============================================================================
128 const string VISU::Result_i::myComment = "RESULT";
129 const char* VISU::Result_i::GetComment() const { return myComment.c_str();}
131 VISU::Result_i::Result_i(SALOMEDS::Study_ptr theStudy,
132 const ESourceId& theSourceId,
133 const ECreationId& theCreationId):
134 myStudyDocument(SALOMEDS::Study::_duplicate(theStudy)),
135 myCreationId(theCreationId),
136 mySourceId(theSourceId),
143 void VISU::Result_i::RemoveFromStudy(){
144 VISU::RemoveFromStudy(mySObject,false);
153 float aSize = myInput->GetSize();
154 bool aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
155 MESSAGE("Result_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<float(aResult));
157 }catch(std::exception& exc){
158 INFOS("Follow exception was occured :\n"<<exc.what());
160 INFOS("Unknown exception was occured!");
170 if(MYDEBUG) MESSAGE("Result_i::Build - myIsDone = "<<myIsDone);
171 if(myIsDone) return 1;
172 if(!IsPossible()) return 0;
174 const VISU::TMeshMap& aMeshMap = myInput->GetMeshMap();
175 VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
176 for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
177 const string& aMeshName = aMeshMapIter->first;
178 const VISU::PMesh aMesh = aMeshMapIter->second;
179 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
180 VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter;
182 aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
183 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
184 const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
185 const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
186 const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
187 VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
188 for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){
189 const string& aFieldName = aFieldMapIter->first;
190 const VISU::PField aField = aFieldMapIter->second;
191 const VISU::TValField& aValField = aField->myValField;
192 VISU::TValField::const_iterator aValFieldIter = aValField.begin();
193 for(; aValFieldIter != aValField.end(); aValFieldIter++){
194 int aTimeStamp = aValFieldIter->first;
196 myInput->GetTimeStampOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp);
197 }catch(std::exception& exc){
198 INFOS("Follow exception was occured :\n"<<exc.what());
200 INFOS("Unknown exception was occured!!!");
205 const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
206 VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin();
207 for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){
208 const string& aGroupName = aGroupMapIter->first;
210 myInput->GetMeshOnGroup(aMeshName,aGroupName);
211 }catch(std::exception& exc){
212 INFOS("Follow exception was occured :\n"<<exc.what());
214 INFOS("Unknown exception was occured!!!");
218 const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
219 VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
220 for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
221 const string& aFamilyName = aFamilyMapIter->first;
223 myInput->GetMeshOnEntity(aMeshName,anEntity,aFamilyName);
224 }catch(std::exception& exc){
225 INFOS("Follow exception was occured :\n"<<exc.what());
227 INFOS("Unknown exception was occured!!!");
230 //Import mesh on entity
232 myInput->GetMeshOnEntity(aMeshName,anEntity);
233 }catch(std::exception& exc){
234 INFOS("Follow exception was occured :\n"<<exc.what());
236 INFOS("Unknown exception was occured!!!");
241 }catch(std::exception& exc){
242 INFOS("Follow exception was occured :\n"<<exc.what());
244 INFOS("Unknown exception was occured!!!");
252 Build(SALOMEDS::SObject_ptr theSObject)
254 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
255 aStudyBuilder->NewCommand(); // There is a transaction
256 if(MYDEBUG) MESSAGE("Result_i::Build");
258 const TMeshMap& aMeshMap = myInput->GetMeshMap();
260 throw std::runtime_error("Build - There is no any mesh information in the file !!!");
261 mySComponent = FindOrCreateVisuComponent(myStudyDocument);
262 CORBA::String_var aSComponentEntry = mySComponent->GetID(), anIOR(GetID());
263 string aRefFatherEntry = GetRefFatherEntry();
265 aComment.sprintf("myComment=%s;myType=%d;myFileName=%s;myInitFileName=%s",
268 myFileInfo.filePath().latin1(),
269 myInitFileName.c_str()); // Restoring of Python dump
270 string aResultEntry =
271 CreateAttributes(myStudyDocument,
273 aRefFatherEntry.c_str(),
279 mySObject = myStudyDocument->FindObjectID(aResultEntry.c_str());
280 if(mySObject->_is_nil()) throw std::runtime_error("Build - There is no SObject for the Result !!!");
281 if(!CORBA::is_nil(theSObject)){
282 CORBA::String_var aString = theSObject->GetID();
283 CreateReference(myStudyDocument,aResultEntry,aString.in());
285 TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
286 for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
287 const string& aMeshName = aMeshMapIter->first;
288 const VISU::PMesh aMesh = aMeshMapIter->second;
289 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
290 VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter;
291 aComment.sprintf("myComment=MESH;myName=%s;myDim=%d",
292 aMeshName.c_str(),aMesh->myDim);
293 string aMeshEntry = CreateAttributes(myStudyDocument,aResultEntry.c_str(),aRefFatherEntry.c_str(),
294 "",aMeshName.c_str(),"",aComment.latin1(),true);
295 if(aMeshOnEntityMap.empty()) continue;
296 aComment.sprintf("myComment=FAMILIES;myMeshName=%s",aMeshName.c_str());
297 string aSubMeshesEntry = CreateAttributes(myStudyDocument,aMeshEntry.c_str(),aRefFatherEntry.c_str(),
298 "","Families","",aComment.latin1(),true);
299 //Import entities and according families
300 aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
301 typedef std::map<std::string,std::string> TComment2EntryMap;
302 TComment2EntryMap aComment2EntryMap;
303 typedef std::map<VISU::TEntity,std::string> TEntity2EntryMap;
304 TEntity2EntryMap aEntity2EntryMap;
305 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
306 const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
307 aComment.sprintf("myComment=ENTITY;myType=%d;myMeshName=%s;myId=%d",
313 case VISU::NODE_ENTITY : anEntityName = "onNodes"; break;
314 case VISU::EDGE_ENTITY : anEntityName = "onEdges"; break;
315 case VISU::FACE_ENTITY : anEntityName = "onFaces"; break;
316 case VISU::CELL_ENTITY : anEntityName = "onCells"; break;
318 throw std::runtime_error("Build >> Value of entity is incorrect!");
320 aEntity2EntryMap[anEntity] = CreateAttributes(myStudyDocument,aSubMeshesEntry.c_str(),aRefFatherEntry.c_str(),
321 "",anEntityName.c_str(),"",aComment.latin1(),true);
322 const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
323 const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
324 VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
325 for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
326 const string& aFamilyName = aFamilyMapIter->first;
327 aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s",
331 aFamilyName.c_str());
332 aComment2EntryMap[aComment.latin1()] =
333 CreateAttributes(myStudyDocument,
334 aEntity2EntryMap[anEntity].c_str(),
335 aRefFatherEntry.c_str(),
344 const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
345 if(aGroupMap.size() > 0){
346 aComment.sprintf("myComment=GROUPS;myMeshName=%s",
348 string aGroupsEntry =
349 CreateAttributes(myStudyDocument,
351 aRefFatherEntry.c_str(),
357 VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin();
358 for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){
359 const string& aGroupName = aGroupMapIter->first;
360 aComment.sprintf("myComment=GROUP;myType=%d;myMeshName=%s;myName=%s",
361 VISU::TGROUP,aMeshName.c_str(),aGroupName.c_str());
362 string aGroupEntry = CreateAttributes(myStudyDocument,aGroupsEntry.c_str(),aRefFatherEntry.c_str(),
363 "",aGroupName.c_str(),"",aComment.latin1(),true);
364 const VISU::PGroup aGroup = aGroupMapIter->second;
365 const VISU::TFamilyAndEntitySet& aFamilyAndEntitySet = aGroup->myFamilyAndEntitySet;
366 VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = aFamilyAndEntitySet.begin();
367 for(; aFamilyAndEntitySetIter != aFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){
368 const VISU::TFamilyAndEntity& aFamilyAndEntity = *aFamilyAndEntitySetIter;
369 const string& aFamilyName = aFamilyAndEntity.first;
370 const VISU::TEntity& anEntity = aFamilyAndEntity.second;
371 aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s",
375 aFamilyName.c_str());
376 CreateReference(myStudyDocument,aGroupEntry,aComment2EntryMap[aComment.latin1()]);
382 bool isFieldEntryCreated = 0;
383 aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
384 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
385 const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
386 const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
387 const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
388 VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
389 for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){
390 if(!isFieldEntryCreated){
391 aComment.sprintf("myComment=FIELDS;myMeshName=%s",
394 CreateAttributes(myStudyDocument,
396 aRefFatherEntry.c_str(),
402 isFieldEntryCreated = true;
404 const string& aFieldName = aFieldMapIter->first;
405 const VISU::PField aField = aFieldMapIter->second;
406 const VISU::TValField& aValField = aField->myValField;
407 QString aFieldNameWithUnit = ::GenerateFieldName(aFieldName,aField->myUnitNames[0]);
408 aComment.sprintf("myComment=FIELD;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s;myNbTimeStamps=%d;myNumComponent=%d",
409 VISU::TFIELD,aMeshName.c_str(),anEntity,aFieldName.c_str(),aValField.size(),aField->myNbComp);
410 string aFieldEntry = CreateAttributes(myStudyDocument,aFieldsEntry.c_str(),aRefFatherEntry.c_str(),
411 "",aFieldNameWithUnit.latin1(),"",aComment.latin1(),true);
412 CreateReference(myStudyDocument,aFieldEntry,aEntity2EntryMap[anEntity]);
413 VISU::TValField::const_iterator aValFieldIter = aValField.begin();
414 for(; aValFieldIter != aValField.end(); aValFieldIter++){
415 int aTimeStamp = aValFieldIter->first;
416 const VISU::PValForTime aValForTime = aValFieldIter->second;
417 aComment.sprintf("myComment=TIMESTAMP;myType=%d;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d",
418 VISU::TTIMESTAMP,aMeshName.c_str(),anEntity,aFieldName.c_str(),aTimeStamp,aField->myNbComp);
419 string aTimeStampId = VISU_Convertor::GenerateName(aValForTime->myTime);
420 CreateAttributes(myStudyDocument,aFieldEntry.c_str(),aRefFatherEntry.c_str(),
421 "",aTimeStampId.c_str(),"",aComment.latin1(),true);
426 QString aIsBuild = VISU::GetResourceMgr()->stringValue("Visu:BuildResult");
427 bool isBuildAll = aIsBuild.isEmpty()? 0 : aIsBuild.toInt();
428 if(isBuildAll) BuildAll();
429 }catch(std::exception& exc){
430 INFOS("Follow exception was occured :\n"<<exc.what());
433 INFOS("Unknown exception was occured!!!");
436 aStudyBuilder->CommitCommand();
443 Create(const char* theFileName)
446 myFileInfo.setFile(theFileName);
447 myInitFileName = myFileInfo.filePath().latin1();
448 myName = ::GenerateName(myFileInfo.fileName()).latin1();
449 if(mySourceId == eRestoredFile){
450 std::string aTmpDir(SALOMEDS_Tool::GetTmpDir());
451 static QString aCommand;
452 aCommand.sprintf("cp %s %s",myFileInfo.absFilePath().latin1(),aTmpDir.c_str());
453 if(system(aCommand) == -1){
454 MESSAGE("Create - Can't execute the command :"<<aCommand);
457 if(MYDEBUG) MESSAGE("Result_i::Create - aCommand = "<<aCommand);
458 myFileInfo.setFile(QString(aTmpDir.c_str()) + myFileInfo.fileName());
460 myInput = CreateConvertor(myFileInfo.absFilePath().latin1());
462 throw std::runtime_error("Create - Cannot create a Convertor for this file!!!"); return Build();
463 }catch(std::exception& exc){
464 INFOS("Follow exception was occured :\n"<<exc.what());
466 INFOS("Unknown exception was occured!!!");
474 Create(SALOMEDS::SObject_ptr theMedSObject)
476 if(MYDEBUG) MESSAGE("Result_i::Create MedObject from SALOMEDS::SObject_ptr");
478 myInput = CreateMEDConvertor(theMedSObject);
482 string aCompDataType = GetComponentDataType(theMedSObject);
483 myFileInfo.setFile(aCompDataType.c_str());
484 myInitFileName = aCompDataType;
486 myName = ::GenerateName("aResult").latin1();
488 VISU::Storable* aStorable = Build(theMedSObject);
490 }catch(std::exception& exc){
491 INFOS("Follow exception was occured :\n"<<exc.what());
493 INFOS("Unknown exception was occured!!!");
500 Create(SALOME_MED::FIELD_ptr theField)
502 if(MYDEBUG) MESSAGE("Result_i::Create MedObject from SALOME_MED::FIELD_ptr");
504 myInput = CreateMEDFieldConvertor(theField);
508 string aCompDataType = "MED";
509 myFileInfo.setFile(aCompDataType.c_str());
510 myInitFileName = aCompDataType;
512 myName = ::GenerateName("aResult").latin1();
514 CORBA::String_var anIOR = myStudyDocument->ConvertObjectToIOR(theField);
515 SALOMEDS::SObject_var aFieldSObject = myStudyDocument->FindObjectIOR(anIOR);
517 VISU::Storable* aStorable = Build(aFieldSObject);
519 }catch(std::exception& exc){
520 INFOS("Follow exception was occured :\n"<<exc.what());
522 INFOS("Unknown exception was occured!!!");
530 Restore(SALOMEDS::SObject_ptr theSObject,
531 const Storable::TRestoringMap& theMap,
532 const string& thePrefix)
534 if(MYDEBUG) MESSAGE("Result_i::Restore - "<<thePrefix);
536 mySObject = SALOMEDS::SObject::_duplicate(theSObject);
537 myStudyDocument = mySObject->GetStudy();
538 mySComponent = mySObject->GetFatherComponent();
539 myName = VISU::Storable::FindValue(theMap,"myName").latin1();
540 myInitFileName = VISU::Storable::FindValue(theMap,"myInitFileName").latin1();
541 SALOMEDS::SObject_var aRefSObj, aTargetRefSObj;
542 if(mySObject->FindSubObject(1,aRefSObj) && aRefSObj->ReferencedObject(aTargetRefSObj)){
543 if(MYDEBUG) MESSAGE("Result_i::GetInput - There is some reference.");
544 SALOMEDS::SComponent_var aCompRefSObj = aTargetRefSObj->GetFatherComponent();
545 CORBA::String_var aDataType = aCompRefSObj->ComponentDataType();
546 myFileInfo.setFile(aDataType.in());
547 if(MYDEBUG) MESSAGE("Result_i::GetInput - aDataType = "<<aDataType);
548 Engines::Component_var aEngComp = Base_i::myEnginesLifeCycle->FindOrLoad_Component("FactoryServer", aDataType.in());
549 if (CORBA::is_nil(aEngComp))
550 throw std::runtime_error("Restore - There is no aEngComp for the aDataType !!!");
551 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
552 SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(aEngComp);
553 aStudyBuilder->LoadWith(aCompRefSObj,aDriver);
554 if(strcmp(aDataType,"MED") == 0)
555 myInput = CreateMEDConvertor(aTargetRefSObj);
557 throw std::runtime_error("GetInput - There is no convertor for the aDataType !!!");
559 myFileInfo.setFile(thePrefix.c_str());
561 string aStudyPrefix("");
562 if (IsMultifile()) aStudyPrefix = (SALOMEDS_Tool::GetNameFromPath(myStudyDocument->URL()));
563 if(!myFileInfo.isFile()){
564 string aFileName = thePrefix + aStudyPrefix + "_" + myName;
565 myFileInfo.setFile(aFileName.c_str());
568 MESSAGE("Result_i::Restore - aFileName = "<<myFileInfo.filePath()<<"; "<<myFileInfo.isFile());
570 if (HDFascii::isASCII(myFileInfo.filePath().latin1())) {
571 char* aResultPath = HDFascii::ConvertFromASCIIToHDF(myFileInfo.filePath().latin1());
572 char* aHDFFileName = new char[strlen(aResultPath) + 19];
573 sprintf(aHDFFileName, "%shdf_from_ascii.hdf", aResultPath);
575 if (IsMultifile()) { // set this file as new - temporary
576 static QString aCommand;
577 aCommand.sprintf("mv %s %s%s",aHDFFileName, aResultPath, myFileInfo.baseName().latin1());
578 if(system(aCommand) == -1){
579 if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - Can't execute the command :"<<aCommand);
581 } else if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - "<<aCommand);
582 myFileInfo.setFile(QString(aResultPath)+QString(myFileInfo.baseName().latin1()));
583 } else { // change current temporary file to the new: with hdf-format
584 static QString aCommand;
585 aCommand.sprintf("mv %s %s\0",aHDFFileName, myFileInfo.filePath().latin1());
586 if(system(aCommand.latin1()) == -1) {
587 if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - Can't execute the command :"<<aCommand);
589 } else if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - "<<aCommand);
590 SALOMEDS::ListOfFileNames_var anEmptyList = new SALOMEDS::ListOfFileNames;
591 SALOMEDS_Tool::RemoveTemporaryFiles(aResultPath, anEmptyList.in(), true);
593 mySourceId = eRestoredFile;
595 delete(aHDFFileName);
596 } else if (!IsMultifile())
597 mySourceId = eRestoredFile;
600 if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - mySourceId = "<<mySourceId);
601 myInput = CreateConvertor(myFileInfo.filePath().latin1());
603 aComment.sprintf("myComment=%s;myType=%d;myFileName=%s;myInitFileName=%s",
604 GetComment(),VISU::TRESULT,myFileInfo.filePath().latin1(),
605 myInitFileName.c_str()); // Restoring of Python dump
606 SALOMEDS::GenericAttribute_var anAttr;
607 if(!theSObject->FindAttribute(anAttr, "AttributeComment"))
608 throw std::runtime_error("Build - There is no AttributeComment for the SObject !!!");
609 SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr);
610 aCmnt->SetValue(aComment.latin1());
612 QString aIsBuild = VISU::GetResourceMgr()->stringValue("Visu:BuildResult");
613 if(aIsBuild.isEmpty()? 0 : aIsBuild.toInt())
616 }catch(std::exception& exc){
617 INFOS("Follow exception was occured :\n"<<exc.what());
619 INFOS("Unknown exception was occured!!!");
624 VISU::Result_i::TInput* VISU::Result_i::GetInput() {
628 void VISU::Result_i::ToStream(std::ostringstream& theStr){
629 if(MYDEBUG) MESSAGE(GetComment());
630 Storable::DataToStream(theStr,"myName",myName.c_str());
631 Storable::DataToStream(theStr,"myInitFileName",myInitFileName.c_str());
632 Storable::DataToStream(theStr,"myCreationId",myCreationId);
636 VISU::Result_i::Restore(SALOMEDS::SObject_ptr theSObject,
637 const string& thePrefix,
638 const Storable::TRestoringMap& theMap)
640 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
642 ECreationId aCreationId = ECreationId(Storable::FindValue(theMap,"myCreationId").toInt());
643 ESourceId aSourceId = eRestoredFile;
644 if(aCreationId == eImportMed || aCreationId == eImportMedField)
645 aSourceId = eRestoredComponent;
647 VISU::Result_i* pResult = new VISU::Result_i(aStudy,aSourceId,aCreationId);
651 return pResult->Restore(theSObject,theMap,thePrefix);
654 string VISU::Result_i::GetRefFatherEntry() {
655 //return QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry();
659 string VISU::Result_i::GetEntry(){
660 CORBA::String_var anEntry = mySObject->GetID();
661 return string(anEntry);
664 const SALOMEDS::SObject_var& VISU::Result_i::GetSObject() const { return mySObject;}
665 const SALOMEDS::Study_var& VISU::Result_i::GetStudyDocument() const { return myStudyDocument;}
666 const SALOMEDS::SComponent_var& VISU::Result_i::GetSComponent() const { return mySComponent;}
667 std::string VISU::Result_i::GetEntry(const std::string& theComment)
669 return FindEntryWithComment(myStudyDocument,GetEntry().c_str(),theComment.c_str());
672 VISU::Result_i::~Result_i() {
673 MESSAGE("Result_i::~Result_i() - this = "<<this);
674 if(mySourceId == eRestoredFile){
675 static QString aCommand;
676 aCommand.sprintf("rm %s",myFileInfo.filePath().latin1());
677 MESSAGE("Result_i::~Result_i - system("<<aCommand<<") = "<<system(aCommand));
678 aCommand.sprintf("rmdir --ignore-fail-on-non-empty %s",myFileInfo.dirPath().latin1());
679 MESSAGE("Result_i::~Result_i - system("<<aCommand<<") = "<<system(aCommand));
681 if(myInput) delete myInput;