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"
29 #include "VISU_Convertor_impl.hxx"
30 #include "VISU_CorbaMedConvertor.hxx"
31 #include "VISU_PipeLine.hxx"
33 #include "SUIT_ResourceMgr.h"
35 #include "SALOMEDS_Tool.hxx"
36 #include "HDFascii.hxx"
40 #include <qfileinfo.h>
44 #include <vtkUnstructuredGrid.h>
47 #include <Bnd_Box.hxx>
53 static int MYDEBUG = 0;
55 static int MYDEBUG = 0;
58 VISU::Result_var VISU::FindResult (SALOMEDS::SObject_ptr theSObject)
60 SALOMEDS::SComponent_var aSComponent = theSObject->GetFatherComponent();
61 SALOMEDS::SObject_var aFather = theSObject->GetFather();
62 CORBA::String_var aComponentID (aSComponent->GetID());
63 CORBA::String_var aFatherID (aFather->GetID());
64 VISU::Result_var aResult;
65 while (strcmp(aComponentID, aFatherID) != 0) {
66 CORBA::Object_var anObject = VISU::SObjectToObject(aFather);
67 if (!CORBA::is_nil(anObject)) {
68 aResult = VISU::Result::_narrow(anObject);
69 if (!aResult->_is_nil()) return aResult;
71 aFather = aFather->GetFather();
72 aFatherID = aFather->GetID();
77 QString GenerateName (const char* theName)
79 typedef map<string,int> TNameMap;
81 TNameMap::const_iterator i = aMap.find(theName);
83 if (i == aMap.end()) {
87 tmp = VISU::GenerateName(theName,++aMap[theName]);
89 if(MYDEBUG) MESSAGE("GenerateName - "<<tmp<<" from - "<<theName<<"; " <<aMap[theName]);
93 QString GenerateFieldName (const string& theName, const string& theUnits)
96 const string tmp (theUnits.size(),' ');
97 if (theUnits == "" || theUnits == tmp)
98 aName.sprintf("%s, -",theName.c_str());
100 aName.sprintf("%s, %s",theName.c_str(),theUnits.c_str());
101 aName = aName.simplifyWhiteSpace();
102 return aName.latin1();
105 void CreateReference (SALOMEDS::Study_ptr theStudyDocument,
106 const string& theFatherEntry, const string& theRefEntry)
108 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
109 SALOMEDS::SObject_var aFather = theStudyDocument->FindObjectID(theFatherEntry.c_str());
110 SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(aFather);
111 SALOMEDS::SObject_var aRefSObj = theStudyDocument->FindObjectID(theRefEntry.c_str());
112 aStudyBuilder->Addreference(newObj,aRefSObj);
115 string GetComponentDataType (SALOMEDS::SObject_ptr theSObject)
117 SALOMEDS::SComponent_var aCompRefSObj = theSObject->GetFatherComponent();
118 CORBA::String_var aDataType = aCompRefSObj->ComponentDataType();
119 return aDataType.in();
122 //==============================================================================
124 const string VISU::Result_i::myComment = "RESULT";
125 const char* VISU::Result_i::GetComment() const { return myComment.c_str();}
127 VISU::Result_i::Result_i (SALOMEDS::Study_ptr theStudy,
128 const ESourceId& theSourceId,
129 const ECreationId& theCreationId):
130 myStudyDocument(SALOMEDS::Study::_duplicate(theStudy)),
131 myCreationId(theCreationId),
132 mySourceId(theSourceId),
139 void VISU::Result_i::RemoveFromStudy()
141 // Remove the result with all presentations and other possible sub-objects
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 if(MYDEBUG) MESSAGE("Result_i::Build");
254 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
255 aStudyBuilder->NewCommand(); // There is a transaction
258 const TMeshMap& aMeshMap = myInput->GetMeshMap();
259 if (aMeshMap.empty())
260 throw std::runtime_error("Build - There is no any mesh information in the file !!!");
262 mySComponent = FindOrCreateVisuComponent(myStudyDocument);
263 CORBA::String_var aSComponentEntry = mySComponent->GetID(), anIOR(GetID());
264 string aRefFatherEntry = GetRefFatherEntry();
267 aComment.sprintf("myComment=%s;myType=%d;myFileName=%s;myInitFileName=%s",
268 GetComment(), VISU::TRESULT, myFileInfo.filePath().latin1(),
269 myInitFileName.c_str()); // Restoring of Python dump
270 string aResultEntry =
271 CreateAttributes(myStudyDocument, aSComponentEntry, aRefFatherEntry.c_str(),
272 anIOR, myName.c_str(), "", aComment.latin1(), true);
274 mySObject = myStudyDocument->FindObjectID(aResultEntry.c_str());
275 if (mySObject->_is_nil())
276 throw std::runtime_error("Build - There is no SObject for the Result !!!");
278 if (!CORBA::is_nil(theSObject)) {
279 CORBA::String_var aString = theSObject->GetID();
280 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 aComment.sprintf("myComment=MESH;myName=%s;myDim=%d",
288 aMeshName.c_str(), aMesh->myDim);
290 CreateAttributes(myStudyDocument, aResultEntry.c_str(), aRefFatherEntry.c_str(),
291 "", aMeshName.c_str(), "", aComment.latin1(), true);
293 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
294 if (aMeshOnEntityMap.empty()) continue;
296 aComment.sprintf("myComment=FAMILIES;myMeshName=%s", aMeshName.c_str());
297 string aSubMeshesEntry =
298 CreateAttributes(myStudyDocument, aMeshEntry.c_str(), aRefFatherEntry.c_str(),
299 "", "Families", "", aComment.latin1(), true);
301 //Import entities and according families
302 typedef std::map<std::string,std::string> TComment2EntryMap;
303 typedef std::map<VISU::TEntity,std::string> TEntity2EntryMap;
304 TComment2EntryMap aComment2EntryMap;
305 TEntity2EntryMap aEntity2EntryMap;
307 VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
308 for (; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++) {
309 const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
310 aComment.sprintf("myComment=ENTITY;myType=%d;myMeshName=%s;myId=%d",
311 VISU::TENTITY, aMeshName.c_str(), anEntity);
314 case VISU::NODE_ENTITY : anEntityName = "onNodes"; break;
315 case VISU::EDGE_ENTITY : anEntityName = "onEdges"; break;
316 case VISU::FACE_ENTITY : anEntityName = "onFaces"; break;
317 case VISU::CELL_ENTITY : anEntityName = "onCells"; break;
319 throw std::runtime_error("Build >> Value of entity is incorrect!");
321 aEntity2EntryMap[anEntity] = CreateAttributes
322 (myStudyDocument, aSubMeshesEntry.c_str(), aRefFatherEntry.c_str(),
323 "", anEntityName.c_str(), "", aComment.latin1(), true);
325 const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
326 const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
327 VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
328 for (; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++) {
329 const string& aFamilyName = aFamilyMapIter->first;
330 aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s",
331 VISU::TFAMILY, aMeshName.c_str(), anEntity, aFamilyName.c_str());
332 aComment2EntryMap[aComment.latin1()] =
333 CreateAttributes(myStudyDocument, aEntity2EntryMap[anEntity].c_str(), aRefFatherEntry.c_str(),
334 "", aFamilyName.c_str(), "", aComment.latin1(), true);
339 const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
340 if (aGroupMap.size() > 0) {
341 aComment.sprintf("myComment=GROUPS;myMeshName=%s", aMeshName.c_str());
342 string aGroupsEntry =
343 CreateAttributes(myStudyDocument, aMeshEntry.c_str(), aRefFatherEntry.c_str(),
344 "", "Groups", "", aComment.latin1(), true);
346 VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin();
347 for (; aGroupMapIter != aGroupMap.end(); aGroupMapIter++) {
348 const string& aGroupName = aGroupMapIter->first;
349 aComment.sprintf("myComment=GROUP;myType=%d;myMeshName=%s;myName=%s",
350 VISU::TGROUP, aMeshName.c_str(), aGroupName.c_str());
352 CreateAttributes(myStudyDocument, aGroupsEntry.c_str(), aRefFatherEntry.c_str(),
353 "", aGroupName.c_str(), "", aComment.latin1(), true);
355 const VISU::PGroup aGroup = aGroupMapIter->second;
356 const VISU::TFamilyAndEntitySet& aFamilyAndEntitySet = aGroup->myFamilyAndEntitySet;
357 VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = aFamilyAndEntitySet.begin();
358 for (; aFamilyAndEntitySetIter != aFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++) {
359 const VISU::TFamilyAndEntity& aFamilyAndEntity = *aFamilyAndEntitySetIter;
360 const string& aFamilyName = aFamilyAndEntity.first;
361 const VISU::TEntity& anEntity = aFamilyAndEntity.second;
362 aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s",
363 VISU::TFAMILY, aMeshName.c_str(), anEntity, aFamilyName.c_str());
364 if (aComment2EntryMap.count(aComment.latin1()) > 0)
365 CreateReference(myStudyDocument, aGroupEntry, aComment2EntryMap[aComment.latin1()]);
372 bool isFieldEntryCreated = 0;
373 aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
374 for (; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++) {
375 const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
376 const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
377 const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
378 VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
379 for (; aFieldMapIter != aFieldMap.end(); aFieldMapIter++) {
380 if (!isFieldEntryCreated) {
381 aComment.sprintf("myComment=FIELDS;myMeshName=%s", aMeshName.c_str());
383 CreateAttributes(myStudyDocument, aMeshEntry.c_str(), aRefFatherEntry.c_str(),
384 "", "Fields", "", aComment.latin1(), true);
385 isFieldEntryCreated = true;
387 const string& aFieldName = aFieldMapIter->first;
388 const VISU::PField aField = aFieldMapIter->second;
389 const VISU::TValField& aValField = aField->myValField;
390 QString aFieldNameWithUnit = ::GenerateFieldName(aFieldName,aField->myUnitNames[0]);
391 aComment.sprintf("myComment=FIELD;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s;"
392 "myNbTimeStamps=%d;myNumComponent=%d",
393 VISU::TFIELD, aMeshName.c_str(), anEntity, aFieldName.c_str(),
394 aValField.size(), aField->myNbComp);
396 CreateAttributes(myStudyDocument, aFieldsEntry.c_str(), aRefFatherEntry.c_str(),
397 "", aFieldNameWithUnit.latin1(), "", aComment.latin1(), true);
398 CreateReference(myStudyDocument, aFieldEntry, aEntity2EntryMap[anEntity]);
400 VISU::TValField::const_iterator aValFieldIter = aValField.begin();
401 for (; aValFieldIter != aValField.end(); aValFieldIter++) {
402 int aTimeStamp = aValFieldIter->first;
403 const VISU::PValForTime aValForTime = aValFieldIter->second;
404 aComment.sprintf("myComment=TIMESTAMP;myType=%d;myMeshName=%s;myEntityId=%d;"
405 "myFieldName=%s;myTimeStampId=%d;myNumComponent=%d",
406 VISU::TTIMESTAMP, aMeshName.c_str(), anEntity,
407 aFieldName.c_str(), aTimeStamp, aField->myNbComp);
408 string aTimeStampId = VISU_Convertor::GenerateName(aValForTime->myTime);
409 CreateAttributes(myStudyDocument, aFieldEntry.c_str(), aRefFatherEntry.c_str(),
410 "", aTimeStampId.c_str(), "", aComment.latin1(), true);
415 bool isBuildAll = VISU::GetResourceMgr()->booleanValue("VISU", "full_med_loading", false);
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();
431 Create(const char* theFileName)
434 myFileInfo.setFile(theFileName);
435 myInitFileName = myFileInfo.filePath().latin1();
436 myName = ::GenerateName(myFileInfo.fileName()).latin1();
437 if(mySourceId == eRestoredFile){
438 std::string aTmpDir(SALOMEDS_Tool::GetTmpDir());
439 static QString aCommand;
440 aCommand.sprintf("cp %s %s",myFileInfo.absFilePath().latin1(),aTmpDir.c_str());
441 if(system(aCommand) == -1){
442 MESSAGE("Create - Can't execute the command :"<<aCommand);
445 if(MYDEBUG) MESSAGE("Result_i::Create - aCommand = "<<aCommand);
446 myFileInfo.setFile(QString(aTmpDir.c_str()) + myFileInfo.fileName());
448 myInput = CreateConvertor(myFileInfo.absFilePath().latin1());
450 throw std::runtime_error("Create - Cannot create a Convertor for this file!!!");
452 }catch(std::exception& exc){
453 INFOS("Follow exception was occured :\n"<<exc.what());
455 INFOS("Unknown exception was occured!!!");
463 Create(SALOMEDS::SObject_ptr theMedSObject)
465 if(MYDEBUG) MESSAGE("Result_i::Create MedObject from SALOMEDS::SObject_ptr");
467 myInput = CreateMEDConvertor(theMedSObject);
471 string aCompDataType = GetComponentDataType(theMedSObject);
472 myFileInfo.setFile(aCompDataType.c_str());
473 myInitFileName = aCompDataType;
475 myName = ::GenerateName("aResult").latin1();
477 VISU::Storable* aStorable = Build(theMedSObject);
479 }catch(std::exception& exc){
480 INFOS("Follow exception was occured :\n"<<exc.what());
482 INFOS("Unknown exception was occured!!!");
489 Create(SALOME_MED::FIELD_ptr theField)
491 if(MYDEBUG) MESSAGE("Result_i::Create MedObject from SALOME_MED::FIELD_ptr");
493 myInput = CreateMEDFieldConvertor(theField);
497 string aCompDataType = "MED";
498 myFileInfo.setFile(aCompDataType.c_str());
499 myInitFileName = aCompDataType;
501 myName = ::GenerateName("aResult").latin1();
503 CORBA::String_var anIOR = myStudyDocument->ConvertObjectToIOR(theField);
504 SALOMEDS::SObject_var aFieldSObject = myStudyDocument->FindObjectIOR(anIOR);
506 VISU::Storable* aStorable = Build(aFieldSObject);
508 }catch(std::exception& exc){
509 INFOS("Follow exception was occured :\n"<<exc.what());
511 INFOS("Unknown exception was occured!!!");
519 Restore(SALOMEDS::SObject_ptr theSObject,
520 const Storable::TRestoringMap& theMap,
521 const string& thePrefix)
523 if(MYDEBUG) MESSAGE("Result_i::Restore - " << thePrefix);
525 mySObject = SALOMEDS::SObject::_duplicate(theSObject);
526 myStudyDocument = mySObject->GetStudy();
527 mySComponent = mySObject->GetFatherComponent();
528 myName = VISU::Storable::FindValue(theMap, "myName").latin1();
529 myInitFileName = VISU::Storable::FindValue(theMap, "myInitFileName").latin1();
531 SALOMEDS::SObject_var aRefSObj, aTargetRefSObj;
532 if (mySObject->FindSubObject(1, aRefSObj) &&
533 aRefSObj->ReferencedObject(aTargetRefSObj)) {
534 if(MYDEBUG) MESSAGE("Result_i::GetInput - There is some reference.");
535 SALOMEDS::SComponent_var aCompRefSObj = aTargetRefSObj->GetFatherComponent();
536 CORBA::String_var aDataType = aCompRefSObj->ComponentDataType();
537 myFileInfo.setFile(aDataType.in());
538 if(MYDEBUG) MESSAGE("Result_i::GetInput - aDataType = " << aDataType);
539 Engines::Component_var aEngComp =
540 Base_i::myEnginesLifeCycle->FindOrLoad_Component("FactoryServer", aDataType.in());
541 if (CORBA::is_nil(aEngComp))
542 throw std::runtime_error("Restore - There is no aEngComp for the aDataType !!!");
543 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
544 SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(aEngComp);
545 aStudyBuilder->LoadWith(aCompRefSObj, aDriver);
546 if (strcmp(aDataType, "MED") == 0)
547 myInput = CreateMEDConvertor(aTargetRefSObj);
549 throw std::runtime_error("GetInput - There is no convertor for the aDataType !!!");
551 myFileInfo.setFile(thePrefix.c_str());
553 string aStudyPrefix ("");
555 aStudyPrefix = SALOMEDS_Tool::GetNameFromPath(myStudyDocument->URL());
556 if (!myFileInfo.isFile()) {
557 string aFileName = thePrefix + aStudyPrefix + "_" + myName;
558 myFileInfo.setFile(aFileName.c_str());
561 MESSAGE("Result_i::Restore - aFileName = " << myFileInfo.filePath() << "; " << myFileInfo.isFile());
563 const char* aPathLatin = myFileInfo.filePath().latin1();
564 if (HDFascii::isASCII(aPathLatin)) {
565 MESSAGE("ConvertFromASCIIToHDF(" << aPathLatin << ")");
566 char* aResultPath = HDFascii::ConvertFromASCIIToHDF(aPathLatin);
567 MESSAGE("ConvertFromASCIIToHDF() DONE : " << aResultPath);
568 char* aHDFFileName = new char[strlen(aResultPath) + 19];
569 sprintf(aHDFFileName, "%shdf_from_ascii.hdf", aResultPath);
571 if (IsMultifile()) { // set this file as new - temporary
572 static QString aCommand;
573 aCommand.sprintf("mv %s %s%s",aHDFFileName, aResultPath, myFileInfo.baseName().latin1());
574 if (system(aCommand) == -1) {
575 if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - Can't execute the command :" << aCommand);
578 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);
588 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;
601 if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - mySourceId = " << mySourceId);
602 myInput = CreateConvertor(myFileInfo.filePath().latin1());
604 aComment.sprintf("myComment=%s;myType=%d;myFileName=%s;myInitFileName=%s",
605 GetComment(), VISU::TRESULT, myFileInfo.filePath().latin1(),
606 myInitFileName.c_str()); // Restoring of Python dump
607 SALOMEDS::GenericAttribute_var anAttr;
608 if (!theSObject->FindAttribute(anAttr, "AttributeComment"))
609 throw std::runtime_error("Build - There is no AttributeComment for the SObject !!!");
610 SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr);
611 aCmnt->SetValue(aComment.latin1());
613 bool isBuildAll = VISU::GetResourceMgr()->booleanValue("VISU", "full_med_loading", false);
617 } catch(std::exception& exc) {
618 INFOS("Follow exception was occured :\n"<<exc.what());
620 INFOS("Unknown exception was occured!!!");
625 VISU::Result_i::TInput* VISU::Result_i::GetInput() {
629 void VISU::Result_i::ToStream(std::ostringstream& theStr){
630 if(MYDEBUG) MESSAGE(GetComment());
631 Storable::DataToStream(theStr,"myName",myName.c_str());
632 Storable::DataToStream(theStr,"myInitFileName",myInitFileName.c_str());
633 Storable::DataToStream(theStr,"myCreationId",myCreationId);
637 VISU::Result_i::Restore(SALOMEDS::SObject_ptr theSObject,
638 const string& thePrefix,
639 const Storable::TRestoringMap& theMap)
641 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
643 ECreationId aCreationId = ECreationId(Storable::FindValue(theMap,"myCreationId").toInt());
644 ESourceId aSourceId = eRestoredFile;
645 if(aCreationId == eImportMed || aCreationId == eImportMedField)
646 aSourceId = eRestoredComponent;
648 VISU::Result_i* pResult = new VISU::Result_i(aStudy,aSourceId,aCreationId);
652 return pResult->Restore(theSObject,theMap,thePrefix);
655 string VISU::Result_i::GetRefFatherEntry() {
656 //return QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry();
660 string VISU::Result_i::GetEntry(){
661 CORBA::String_var anEntry = mySObject->GetID();
662 return string(anEntry);
665 const SALOMEDS::SObject_var& VISU::Result_i::GetSObject() const { return mySObject;}
666 const SALOMEDS::Study_var& VISU::Result_i::GetStudyDocument() const { return myStudyDocument;}
667 const SALOMEDS::SComponent_var& VISU::Result_i::GetSComponent() const { return mySComponent;}
668 std::string VISU::Result_i::GetEntry(const std::string& theComment)
670 return FindEntryWithComment(myStudyDocument,GetEntry().c_str(),theComment.c_str());
673 VISU::Result_i::~Result_i()
675 MESSAGE("Result_i::~Result_i() - this = "<<this);
676 if (mySourceId == eRestoredFile) {
677 static QString aCommand;
678 aCommand.sprintf("rm %s",myFileInfo.filePath().latin1());
679 MESSAGE("Result_i::~Result_i - system("<<aCommand<<") = "<<system(aCommand));
680 aCommand.sprintf("rmdir --ignore-fail-on-non-empty %s",myFileInfo.dirPath().latin1());
681 MESSAGE("Result_i::~Result_i - system("<<aCommand<<") = "<<system(aCommand));
683 if(myInput) delete myInput;
686 //=======================================================================
687 //function : GetAxisInfo
689 //=======================================================================
690 const vector< float >* Result_i::GetAxisInfo(const string& theMeshName,
692 gp_Dir& thePlaneNormal)
694 const vector< float >* components = NULL;
696 if ( theAxis < AXIS_X || theAxis > AXIS_Z ) {
697 MESSAGE(" Bad axis index " << theAxis );
701 map< string, TGridInfo >::iterator name_info;
702 name_info = myMeshName2GridInfoMap.find( theMeshName );
703 TGridInfo * gInfo = 0;
705 if ( name_info != myMeshName2GridInfoMap.end() )
707 gInfo = & name_info->second;
709 else if ( myInput && IsPossible() && theAxis >= AXIS_X && theAxis <= AXIS_Z )
711 // check presence of theMeshName
712 const VISU::TMeshMap& meshMap = myInput->GetMeshMap();
713 if ( meshMap.find( theMeshName ) == meshMap.end() ) {
714 MESSAGE("No mesh named " << theMeshName );
717 VISU_Convertor::TOutput* vtkMesh = myInput->GetMeshOnEntity (theMeshName,
719 if ( !vtkMesh || vtkMesh->GetNumberOfCells() == 0 ) {
720 MESSAGE( "No cells in the mesh: " << theMeshName );
724 // define axis directions and min cell size in each direction
725 const int nbAxes = 3;
727 gp_Vec axDirs[ nbAxes ];
728 float minSize[3] = { FLT_MAX, FLT_MAX, FLT_MAX };
729 bool axesComputed = false;
730 for ( vtkIdType iCell = 0; iCell < vtkMesh->GetNumberOfCells(); ++iCell )
732 vtkCell* cell = vtkMesh->GetCell( iCell );
733 int nbPnt = cell->GetNumberOfPoints();
736 vtkPoints * points = cell->GetPoints();
738 coords[0] = points->GetPoint( 0 );
739 coords[1] = points->GetPoint( 1 );
740 coords[2] = points->GetPoint( 3 );
741 coords[3] = points->GetPoint( 4 );
742 gp_Pnt p0( coords[0][0], coords[0][1], coords[0][2] );
743 for ( iAx = 0; iAx < nbAxes; ++iAx )
745 float* coo = coords[ iAx + 1 ];
746 gp_Pnt p( coo[0], coo[1], coo[2] );
748 float size = p0.SquareDistance( p );
749 if ( size > FLT_MIN && size < minSize[ iAx ] )
750 minSize[ iAx ] = size;
752 if ( !axesComputed ) {
754 if ( dir.SquareMagnitude() <= DBL_MIN )
762 if ( !axesComputed ) {
763 MESSAGE("No good hexahedrons in the mesh: " << theMeshName );
768 gInfo = & myMeshName2GridInfoMap[ theMeshName ];
769 for ( iAx = 0; iAx < nbAxes; ++iAx )
771 int iPrev = ( iAx == 0 ) ? 2 : iAx - 1;
772 int iNext = ( iAx == 2 ) ? 0 : iAx + 1;
773 gInfo->myAxis[ iAx ] = axDirs[ iPrev ] ^ axDirs[ iNext ];
776 // get and sort intermediate component values - projections of nodes
777 // on axis direction; define bnd box
778 set< float > comps[ 3 ];
780 vtkPoints * points = vtkMesh->GetPoints();
781 vtkIdType iP, nbP = vtkMesh->GetNumberOfPoints();
782 for ( iP = 0; iP < nbP; ++iP )
784 float* coo = points->GetPoint( iP );
785 gp_Pnt p( coo[0], coo[1], coo[2] );
787 for ( iAx = 0; iAx < nbAxes; ++iAx ) {
788 const gp_Dir& dir = gInfo->myAxis[ iAx ];
789 float dot = dir.XYZ() * p.XYZ();
790 comps[ iAx ].insert( dot );
794 // find a range of projections of bnd box corners on each axis
795 float range[3], firstValue[3];
796 double x[2],y[2],z[2];
797 box.Get(x[0],y[0],z[0],x[1],y[1],z[1]);
798 for ( iAx = 0; iAx < nbAxes; ++iAx ) {
799 set< float > bndComps;
800 const gp_Dir& dir = gInfo->myAxis[ iAx ];
801 for ( int iX = 0; iX < 2; ++iX ) {
802 for ( int iY = 0; iY < 2; ++iY ) {
803 for ( int iZ = 0; iZ < 2; ++iZ ) {
804 gp_Pnt p( x[ iX ], y[ iY ], z[ iZ ] );
805 float dot = dir.XYZ() * p.XYZ();
806 bndComps.insert( dot );
810 firstValue[ iAx ] = *bndComps.begin();
811 range[ iAx ] = *bndComps.rbegin() - *bndComps.begin();
814 // compute component values
815 for ( iAx = 0; iAx < nbAxes; ++iAx )
817 list< float > values;
819 set< float >& comp = comps[ iAx ];
820 set< float >::iterator val = comp.begin();
821 float bnd = -1., rng = range[ iAx ], first = firstValue[ iAx ];
822 float tol = 0.1 * sqrt( minSize[ iAx ]) / rng;
823 for ( ; val != comp.end(); ++val ) {
824 float value = ( *val - first ) / rng;
826 values.push_back( value );
831 // store values in gInfo
832 vector< float >& myComp = gInfo->myComponets[ iAx ];
833 myComp.resize( nbVals );
834 list< float >::iterator v = values.begin();
835 for ( int i = 0; v != values.end(); ++v )
843 thePlaneNormal = gInfo->myAxis[ theAxis ];
844 components = & gInfo->myComponets[ theAxis ];