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_Prs3d_i.hh"
30 #include "VISU_ViewManager_i.hh"
32 #include "VISU_Convertor_impl.hxx"
33 #include "VISU_CorbaMedConvertor.hxx"
34 #include "VISU_PipeLine.hxx"
35 #include "VISU_Actor.h"
37 //#include "SVTK_ViewWindow.h"
39 //#include "QAD_Desktop.h"
40 //#include "QAD_Application.h"
41 //#include "QAD_Study.h"
42 //#include "QAD_StudyFrame.h"
43 //#include "QAD_RightFrame.h"
45 #include "SUIT_ResourceMgr.h"
46 #include "SALOMEDS_Tool.hxx"
47 #include "HDFascii.hxx"
50 #include <qfileinfo.h>
56 #include <vtkUnstructuredGridReader.h>
57 #include <vtkUnstructuredGridWriter.h>
62 #include <Bnd_Box.hxx>
68 static int MYDEBUG = 0;
70 static int MYDEBUG = 0;
73 VISU::Result_var VISU::FindResult(SALOMEDS::SObject_ptr theSObject){
74 SALOMEDS::SComponent_var aSComponent = theSObject->GetFatherComponent();
75 SALOMEDS::SObject_var aFather = theSObject->GetFather();
76 CORBA::String_var aComponentID(aSComponent->GetID());
77 CORBA::String_var aFatherID(aFather->GetID());
78 VISU::Result_var aResult;
79 while(strcmp(aComponentID,aFatherID) != 0){
80 CORBA::Object_var anObject = VISU::SObjectToObject(aFather);
81 if(!CORBA::is_nil(anObject)){
82 aResult = VISU::Result::_narrow(anObject);
83 if(!aResult->_is_nil()) return aResult;
85 aFather = aFather->GetFather();
90 void VISU::RemoveFromStudy (SALOMEDS::SObject_ptr theSObject,
92 bool theDestroySubObjects)
94 if (theSObject->_is_nil()) return;
96 SALOMEDS::Study_var aStudyDocument = theSObject->GetStudy();
97 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudyDocument->NewBuilder();
99 aStudyBuilder->RemoveAttribute(theSObject,"AttributeIOR");
103 // Remove possible sub-objects
104 SALOMEDS::ChildIterator_var aChildIter = aStudyDocument->NewChildIterator(theSObject);
105 for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) {
106 SALOMEDS::SObject_var aChildSObject = aChildIter->Value();
107 CORBA::Object_var aChildObj = VISU::SObjectToObject(aChildSObject);
108 if (CORBA::is_nil(aChildObj)) continue;
110 VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(aChildObj);
111 if (CORBA::is_nil(aRemovableObject)) continue;
113 aRemovableObject->RemoveFromStudy();
116 if (theDestroySubObjects) {
117 VISU::Prs3d_var aPrs3d = VISU::Prs3d::_narrow(aRemovableObject);
118 if (CORBA::is_nil(aPrs3d)) continue;
123 // Remove the SObject itself
124 aStudyBuilder->RemoveObjectWithChildren(theSObject);
127 QString GenerateName(const char* theName){
128 typedef map<string,int> TNameMap;
129 static TNameMap aMap;
130 TNameMap::const_iterator i = aMap.find(theName);
132 if(i == aMap.end()) {
136 tmp = VISU::GenerateName(theName,++aMap[theName]);
138 if(MYDEBUG) MESSAGE("GenerateName - "<<tmp<<" from - "<<theName<<"; " <<aMap[theName]);
142 QString GenerateFieldName(const string& theName, const string& theUnits){
143 static QString aName;
144 const string tmp(theUnits.size(),' ');
145 if(theUnits == "" || theUnits == tmp)
146 aName.sprintf("%s, -",theName.c_str());
148 aName.sprintf("%s, %s",theName.c_str(),theUnits.c_str());
149 aName = aName.simplifyWhiteSpace();
150 return aName.latin1();
153 void CreateReference(SALOMEDS::Study_ptr theStudyDocument,
154 const string& theFatherEntry, const string& theRefEntry)
156 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
157 SALOMEDS::SObject_var aFather = theStudyDocument->FindObjectID(theFatherEntry.c_str());
158 SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(aFather);
159 SALOMEDS::SObject_var aRefSObj = theStudyDocument->FindObjectID(theRefEntry.c_str());
160 aStudyBuilder->Addreference(newObj,aRefSObj);
163 string GetComponentDataType (SALOMEDS::SObject_ptr theSObject)
165 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
166 SALOMEDS::SComponent_var aCompRefSObj = theSObject->GetFatherComponent();
167 CORBA::String_var aDataType = aCompRefSObj->ComponentDataType();
168 return aDataType.in();
171 //==============================================================================
173 const string VISU::Result_i::myComment = "RESULT";
174 const char* VISU::Result_i::GetComment() const { return myComment.c_str();}
176 VISU::Result_i::Result_i(SALOMEDS::Study_ptr theStudy,
177 const ESourceId& theSourceId,
178 const ECreationId& theCreationId):
179 myStudyDocument(SALOMEDS::Study::_duplicate(theStudy)),
180 myCreationId(theCreationId),
181 mySourceId(theSourceId),
188 void VISU::Result_i::RemoveFromStudy()
190 // Remove the result with all presentations and other possible sub-objects
191 VISU::RemoveFromStudy(mySObject,false);
200 float aSize = myInput->GetSize();
201 bool aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
202 MESSAGE("Result_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<float(aResult));
204 }catch(std::exception& exc){
205 INFOS("Follow exception was occured :\n"<<exc.what());
207 INFOS("Unknown exception was occured!");
217 if(MYDEBUG) MESSAGE("Result_i::Build - myIsDone = "<<myIsDone);
218 if(myIsDone) return 1;
219 if(!IsPossible()) return 0;
221 const VISU::TMeshMap& aMeshMap = myInput->GetMeshMap();
222 VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
223 for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
224 const string& aMeshName = aMeshMapIter->first;
225 const VISU::PMesh aMesh = aMeshMapIter->second;
226 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
227 VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter;
229 aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
230 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
231 const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
232 const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
233 const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
234 VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
235 for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){
236 const string& aFieldName = aFieldMapIter->first;
237 const VISU::PField aField = aFieldMapIter->second;
238 const VISU::TValField& aValField = aField->myValField;
239 VISU::TValField::const_iterator aValFieldIter = aValField.begin();
240 for(; aValFieldIter != aValField.end(); aValFieldIter++){
241 int aTimeStamp = aValFieldIter->first;
243 myInput->GetTimeStampOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp);
244 }catch(std::exception& exc){
245 INFOS("Follow exception was occured :\n"<<exc.what());
247 INFOS("Unknown exception was occured!!!");
252 const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
253 VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin();
254 for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){
255 const string& aGroupName = aGroupMapIter->first;
257 myInput->GetMeshOnGroup(aMeshName,aGroupName);
258 }catch(std::exception& exc){
259 INFOS("Follow exception was occured :\n"<<exc.what());
261 INFOS("Unknown exception was occured!!!");
265 const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
266 VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
267 for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
268 const string& aFamilyName = aFamilyMapIter->first;
270 myInput->GetMeshOnEntity(aMeshName,anEntity,aFamilyName);
271 }catch(std::exception& exc){
272 INFOS("Follow exception was occured :\n"<<exc.what());
274 INFOS("Unknown exception was occured!!!");
277 //Import mesh on entity
279 myInput->GetMeshOnEntity(aMeshName,anEntity);
280 }catch(std::exception& exc){
281 INFOS("Follow exception was occured :\n"<<exc.what());
283 INFOS("Unknown exception was occured!!!");
288 }catch(std::exception& exc){
289 INFOS("Follow exception was occured :\n"<<exc.what());
291 INFOS("Unknown exception was occured!!!");
299 Build(SALOMEDS::SObject_ptr theSObject)
301 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
302 aStudyBuilder->NewCommand(); // There is a transaction
303 if(MYDEBUG) MESSAGE("Result_i::Build");
305 const TMeshMap& aMeshMap = myInput->GetMeshMap();
307 throw std::runtime_error("Build - There is no any mesh information in the file !!!");
308 mySComponent = FindOrCreateVisuComponent(myStudyDocument);
309 CORBA::String_var aSComponentEntry = mySComponent->GetID(), anIOR(GetID());
310 string aRefFatherEntry = GetRefFatherEntry();
312 aComment.sprintf("myComment=%s;myType=%d;myFileName=%s;myInitFileName=%s",
315 myFileInfo.filePath().latin1(),
316 myInitFileName.c_str()); // Restoring of Python dump
317 string aResultEntry =
318 CreateAttributes(myStudyDocument,
320 aRefFatherEntry.c_str(),
326 mySObject = myStudyDocument->FindObjectID(aResultEntry.c_str());
327 if(mySObject->_is_nil()) throw std::runtime_error("Build - There is no SObject for the Result !!!");
328 if(!CORBA::is_nil(theSObject)){
329 CORBA::String_var aString = theSObject->GetID();
330 CreateReference(myStudyDocument,aResultEntry,aString.in());
332 TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
333 for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
334 const string& aMeshName = aMeshMapIter->first;
335 const VISU::PMesh aMesh = aMeshMapIter->second;
336 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
337 VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter;
338 aComment.sprintf("myComment=MESH;myName=%s;myDim=%d",
339 aMeshName.c_str(),aMesh->myDim);
340 string aMeshEntry = CreateAttributes(myStudyDocument,aResultEntry.c_str(),aRefFatherEntry.c_str(),
341 "",aMeshName.c_str(),"",aComment.latin1(),true);
342 if(aMeshOnEntityMap.empty()) continue;
343 aComment.sprintf("myComment=FAMILIES;myMeshName=%s",aMeshName.c_str());
344 string aSubMeshesEntry = CreateAttributes(myStudyDocument,aMeshEntry.c_str(),aRefFatherEntry.c_str(),
345 "","Families","",aComment.latin1(),true);
346 //Import entities and according families
347 aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
348 typedef std::map<std::string,std::string> TComment2EntryMap;
349 TComment2EntryMap aComment2EntryMap;
350 typedef std::map<VISU::TEntity,std::string> TEntity2EntryMap;
351 TEntity2EntryMap aEntity2EntryMap;
352 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
353 const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
354 aComment.sprintf("myComment=ENTITY;myType=%d;myMeshName=%s;myId=%d",
360 case VISU::NODE_ENTITY : anEntityName = "onNodes"; break;
361 case VISU::EDGE_ENTITY : anEntityName = "onEdges"; break;
362 case VISU::FACE_ENTITY : anEntityName = "onFaces"; break;
363 case VISU::CELL_ENTITY : anEntityName = "onCells"; break;
365 throw std::runtime_error("Build >> Value of entity is incorrect!");
367 aEntity2EntryMap[anEntity] = CreateAttributes(myStudyDocument,aSubMeshesEntry.c_str(),aRefFatherEntry.c_str(),
368 "",anEntityName.c_str(),"",aComment.latin1(),true);
369 const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
370 const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
371 VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
372 for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
373 const string& aFamilyName = aFamilyMapIter->first;
374 aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s",
378 aFamilyName.c_str());
379 aComment2EntryMap[aComment.latin1()] =
380 CreateAttributes(myStudyDocument,
381 aEntity2EntryMap[anEntity].c_str(),
382 aRefFatherEntry.c_str(),
391 const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
392 if(aGroupMap.size() > 0){
393 aComment.sprintf("myComment=GROUPS;myMeshName=%s",
395 string aGroupsEntry =
396 CreateAttributes(myStudyDocument,
398 aRefFatherEntry.c_str(),
404 VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin();
405 for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){
406 const string& aGroupName = aGroupMapIter->first;
407 aComment.sprintf("myComment=GROUP;myType=%d;myMeshName=%s;myName=%s",
408 VISU::TGROUP,aMeshName.c_str(),aGroupName.c_str());
409 string aGroupEntry = CreateAttributes(myStudyDocument,aGroupsEntry.c_str(),aRefFatherEntry.c_str(),
410 "",aGroupName.c_str(),"",aComment.latin1(),true);
411 const VISU::PGroup aGroup = aGroupMapIter->second;
412 const VISU::TFamilyAndEntitySet& aFamilyAndEntitySet = aGroup->myFamilyAndEntitySet;
413 VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = aFamilyAndEntitySet.begin();
414 for(; aFamilyAndEntitySetIter != aFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){
415 const VISU::TFamilyAndEntity& aFamilyAndEntity = *aFamilyAndEntitySetIter;
416 const string& aFamilyName = aFamilyAndEntity.first;
417 const VISU::TEntity& anEntity = aFamilyAndEntity.second;
418 aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s",
422 aFamilyName.c_str());
423 CreateReference(myStudyDocument,aGroupEntry,aComment2EntryMap[aComment.latin1()]);
429 bool isFieldEntryCreated = 0;
430 aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
431 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
432 const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
433 const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
434 const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
435 VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
436 for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){
437 if(!isFieldEntryCreated){
438 aComment.sprintf("myComment=FIELDS;myMeshName=%s",
441 CreateAttributes(myStudyDocument,
443 aRefFatherEntry.c_str(),
449 isFieldEntryCreated = true;
451 const string& aFieldName = aFieldMapIter->first;
452 const VISU::PField aField = aFieldMapIter->second;
453 const VISU::TValField& aValField = aField->myValField;
454 QString aFieldNameWithUnit = ::GenerateFieldName(aFieldName,aField->myUnitNames[0]);
455 aComment.sprintf("myComment=FIELD;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s;myNbTimeStamps=%d;myNumComponent=%d",
456 VISU::TFIELD,aMeshName.c_str(),anEntity,aFieldName.c_str(),aValField.size(),aField->myNbComp);
457 string aFieldEntry = CreateAttributes(myStudyDocument,aFieldsEntry.c_str(),aRefFatherEntry.c_str(),
458 "",aFieldNameWithUnit.latin1(),"",aComment.latin1(),true);
459 CreateReference(myStudyDocument,aFieldEntry,aEntity2EntryMap[anEntity]);
460 VISU::TValField::const_iterator aValFieldIter = aValField.begin();
461 for(; aValFieldIter != aValField.end(); aValFieldIter++){
462 int aTimeStamp = aValFieldIter->first;
463 const VISU::PValForTime aValForTime = aValFieldIter->second;
464 aComment.sprintf("myComment=TIMESTAMP;myType=%d;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d",
465 VISU::TTIMESTAMP,aMeshName.c_str(),anEntity,aFieldName.c_str(),aTimeStamp,aField->myNbComp);
466 string aTimeStampId = VISU_Convertor::GenerateName(aValForTime->myTime);
467 CreateAttributes(myStudyDocument,aFieldEntry.c_str(),aRefFatherEntry.c_str(),
468 "",aTimeStampId.c_str(),"",aComment.latin1(),true);
473 QString aIsBuild = VISU::GetResourceMgr()->stringValue("Visu:BuildResult");
474 bool isBuildAll = aIsBuild.isEmpty()? 0 : aIsBuild.toInt();
475 if(isBuildAll) BuildAll();
476 }catch(std::exception& exc){
477 INFOS("Follow exception was occured :\n"<<exc.what());
480 INFOS("Unknown exception was occured!!!");
483 aStudyBuilder->CommitCommand();
490 Create(const char* theFileName)
493 myFileInfo.setFile(theFileName);
494 myInitFileName = myFileInfo.filePath().latin1();
495 myName = ::GenerateName(myFileInfo.fileName()).latin1();
496 if(mySourceId == eRestoredFile){
497 std::string aTmpDir(SALOMEDS_Tool::GetTmpDir());
498 static QString aCommand;
499 aCommand.sprintf("cp %s %s",myFileInfo.absFilePath().latin1(),aTmpDir.c_str());
500 if(system(aCommand) == -1){
501 MESSAGE("Create - Can't execute the command :"<<aCommand);
504 if(MYDEBUG) MESSAGE("Result_i::Create - aCommand = "<<aCommand);
505 myFileInfo.setFile(QString(aTmpDir.c_str()) + myFileInfo.fileName());
507 myInput = CreateConvertor(myFileInfo.absFilePath().latin1());
509 throw std::runtime_error("Create - Cannot create a Convertor for this file!!!"); return Build();
510 }catch(std::exception& exc){
511 INFOS("Follow exception was occured :\n"<<exc.what());
513 INFOS("Unknown exception was occured!!!");
521 Create(SALOMEDS::SObject_ptr theMedSObject)
523 if(MYDEBUG) MESSAGE("Result_i::Create MedObject from SALOMEDS::SObject_ptr");
525 myInput = CreateMEDConvertor(theMedSObject);
529 string aCompDataType = GetComponentDataType(theMedSObject);
530 myFileInfo.setFile(aCompDataType.c_str());
531 myInitFileName = aCompDataType;
533 myName = ::GenerateName("aResult").latin1();
535 VISU::Storable* aStorable = Build(theMedSObject);
537 }catch(std::exception& exc){
538 INFOS("Follow exception was occured :\n"<<exc.what());
540 INFOS("Unknown exception was occured!!!");
547 Create(SALOME_MED::FIELD_ptr theField)
549 if(MYDEBUG) MESSAGE("Result_i::Create MedObject from SALOME_MED::FIELD_ptr");
551 myInput = CreateMEDFieldConvertor(theField);
555 string aCompDataType = "MED";
556 myFileInfo.setFile(aCompDataType.c_str());
557 myInitFileName = aCompDataType;
559 myName = ::GenerateName("aResult").latin1();
561 CORBA::String_var anIOR = myStudyDocument->ConvertObjectToIOR(theField);
562 SALOMEDS::SObject_var aFieldSObject = myStudyDocument->FindObjectIOR(anIOR);
564 VISU::Storable* aStorable = Build(aFieldSObject);
566 }catch(std::exception& exc){
567 INFOS("Follow exception was occured :\n"<<exc.what());
569 INFOS("Unknown exception was occured!!!");
577 Restore(SALOMEDS::SObject_ptr theSObject,
578 const Storable::TRestoringMap& theMap,
579 const string& thePrefix)
581 if(MYDEBUG) MESSAGE("Result_i::Restore - "<<thePrefix);
583 mySObject = SALOMEDS::SObject::_duplicate(theSObject);
584 myStudyDocument = mySObject->GetStudy();
585 mySComponent = mySObject->GetFatherComponent();
586 myName = VISU::Storable::FindValue(theMap,"myName").latin1();
587 myInitFileName = VISU::Storable::FindValue(theMap,"myInitFileName").latin1();
588 SALOMEDS::SObject_var aRefSObj, aTargetRefSObj;
589 if(mySObject->FindSubObject(1,aRefSObj) && aRefSObj->ReferencedObject(aTargetRefSObj)){
590 if(MYDEBUG) MESSAGE("Result_i::GetInput - There is some reference.");
591 SALOMEDS::SComponent_var aCompRefSObj = aTargetRefSObj->GetFatherComponent();
592 CORBA::String_var aDataType = aCompRefSObj->ComponentDataType();
593 myFileInfo.setFile(aDataType.in());
594 if(MYDEBUG) MESSAGE("Result_i::GetInput - aDataType = "<<aDataType);
595 Engines::Component_var aEngComp = Base_i::myEnginesLifeCycle->FindOrLoad_Component("FactoryServer", aDataType.in());
596 if (CORBA::is_nil(aEngComp))
597 throw std::runtime_error("Restore - There is no aEngComp for the aDataType !!!");
598 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
599 SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(aEngComp);
600 aStudyBuilder->LoadWith(aCompRefSObj,aDriver);
601 if(strcmp(aDataType,"MED") == 0)
602 myInput = CreateMEDConvertor(aTargetRefSObj);
604 throw std::runtime_error("GetInput - There is no convertor for the aDataType !!!");
606 myFileInfo.setFile(thePrefix.c_str());
608 string aStudyPrefix("");
609 if (IsMultifile()) aStudyPrefix = (SALOMEDS_Tool::GetNameFromPath(myStudyDocument->URL()));
610 if(!myFileInfo.isFile()){
611 string aFileName = thePrefix + aStudyPrefix + "_" + myName;
612 myFileInfo.setFile(aFileName.c_str());
615 MESSAGE("Result_i::Restore - aFileName = "<<myFileInfo.filePath()<<"; "<<myFileInfo.isFile());
617 if (HDFascii::isASCII(myFileInfo.filePath().latin1())) {
618 char* aResultPath = HDFascii::ConvertFromASCIIToHDF(myFileInfo.filePath().latin1());
619 char* aHDFFileName = new char[strlen(aResultPath) + 19];
620 sprintf(aHDFFileName, "%shdf_from_ascii.hdf", aResultPath);
622 if (IsMultifile()) { // set this file as new - temporary
623 static QString aCommand;
624 aCommand.sprintf("mv %s %s%s",aHDFFileName, aResultPath, myFileInfo.baseName().latin1());
625 if(system(aCommand) == -1){
626 if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - Can't execute the command :"<<aCommand);
628 } else if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - "<<aCommand);
629 myFileInfo.setFile(QString(aResultPath)+QString(myFileInfo.baseName().latin1()));
630 } else { // change current temporary file to the new: with hdf-format
631 static QString aCommand;
632 aCommand.sprintf("mv %s %s\0",aHDFFileName, myFileInfo.filePath().latin1());
633 if(system(aCommand.latin1()) == -1) {
634 if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - Can't execute the command :"<<aCommand);
636 } else if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - "<<aCommand);
637 SALOMEDS::ListOfFileNames_var anEmptyList = new SALOMEDS::ListOfFileNames;
638 SALOMEDS_Tool::RemoveTemporaryFiles(aResultPath, anEmptyList.in(), true);
640 mySourceId = eRestoredFile;
642 delete(aHDFFileName);
643 } else if (!IsMultifile())
644 mySourceId = eRestoredFile;
647 if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - mySourceId = "<<mySourceId);
648 myInput = CreateConvertor(myFileInfo.filePath().latin1());
650 aComment.sprintf("myComment=%s;myType=%d;myFileName=%s;myInitFileName=%s",
651 GetComment(),VISU::TRESULT,myFileInfo.filePath().latin1(),
652 myInitFileName.c_str()); // Restoring of Python dump
653 SALOMEDS::GenericAttribute_var anAttr;
654 if(!theSObject->FindAttribute(anAttr, "AttributeComment"))
655 throw std::runtime_error("Build - There is no AttributeComment for the SObject !!!");
656 SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr);
657 aCmnt->SetValue(aComment.latin1());
659 QString aIsBuild = VISU::GetResourceMgr()->stringValue("Visu:BuildResult");
660 if(aIsBuild.isEmpty()? 0 : aIsBuild.toInt())
663 }catch(std::exception& exc){
664 INFOS("Follow exception was occured :\n"<<exc.what());
666 INFOS("Unknown exception was occured!!!");
671 VISU::Result_i::TInput* VISU::Result_i::GetInput() {
675 void VISU::Result_i::ToStream(std::ostringstream& theStr){
676 if(MYDEBUG) MESSAGE(GetComment());
677 Storable::DataToStream(theStr,"myName",myName.c_str());
678 Storable::DataToStream(theStr,"myInitFileName",myInitFileName.c_str());
679 Storable::DataToStream(theStr,"myCreationId",myCreationId);
683 VISU::Result_i::Restore(SALOMEDS::SObject_ptr theSObject,
684 const string& thePrefix,
685 const Storable::TRestoringMap& theMap)
687 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
689 ECreationId aCreationId = ECreationId(Storable::FindValue(theMap,"myCreationId").toInt());
690 ESourceId aSourceId = eRestoredFile;
691 if(aCreationId == eImportMed || aCreationId == eImportMedField)
692 aSourceId = eRestoredComponent;
694 VISU::Result_i* pResult = new VISU::Result_i(aStudy,aSourceId,aCreationId);
698 return pResult->Restore(theSObject,theMap,thePrefix);
701 string VISU::Result_i::GetRefFatherEntry() {
702 //return QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry();
706 string VISU::Result_i::GetEntry(){
707 CORBA::String_var anEntry = mySObject->GetID();
708 return string(anEntry);
711 const SALOMEDS::SObject_var& VISU::Result_i::GetSObject() const { return mySObject;}
712 const SALOMEDS::Study_var& VISU::Result_i::GetStudyDocument() const { return myStudyDocument;}
713 const SALOMEDS::SComponent_var& VISU::Result_i::GetSComponent() const { return mySComponent;}
714 std::string VISU::Result_i::GetEntry(const std::string& theComment)
716 return FindEntryWithComment(myStudyDocument,GetEntry().c_str(),theComment.c_str());
719 VISU::Result_i::~Result_i() {
720 MESSAGE("Result_i::~Result_i() - this = "<<this);
721 if(mySourceId == eRestoredFile){
722 static QString aCommand;
723 aCommand.sprintf("rm %s",myFileInfo.filePath().latin1());
724 MESSAGE("Result_i::~Result_i - system("<<aCommand<<") = "<<system(aCommand));
725 aCommand.sprintf("rmdir --ignore-fail-on-non-empty %s",myFileInfo.dirPath().latin1());
726 MESSAGE("Result_i::~Result_i - system("<<aCommand<<") = "<<system(aCommand));
728 if(myInput) delete myInput;
731 //=======================================================================
732 //function : GetAxisInfo
734 //=======================================================================
735 const vector< float >* Result_i::GetAxisInfo(const string& theMeshName,
737 gp_Dir& thePlaneNormal)
739 const vector< float >* components = NULL;
741 if ( theAxis < AXIS_X || theAxis > AXIS_Z ) {
742 MESSAGE(" Bad axis index " << theAxis );
746 map< string, TGridInfo >::iterator name_info;
747 name_info = myMeshName2GridInfoMap.find( theMeshName );
748 TGridInfo * gInfo = 0;
750 if ( name_info != myMeshName2GridInfoMap.end() )
752 gInfo = & name_info->second;
754 else if ( myInput && IsPossible() && theAxis >= AXIS_X && theAxis <= AXIS_Z )
756 // check presence of theMeshName
757 const VISU::TMeshMap& meshMap = myInput->GetMeshMap();
758 if ( meshMap.find( theMeshName ) == meshMap.end() ) {
759 MESSAGE("No mesh named " << theMeshName );
762 VISU_Convertor::TOutput* vtkMesh = myInput->GetMeshOnEntity (theMeshName,
764 if ( !vtkMesh || vtkMesh->GetNumberOfCells() == 0 ) {
765 MESSAGE( "No cells in the mesh: " << theMeshName );
769 // define axis directions and min cell size in each direction
770 const int nbAxes = 3;
772 gp_Vec axDirs[ nbAxes ];
773 float minSize[3] = { FLT_MAX, FLT_MAX, FLT_MAX };
774 bool axesComputed = false;
775 for ( vtkIdType iCell = 0; iCell < vtkMesh->GetNumberOfCells(); ++iCell )
777 vtkCell* cell = vtkMesh->GetCell( iCell );
778 int nbPnt = cell->GetNumberOfPoints();
781 vtkPoints * points = cell->GetPoints();
783 coords[0] = points->GetPoint( 0 );
784 coords[1] = points->GetPoint( 1 );
785 coords[2] = points->GetPoint( 3 );
786 coords[3] = points->GetPoint( 4 );
787 gp_Pnt p0( coords[0][0], coords[0][1], coords[0][2] );
788 for ( iAx = 0; iAx < nbAxes; ++iAx )
790 float* coo = coords[ iAx + 1 ];
791 gp_Pnt p( coo[0], coo[1], coo[2] );
793 float size = p0.SquareDistance( p );
794 if ( size > FLT_MIN && size < minSize[ iAx ] )
795 minSize[ iAx ] = size;
797 if ( !axesComputed ) {
799 if ( dir.SquareMagnitude() <= DBL_MIN )
807 if ( !axesComputed ) {
808 MESSAGE("No good hexahedrons in the mesh: " << theMeshName );
813 gInfo = & myMeshName2GridInfoMap[ theMeshName ];
814 for ( iAx = 0; iAx < nbAxes; ++iAx )
816 int iPrev = ( iAx == 0 ) ? 2 : iAx - 1;
817 int iNext = ( iAx == 2 ) ? 0 : iAx + 1;
818 gInfo->myAxis[ iAx ] = axDirs[ iPrev ] ^ axDirs[ iNext ];
821 // get and sort intermediate component values - projections of nodes
822 // on axis direction; define bnd box
823 set< float > comps[ 3 ];
825 vtkPoints * points = vtkMesh->GetPoints();
826 vtkIdType iP, nbP = vtkMesh->GetNumberOfPoints();
827 for ( iP = 0; iP < nbP; ++iP )
829 float* coo = points->GetPoint( iP );
830 gp_Pnt p( coo[0], coo[1], coo[2] );
832 for ( iAx = 0; iAx < nbAxes; ++iAx ) {
833 const gp_Dir& dir = gInfo->myAxis[ iAx ];
834 float dot = dir.XYZ() * p.XYZ();
835 comps[ iAx ].insert( dot );
839 // find a range of projections of bnd box corners on each axis
840 float range[3], firstValue[3];
841 double x[2],y[2],z[2];
842 box.Get(x[0],y[0],z[0],x[1],y[1],z[1]);
843 for ( iAx = 0; iAx < nbAxes; ++iAx ) {
844 set< float > bndComps;
845 const gp_Dir& dir = gInfo->myAxis[ iAx ];
846 for ( int iX = 0; iX < 2; ++iX ) {
847 for ( int iY = 0; iY < 2; ++iY ) {
848 for ( int iZ = 0; iZ < 2; ++iZ ) {
849 gp_Pnt p( x[ iX ], y[ iY ], z[ iZ ] );
850 float dot = dir.XYZ() * p.XYZ();
851 bndComps.insert( dot );
855 firstValue[ iAx ] = *bndComps.begin();
856 range[ iAx ] = *bndComps.rbegin() - *bndComps.begin();
859 // compute component values
860 for ( iAx = 0; iAx < nbAxes; ++iAx )
862 list< float > values;
864 set< float >& comp = comps[ iAx ];
865 set< float >::iterator val = comp.begin();
866 float bnd = -1., rng = range[ iAx ], first = firstValue[ iAx ];
867 float tol = 0.1 * sqrt( minSize[ iAx ]) / rng;
868 for ( ; val != comp.end(); ++val ) {
869 float value = ( *val - first ) / rng;
871 values.push_back( value );
876 // store values in gInfo
877 vector< float >& myComp = gInfo->myComponets[ iAx ];
878 myComp.resize( nbVals );
879 list< float >::iterator v = values.begin();
880 for ( int i = 0; v != values.end(); ++v )
888 thePlaneNormal = gInfo->myAxis[ theAxis ];
889 components = & gInfo->myComponets[ theAxis ];