// QT Includes
#include <qstring.h>
#include <qfileinfo.h>
+#include <qsemaphore.h>
+#include <qthread.h>
// VTK Includes
#include <vtkCell.h>
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)
{
}
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();
}
}
}
+
+ aStudyBuilder->CommitCommand();
}
-//---------------------------------------------------------------
namespace
{
+ //---------------------------------------------------------------
struct TMemManager
{
VISU::Result_i* myResult;
}
};
+
+ //---------------------------------------------------------------
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
if (myStudyId == aCStudy->StudyId()) {
MESSAGE("Result_i::updateObjectBrowser");
anApp->updateObjectBrowser();
+ myIsDone = true;
break;
}
}
}
}
};
-}
-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;
+ }
}
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;
}
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"<<exc.what());
return NULL;
}
- aStudyBuilder->CommitCommand();
-
return this;
}