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){
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,
130 const ESourceId& theSourceId,
131 const ECreationId& theCreationId):
132 myStudyDocument(SALOMEDS::Study::_duplicate(theStudy)),
133 myCreationId(theCreationId),
134 mySourceId(theSourceId),
141 void VISU::Result_i::RemoveFromStudy(){
142 VISU::RemoveFromStudy(mySObject,false);
151 float aSize = myInput->GetSize();
152 bool aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
153 MESSAGE("Result_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<float(aResult));
155 }catch(std::exception& exc){
156 INFOS("Follow exception was occured :\n"<<exc.what());
158 INFOS("Unknown exception was occured!");
168 if(MYDEBUG) MESSAGE("Result_i::Build - myIsDone = "<<myIsDone);
169 if(myIsDone) return 1;
170 if(!IsPossible()) return 0;
172 const VISU::TMeshMap& aMeshMap = myInput->GetMeshMap();
173 VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
174 for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
175 const string& aMeshName = aMeshMapIter->first;
176 const VISU::PMesh aMesh = aMeshMapIter->second;
177 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
178 VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter;
180 aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
181 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
182 const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
183 const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
184 const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
185 VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
186 for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){
187 const string& aFieldName = aFieldMapIter->first;
188 const VISU::PField aField = aFieldMapIter->second;
189 const VISU::TValField& aValField = aField->myValField;
190 VISU::TValField::const_iterator aValFieldIter = aValField.begin();
191 for(; aValFieldIter != aValField.end(); aValFieldIter++){
192 int aTimeStamp = aValFieldIter->first;
194 myInput->GetTimeStampOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp);
195 }catch(std::exception& exc){
196 INFOS("Follow exception was occured :\n"<<exc.what());
198 INFOS("Unknown exception was occured!!!");
203 const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
204 VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin();
205 for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){
206 const string& aGroupName = aGroupMapIter->first;
208 myInput->GetMeshOnGroup(aMeshName,aGroupName);
209 }catch(std::exception& exc){
210 INFOS("Follow exception was occured :\n"<<exc.what());
212 INFOS("Unknown exception was occured!!!");
216 const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
217 VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
218 for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
219 const string& aFamilyName = aFamilyMapIter->first;
221 myInput->GetMeshOnEntity(aMeshName,anEntity,aFamilyName);
222 }catch(std::exception& exc){
223 INFOS("Follow exception was occured :\n"<<exc.what());
225 INFOS("Unknown exception was occured!!!");
228 //Import mesh on entity
230 myInput->GetMeshOnEntity(aMeshName,anEntity);
231 }catch(std::exception& exc){
232 INFOS("Follow exception was occured :\n"<<exc.what());
234 INFOS("Unknown exception was occured!!!");
239 }catch(std::exception& exc){
240 INFOS("Follow exception was occured :\n"<<exc.what());
242 INFOS("Unknown exception was occured!!!");
250 Build(SALOMEDS::SObject_ptr theSObject)
252 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
253 aStudyBuilder->NewCommand(); // There is a transaction
254 if(MYDEBUG) MESSAGE("Result_i::Build");
256 const TMeshMap& aMeshMap = myInput->GetMeshMap();
258 throw std::runtime_error("Build - There is no any mesh information in the file !!!");
259 mySComponent = FindOrCreateVisuComponent(myStudyDocument);
260 CORBA::String_var aSComponentEntry = mySComponent->GetID(), anIOR(GetID());
261 string aRefFatherEntry = GetRefFatherEntry();
263 aComment.sprintf("myComment=%s;myType=%d;myFileName=%s;myInitFileName=%s",
266 myFileInfo.filePath().latin1(),
267 myInitFileName.c_str()); // Restoring of Python dump
268 string aResultEntry =
269 CreateAttributes(myStudyDocument,
271 aRefFatherEntry.c_str(),
277 mySObject = myStudyDocument->FindObjectID(aResultEntry.c_str());
278 if(mySObject->_is_nil()) throw std::runtime_error("Build - There is no SObject for the Result !!!");
279 if(!CORBA::is_nil(theSObject)){
280 CORBA::String_var aString = theSObject->GetID();
281 CreateReference(myStudyDocument,aResultEntry,aString.in());
283 TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
284 for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
285 const string& aMeshName = aMeshMapIter->first;
286 const VISU::PMesh aMesh = aMeshMapIter->second;
287 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
288 VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter;
289 aComment.sprintf("myComment=MESH;myName=%s;myDim=%d",
290 aMeshName.c_str(),aMesh->myDim);
291 string aMeshEntry = CreateAttributes(myStudyDocument,aResultEntry.c_str(),aRefFatherEntry.c_str(),
292 "",aMeshName.c_str(),"",aComment.latin1(),true);
293 if(aMeshOnEntityMap.empty()) continue;
294 aComment.sprintf("myComment=FAMILIES;myMeshName=%s",aMeshName.c_str());
295 string aSubMeshesEntry = CreateAttributes(myStudyDocument,aMeshEntry.c_str(),aRefFatherEntry.c_str(),
296 "","Families","",aComment.latin1(),true);
297 //Import entities and according families
298 aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
299 typedef std::map<std::string,std::string> TComment2EntryMap;
300 TComment2EntryMap aComment2EntryMap;
301 typedef std::map<VISU::TEntity,std::string> TEntity2EntryMap;
302 TEntity2EntryMap aEntity2EntryMap;
303 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
304 const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
305 aComment.sprintf("myComment=ENTITY;myType=%d;myMeshName=%s;myId=%d",
311 case VISU::NODE_ENTITY : anEntityName = "onNodes"; break;
312 case VISU::EDGE_ENTITY : anEntityName = "onEdges"; break;
313 case VISU::FACE_ENTITY : anEntityName = "onFaces"; break;
314 case VISU::CELL_ENTITY : anEntityName = "onCells"; break;
316 throw std::runtime_error("Build >> Value of entity is incorrect!");
318 aEntity2EntryMap[anEntity] = CreateAttributes(myStudyDocument,aSubMeshesEntry.c_str(),aRefFatherEntry.c_str(),
319 "",anEntityName.c_str(),"",aComment.latin1(),true);
320 const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
321 const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
322 VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
323 for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
324 const string& aFamilyName = aFamilyMapIter->first;
325 aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s",
329 aFamilyName.c_str());
330 aComment2EntryMap[aComment.latin1()] =
331 CreateAttributes(myStudyDocument,
332 aEntity2EntryMap[anEntity].c_str(),
333 aRefFatherEntry.c_str(),
342 const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
343 if(aGroupMap.size() > 0){
344 aComment.sprintf("myComment=GROUPS;myMeshName=%s",
346 string aGroupsEntry =
347 CreateAttributes(myStudyDocument,
349 aRefFatherEntry.c_str(),
355 VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin();
356 for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){
357 const string& aGroupName = aGroupMapIter->first;
358 aComment.sprintf("myComment=GROUP;myType=%d;myMeshName=%s;myName=%s",
359 VISU::TGROUP,aMeshName.c_str(),aGroupName.c_str());
360 string aGroupEntry = CreateAttributes(myStudyDocument,aGroupsEntry.c_str(),aRefFatherEntry.c_str(),
361 "",aGroupName.c_str(),"",aComment.latin1(),true);
362 const VISU::PGroup aGroup = aGroupMapIter->second;
363 const VISU::TFamilyAndEntitySet& aFamilyAndEntitySet = aGroup->myFamilyAndEntitySet;
364 VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = aFamilyAndEntitySet.begin();
365 for(; aFamilyAndEntitySetIter != aFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){
366 const VISU::TFamilyAndEntity& aFamilyAndEntity = *aFamilyAndEntitySetIter;
367 const string& aFamilyName = aFamilyAndEntity.first;
368 const VISU::TEntity& anEntity = aFamilyAndEntity.second;
369 aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s",
373 aFamilyName.c_str());
374 CreateReference(myStudyDocument,aGroupEntry,aComment2EntryMap[aComment.latin1()]);
380 bool isFieldEntryCreated = 0;
381 aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
382 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
383 const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
384 const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
385 const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
386 VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
387 for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){
388 if(!isFieldEntryCreated){
389 aComment.sprintf("myComment=FIELDS;myMeshName=%s",
392 CreateAttributes(myStudyDocument,
394 aRefFatherEntry.c_str(),
400 isFieldEntryCreated = true;
402 const string& aFieldName = aFieldMapIter->first;
403 const VISU::PField aField = aFieldMapIter->second;
404 const VISU::TValField& aValField = aField->myValField;
405 QString aFieldNameWithUnit = ::GenerateFieldName(aFieldName,aField->myUnitNames[0]);
406 aComment.sprintf("myComment=FIELD;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s;myNbTimeStamps=%d;myNumComponent=%d",
407 VISU::TFIELD,aMeshName.c_str(),anEntity,aFieldName.c_str(),aValField.size(),aField->myNbComp);
408 string aFieldEntry = CreateAttributes(myStudyDocument,aFieldsEntry.c_str(),aRefFatherEntry.c_str(),
409 "",aFieldNameWithUnit.latin1(),"",aComment.latin1(),true);
410 CreateReference(myStudyDocument,aFieldEntry,aEntity2EntryMap[anEntity]);
411 VISU::TValField::const_iterator aValFieldIter = aValField.begin();
412 for(; aValFieldIter != aValField.end(); aValFieldIter++){
413 int aTimeStamp = aValFieldIter->first;
414 const VISU::PValForTime aValForTime = aValFieldIter->second;
415 aComment.sprintf("myComment=TIMESTAMP;myType=%d;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d",
416 VISU::TTIMESTAMP,aMeshName.c_str(),anEntity,aFieldName.c_str(),aTimeStamp,aField->myNbComp);
417 string aTimeStampId = VISU_Convertor::GenerateName(aValForTime->myTime);
418 CreateAttributes(myStudyDocument,aFieldEntry.c_str(),aRefFatherEntry.c_str(),
419 "",aTimeStampId.c_str(),"",aComment.latin1(),true);
424 QString aIsBuild = VISU::GetResourceMgr()->stringValue("Visu:BuildResult");
425 bool isBuildAll = aIsBuild.isEmpty()? 0 : aIsBuild.toInt();
426 if(isBuildAll) BuildAll();
427 }catch(std::exception& exc){
428 INFOS("Follow exception was occured :\n"<<exc.what());
431 INFOS("Unknown exception was occured!!!");
434 aStudyBuilder->CommitCommand();
441 Create(const char* theFileName)
444 myFileInfo.setFile(theFileName);
445 myInitFileName = myFileInfo.filePath().latin1();
446 myName = ::GenerateName(myFileInfo.fileName()).latin1();
447 if(mySourceId == eRestoredFile){
448 std::string aTmpDir(SALOMEDS_Tool::GetTmpDir());
449 static QString aCommand;
450 aCommand.sprintf("cp %s %s",myFileInfo.absFilePath().latin1(),aTmpDir.c_str());
451 if(system(aCommand) == -1){
452 MESSAGE("Create - Can't execute the command :"<<aCommand);
455 if(MYDEBUG) MESSAGE("Result_i::Create - aCommand = "<<aCommand);
456 myFileInfo.setFile(QString(aTmpDir.c_str()) + myFileInfo.fileName());
458 myInput = CreateConvertor(myFileInfo.absFilePath().latin1());
460 throw std::runtime_error("Create - Cannot create a Convertor for this file!!!"); return Build();
461 }catch(std::exception& exc){
462 INFOS("Follow exception was occured :\n"<<exc.what());
464 INFOS("Unknown exception was occured!!!");
472 Create(SALOMEDS::SObject_ptr theMedSObject)
474 if(MYDEBUG) MESSAGE("Result_i::Create MedObject from SALOMEDS::SObject_ptr");
476 myInput = CreateMEDConvertor(theMedSObject);
480 string aCompDataType = GetComponentDataType(theMedSObject);
481 myFileInfo.setFile(aCompDataType.c_str());
482 myInitFileName = aCompDataType;
484 myName = ::GenerateName("aResult").latin1();
486 VISU::Storable* aStorable = Build(theMedSObject);
488 }catch(std::exception& exc){
489 INFOS("Follow exception was occured :\n"<<exc.what());
491 INFOS("Unknown exception was occured!!!");
498 Create(SALOME_MED::FIELD_ptr theField)
500 if(MYDEBUG) MESSAGE("Result_i::Create MedObject from SALOME_MED::FIELD_ptr");
502 myInput = CreateMEDFieldConvertor(theField);
506 string aCompDataType = "MED";
507 myFileInfo.setFile(aCompDataType.c_str());
508 myInitFileName = aCompDataType;
510 myName = ::GenerateName("aResult").latin1();
512 CORBA::String_var anIOR = myStudyDocument->ConvertObjectToIOR(theField);
513 SALOMEDS::SObject_var aFieldSObject = myStudyDocument->FindObjectIOR(anIOR);
515 VISU::Storable* aStorable = Build(aFieldSObject);
517 }catch(std::exception& exc){
518 INFOS("Follow exception was occured :\n"<<exc.what());
520 INFOS("Unknown exception was occured!!!");
528 Restore(SALOMEDS::SObject_ptr theSObject,
529 const Storable::TRestoringMap& theMap,
530 const string& thePrefix)
532 if(MYDEBUG) MESSAGE("Result_i::Restore - "<<thePrefix);
534 mySObject = SALOMEDS::SObject::_duplicate(theSObject);
535 myStudyDocument = mySObject->GetStudy();
536 mySComponent = mySObject->GetFatherComponent();
537 myName = VISU::Storable::FindValue(theMap,"myName").latin1();
538 myInitFileName = VISU::Storable::FindValue(theMap,"myInitFileName").latin1();
539 SALOMEDS::SObject_var aRefSObj, aTargetRefSObj;
540 if(mySObject->FindSubObject(1,aRefSObj) && aRefSObj->ReferencedObject(aTargetRefSObj)){
541 if(MYDEBUG) MESSAGE("Result_i::GetInput - There is some reference.");
542 SALOMEDS::SComponent_var aCompRefSObj = aTargetRefSObj->GetFatherComponent();
543 CORBA::String_var aDataType = aCompRefSObj->ComponentDataType();
544 myFileInfo.setFile(aDataType.in());
545 if(MYDEBUG) MESSAGE("Result_i::GetInput - aDataType = "<<aDataType);
546 Engines::Component_var aEngComp = Base_i::myEnginesLifeCycle->FindOrLoad_Component("FactoryServer", aDataType.in());
547 if (CORBA::is_nil(aEngComp))
548 throw std::runtime_error("Restore - There is no aEngComp for the aDataType !!!");
549 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
550 SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(aEngComp);
551 aStudyBuilder->LoadWith(aCompRefSObj,aDriver);
552 if(strcmp(aDataType,"MED") == 0)
553 myInput = CreateMEDConvertor(aTargetRefSObj);
555 throw std::runtime_error("GetInput - There is no convertor for the aDataType !!!");
557 myFileInfo.setFile(thePrefix.c_str());
559 string aStudyPrefix("");
560 if (IsMultifile()) aStudyPrefix = (SALOMEDS_Tool::GetNameFromPath(myStudyDocument->URL()));
561 if(!myFileInfo.isFile()){
562 string aFileName = thePrefix + aStudyPrefix + "_" + myName;
563 myFileInfo.setFile(aFileName.c_str());
566 MESSAGE("Result_i::Restore - aFileName = "<<myFileInfo.filePath()<<"; "<<myFileInfo.isFile());
568 if (HDFascii::isASCII(myFileInfo.filePath().latin1())) {
569 char* aResultPath = HDFascii::ConvertFromASCIIToHDF(myFileInfo.filePath().latin1());
570 char* aHDFFileName = new char[strlen(aResultPath) + 19];
571 sprintf(aHDFFileName, "%shdf_from_ascii.hdf", aResultPath);
573 if (IsMultifile()) { // set this file as new - temporary
574 static QString aCommand;
575 aCommand.sprintf("mv %s %s%s",aHDFFileName, aResultPath, myFileInfo.baseName().latin1());
576 if(system(aCommand) == -1){
577 if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - Can't execute the command :"<<aCommand);
579 } else if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - "<<aCommand);
580 myFileInfo.setFile(QString(aResultPath)+QString(myFileInfo.baseName().latin1()));
581 } else { // change current temporary file to the new: with hdf-format
582 static QString aCommand;
583 aCommand.sprintf("mv %s %s\0",aHDFFileName, myFileInfo.filePath().latin1());
584 if(system(aCommand.latin1()) == -1) {
585 if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - Can't execute the command :"<<aCommand);
587 } else if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - "<<aCommand);
588 SALOMEDS::ListOfFileNames_var anEmptyList = new SALOMEDS::ListOfFileNames;
589 SALOMEDS_Tool::RemoveTemporaryFiles(aResultPath, anEmptyList.in(), true);
591 mySourceId = eRestoredFile;
593 delete(aHDFFileName);
594 } else if (!IsMultifile())
595 mySourceId = eRestoredFile;
598 if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - mySourceId = "<<mySourceId);
599 myInput = CreateConvertor(myFileInfo.filePath().latin1());
601 aComment.sprintf("myComment=%s;myType=%d;myFileName=%s;myInitFileName=%s",
602 GetComment(),VISU::TRESULT,myFileInfo.filePath().latin1(),
603 myInitFileName.c_str()); // Restoring of Python dump
604 SALOMEDS::GenericAttribute_var anAttr;
605 if(!theSObject->FindAttribute(anAttr, "AttributeComment"))
606 throw std::runtime_error("Build - There is no AttributeComment for the SObject !!!");
607 SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr);
608 aCmnt->SetValue(aComment.latin1());
610 QString aIsBuild = VISU::GetResourceMgr()->stringValue("Visu:BuildResult");
611 if(aIsBuild.isEmpty()? 0 : aIsBuild.toInt())
614 }catch(std::exception& exc){
615 INFOS("Follow exception was occured :\n"<<exc.what());
617 INFOS("Unknown exception was occured!!!");
622 VISU::Result_i::TInput* VISU::Result_i::GetInput() {
626 void VISU::Result_i::ToStream(std::ostringstream& theStr){
627 if(MYDEBUG) MESSAGE(GetComment());
628 Storable::DataToStream(theStr,"myName",myName.c_str());
629 Storable::DataToStream(theStr,"myInitFileName",myInitFileName.c_str());
630 Storable::DataToStream(theStr,"myCreationId",myCreationId);
634 VISU::Result_i::Restore(SALOMEDS::SObject_ptr theSObject,
635 const string& thePrefix,
636 const Storable::TRestoringMap& theMap)
638 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
640 ECreationId aCreationId = ECreationId(Storable::FindValue(theMap,"myCreationId").toInt());
641 ESourceId aSourceId = eRestoredFile;
642 if(aCreationId == eImportMed || aCreationId == eImportMedField)
643 aSourceId = eRestoredComponent;
645 VISU::Result_i* pResult = new VISU::Result_i(aStudy,aSourceId,aCreationId);
649 return pResult->Restore(theSObject,theMap,thePrefix);
652 string VISU::Result_i::GetRefFatherEntry() {
653 //return QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry();
657 string VISU::Result_i::GetEntry(){
658 CORBA::String_var anEntry = mySObject->GetID();
659 return string(anEntry);
662 const SALOMEDS::SObject_var& VISU::Result_i::GetSObject() const { return mySObject;}
663 const SALOMEDS::Study_var& VISU::Result_i::GetStudyDocument() const { return myStudyDocument;}
664 const SALOMEDS::SComponent_var& VISU::Result_i::GetSComponent() const { return mySComponent;}
665 std::string VISU::Result_i::GetEntry(const std::string& theComment)
667 return FindEntryWithComment(myStudyDocument,GetEntry().c_str(),theComment.c_str());
670 VISU::Result_i::~Result_i() {
671 MESSAGE("Result_i::~Result_i() - this = "<<this);
672 if(mySourceId == eRestoredFile){
673 static QString aCommand;
674 aCommand.sprintf("rm %s",myFileInfo.filePath().latin1());
675 MESSAGE("Result_i::~Result_i - system("<<aCommand<<") = "<<system(aCommand));
676 aCommand.sprintf("rmdir --ignore-fail-on-non-empty %s",myFileInfo.dirPath().latin1());
677 MESSAGE("Result_i::~Result_i - system("<<aCommand<<") = "<<system(aCommand));
679 if(myInput) delete myInput;