From d23ff02a3da21e4f3cbb7f5f62a2a4ed338b544b Mon Sep 17 00:00:00 2001 From: apo Date: Mon, 21 Nov 2005 10:01:18 +0000 Subject: [PATCH] Fix for Bug GVIEW10573 time to load sandia file too long Now all entites (fields, groups and families) of a MED file will be processed in different threads and published into data tree browser automaticaly. Corresponding flags that let to know what type of entities already prepared for usage introduced --- idl/VISU_Gen.idl | 9 + src/VISU_I/VISU_Result_i.cc | 444 ++++++++++++++++++++---------------- src/VISU_I/VISU_Result_i.hh | 10 +- 3 files changed, 268 insertions(+), 195 deletions(-) diff --git a/idl/VISU_Gen.idl b/idl/VISU_Gen.idl index 2b04645b..77e4921e 100644 --- a/idl/VISU_Gen.idl +++ b/idl/VISU_Gen.idl @@ -1254,6 +1254,15 @@ module VISU { /*! Reads all data from the corresponding sources. By default the data is loaded on demand. */ boolean BuildAll(); + + /*! Allow to check is corresponding MED fields already loaded or not */ + boolean IsFieldsDone(); + + /*! Allow to check is corresponding MED groups and families already loaded or not */ + boolean IsGroupsDone(); + + /*! Allow to check is min / max calculation over field's components already perfrormed or not */ + boolean IsMinMaxDone(); }; //------------------------------------------------------- diff --git a/src/VISU_I/VISU_Result_i.cc b/src/VISU_I/VISU_Result_i.cc index 2b9ea7f9..b90709f9 100644 --- a/src/VISU_I/VISU_Result_i.cc +++ b/src/VISU_I/VISU_Result_i.cc @@ -46,6 +46,8 @@ // QT Includes #include #include +#include +#include // VTK Includes #include @@ -132,13 +134,17 @@ string GetComponentDataType (SALOMEDS::SObject_ptr theSObject) const string VISU::Result_i::myComment = "RESULT"; const char* VISU::Result_i::GetComment() const { return myComment.c_str();} -VISU::Result_i::Result_i (SALOMEDS::Study_ptr theStudy, - const ESourceId& theSourceId, - const ECreationId& theCreationId): +VISU::Result_i +::Result_i (SALOMEDS::Study_ptr theStudy, + const ESourceId& theSourceId, + const ECreationId& theCreationId): myStudyDocument(SALOMEDS::Study::_duplicate(theStudy)), myCreationId(theCreationId), mySourceId(theSourceId), myInput(NULL), + myIsFieldsDone(0), + myIsGroupsDone(0), + myIsMinMaxDone(0), myIsDone(0) { } @@ -260,6 +266,9 @@ void VISU::Result_i ::BuildEntities(SALOMEDS::SObject_ptr theSObject) { + SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder(); + aStudyBuilder->NewCommand(); // There is a transaction + QString aComment; myInput->BuildEntities(); string aRefFatherEntry = GetRefFatherEntry(); @@ -361,12 +370,14 @@ VISU::Result_i } } } + + aStudyBuilder->CommitCommand(); } -//--------------------------------------------------------------- namespace { + //--------------------------------------------------------------- struct TMemManager { VISU::Result_i* myResult; @@ -382,12 +393,16 @@ namespace } }; + + //--------------------------------------------------------------- struct TUpdateObjBrowser: public SALOME_Event { int myStudyId; - - TUpdateObjBrowser(const int theStudyId): - myStudyId(theStudyId) + CORBA::Boolean& myIsDone; + TUpdateObjBrowser(const int theStudyId, + CORBA::Boolean& theIsDone): + myStudyId(theStudyId), + myIsDone(theIsDone) {} virtual @@ -404,6 +419,7 @@ namespace if (myStudyId == aCStudy->StudyId()) { MESSAGE("Result_i::updateObjectBrowser"); anApp->updateObjectBrowser(); + myIsDone = true; break; } } @@ -413,204 +429,222 @@ namespace } } }; -} -void -VISU::Result_i -::BuildGroups() -{ - TMemManager aMemManager(this); - QString aComment; - myInput->BuildGroups(); - string aRefFatherEntry = GetRefFatherEntry(); - const TMeshMap& aMeshMap = myInput->GetMeshMap(); - TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin(); - for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){ - const string& aMeshName = aMeshMapIter->first; - const PMesh& aMesh = aMeshMapIter->second; - - const TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap; - if(aMeshOnEntityMap.empty()) - continue; - - TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.begin(); - for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){ - const TEntity& anEntity = aMeshOnEntityMapIter->first; - const PMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second; - - const TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap; - TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin(); - for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){ - const string& aFamilyName = aFamilyMapIter->first; - const PFamily& aFamily = aFamilyMapIter->second; - aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s", - TFAMILY, - aMeshName.c_str(), - anEntity, - aFamilyName.c_str()); - aFamily->myEntry = - CreateAttributes(myStudyDocument, - aMeshOnEntity->myEntry.c_str(), - aRefFatherEntry.c_str(), - "", - aFamilyName.c_str(), - "", - aComment.latin1(), - true); + //--------------------------------------------------------------- + void + BuildGroups(VISU::Result_i* theResult, + VISU_Convertor* theInput, + CORBA::Boolean& theIsDone, + SALOMEDS::Study_var theStudyDocument, + const std::string& theRefFatherEntry) + { + TMemManager aMemManager(theResult); + + SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder(); + aStudyBuilder->NewCommand(); // There is a transaction + + QString aComment; + theInput->BuildGroups(); + const TMeshMap& aMeshMap = theInput->GetMeshMap(); + TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin(); + for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){ + const string& aMeshName = aMeshMapIter->first; + const PMesh& aMesh = aMeshMapIter->second; + + const TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap; + if(aMeshOnEntityMap.empty()) + continue; + + TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.begin(); + for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){ + const TEntity& anEntity = aMeshOnEntityMapIter->first; + const PMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second; + + const TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap; + TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin(); + for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){ + const string& aFamilyName = aFamilyMapIter->first; + const PFamily& aFamily = aFamilyMapIter->second; + aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s", + TFAMILY, + aMeshName.c_str(), + anEntity, + aFamilyName.c_str()); + aFamily->myEntry = + CreateAttributes(theStudyDocument, + aMeshOnEntity->myEntry.c_str(), + theRefFatherEntry.c_str(), + "", + aFamilyName.c_str(), + "", + aComment.latin1(), + true); + } } - } - //Importing groups - const TGroupMap& aGroupMap = aMesh->myGroupMap; - if(!aGroupMap.empty()){ - aComment.sprintf("myComment=GROUPS;myMeshName=%s", - aMeshName.c_str()); - string aGroupsEntry = - CreateAttributes(myStudyDocument, - aMesh->myEntry.c_str(), - aRefFatherEntry.c_str(), - "", - "Groups", - "", - aComment.latin1(), - true); - TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin(); - for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){ - const string& aGroupName = aGroupMapIter->first; - const PGroup& aGroup = aGroupMapIter->second; - aComment.sprintf("myComment=GROUP;myType=%d;myMeshName=%s;myName=%s", - TGROUP,aMeshName.c_str(),aGroupName.c_str()); - aGroup->myEntry = - CreateAttributes(myStudyDocument, - aGroupsEntry.c_str(), - aRefFatherEntry.c_str(), + //Importing groups + const TGroupMap& aGroupMap = aMesh->myGroupMap; + if(!aGroupMap.empty()){ + aComment.sprintf("myComment=GROUPS;myMeshName=%s", + aMeshName.c_str()); + string aGroupsEntry = + CreateAttributes(theStudyDocument, + aMesh->myEntry.c_str(), + theRefFatherEntry.c_str(), "", - aGroupName.c_str(), + "Groups", "", aComment.latin1(), true); - const TFamilySet& aFamilySet = aGroup->myFamilySet; - TFamilySet::const_iterator aFamilyIter = aFamilySet.begin(); - for(; aFamilyIter != aFamilySet.end(); aFamilyIter++){ - const PFamily& aFamily = *aFamilyIter; - CreateReference(myStudyDocument, - aGroup->myEntry, - aFamily->myEntry); + TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin(); + for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){ + const string& aGroupName = aGroupMapIter->first; + const PGroup& aGroup = aGroupMapIter->second; + aComment.sprintf("myComment=GROUP;myType=%d;myMeshName=%s;myName=%s", + TGROUP,aMeshName.c_str(),aGroupName.c_str()); + aGroup->myEntry = + CreateAttributes(theStudyDocument, + aGroupsEntry.c_str(), + theRefFatherEntry.c_str(), + "", + aGroupName.c_str(), + "", + aComment.latin1(), + true); + const TFamilySet& aFamilySet = aGroup->myFamilySet; + TFamilySet::const_iterator aFamilyIter = aFamilySet.begin(); + for(; aFamilyIter != aFamilySet.end(); aFamilyIter++){ + const PFamily& aFamily = *aFamilyIter; + CreateReference(theStudyDocument, + aGroup->myEntry, + aFamily->myEntry); + } } } } - } + + aStudyBuilder->CommitCommand(); - ProcessVoidEvent(new TUpdateObjBrowser(myStudyDocument->StudyId())); -} + ProcessVoidEvent(new TUpdateObjBrowser(theStudyDocument->StudyId(),theIsDone)); + } -//--------------------------------------------------------------- -void -VISU::Result_i -::BuildFields() -{ - TMemManager aMemManager(this); + //--------------------------------------------------------------- + void + BuildFields(VISU::Result_i* theResult, + VISU_Convertor* theInput, + CORBA::Boolean& theIsDone, + SALOMEDS::Study_var theStudyDocument, + const std::string& theRefFatherEntry) + { + TMemManager aMemManager(theResult); - QString aComment; - myInput->BuildFields(); - string aRefFatherEntry = GetRefFatherEntry(); - const TMeshMap& aMeshMap = myInput->GetMeshMap(); - TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin(); - for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){ - const string& aMeshName = aMeshMapIter->first; - const PMesh& aMesh = aMeshMapIter->second; - - const TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap; - if(aMeshOnEntityMap.empty()) - continue; - - //Import fields - string aFieldsEntry; - bool anIsFieldsEntryCreated = false; - - TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.begin(); - for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){ - const TEntity& anEntity = aMeshOnEntityMapIter->first; - const PMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second; - const TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap; - TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin(); - for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){ - if(!anIsFieldsEntryCreated){ - aComment.sprintf("myComment=FIELDS;myMeshName=%s", - aMeshName.c_str()); - aFieldsEntry = - CreateAttributes(myStudyDocument, - aMesh->myEntry.c_str(), - aRefFatherEntry.c_str(), - "", - "Fields", - "", - aComment.latin1(), - true); - anIsFieldsEntryCreated = true; - } - const string& aFieldName = aFieldMapIter->first; - const PField& aField = aFieldMapIter->second; - const TValField& aValField = aField->myValField; - QString aFieldNameWithUnit = ::GenerateFieldName(aFieldName,aField->myUnitNames[0]); - aComment.sprintf("myComment=FIELD;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s;myNbTimeStamps=%d;myNumComponent=%d", - VISU::TFIELD, - aMeshName.c_str(), - anEntity, - aFieldName.c_str(), - aValField.size(), - aField->myNbComp); - aField->myEntry = - CreateAttributes(myStudyDocument, - aFieldsEntry.c_str(), - aRefFatherEntry.c_str(), - "", - aFieldNameWithUnit.latin1(), - "", - aComment.latin1(), - true); - CreateReference(myStudyDocument, - aField->myEntry, - aMeshOnEntity->myEntry); - TValField::const_iterator aValFieldIter = aValField.begin(); - for(; aValFieldIter != aValField.end(); aValFieldIter++){ - int aTimeStamp = aValFieldIter->first; - const PValForTime& aValForTime = aValFieldIter->second; - aComment.sprintf("myComment=TIMESTAMP;myType=%d;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d", - VISU::TTIMESTAMP, + SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder(); + aStudyBuilder->NewCommand(); // There is a transaction + + QString aComment; + theInput->BuildFields(); + const TMeshMap& aMeshMap = theInput->GetMeshMap(); + TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin(); + for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){ + const string& aMeshName = aMeshMapIter->first; + const PMesh& aMesh = aMeshMapIter->second; + + const TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap; + if(aMeshOnEntityMap.empty()) + continue; + + //Import fields + string aFieldsEntry; + bool anIsFieldsEntryCreated = false; + + TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.begin(); + for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){ + const TEntity& anEntity = aMeshOnEntityMapIter->first; + const PMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second; + const TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap; + TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin(); + for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){ + if(!anIsFieldsEntryCreated){ + aComment.sprintf("myComment=FIELDS;myMeshName=%s", + aMeshName.c_str()); + aFieldsEntry = + CreateAttributes(theStudyDocument, + aMesh->myEntry.c_str(), + theRefFatherEntry.c_str(), + "", + "Fields", + "", + aComment.latin1(), + true); + anIsFieldsEntryCreated = true; + } + const string& aFieldName = aFieldMapIter->first; + const PField& aField = aFieldMapIter->second; + const TValField& aValField = aField->myValField; + QString aFieldNameWithUnit = ::GenerateFieldName(aFieldName,aField->myUnitNames[0]); + aComment.sprintf("myComment=FIELD;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s;myNbTimeStamps=%d;myNumComponent=%d", + VISU::TFIELD, aMeshName.c_str(), anEntity, aFieldName.c_str(), - aTimeStamp, + aValField.size(), aField->myNbComp); - string aTimeStampId = VISU_Convertor::GenerateName(aValForTime->myTime); - aValForTime->myEntry = - CreateAttributes(myStudyDocument, - aField->myEntry.c_str(), - aRefFatherEntry.c_str(), + aField->myEntry = + CreateAttributes(theStudyDocument, + aFieldsEntry.c_str(), + theRefFatherEntry.c_str(), "", - aTimeStampId.c_str(), + aFieldNameWithUnit.latin1(), "", aComment.latin1(), true); + CreateReference(theStudyDocument, + aField->myEntry, + aMeshOnEntity->myEntry); + TValField::const_iterator aValFieldIter = aValField.begin(); + for(; aValFieldIter != aValField.end(); aValFieldIter++){ + int aTimeStamp = aValFieldIter->first; + const PValForTime& aValForTime = aValFieldIter->second; + aComment.sprintf("myComment=TIMESTAMP;myType=%d;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d", + VISU::TTIMESTAMP, + aMeshName.c_str(), + anEntity, + aFieldName.c_str(), + aTimeStamp, + aField->myNbComp); + string aTimeStampId = VISU_Convertor::GenerateName(aValForTime->myTime); + aValForTime->myEntry = + CreateAttributes(theStudyDocument, + aField->myEntry.c_str(), + theRefFatherEntry.c_str(), + "", + aTimeStampId.c_str(), + "", + aComment.latin1(), + true); + } } } } - } - - ProcessVoidEvent(new TUpdateObjBrowser(myStudyDocument->StudyId())); -} + + aStudyBuilder->CommitCommand(); + ProcessVoidEvent(new TUpdateObjBrowser(theStudyDocument->StudyId(),theIsDone)); + } -//--------------------------------------------------------------- -void -VISU::Result_i -::BuildMinMax() -{ - TMemManager aMemManager(this); - myInput->BuildMinMax(); + //--------------------------------------------------------------- + void + BuildMinMax(VISU::Result_i* theResult, + VISU_Convertor* theInput, + CORBA::Boolean theIsDone) + { + TMemManager aMemManager(theResult); + + theInput->BuildMinMax(); + theIsDone = true; + } } @@ -628,13 +662,29 @@ VISU::Result_i BuildEntities(theSObject); - boost::thread(boost::bind(&Result_i::BuildFields,this)); - - boost::thread(boost::bind(&Result_i::BuildGroups,this)); - - boost::thread(boost::bind(&Result_i::BuildMinMax,this)); - - aStudyBuilder->CommitCommand(); + std::string aRefFatherEntry = GetRefFatherEntry(); + + // To start build of the fields + boost::thread aThread1(boost::bind(&BuildFields, + this, + myInput, + myIsFieldsDone, + myStudyDocument, + aRefFatherEntry)); + + // To start build of the groups + boost::thread aThread2(boost::bind(&BuildGroups, + this, + myInput, + myIsGroupsDone, + myStudyDocument, + aRefFatherEntry)); + + // To start min/max calculation + boost::thread aThread3(boost::bind(&BuildMinMax, + this, + myInput, + myIsMinMaxDone)); return this; } @@ -646,14 +696,28 @@ VISU::Storable* VISU::Result_i ::BuildAll(SALOMEDS::SObject_ptr theSObject) { - SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder(); - aStudyBuilder->NewCommand(); // There is a transaction - if(MYDEBUG) MESSAGE("Result_i::Build"); try{ BuildEntities(theSObject); - BuildFields(); - BuildGroups(); + + std::string aRefFatherEntry = GetRefFatherEntry(); + + BuildFields(this, + myInput, + myIsFieldsDone, + myStudyDocument, + aRefFatherEntry); + + BuildGroups(this, + myInput, + myIsGroupsDone, + myStudyDocument, + aRefFatherEntry); + + BuildMinMax(this, + myInput, + myIsMinMaxDone); + BuildAll(); }catch(std::exception& exc){ INFOS("Follow exception was occured :\n"<CommitCommand(); - return this; } diff --git a/src/VISU_I/VISU_Result_i.hh b/src/VISU_I/VISU_Result_i.hh index f560ee11..af6c757b 100644 --- a/src/VISU_I/VISU_Result_i.hh +++ b/src/VISU_I/VISU_Result_i.hh @@ -58,9 +58,9 @@ namespace VISU{ virtual VISU::VISUType GetType() { return VISU::TRESULT;} virtual CORBA::Boolean BuildAll(); - virtual void BuildGroups(); - virtual void BuildFields(); - virtual void BuildMinMax(); + virtual CORBA::Boolean IsFieldsDone(); + virtual CORBA::Boolean IsGroupsDone(); + virtual CORBA::Boolean IsMinMaxDone(); typedef VISU_Convertor TInput; @@ -78,6 +78,9 @@ namespace VISU{ virtual Storable* BuildAll(SALOMEDS::SObject_ptr theSObject) ; void BuildEntities(SALOMEDS::SObject_ptr theSObject); + CORBA::Boolean myIsFieldsDone; + CORBA::Boolean myIsGroupsDone; + CORBA::Boolean myIsMinMaxDone; public: virtual int IsPossible(); @@ -106,7 +109,6 @@ namespace VISU{ private: SALOMEDS::SObject_var mySObject; - SALOMEDS::SObject_var myRefSObject; SALOMEDS::Study_var myStudyDocument; SALOMEDS::SComponent_var mySComponent; -- 2.39.2