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_ConvertorUtils.hxx"
32 #include "VISU_PipeLine.hxx"
34 #include "SUIT_ResourceMgr.h"
36 #include "SALOMEDS_Tool.hxx"
37 #include "HDFascii.hxx"
39 #include "SUIT_Session.h"
40 #include "SALOME_Event.hxx"
41 #include "SalomeApp_Study.h"
42 #include "SalomeApp_Application.h"
44 #include <boost/thread/recursive_mutex.hpp>
45 #include <boost/thread/thread.hpp>
47 #include <boost/thread/mutex.hpp>
48 #include <boost/bind.hpp>
52 #include <qfileinfo.h>
53 #include <qsemaphore.h>
58 #include <vtkUnstructuredGrid.h>
61 #include <Bnd_Box.hxx>
67 static int MYDEBUG = 0;
68 static int MYTIMEDEBUG = 0;
70 static int MYDEBUG = 0;
71 static int MYTIMEDEBUG = 0;
77 //---------------------------------------------------------------
79 FindResult (SALOMEDS::SObject_ptr theSObject)
81 SALOMEDS::SComponent_var aSComponent = theSObject->GetFatherComponent();
82 SALOMEDS::SObject_var aFather = theSObject->GetFather();
83 CORBA::String_var aComponentID (aSComponent->GetID());
84 CORBA::String_var aFatherID (aFather->GetID());
86 while (strcmp(aComponentID, aFatherID) != 0) {
87 CORBA::Object_var anObject = SObjectToObject(aFather);
88 if (!CORBA::is_nil(anObject)) {
89 aResult = Result::_narrow(anObject);
90 if (!aResult->_is_nil()) return aResult;
92 aFather = aFather->GetFather();
93 aFatherID = aFather->GetID();
99 //---------------------------------------------------------------
100 typedef boost::recursive_mutex TMutex;
101 typedef TMutex::scoped_lock TLock;
103 static TMutex myMutex;
105 //---------------------------------------------------------------
106 struct TGetStudy: public SALOME_Event
108 typedef _PTR(Study) TResult;
112 TGetStudy(const int theStudyId):
113 myStudyId(theStudyId)
120 SUIT_Session* aSession = SUIT_Session::session();
121 QPtrList<SUIT_Application> anApplications = aSession->applications();
122 QPtrListIterator<SUIT_Application> anIter (anApplications);
123 while (SUIT_Application* aSApp = anIter.current()) {
124 if(SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(aSApp)){
125 if(SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(anApp->activeStudy())) {
126 if(_PTR(Study) aStudyDS = aStudy->studyDS()){
127 if(aStudyDS->StudyId() == myStudyId){
128 myResult = aStudy->studyDS();
140 //---------------------------------------------------------------
142 GenerateName (const char* theName)
144 TLock aLock(myMutex);
146 typedef map<string,int> TNameMap;
147 static TNameMap aMap;
149 TNameMap::const_iterator i = aMap.find(theName);
151 if (i == aMap.end()) {
155 tmp = GenerateName(theName,++aMap[theName]);
157 if(MYDEBUG) MESSAGE("GenerateName - "<<tmp<<" from - "<<theName<<"; " <<aMap[theName]);
162 //---------------------------------------------------------------
164 GenerateFieldName (const string& theName, const string& theUnits)
167 const string tmp (theUnits.size(),' ');
168 if (theUnits == "" || theUnits == tmp)
169 aName.sprintf("%s, -",theName.c_str());
171 aName.sprintf("%s, %s",theName.c_str(),theUnits.c_str());
172 aName = aName.simplifyWhiteSpace();
173 return aName.latin1();
177 //---------------------------------------------------------------
179 GetComponentDataType (SALOMEDS::SObject_ptr theSObject)
181 SALOMEDS::SComponent_var aCompRefSObj = theSObject->GetFatherComponent();
182 CORBA::String_var aDataType = aCompRefSObj->ComponentDataType();
183 return aDataType.in();
187 //---------------------------------------------------------------
189 CreateReference (SALOMEDS::Study_ptr theStudyDocument,
190 const string& theFatherEntry,
191 const string& theRefEntry)
193 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
194 SALOMEDS::SObject_var aFather = theStudyDocument->FindObjectID(theFatherEntry.c_str());
195 SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(aFather);
196 SALOMEDS::SObject_var aRefSObj = theStudyDocument->FindObjectID(theRefEntry.c_str());
197 aStudyBuilder->Addreference(newObj,aRefSObj);
201 //---------------------------------------------------------------
203 CreateReference (_PTR(Study) theStudyDocument,
204 const string& theFatherEntry,
205 const string& theRefEntry)
207 TLock aLock(myMutex);
209 _PTR(StudyBuilder) aStudyBuilder = theStudyDocument->NewBuilder();
210 _PTR(SObject) aFather = theStudyDocument->FindObjectID(theFatherEntry);
211 _PTR(SObject) aNewObj = aStudyBuilder->NewObject(aFather);
212 _PTR(SObject) aRefSObj = theStudyDocument->FindObjectID(theRefEntry);
213 aStudyBuilder->Addreference(aNewObj,aRefSObj);
217 CreateAttributes(_PTR(Study) theStudyDocument,
218 const string& theFatherEntry,
219 const string& theIOR,
220 const string& theName,
221 const string& thePersistentRef,
222 const string& theComment,
223 CORBA::Boolean theCreateNew)
225 TLock aLock(myMutex);
227 _PTR(StudyBuilder) aStudyBuilder = theStudyDocument->NewBuilder();
228 _PTR(SObject) aFather = theStudyDocument->FindObjectID(theFatherEntry);
230 _PTR(SObject) aNewObj;
232 aNewObj = aStudyBuilder->NewObject(aFather);
236 _PTR(GenericAttribute) anAttr;
238 anAttr = aStudyBuilder->FindOrCreateAttribute(aNewObj, "AttributeIOR");
239 _PTR(AttributeIOR) anIOR (anAttr);
240 anIOR->SetValue(theIOR);
243 anAttr = aStudyBuilder->FindOrCreateAttribute(aNewObj, "AttributeName");
244 _PTR(AttributeName) aName (anAttr);
245 aName->SetValue(theName);
247 if (thePersistentRef != "") {
248 anAttr = aStudyBuilder->FindOrCreateAttribute(aNewObj, "AttributePersistentRef");
249 _PTR(AttributePersistentRef) aPRef (anAttr);
250 aPRef->SetValue(thePersistentRef);
252 if (theComment != "") {
253 anAttr = aStudyBuilder->FindOrCreateAttribute(aNewObj, "AttributeComment");
254 _PTR(AttributeComment) aCmnt (anAttr);
255 aCmnt->SetValue(theComment);
257 return aNewObj->GetID();
260 //---------------------------------------------------------------
261 struct TResultManager
265 TResultManager(Result_i* theResult):
268 myResult->Register();
278 //---------------------------------------------------------------
279 struct TTransactionManager
281 _PTR(StudyBuilder) myStudyBuilder;
283 TTransactionManager(_PTR(Study) theStudyDocument):
284 myStudyBuilder(theStudyDocument->NewBuilder())
286 TLock aLock(myMutex);
287 myStudyBuilder->NewCommand();
290 ~TTransactionManager()
292 TLock aLock(myMutex);
293 myStudyBuilder->CommitCommand();
298 //---------------------------------------------------------------
299 struct TUpdateObjBrowser: public SALOME_Event
302 CORBA::Boolean* myIsDone;
303 TUpdateObjBrowser(const int theStudyId,
304 CORBA::Boolean* theIsDone):
305 myStudyId(theStudyId),
313 TLock aLock(myMutex);
314 SUIT_Session* aSession = SUIT_Session::session();
315 QPtrList<SUIT_Application> anApplications = aSession->applications();
316 QPtrListIterator<SUIT_Application> anIter (anApplications);
317 while (SUIT_Application* aSApp = anIter.current()) {
318 if(SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(aSApp)){
319 if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(anApp->activeStudy())) {
320 if (_PTR(Study) aCStudy = aStudy->studyDS()) {
321 if (myStudyId == aCStudy->StudyId()) {
322 TTimerLog aTimerLog(MYTIMEDEBUG,"Result_i::updateObjectBrowser");
323 anApp->updateObjectBrowser();
336 //---------------------------------------------------------------
338 BuildEntities(Result_i* theResult,
339 VISU_Convertor* theInput,
340 CORBA::Boolean* theIsDone,
341 std::string theResultEntry,
342 _PTR(Study) theStudy)
347 TTimerLog aTimerLog(MYTIMEDEBUG,"Result_i::BuildEntities");
348 TResultManager aResultManager(theResult);
349 TTransactionManager aTransactionManager(theStudy);
352 TTimerLog aTimerLog(MYTIMEDEBUG,"theInput->BuildEntities");
353 theInput->BuildEntities();
357 const TMeshMap& aMeshMap = theInput->GetMeshMap();
358 TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
359 for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
360 const string& aMeshName = aMeshMapIter->first;
361 const PMesh& aMesh = aMeshMapIter->second;
362 const TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
363 if(aMeshOnEntityMap.empty())
366 aComment.sprintf("myComment=MESH;myName=%s;myDim=%d",
370 CreateAttributes(theStudy,
378 aComment.sprintf("myComment=FAMILIES;myMeshName=%s",
380 string aSubMeshesEntry =
381 CreateAttributes(theStudy,
389 TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
390 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
391 const TEntity& anEntity = aMeshOnEntityMapIter->first;
392 const PMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
397 anEntityName = "onNodes";
400 anEntityName = "onEdges";
403 anEntityName = "onFaces";
406 anEntityName = "onCells";
412 aComment.sprintf("myComment=ENTITY;myType=%d;myMeshName=%s;myId=%d",
417 aMeshOnEntity->myEntry =
418 CreateAttributes(theStudy,
421 anEntityName.c_str(),
428 ProcessVoidEvent(new TUpdateObjBrowser(theStudy->StudyId(),theIsDone));
431 //---------------------------------------------------------------
433 BuildGroups(Result_i* theResult,
434 VISU_Convertor* theInput,
435 CORBA::Boolean* theIsDone,
436 CORBA::Boolean theIsBuild,
437 _PTR(Study) theStudy)
439 if(!theIsBuild || *theIsDone)
442 TTimerLog aTimerLog(MYTIMEDEBUG,"Result_i::BuildGroups");
443 TResultManager aResultManager(theResult);
444 TTransactionManager aTransactionManager(theStudy);
447 TTimerLog aTimerLog(MYTIMEDEBUG,"theInput->BuildGroups");
448 theInput->BuildGroups();
452 const TMeshMap& aMeshMap = theInput->GetMeshMap();
453 TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
454 for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
455 const string& aMeshName = aMeshMapIter->first;
456 const PMesh& aMesh = aMeshMapIter->second;
458 const TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
459 if(aMeshOnEntityMap.empty())
462 TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
463 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
464 const TEntity& anEntity = aMeshOnEntityMapIter->first;
465 const PMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
467 const TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
468 TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
469 for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
470 const string& aFamilyName = aFamilyMapIter->first;
471 const PFamily& aFamily = aFamilyMapIter->second;
472 aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s",
476 aFamilyName.c_str());
478 CreateAttributes(theStudy,
479 aMeshOnEntity->myEntry,
488 const TGroupMap& aGroupMap = aMesh->myGroupMap;
489 if(!aGroupMap.empty()){
490 aComment.sprintf("myComment=GROUPS;myMeshName=%s",
492 string aGroupsEntry =
493 CreateAttributes(theStudy,
500 TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin();
501 for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){
502 const string& aGroupName = aGroupMapIter->first;
503 const PGroup& aGroup = aGroupMapIter->second;
504 aComment.sprintf("myComment=GROUP;myType=%d;myMeshName=%s;myName=%s",
505 TGROUP,aMeshName.c_str(),aGroupName.c_str());
507 CreateAttributes(theStudy,
514 const TFamilySet& aFamilySet = aGroup->myFamilySet;
515 TFamilySet::const_iterator aFamilyIter = aFamilySet.begin();
516 for(; aFamilyIter != aFamilySet.end(); aFamilyIter++){
517 const PFamily& aFamily = *aFamilyIter;
518 CreateReference(theStudy,
526 ProcessVoidEvent(new TUpdateObjBrowser(theStudy->StudyId(),theIsDone));
530 //---------------------------------------------------------------
532 BuildFields(Result_i* theResult,
533 VISU_Convertor* theInput,
534 CORBA::Boolean* theIsDone,
535 CORBA::Boolean theIsBuild,
536 _PTR(Study) theStudy)
538 if(!theIsBuild || *theIsDone)
541 TTimerLog aTimerLog(MYTIMEDEBUG,"Result_i::BuildFields");
542 TResultManager aResultManager(theResult);
543 TTransactionManager aTransactionManager(theStudy);
546 TTimerLog aTimerLog(MYTIMEDEBUG,"theInput->BuildFields");
547 theInput->BuildFields();
551 const TMeshMap& aMeshMap = theInput->GetMeshMap();
552 TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
553 for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
554 const string& aMeshName = aMeshMapIter->first;
555 const PMesh& aMesh = aMeshMapIter->second;
557 const TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
558 if(aMeshOnEntityMap.empty())
563 bool anIsFieldsEntryCreated = false;
565 TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
566 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
567 const TEntity& anEntity = aMeshOnEntityMapIter->first;
568 const PMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
569 const TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
570 TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
571 for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){
572 if(!anIsFieldsEntryCreated){
573 aComment.sprintf("myComment=FIELDS;myMeshName=%s",
576 CreateAttributes(theStudy,
583 anIsFieldsEntryCreated = true;
585 const string& aFieldName = aFieldMapIter->first;
586 const PField& aField = aFieldMapIter->second;
587 const TValField& aValField = aField->myValField;
588 QString aFieldNameWithUnit = GenerateFieldName(aFieldName,aField->myUnitNames[0]);
589 aComment.sprintf("myComment=FIELD;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s;myNbTimeStamps=%d;myNumComponent=%d",
597 CreateAttributes(theStudy,
600 aFieldNameWithUnit.latin1(),
604 CreateReference(theStudy,
606 aMeshOnEntity->myEntry);
607 TValField::const_iterator aValFieldIter = aValField.begin();
608 for(; aValFieldIter != aValField.end(); aValFieldIter++){
609 int aTimeStamp = aValFieldIter->first;
610 const PValForTime& aValForTime = aValFieldIter->second;
611 aComment.sprintf("myComment=TIMESTAMP;myType=%d;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d",
618 string aTimeStampId = VISU_Convertor::GenerateName(aValForTime->myTime);
619 aValForTime->myEntry =
620 CreateAttributes(theStudy,
632 ProcessVoidEvent(new TUpdateObjBrowser(theStudy->StudyId(),theIsDone));
636 //---------------------------------------------------------------
638 BuildMinMax(Result_i* theResult,
639 VISU_Convertor* theInput,
640 CORBA::Boolean* theIsDone,
641 CORBA::Boolean theIsBuild,
642 Result_i::TUpdateMinMaxSignal* theUpdateMinMaxSignal)
644 if(!theIsBuild || *theIsDone)
647 TTimerLog aTimerLog(MYTIMEDEBUG,"Result_i::BuildMinMax");
648 TResultManager aResultManager(theResult);
650 theInput->BuildMinMax();
654 (*theUpdateMinMaxSignal)();
658 //---------------------------------------------------------------
660 BuildFieldDataTree(Result_i* theResult,
661 VISU_Convertor* theInput,
662 CORBA::Boolean* theIsFieldsDone,
663 CORBA::Boolean theIsBuildFields,
664 CORBA::Boolean* theIsMinMaxDone,
665 CORBA::Boolean theIsBuildMinMax,
666 Result_i::TUpdateMinMaxSignal* theUpdateMinMaxSignal,
667 _PTR(Study) theStudy)
669 BuildFields(theResult,
675 BuildMinMax(theResult,
679 theUpdateMinMaxSignal);
683 //---------------------------------------------------------------
687 VISU_Convertor* myInput;
688 CORBA::Boolean* myIsEntitiesDone;
689 std::string myResultEntry;
690 CORBA::Boolean* myIsFieldsDone;
691 CORBA::Boolean myIsBuildFields;
692 CORBA::Boolean* myIsMinMaxDone;
693 CORBA::Boolean myIsBuildMinMax;
694 Result_i::TUpdateMinMaxSignal* myUpdateMinMaxSignal;
695 CORBA::Boolean* myIsGroupsDone;
696 CORBA::Boolean myIsBuildGroups;
699 TBuildArgs(Result_i* theResult,
700 VISU_Convertor* theInput,
701 CORBA::Boolean* theIsEntitiesDone,
702 std::string theResultEntry,
703 CORBA::Boolean* theIsFieldsDone,
704 CORBA::Boolean theIsBuildFields,
705 CORBA::Boolean* theIsMinMaxDone,
706 CORBA::Boolean theIsBuildMinMax,
707 Result_i::TUpdateMinMaxSignal* theUpdateMinMaxSignal,
708 CORBA::Boolean* theIsGroupsDone,
709 CORBA::Boolean theIsBuildGroups,
710 _PTR(Study) theStudy):
713 myIsEntitiesDone(theIsEntitiesDone),
714 myResultEntry(theResultEntry),
715 myIsFieldsDone(theIsFieldsDone),
716 myIsBuildFields(theIsBuildFields),
717 myIsMinMaxDone(theIsMinMaxDone),
718 myIsBuildMinMax(theIsBuildMinMax),
719 myUpdateMinMaxSignal(theUpdateMinMaxSignal),
720 myIsGroupsDone(theIsGroupsDone),
721 myIsBuildGroups(theIsBuildGroups),
727 //---------------------------------------------------------------
729 BuildDataTree(TBuildArgs theBuildArgs)
731 BuildEntities(theBuildArgs.myResult,
732 theBuildArgs.myInput,
733 theBuildArgs.myIsEntitiesDone,
734 theBuildArgs.myResultEntry,
735 theBuildArgs.myStudy);
737 boost::thread aThread(boost::bind(&BuildGroups,
738 theBuildArgs.myResult,
739 theBuildArgs.myInput,
740 theBuildArgs.myIsGroupsDone,
741 theBuildArgs.myIsBuildGroups,
742 theBuildArgs.myStudy));
745 boost::thread aThread(boost::bind(&BuildFieldDataTree,
746 theBuildArgs.myResult,
747 theBuildArgs.myInput,
748 theBuildArgs.myIsFieldsDone,
749 theBuildArgs.myIsBuildFields,
750 theBuildArgs.myIsMinMaxDone,
751 theBuildArgs.myIsBuildMinMax,
752 theBuildArgs.myUpdateMinMaxSignal,
753 theBuildArgs.myStudy));
760 //---------------------------------------------------------------
763 myMinMaxIsInitilized(false)
768 ::IsMinMaxInitilized()
770 return myMinMaxIsInitilized;
777 myMinMaxIsInitilized = true;
781 //---------------------------------------------------------------
782 const string VISU::Result_i::myComment = "RESULT";
783 const char* VISU::Result_i::GetComment() const { return myComment.c_str();}
785 //---------------------------------------------------------------
787 ::Result_i (SALOMEDS::Study_ptr theStudy,
788 const ESourceId& theSourceId,
789 const ECreationId& theCreationId,
790 CORBA::Boolean theIsBuildImmediately):
791 myStudyDocument(SALOMEDS::Study::_duplicate(theStudy)),
792 myCreationId(theCreationId),
793 mySourceId(theSourceId),
794 myIsBuildImmediately(theIsBuildImmediately),
796 myIsEntitiesDone(false),
797 myIsFieldsDone(false),
798 myIsGroupsDone(false),
799 myIsMinMaxDone(false),
800 myIsBuildFields(true),
801 myIsBuildGroups(true),
802 myIsBuildMinMax(true),
805 myStudy = ProcessEvent(new TGetStudy(myStudyDocument->StudyId()));
809 //---------------------------------------------------------------
814 struct TRemoveFromStudy: public SALOME_Event
816 VISU::Result_i* myRemovable;
817 TRemoveFromStudy(VISU::Result_i* theRemovable):
818 myRemovable(theRemovable)
825 VISU::RemoveFromStudy(myRemovable->GetSObject(),false);
826 myRemovable->Destroy();
830 // Remove the result with all presentations and other possible sub-objects
831 ProcessVoidEvent(new TRemoveFromStudy(this));
835 //---------------------------------------------------------------
838 ::MinMaxConnect(VISU::MinMaxCunsomer* theMinMaxCunsomer)
840 myUpdateMinMaxSignal.connect(boost::bind(&MinMaxCunsomer::UpdateMinMax,theMinMaxCunsomer));
844 //---------------------------------------------------------------
850 float aSize = myInput->GetSize();
851 bool aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
852 MESSAGE("Result_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<float(aResult));
854 }catch(std::exception& exc){
855 INFOS("Follow exception was occured :\n"<<exc.what());
857 INFOS("Unknown exception was occured!");
863 //---------------------------------------------------------------
868 if(MYDEBUG) MESSAGE("Result_i::Build - myIsAllDone = "<<myIsAllDone);
874 const VISU::TMeshMap& aMeshMap = myInput->GetMeshMap();
875 VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
876 for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
877 const string& aMeshName = aMeshMapIter->first;
878 const VISU::PMesh aMesh = aMeshMapIter->second;
879 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
880 VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter;
882 aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
883 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
884 const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
885 const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
886 const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
887 VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
888 for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){
889 const string& aFieldName = aFieldMapIter->first;
890 const VISU::PField aField = aFieldMapIter->second;
891 const VISU::TValField& aValField = aField->myValField;
892 VISU::TValField::const_iterator aValFieldIter = aValField.begin();
893 for(; aValFieldIter != aValField.end(); aValFieldIter++){
894 int aTimeStamp = aValFieldIter->first;
896 myInput->GetTimeStampOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp);
897 }catch(std::exception& exc){
898 INFOS("Follow exception was occured :\n"<<exc.what());
900 INFOS("Unknown exception was occured!!!");
905 const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
906 VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin();
907 for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){
908 const string& aGroupName = aGroupMapIter->first;
910 myInput->GetMeshOnGroup(aMeshName,aGroupName);
911 }catch(std::exception& exc){
912 INFOS("Follow exception was occured :\n"<<exc.what());
914 INFOS("Unknown exception was occured!!!");
918 const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
919 VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
920 for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
921 const string& aFamilyName = aFamilyMapIter->first;
923 myInput->GetFamilyOnEntity(aMeshName,anEntity,aFamilyName);
924 }catch(std::exception& exc){
925 INFOS("Follow exception was occured :\n"<<exc.what());
927 INFOS("Unknown exception was occured!!!");
930 //Import mesh on entity
932 myInput->GetMeshOnEntity(aMeshName,anEntity);
933 }catch(std::exception& exc){
934 INFOS("Follow exception was occured :\n"<<exc.what());
936 INFOS("Unknown exception was occured!!!");
941 }catch(std::exception& exc){
942 INFOS("Follow exception was occured :\n"<<exc.what());
944 INFOS("Unknown exception was occured!!!");
950 //---------------------------------------------------------------
953 ::Build(CORBA::Boolean theIsBuildAll,
954 CORBA::Boolean theIsAtOnce)
959 if(Build(SALOMEDS::SObject::_nil(),theIsAtOnce)){
969 //---------------------------------------------------------------
972 ::Build(SALOMEDS::SObject_ptr theSObject,
973 CORBA::Boolean theIsAtOnce)
981 mySComponent = FindOrCreateVisuComponent(myStudyDocument);
982 CORBA::String_var aSComponentEntry = mySComponent->GetID();
983 CORBA::String_var anIOR(GetID());
985 aComment.sprintf("myComment=%s;myType=%d;myFileName=%s;myInitFileName=%s",
988 myFileInfo.filePath().latin1(),
989 myInitFileName.c_str()); // Restoring of Python dump
990 string aResultEntry =
991 CreateAttributes(myStudy,
992 aSComponentEntry.in(),
998 mySObject = myStudyDocument->FindObjectID(aResultEntry.c_str());
999 if(!CORBA::is_nil(theSObject)){
1000 CORBA::String_var aString = theSObject->GetID();
1001 CreateReference(myStudyDocument,aResultEntry,aString.in());
1027 &myUpdateMinMaxSignal);
1030 TBuildArgs aBuildArgs(this,
1038 &myUpdateMinMaxSignal,
1042 boost::thread aThread(boost::bind(&BuildDataTree,
1050 //---------------------------------------------------------------
1053 ::BuildAll(SALOMEDS::SObject_ptr theSObject)
1055 if(MYDEBUG) MESSAGE("Result_i::Build");
1059 }catch(std::exception& exc){
1060 INFOS("Follow exception was occured :\n"<<exc.what());
1063 INFOS("Unknown exception was occured!!!");
1071 //---------------------------------------------------------------
1074 Create(const char* theFileName)
1077 myFileInfo.setFile(theFileName);
1078 myInitFileName = myFileInfo.filePath().latin1();
1079 myName = ::GenerateName(myFileInfo.fileName()).latin1();
1080 if(mySourceId == eRestoredFile){
1081 std::string aTmpDir(SALOMEDS_Tool::GetTmpDir());
1082 static QString aCommand;
1083 aCommand.sprintf("cp %s %s",myFileInfo.absFilePath().latin1(),aTmpDir.c_str());
1084 if(system(aCommand) == -1){
1085 MESSAGE("Create - Can't execute the command :"<<aCommand);
1088 if(MYDEBUG) MESSAGE("Result_i::Create - aCommand = "<<aCommand);
1089 myFileInfo.setFile(QString(aTmpDir.c_str()) + myFileInfo.fileName());
1091 myInput = CreateConvertor(myFileInfo.absFilePath().latin1());
1093 if(myIsBuildImmediately)
1094 Build(SALOMEDS::SObject::_nil());
1097 }catch(std::exception& exc){
1098 INFOS("Follow exception was occured :\n"<<exc.what());
1100 INFOS("Unknown exception was occured!!!");
1106 //---------------------------------------------------------------
1109 Create(SALOMEDS::SObject_ptr theMedSObject)
1111 if(MYDEBUG) MESSAGE("Result_i::Create MedObject from SALOMEDS::SObject_ptr");
1113 myInput = CreateMEDConvertor(theMedSObject);
1119 string aCompDataType = GetComponentDataType(theMedSObject);
1120 myFileInfo.setFile(aCompDataType.c_str());
1121 myInitFileName = aCompDataType;
1123 myName = ::GenerateName("aResult").latin1();
1125 return Build(theMedSObject);
1126 }catch(std::exception& exc){
1127 INFOS("Follow exception was occured :\n"<<exc.what());
1129 INFOS("Unknown exception was occured!!!");
1135 //---------------------------------------------------------------
1138 Create(SALOME_MED::FIELD_ptr theField)
1140 if(MYDEBUG) MESSAGE("Result_i::Create MedObject from SALOME_MED::FIELD_ptr");
1142 myInput = CreateMEDFieldConvertor(theField);
1148 string aCompDataType = "MED";
1149 myFileInfo.setFile(aCompDataType.c_str());
1150 myInitFileName = aCompDataType;
1152 myName = ::GenerateName("aResult").latin1();
1154 CORBA::String_var anIOR = myStudyDocument->ConvertObjectToIOR(theField);
1155 SALOMEDS::SObject_var aFieldSObject = myStudyDocument->FindObjectIOR(anIOR);
1157 return Build(aFieldSObject);
1158 }catch(std::exception& exc){
1159 INFOS("Follow exception was occured :\n"<<exc.what());
1161 INFOS("Unknown exception was occured!!!");
1167 //---------------------------------------------------------------
1170 Restore(SALOMEDS::SObject_ptr theSObject,
1171 const Storable::TRestoringMap& theMap,
1172 const string& thePrefix)
1174 if(MYDEBUG) MESSAGE("Result_i::Restore - " << thePrefix);
1176 mySObject = SALOMEDS::SObject::_duplicate(theSObject);
1177 myStudyDocument = mySObject->GetStudy();
1178 mySComponent = mySObject->GetFatherComponent();
1179 myName = VISU::Storable::FindValue(theMap, "myName").latin1();
1180 myInitFileName = VISU::Storable::FindValue(theMap, "myInitFileName").latin1();
1182 SALOMEDS::SObject_var aRefSObj, aTargetRefSObj;
1183 if (mySObject->FindSubObject(1, aRefSObj) &&
1184 aRefSObj->ReferencedObject(aTargetRefSObj)) {
1185 if(MYDEBUG) MESSAGE("Result_i::GetInput - There is some reference.");
1186 SALOMEDS::SComponent_var aCompRefSObj = aTargetRefSObj->GetFatherComponent();
1187 CORBA::String_var aDataType = aCompRefSObj->ComponentDataType();
1188 myFileInfo.setFile(aDataType.in());
1189 if(MYDEBUG) MESSAGE("Result_i::GetInput - aDataType = " << aDataType);
1190 Engines::Component_var aEngComp =
1191 Base_i::myEnginesLifeCycle->FindOrLoad_Component("FactoryServer", aDataType.in());
1192 if (CORBA::is_nil(aEngComp))
1193 throw std::runtime_error("Restore - There is no aEngComp for the aDataType !!!");
1194 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
1195 SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(aEngComp);
1196 aStudyBuilder->LoadWith(aCompRefSObj, aDriver);
1197 if (strcmp(aDataType, "MED") == 0){
1198 // create field or MED converter
1199 CORBA::Object_var aMedObject = VISU::SObjectToObject(aTargetRefSObj);
1200 SALOME_MED::FIELD_var aField = SALOME_MED::FIELD::_narrow(aMedObject);
1201 if(!CORBA::is_nil(aField))
1202 myInput = CreateMEDFieldConvertor(aField);
1204 myInput = CreateMEDConvertor(aTargetRefSObj);
1207 throw std::runtime_error("GetInput - There is no convertor for the aDataType !!!");
1209 myFileInfo.setFile(thePrefix.c_str());
1211 string aStudyPrefix ("");
1213 aStudyPrefix = SALOMEDS_Tool::GetNameFromPath(myStudyDocument->URL());
1214 if (!myFileInfo.isFile()) {
1215 string aFileName = thePrefix + aStudyPrefix + "_" + myName;
1216 myFileInfo.setFile(aFileName.c_str());
1219 MESSAGE("Result_i::Restore - aFileName = " << myFileInfo.filePath() << "; " << myFileInfo.isFile());
1221 const char* aPathLatin = myFileInfo.filePath().latin1();
1222 if (HDFascii::isASCII(aPathLatin)) {
1223 MESSAGE("ConvertFromASCIIToHDF(" << aPathLatin << ")");
1224 char* aResultPath = HDFascii::ConvertFromASCIIToHDF(aPathLatin);
1225 MESSAGE("ConvertFromASCIIToHDF() DONE : " << aResultPath);
1226 char* aHDFFileName = new char[strlen(aResultPath) + 19];
1227 sprintf(aHDFFileName, "%shdf_from_ascii.hdf", aResultPath);
1229 if (IsMultifile()) { // set this file as new - temporary
1230 static QString aCommand;
1231 aCommand.sprintf("mv %s %s%s",aHDFFileName, aResultPath, myFileInfo.baseName().latin1());
1232 if (system(aCommand) == -1) {
1233 if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - Can't execute the command :" << aCommand);
1236 if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - " << aCommand);
1238 myFileInfo.setFile(QString(aResultPath) + QString(myFileInfo.baseName().latin1()));
1239 } else { // change current temporary file to the new: with hdf-format
1240 static QString aCommand;
1241 aCommand.sprintf("mv %s %s\0",aHDFFileName, myFileInfo.filePath().latin1());
1242 if (system(aCommand.latin1()) == -1) {
1243 if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - Can't execute the command :" << aCommand);
1246 if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - " << aCommand);
1248 SALOMEDS::ListOfFileNames_var anEmptyList = new SALOMEDS::ListOfFileNames;
1249 SALOMEDS_Tool::RemoveTemporaryFiles(aResultPath, anEmptyList.in(), true);
1251 mySourceId = eRestoredFile;
1252 delete(aResultPath);
1253 delete(aHDFFileName);
1254 } else if (!IsMultifile()) {
1255 mySourceId = eRestoredFile;
1259 if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - mySourceId = " << mySourceId);
1260 myInput = CreateConvertor(myFileInfo.filePath().latin1());
1263 aComment.sprintf("myComment=%s;myType=%d;myFileName=%s;myInitFileName=%s",
1264 GetComment(), VISU::TRESULT, myFileInfo.filePath().latin1(),
1265 myInitFileName.c_str()); // Restoring of Python dump
1266 SALOMEDS::GenericAttribute_var anAttr;
1267 if (!theSObject->FindAttribute(anAttr, "AttributeComment"))
1268 throw std::runtime_error("Build - There is no AttributeComment for the SObject !!!");
1269 SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr);
1270 aCmnt->SetValue(aComment.latin1());
1272 bool isBuildAll = VISU::GetResourceMgr()->booleanValue("VISU", "full_med_loading", false);
1276 } catch(std::exception& exc) {
1277 INFOS("Follow exception was occured :\n"<<exc.what());
1279 INFOS("Unknown exception was occured!!!");
1284 //---------------------------------------------------------------
1285 VISU::Result_i::TInput*
1292 //---------------------------------------------------------------
1299 (myIsBuildFields? myIsFieldsDone: true) &&
1300 (myIsBuildMinMax? myIsMinMaxDone: true) &&
1301 (myIsBuildGroups? myIsGroupsDone: true);
1308 return myIsEntitiesDone;
1313 ::SetBuildFields(CORBA::Boolean theIsBuildFields,
1314 CORBA::Boolean theIsCalculateMinMax)
1316 myIsBuildFields = theIsBuildFields;
1317 if(theIsBuildFields)
1318 myIsBuildMinMax = theIsCalculateMinMax;
1320 myIsBuildMinMax = false;
1325 ::SetBuildGroups(CORBA::Boolean theIsBuildGroups)
1327 myIsBuildGroups = theIsBuildGroups;
1334 return myIsFieldsDone;
1341 return myIsGroupsDone;
1348 return myIsMinMaxDone;
1351 //---------------------------------------------------------------
1354 ::ToStream(std::ostringstream& theStr)
1356 if(MYDEBUG) MESSAGE(GetComment());
1357 Storable::DataToStream(theStr,"myName",myName.c_str());
1358 Storable::DataToStream(theStr,"myInitFileName",myInitFileName.c_str());
1359 Storable::DataToStream(theStr,"myCreationId",myCreationId);
1363 //---------------------------------------------------------------
1366 ::Restore(SALOMEDS::SObject_ptr theSObject,
1367 const string& thePrefix,
1368 const Storable::TRestoringMap& theMap)
1370 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
1372 ECreationId aCreationId = ECreationId(Storable::FindValue(theMap,"myCreationId").toInt());
1373 ESourceId aSourceId = eRestoredFile;
1374 if(aCreationId == eImportMed || aCreationId == eImportMedField)
1375 aSourceId = eRestoredComponent;
1377 VISU::Result_i* pResult = new VISU::Result_i(aStudy,aSourceId,aCreationId);
1378 if (pResult == NULL)
1381 return pResult->Restore(theSObject,theMap,thePrefix);
1385 //---------------------------------------------------------------
1388 ::GetRefFatherEntry()
1397 CORBA::String_var anEntry = mySObject->GetID();
1398 return string(anEntry);
1401 const SALOMEDS::SObject_var&
1403 ::GetSObject() const
1408 const SALOMEDS::Study_var&
1410 ::GetStudyDocument() const
1412 return myStudyDocument;
1415 const SALOMEDS::SComponent_var&
1417 ::GetSComponent() const
1419 return mySComponent;
1424 ::GetEntry(const std::string& theComment)
1426 return FindEntryWithComment(myStudyDocument,GetEntry().c_str(),theComment.c_str());
1430 //---------------------------------------------------------------
1434 MESSAGE("Result_i::~Result_i() - this = "<<this);
1435 if (mySourceId == eRestoredFile) {
1436 static QString aCommand;
1437 aCommand.sprintf("rm %s",myFileInfo.filePath().latin1());
1438 MESSAGE("Result_i::~Result_i - system("<<aCommand<<") = "<<system(aCommand));
1439 aCommand.sprintf("rmdir --ignore-fail-on-non-empty %s",myFileInfo.dirPath().latin1());
1440 MESSAGE("Result_i::~Result_i - system("<<aCommand<<") = "<<system(aCommand));
1442 if(myInput) delete myInput;
1445 //=======================================================================
1446 //function : GetAxisInfo
1448 //=======================================================================
1449 const vector< float >* Result_i::GetAxisInfo(const string& theMeshName,
1451 gp_Dir& thePlaneNormal)
1453 const vector< float >* components = NULL;
1455 if ( theAxis < AXIS_X || theAxis > AXIS_Z ) {
1456 MESSAGE(" Bad axis index " << theAxis );
1460 map< string, TGridInfo >::iterator name_info;
1461 name_info = myMeshName2GridInfoMap.find( theMeshName );
1462 TGridInfo * gInfo = 0;
1464 if ( name_info != myMeshName2GridInfoMap.end() )
1466 gInfo = & name_info->second;
1468 else if ( myInput && IsPossible() && theAxis >= AXIS_X && theAxis <= AXIS_Z )
1470 // check presence of theMeshName
1471 const VISU::TMeshMap& meshMap = myInput->GetMeshMap();
1472 if ( meshMap.find( theMeshName ) == meshMap.end() ) {
1473 MESSAGE("No mesh named " << theMeshName );
1477 VISU::PIDMapper anIDMapper = myInput->GetMeshOnEntity(theMeshName,
1479 VISU::TVTKOutput* aMesh = anIDMapper->GetVTKOutput();
1481 if ( !aMesh || aMesh->GetNumberOfCells() == 0 ) {
1482 MESSAGE( "No cells in the mesh: " << theMeshName );
1486 // define axis directions and min cell size in each direction
1487 const int nbAxes = 3;
1489 gp_Vec axDirs[ nbAxes ];
1490 float minSize[3] = { FLT_MAX, FLT_MAX, FLT_MAX };
1491 bool axesComputed = false;
1492 for ( vtkIdType iCell = 0; iCell < aMesh->GetNumberOfCells(); ++iCell )
1494 vtkCell* cell = aMesh->GetCell( iCell );
1495 int nbPnt = cell->GetNumberOfPoints();
1498 vtkPoints * points = cell->GetPoints();
1500 coords[0] = points->GetPoint( 0 );
1501 coords[1] = points->GetPoint( 1 );
1502 coords[2] = points->GetPoint( 3 );
1503 coords[3] = points->GetPoint( 4 );
1504 gp_Pnt p0( coords[0][0], coords[0][1], coords[0][2] );
1505 for ( iAx = 0; iAx < nbAxes; ++iAx )
1507 float* coo = coords[ iAx + 1 ];
1508 gp_Pnt p( coo[0], coo[1], coo[2] );
1510 float size = p0.SquareDistance( p );
1511 if ( size > FLT_MIN && size < minSize[ iAx ] )
1512 minSize[ iAx ] = size;
1514 if ( !axesComputed ) {
1515 gp_Vec dir( p0, p );
1516 if ( dir.SquareMagnitude() <= DBL_MIN )
1518 axDirs[ iAx ] = dir;
1521 if ( iAx == nbAxes )
1522 axesComputed = true;
1524 if ( !axesComputed ) {
1525 MESSAGE("No good hexahedrons in the mesh: " << theMeshName );
1529 // compute axes dirs
1530 gInfo = & myMeshName2GridInfoMap[ theMeshName ];
1531 for ( iAx = 0; iAx < nbAxes; ++iAx )
1533 int iPrev = ( iAx == 0 ) ? 2 : iAx - 1;
1534 int iNext = ( iAx == 2 ) ? 0 : iAx + 1;
1535 gInfo->myAxis[ iAx ] = axDirs[ iPrev ] ^ axDirs[ iNext ];
1538 // get and sort intermediate component values - projections of nodes
1539 // on axis direction; define bnd box
1540 set< float > comps[ 3 ];
1542 vtkPoints * points = aMesh->GetPoints();
1543 vtkIdType iP, nbP = aMesh->GetNumberOfPoints();
1544 for ( iP = 0; iP < nbP; ++iP )
1546 float* coo = points->GetPoint( iP );
1547 gp_Pnt p( coo[0], coo[1], coo[2] );
1549 for ( iAx = 0; iAx < nbAxes; ++iAx ) {
1550 const gp_Dir& dir = gInfo->myAxis[ iAx ];
1551 float dot = dir.XYZ() * p.XYZ();
1552 comps[ iAx ].insert( dot );
1556 // find a range of projections of bnd box corners on each axis
1557 float range[3], firstValue[3];
1558 double x[2],y[2],z[2];
1559 box.Get(x[0],y[0],z[0],x[1],y[1],z[1]);
1560 for ( iAx = 0; iAx < nbAxes; ++iAx ) {
1561 set< float > bndComps;
1562 const gp_Dir& dir = gInfo->myAxis[ iAx ];
1563 for ( int iX = 0; iX < 2; ++iX ) {
1564 for ( int iY = 0; iY < 2; ++iY ) {
1565 for ( int iZ = 0; iZ < 2; ++iZ ) {
1566 gp_Pnt p( x[ iX ], y[ iY ], z[ iZ ] );
1567 float dot = dir.XYZ() * p.XYZ();
1568 bndComps.insert( dot );
1572 firstValue[ iAx ] = *bndComps.begin();
1573 range[ iAx ] = *bndComps.rbegin() - *bndComps.begin();
1576 // compute component values
1577 for ( iAx = 0; iAx < nbAxes; ++iAx )
1579 list< float > values;
1581 set< float >& comp = comps[ iAx ];
1582 set< float >::iterator val = comp.begin();
1583 float bnd = -1., rng = range[ iAx ], first = firstValue[ iAx ];
1584 float tol = 0.1 * sqrt( minSize[ iAx ]) / rng;
1585 for ( ; val != comp.end(); ++val ) {
1586 float value = ( *val - first ) / rng;
1587 if ( value > bnd ) {
1588 values.push_back( value );
1593 // store values in gInfo
1594 vector< float >& myComp = gInfo->myComponets[ iAx ];
1595 myComp.resize( nbVals );
1596 list< float >::iterator v = values.begin();
1597 for ( int i = 0; v != values.end(); ++v )
1602 // set return values
1605 thePlaneNormal = gInfo->myAxis[ theAxis ];
1606 components = & gInfo->myComponets[ theAxis ];