-using namespace std;
-// File: VISU_Result_i.cc
-// Created: Fri Jan 10 13:56:05 2003
-// Author: Alexey PETROV
-// <apo@ivanox.nnov.matra-dtv.fr>
+// VISU OBJECT : interactive object for VISU entities implementation
+//
+// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+//
+//
+// File : VISU_Result_i.cc
+// Author : Alexey PETROV
+// Module : VISU
#include "VISU_Result_i.hh"
+
#include "VISU_Convertor_impl.hxx"
#include "VISU_CorbaMedConvertor.hxx"
-#include "VISU_Extractor.hxx"
-using namespace VISU;
+#include "VISU_PipeLine.hxx"
+
+#include "SUIT_ResourceMgr.h"
#include "SALOMEDS_Tool.hxx"
+#include "HDFascii.hxx"
+// QT Includes
#include <qstring.h>
#include <qfileinfo.h>
-#include <fstream>
+// VTK Includes
+#include <vtkCell.h>
+#include <vtkUnstructuredGrid.h>
-#include <vtkUnstructuredGridReader.h>
-#include <vtkUnstructuredGridWriter.h>
+// OCCT Includes
+#include <Bnd_Box.hxx>
+using namespace VISU;
using namespace std;
-#ifdef DEBUG
-static int MYDEBUG = 1;
-static int MYDEBUGWITHFILES = 0;
+#ifdef _DEBUG_
+static int MYDEBUG = 0;
#else
static int MYDEBUG = 0;
-static int MYDEBUGWITHFILES = 0;
#endif
-VISU::Result_var VISU::FindResult(SALOMEDS::SObject_ptr theSObject){
+VISU::Result_var VISU::FindResult (SALOMEDS::SObject_ptr theSObject)
+{
SALOMEDS::SComponent_var aSComponent = theSObject->GetFatherComponent();
SALOMEDS::SObject_var aFather = theSObject->GetFather();
- CORBA::String_var aComponentID(aSComponent->GetID());
- CORBA::String_var aFatherID(aFather->GetID());
+ CORBA::String_var aComponentID (aSComponent->GetID());
+ CORBA::String_var aFatherID (aFather->GetID());
VISU::Result_var aResult;
- while(strcmp(aComponentID,aFatherID) != 0){
+ while (strcmp(aComponentID, aFatherID) != 0) {
CORBA::Object_var anObject = VISU::SObjectToObject(aFather);
- if(!CORBA::is_nil(anObject)){
+ if (!CORBA::is_nil(anObject)) {
aResult = VISU::Result::_narrow(anObject);
- if(!aResult->_is_nil()) return aResult;
+ if (!aResult->_is_nil()) return aResult;
}
aFather = aFather->GetFather();
+ aFatherID = aFather->GetID();
}
return aResult;
}
-QString VISU::GenerateName(const string& theFmt, int theId){
- static QString aName;
- if(theId > 0)
- aName.sprintf("%s:%d",theFmt.c_str(),theId);
- else
- aName.sprintf("%s",theFmt.c_str());
- return aName;
-}
-
-void VISU::WriteToFile(vtkUnstructuredGrid* theDataSet, const string& theFileName){
- vtkUnstructuredGridWriter* aWriter = vtkUnstructuredGridWriter::New();
- aWriter->SetFileName(theFileName.c_str());
- aWriter->SetInput(theDataSet);
- aWriter->Write();
- aWriter->Delete();
-}
-
-QString GenerateName(const char* theName){
+QString GenerateName (const char* theName)
+{
typedef map<string,int> TNameMap;
static TNameMap aMap;
TNameMap::const_iterator i = aMap.find(theName);
QString tmp;
- if(i == aMap.end()) {
+ if (i == aMap.end()) {
aMap[theName] = 0;
tmp = theName;
- }else{
+ } else {
tmp = VISU::GenerateName(theName,++aMap[theName]);
}
if(MYDEBUG) MESSAGE("GenerateName - "<<tmp<<" from - "<<theName<<"; " <<aMap[theName]);
return tmp;
}
-void CreateReference(SALOMEDS::Study_ptr theStudyDocument,
- const string& theFatherEntry, const string& theRefEntry)
+QString GenerateFieldName (const string& theName, const string& theUnits)
+{
+ static QString aName;
+ const string tmp (theUnits.size(),' ');
+ if (theUnits == "" || theUnits == tmp)
+ aName.sprintf("%s, -",theName.c_str());
+ else
+ aName.sprintf("%s, %s",theName.c_str(),theUnits.c_str());
+ aName = aName.simplifyWhiteSpace();
+ return aName.latin1();
+}
+
+void CreateReference (SALOMEDS::Study_ptr theStudyDocument,
+ const string& theFatherEntry, const string& theRefEntry)
{
SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
SALOMEDS::SObject_var aFather = theStudyDocument->FindObjectID(theFatherEntry.c_str());
aStudyBuilder->Addreference(newObj,aRefSObj);
}
+string GetComponentDataType (SALOMEDS::SObject_ptr theSObject)
+{
+ SALOMEDS::SComponent_var aCompRefSObj = theSObject->GetFatherComponent();
+ CORBA::String_var aDataType = aCompRefSObj->ComponentDataType();
+ return aDataType.in();
+}
+
//==============================================================================
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) {
- myStudyDocument = SALOMEDS::Study::_duplicate(theStudy);
+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),
+ myIsDone(0)
+{
}
-VISU::Storable* VISU::Result_i::Build() {
- if(MYDEBUG) MESSAGE("Result_i::Build");
+
+void VISU::Result_i::RemoveFromStudy()
+{
+ // Remove the result with all presentations and other possible sub-objects
+ VISU::RemoveFromStudy(mySObject,false);
+}
+
+
+int
+VISU::Result_i::
+IsPossible()
+{
+ try{
+ float aSize = myInput->GetSize();
+ bool aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
+ MESSAGE("Result_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<float(aResult));
+ return aResult;
+ }catch(std::exception& exc){
+ INFOS("Follow exception was occured :\n"<<exc.what());
+ }catch(...){
+ INFOS("Unknown exception was occured!");
+ }
+ return 0;
+}
+
+
+CORBA::Boolean
+VISU::Result_i::
+BuildAll()
+{
+ if(MYDEBUG) MESSAGE("Result_i::Build - myIsDone = "<<myIsDone);
+ if(myIsDone) return 1;
+ if(!IsPossible()) return 0;
try{
+ const VISU::TMeshMap& aMeshMap = myInput->GetMeshMap();
+ VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
+ for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
+ const string& aMeshName = aMeshMapIter->first;
+ const VISU::PMesh aMesh = aMeshMapIter->second;
+ const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
+ VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter;
+ //Import fields
+ aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
+ for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
+ const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
+ const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
+ const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
+ VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
+ for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){
+ const string& aFieldName = aFieldMapIter->first;
+ const VISU::PField aField = aFieldMapIter->second;
+ const VISU::TValField& aValField = aField->myValField;
+ VISU::TValField::const_iterator aValFieldIter = aValField.begin();
+ for(; aValFieldIter != aValField.end(); aValFieldIter++){
+ int aTimeStamp = aValFieldIter->first;
+ try{
+ myInput->GetTimeStampOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp);
+ }catch(std::exception& exc){
+ INFOS("Follow exception was occured :\n"<<exc.what());
+ }catch(...){
+ INFOS("Unknown exception was occured!!!");
+ }
+ }
+ }
+ //Importing groups
+ const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
+ VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin();
+ for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){
+ const string& aGroupName = aGroupMapIter->first;
+ try{
+ myInput->GetMeshOnGroup(aMeshName,aGroupName);
+ }catch(std::exception& exc){
+ INFOS("Follow exception was occured :\n"<<exc.what());
+ }catch(...){
+ INFOS("Unknown exception was occured!!!");
+ }
+ }
+ //Import families
+ const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
+ VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
+ for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
+ const string& aFamilyName = aFamilyMapIter->first;
+ try{
+ myInput->GetMeshOnEntity(aMeshName,anEntity,aFamilyName);
+ }catch(std::exception& exc){
+ INFOS("Follow exception was occured :\n"<<exc.what());
+ }catch(...){
+ INFOS("Unknown exception was occured!!!");
+ }
+ }
+ //Import mesh on entity
+ try{
+ myInput->GetMeshOnEntity(aMeshName,anEntity);
+ }catch(std::exception& exc){
+ INFOS("Follow exception was occured :\n"<<exc.what());
+ }catch(...){
+ INFOS("Unknown exception was occured!!!");
+ }
+ }
+ }
+ myIsDone = 1;
+ }catch(std::exception& exc){
+ INFOS("Follow exception was occured :\n"<<exc.what());
+ }catch(...){
+ INFOS("Unknown exception was occured!!!");
+ }
+ return myIsDone;
+}
+
+
+VISU::Storable*
+VISU::Result_i::
+Build(SALOMEDS::SObject_ptr theSObject)
+{
+ if(MYDEBUG) MESSAGE("Result_i::Build");
+
+ SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
+ aStudyBuilder->NewCommand(); // There is a transaction
+
+ try {
+ const TMeshMap& aMeshMap = myInput->GetMeshMap();
+ if (aMeshMap.empty())
+ throw std::runtime_error("Build - There is no any mesh information in the file !!!");
+
mySComponent = FindOrCreateVisuComponent(myStudyDocument);
CORBA::String_var aSComponentEntry = mySComponent->GetID(), anIOR(GetID());
string aRefFatherEntry = GetRefFatherEntry();
+
QString aComment;
- aComment.sprintf("myComment=%s;myType=%d;myName=%s;myFileName=%s",
- GetComment(),VISU::TRESULT,myName.c_str(),myFileInfo.filePath().latin1());
- string aResultEntry = CreateAttributes(myStudyDocument,aSComponentEntry,aRefFatherEntry.c_str(),
- anIOR,myName.c_str(),"",aComment.latin1(),true);
+ aComment.sprintf("myComment=%s;myType=%d;myFileName=%s;myInitFileName=%s",
+ GetComment(), VISU::TRESULT, myFileInfo.filePath().latin1(),
+ myInitFileName.c_str()); // Restoring of Python dump
+ string aResultEntry =
+ CreateAttributes(myStudyDocument, aSComponentEntry, aRefFatherEntry.c_str(),
+ anIOR, myName.c_str(), "", aComment.latin1(), true);
+
mySObject = myStudyDocument->FindObjectID(aResultEntry.c_str());
- if(mySObject->_is_nil()) throw std::runtime_error("Build - There is no SObject for hte Result !!!");
- const TMeshMap& aMeshMap = *(myInput->GetMeshMap());
- if( &aMeshMap != NULL) {//apo
- TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
- for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
- const string& aMeshName = aMeshMapIter->first;
- const VISU::TMesh& aMesh = aMeshMapIter->second;
- const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh.myMeshOnEntityMap;
- VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter;
- aComment.sprintf("myComment=MESH;myResultName=%s;myName=%s;myDim=%d",
- myName.c_str(),aMeshName.c_str(),aMesh.myDim);
- string aMeshEntry = CreateAttributes(myStudyDocument,aResultEntry.c_str(),aRefFatherEntry.c_str(),
- "",aMeshName.c_str(),"",aComment.latin1(),true);
- if(aMeshOnEntityMap.empty()) continue;
- aComment.sprintf("myComment=FAMILIES;myResultName=%s;myMeshName=%s",myName.c_str(),aMeshName.c_str());
- string aSubMeshesEntry = CreateAttributes(myStudyDocument,aMeshEntry.c_str(),aRefFatherEntry.c_str(),
- "","Families","",aComment.latin1(),true);
- //Import entities and according families
- aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
- typedef map<VISU::TEntity,string> TEntity2Entry;
- TEntity2Entry aEntity2Entry;
- for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
- const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
- aComment.sprintf("myComment=ENTITY;myType=%d;myResultName=%s;myMeshName=%s;myId=%d",
- VISU::TENTITY,myName.c_str(),aMeshName.c_str(),anEntity);
- string anEntityName;
- switch(anEntity){
- case VISU::NODE_ENTITY : anEntityName = "onNodes"; break;
- case VISU::EDGE_ENTITY : anEntityName = "onEdges"; break;
- case VISU::FACE_ENTITY : anEntityName = "onFaces"; break;
- case VISU::CELL_ENTITY : anEntityName = "onCells"; break;
- default:
- throw std::runtime_error("Build >> Value of entity is incorrect!");
- }
- aEntity2Entry[anEntity] = CreateAttributes(myStudyDocument,aSubMeshesEntry.c_str(),aRefFatherEntry.c_str(),
- "",anEntityName.c_str(),"",aComment.latin1(),true);
- const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
- const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity.myFamilyMap;
- VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
- for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
- const string& aFamilyName = aFamilyMapIter->first;
- aComment.sprintf("myComment=FAMILY;myType=%d;myResultName=%s;myMeshName=%s;myEntityId=%d;myName=%s",
- VISU::TFAMILY,myName.c_str(),aMeshName.c_str(),anEntity,aFamilyName.c_str());
- CreateAttributes(myStudyDocument,aEntity2Entry[anEntity].c_str(),aRefFatherEntry.c_str(),
- "",aFamilyName.c_str(),"",aComment.latin1(),true);
- }
+ if (mySObject->_is_nil())
+ throw std::runtime_error("Build - There is no SObject for the Result !!!");
+
+ if (!CORBA::is_nil(theSObject)) {
+ CORBA::String_var aString = theSObject->GetID();
+ CreateReference(myStudyDocument, aResultEntry, aString.in());
+ }
+
+ TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
+ for (; aMeshMapIter != aMeshMap.end(); aMeshMapIter++) {
+ const string& aMeshName = aMeshMapIter->first;
+ const VISU::PMesh aMesh = aMeshMapIter->second;
+ aComment.sprintf("myComment=MESH;myName=%s;myDim=%d",
+ aMeshName.c_str(), aMesh->myDim);
+ string aMeshEntry =
+ CreateAttributes(myStudyDocument, aResultEntry.c_str(), aRefFatherEntry.c_str(),
+ "", aMeshName.c_str(), "", aComment.latin1(), true);
+
+ const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
+ if (aMeshOnEntityMap.empty()) continue;
+
+ aComment.sprintf("myComment=FAMILIES;myMeshName=%s", aMeshName.c_str());
+ string aSubMeshesEntry =
+ CreateAttributes(myStudyDocument, aMeshEntry.c_str(), aRefFatherEntry.c_str(),
+ "", "Families", "", aComment.latin1(), true);
+
+ //Import entities and according families
+ typedef std::map<std::string,std::string> TComment2EntryMap;
+ typedef std::map<VISU::TEntity,std::string> TEntity2EntryMap;
+ TComment2EntryMap aComment2EntryMap;
+ TEntity2EntryMap aEntity2EntryMap;
+
+ VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
+ for (; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++) {
+ const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
+ aComment.sprintf("myComment=ENTITY;myType=%d;myMeshName=%s;myId=%d",
+ VISU::TENTITY, aMeshName.c_str(), anEntity);
+ string anEntityName;
+ switch (anEntity) {
+ case VISU::NODE_ENTITY : anEntityName = "onNodes"; break;
+ case VISU::EDGE_ENTITY : anEntityName = "onEdges"; break;
+ case VISU::FACE_ENTITY : anEntityName = "onFaces"; break;
+ case VISU::CELL_ENTITY : anEntityName = "onCells"; break;
+ default:
+ throw std::runtime_error("Build >> Value of entity is incorrect!");
}
- //Importing groups
- const VISU::TGroupMap& aGroupMap = aMesh.myGroupMap;
- if(aGroupMap.size() > 0){
- aComment.sprintf("myComment=GROUPS;myResultName=%s;myMeshName=%s",myName.c_str(),aMeshName.c_str());
- string aGroupsEntry = CreateAttributes(myStudyDocument,aMeshEntry.c_str(),aRefFatherEntry.c_str(),
- "","Groups","",aComment.latin1(),true);
- VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin();
- for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){
- const string& aGroupName = aGroupMapIter->first;
- aComment.sprintf("myComment=GROUP;myType=%d;myResultName=%s;myMeshName=%s;myName=%s",
- VISU::TGROUP,myName.c_str(),aMeshName.c_str(),aGroupName.c_str());
- string aGroupEntry = CreateAttributes(myStudyDocument,aGroupsEntry.c_str(),aRefFatherEntry.c_str(),
- "",aGroupName.c_str(),"",aComment.latin1(),true);
- const VISU::TGroup& aGroup = aGroupMapIter->second;
- const VISU::TFamilyAndEntitySet& aFamilyAndEntitySet = aGroup.myFamilyAndEntitySet;
- VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = aFamilyAndEntitySet.begin();
- for(; aFamilyAndEntitySetIter != aFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++){
- const VISU::TFamilyAndEntity& aFamilyAndEntity = *aFamilyAndEntitySetIter;
- const string& aFamilyName = aFamilyAndEntity.first;
- const VISU::TEntity& anEntity = aFamilyAndEntity.second;
- aComment.sprintf("myComment=FAMILY;myType=%d;myResultName=%s;myMeshName=%s;myEntityId=%d;myName=%s",
- VISU::TFAMILY,myName.c_str(),aMeshName.c_str(),anEntity,aFamilyName.c_str());
- string anEntry = FindEntryWithComment(myStudyDocument,aEntity2Entry[anEntity].c_str(),aComment);
- CreateReference(myStudyDocument,aGroupEntry,anEntry);
- }
+ aEntity2EntryMap[anEntity] = CreateAttributes
+ (myStudyDocument, aSubMeshesEntry.c_str(), aRefFatherEntry.c_str(),
+ "", anEntityName.c_str(), "", aComment.latin1(), true);
+
+ const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
+ const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
+ VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
+ for (; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++) {
+ const string& aFamilyName = aFamilyMapIter->first;
+ aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s",
+ VISU::TFAMILY, aMeshName.c_str(), anEntity, aFamilyName.c_str());
+ aComment2EntryMap[aComment.latin1()] =
+ CreateAttributes(myStudyDocument, aEntity2EntryMap[anEntity].c_str(), aRefFatherEntry.c_str(),
+ "", aFamilyName.c_str(), "", aComment.latin1(), true);
+ }
+ }
+
+ //Importing groups
+ const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
+ if (aGroupMap.size() > 0) {
+ aComment.sprintf("myComment=GROUPS;myMeshName=%s", aMeshName.c_str());
+ string aGroupsEntry =
+ CreateAttributes(myStudyDocument, aMeshEntry.c_str(), aRefFatherEntry.c_str(),
+ "", "Groups", "", aComment.latin1(), true);
+
+ VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin();
+ for (; aGroupMapIter != aGroupMap.end(); aGroupMapIter++) {
+ const string& aGroupName = aGroupMapIter->first;
+ aComment.sprintf("myComment=GROUP;myType=%d;myMeshName=%s;myName=%s",
+ VISU::TGROUP, aMeshName.c_str(), aGroupName.c_str());
+ string aGroupEntry =
+ CreateAttributes(myStudyDocument, aGroupsEntry.c_str(), aRefFatherEntry.c_str(),
+ "", aGroupName.c_str(), "", aComment.latin1(), true);
+
+ const VISU::PGroup aGroup = aGroupMapIter->second;
+ const VISU::TFamilyAndEntitySet& aFamilyAndEntitySet = aGroup->myFamilyAndEntitySet;
+ VISU::TFamilyAndEntitySet::const_iterator aFamilyAndEntitySetIter = aFamilyAndEntitySet.begin();
+ for (; aFamilyAndEntitySetIter != aFamilyAndEntitySet.end(); aFamilyAndEntitySetIter++) {
+ const VISU::TFamilyAndEntity& aFamilyAndEntity = *aFamilyAndEntitySetIter;
+ const string& aFamilyName = aFamilyAndEntity.first;
+ const VISU::TEntity& anEntity = aFamilyAndEntity.second;
+ aComment.sprintf("myComment=FAMILY;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s",
+ VISU::TFAMILY, aMeshName.c_str(), anEntity, aFamilyName.c_str());
+ if (aComment2EntryMap.count(aComment.latin1()) > 0)
+ CreateReference(myStudyDocument, aGroupEntry, aComment2EntryMap[aComment.latin1()]);
}
}
- //Import fields
- string aFieldsEntry;
- bool isFieldEntryCreated = 0;
- aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
- for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
- const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
- const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
- const VISU::TFieldMap& aFieldMap = aMeshOnEntity.myFieldMap;
- VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
- for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){
- if(!isFieldEntryCreated){
- aComment.sprintf("myComment=FIELDS;myResultName=%s;myMeshName=%s",myName.c_str(),aMeshName.c_str());
- aFieldsEntry = CreateAttributes(myStudyDocument,aMeshEntry.c_str(),aRefFatherEntry.c_str(),
- "","Fields","",aComment.latin1(),true);
- isFieldEntryCreated = true;
- }
- const string& aFieldName = aFieldMapIter->first;
- const VISU::TField& aField = aFieldMapIter->second;
- const VISU::TField::TValField& aValField = aField.myValField;
- aComment.sprintf("myComment=FIELD;myType=%d;myResultName=%s;myMeshName=%s;myEntityId=%d;myName=%s;myNbTimeStamps=%d;myNumComponent=%d",
- VISU::TFIELD,myName.c_str(),aMeshName.c_str(),anEntity,aFieldName.c_str(),aValField.size(),aField.myNbComp);
- string aFieldEntry = CreateAttributes(myStudyDocument,aFieldsEntry.c_str(),aRefFatherEntry.c_str(),
- "",aFieldName.c_str(),"",aComment.latin1(),true);
- CreateReference(myStudyDocument,aFieldEntry,aEntity2Entry[anEntity]);
- VISU::TField::TValField::const_iterator aValFieldIter = aValField.begin();
- for(; aValFieldIter != aValField.end(); aValFieldIter++){
- int aTimeStamp = aValFieldIter->first;
- const VISU::TField::TValForTime& aValForTime = aValFieldIter->second;
- aComment.sprintf("myComment=TIMESTAMP;myType=%d;myResultName=%s;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d",
- VISU::TTIMESTAMP,myName.c_str(),aMeshName.c_str(),anEntity,aFieldName.c_str(),aTimeStamp,aField.myNbComp);
- string aTimeStampId = VISU_Convertor::GenerateName(aValForTime.myTime);
- CreateAttributes(myStudyDocument,aFieldEntry.c_str(),aRefFatherEntry.c_str(),
- "",aTimeStampId.c_str(),"",aComment.latin1(),true);
- }
+ }
+
+ //Import fields
+ string aFieldsEntry;
+ bool isFieldEntryCreated = 0;
+ aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
+ for (; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++) {
+ const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
+ const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
+ const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
+ VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
+ for (; aFieldMapIter != aFieldMap.end(); aFieldMapIter++) {
+ if (!isFieldEntryCreated) {
+ aComment.sprintf("myComment=FIELDS;myMeshName=%s", aMeshName.c_str());
+ aFieldsEntry =
+ CreateAttributes(myStudyDocument, aMeshEntry.c_str(), aRefFatherEntry.c_str(),
+ "", "Fields", "", aComment.latin1(), true);
+ isFieldEntryCreated = true;
+ }
+ const string& aFieldName = aFieldMapIter->first;
+ const VISU::PField aField = aFieldMapIter->second;
+ const VISU::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);
+ string aFieldEntry =
+ CreateAttributes(myStudyDocument, aFieldsEntry.c_str(), aRefFatherEntry.c_str(),
+ "", aFieldNameWithUnit.latin1(), "", aComment.latin1(), true);
+ CreateReference(myStudyDocument, aFieldEntry, aEntity2EntryMap[anEntity]);
+
+ VISU::TValField::const_iterator aValFieldIter = aValField.begin();
+ for (; aValFieldIter != aValField.end(); aValFieldIter++) {
+ int aTimeStamp = aValFieldIter->first;
+ const VISU::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);
+ CreateAttributes(myStudyDocument, aFieldEntry.c_str(), aRefFatherEntry.c_str(),
+ "", aTimeStampId.c_str(), "", aComment.latin1(), true);
}
}
}
}
- return this;
- }catch(std::runtime_error& exc){
- MESSAGE("Follow exception was accured :\n"<<exc.what());
+ bool isBuildAll = VISU::GetResourceMgr()->booleanValue("VISU", "full_med_loading", false);
+ if (isBuildAll) BuildAll();
+ } catch(std::exception& exc) {
+ INFOS("Follow exception was occured :\n"<<exc.what());
+ return NULL;
+ } catch(...) {
+ INFOS("Unknown exception was occured!!!");
+ return NULL;
+ }
+ aStudyBuilder->CommitCommand();
+ return this;
+}
+
+
+VISU::Storable*
+VISU::Result_i::
+Create(const char* theFileName)
+{
+ try{
+ myFileInfo.setFile(theFileName);
+ myInitFileName = myFileInfo.filePath().latin1();
+ myName = ::GenerateName(myFileInfo.fileName()).latin1();
+ if(mySourceId == eRestoredFile){
+ std::string aTmpDir(SALOMEDS_Tool::GetTmpDir());
+ static QString aCommand;
+ aCommand.sprintf("cp %s %s",myFileInfo.absFilePath().latin1(),aTmpDir.c_str());
+ if(system(aCommand) == -1){
+ MESSAGE("Create - Can't execute the command :"<<aCommand);
+ return NULL;
+ }
+ if(MYDEBUG) MESSAGE("Result_i::Create - aCommand = "<<aCommand);
+ myFileInfo.setFile(QString(aTmpDir.c_str()) + myFileInfo.fileName());
+ }
+ myInput = CreateConvertor(myFileInfo.absFilePath().latin1());
+ if(!myInput)
+ throw std::runtime_error("Create - Cannot create a Convertor for this file!!!");
+ return Build();
+ }catch(std::exception& exc){
+ INFOS("Follow exception was occured :\n"<<exc.what());
}catch(...){
- MESSAGE("Unknown exception was accured!");
+ INFOS("Unknown exception was occured!!!");
}
return NULL;
}
-VISU::Storable* VISU::Result_i::Create(const char* theFileName){
- myIsRestored = 0;
- myInput = CreateConvertor(theFileName);
- if(myInput == NULL) return NULL;
- myFileInfo.setFile(theFileName);
- myName = ::GenerateName(myFileInfo.fileName().latin1());
- return Build();
-}
-VISU::Storable* VISU::Result_i::Create(SALOME_MED::MESH_ptr theMesh){
- if(MYDEBUG) MESSAGE("Result_i::Create MedObject from Mesh");
- VISU_MedMeshConvertor* aInput = new VISU_MedMeshConvertor();
- aInput->SetMedMesh(theMesh);
- myInput = aInput;
- //if(myInput->GetOutput() == NULL) return NULL;
- TMeshMap::const_iterator aMeshMapIter = myInput->GetMeshMap()->begin();
- myName = ::GenerateName((aMeshMapIter->first).c_str());
- return Build();
-}
+VISU::Storable*
+VISU::Result_i::
+Create(SALOMEDS::SObject_ptr theMedSObject)
+{
+ if(MYDEBUG) MESSAGE("Result_i::Create MedObject from SALOMEDS::SObject_ptr");
+ try{
+ myInput = CreateMEDConvertor(theMedSObject);
+ if(myInput == NULL)
+ return NULL;
-VISU::Storable* VISU::Result_i::Create(SALOME_MED::SUPPORT_ptr theSupport){
- if(MYDEBUG) MESSAGE("Result_i::Create Mesh from MED::SUPPORT");
- VISU_CorbaMedSupportConvertor* aInput = new VISU_CorbaMedSupportConvertor();
- aInput->SetSupport(theSupport);
- myInput = aInput;
- //if(myInput->GetOutput() == NULL) return NULL;
- TMeshMap::const_iterator aMeshMapIter = myInput->GetMeshMap()->begin();
- myName = ::GenerateName((aMeshMapIter->first).c_str());
- return Build();
-}
+ string aCompDataType = GetComponentDataType(theMedSObject);
+ myFileInfo.setFile(aCompDataType.c_str());
+ myInitFileName = aCompDataType;
+
+ myName = ::GenerateName("aResult").latin1();
-VISU::Storable* VISU::Result_i::Create(SALOME_MED::FIELD_ptr theField){
- if(MYDEBUG) MESSAGE("Result_i::Create MedObject from Field");
- VISU_CorbaMedConvertor* aInput = new VISU_CorbaMedConvertor();
- aInput->SetMedField(theField);
- myInput = aInput;
- //if(myInput->GetOutput() == NULL) return NULL;
- TMeshMap::const_iterator aMeshMapIter = myInput->GetMeshMap()->begin();
- myName = ::GenerateName((aMeshMapIter->first).c_str());
- return Build();
+ VISU::Storable* aStorable = Build(theMedSObject);
+ return aStorable;
+ }catch(std::exception& exc){
+ INFOS("Follow exception was occured :\n"<<exc.what());
+ }catch(...){
+ INFOS("Unknown exception was occured!!!");
+ }
+ return NULL;
}
-VISU::Storable* VISU::Result_i::Restore(SALOMEDS::SObject_ptr theSObject,
- const string& thePrefix, const Storable::TRestoringMap& theMap)
- throw(std::logic_error&)
+VISU::Storable*
+VISU::Result_i::
+Create(SALOME_MED::FIELD_ptr theField)
{
- if(MYDEBUG) MESSAGE("Result_i::Restore - "<<thePrefix);
+ if(MYDEBUG) MESSAGE("Result_i::Create MedObject from SALOME_MED::FIELD_ptr");
try{
- myIsRestored = 1;
+ myInput = CreateMEDFieldConvertor(theField);
+ if(myInput == NULL)
+ return NULL;
+
+ string aCompDataType = "MED";
+ myFileInfo.setFile(aCompDataType.c_str());
+ myInitFileName = aCompDataType;
+
+ myName = ::GenerateName("aResult").latin1();
+
+ CORBA::String_var anIOR = myStudyDocument->ConvertObjectToIOR(theField);
+ SALOMEDS::SObject_var aFieldSObject = myStudyDocument->FindObjectIOR(anIOR);
+
+ VISU::Storable* aStorable = Build(aFieldSObject);
+ return aStorable;
+ }catch(std::exception& exc){
+ INFOS("Follow exception was occured :\n"<<exc.what());
+ }catch(...){
+ INFOS("Unknown exception was occured!!!");
+ }
+ return NULL;
+}
+
+
+VISU::Storable*
+VISU::Result_i::
+Restore(SALOMEDS::SObject_ptr theSObject,
+ const Storable::TRestoringMap& theMap,
+ const string& thePrefix)
+{
+ if(MYDEBUG) MESSAGE("Result_i::Restore - " << thePrefix);
+ try {
mySObject = SALOMEDS::SObject::_duplicate(theSObject);
myStudyDocument = mySObject->GetStudy();
mySComponent = mySObject->GetFatherComponent();
- myName = VISU::Storable::FindValue(theMap,"myName");
- string aFileName(thePrefix);
- string aStudyPrefix = SALOMEDS_Tool::GetNameFromPath(myStudyDocument->URL());
- aFileName += aStudyPrefix + "_" + myName;
- if(MYDEBUG) MESSAGE("Result_i::Restore - aFileName = "<<aFileName);
- myFileInfo.setFile(aFileName.c_str());
- myInput = CreateMedConvertor(aFileName);
- QString aComment;
- aComment.sprintf("myComment=%s;myType=%d;myName=%s;myFileName=%s",
- GetComment(),VISU::TRESULT,myName.c_str(),myFileInfo.filePath().latin1());
- SALOMEDS::GenericAttribute_var anAttr;
- if(!theSObject->FindAttribute(anAttr, "AttributeComment"))
- throw std::runtime_error("Build - There is no AttributeComment for the SObject !!!");
- SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr);
- aCmnt->SetValue(aComment.latin1());
- // remove temporary file, if it's not multifile mode
- if (false || !IsMultifile()) {
- SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
- aSeq->length(1);
- aSeq[0]=(aStudyPrefix + myName).c_str();
- SALOMEDS_Tool::RemoveTemporaryFiles(thePrefix.c_str(), aSeq.in(), true);
+ myName = VISU::Storable::FindValue(theMap, "myName").latin1();
+ myInitFileName = VISU::Storable::FindValue(theMap, "myInitFileName").latin1();
+
+ SALOMEDS::SObject_var aRefSObj, aTargetRefSObj;
+ if (mySObject->FindSubObject(1, aRefSObj) &&
+ aRefSObj->ReferencedObject(aTargetRefSObj)) {
+ if(MYDEBUG) MESSAGE("Result_i::GetInput - There is some reference.");
+ SALOMEDS::SComponent_var aCompRefSObj = aTargetRefSObj->GetFatherComponent();
+ CORBA::String_var aDataType = aCompRefSObj->ComponentDataType();
+ myFileInfo.setFile(aDataType.in());
+ if(MYDEBUG) MESSAGE("Result_i::GetInput - aDataType = " << aDataType);
+ Engines::Component_var aEngComp =
+ Base_i::myEnginesLifeCycle->FindOrLoad_Component("FactoryServer", aDataType.in());
+ if (CORBA::is_nil(aEngComp))
+ throw std::runtime_error("Restore - There is no aEngComp for the aDataType !!!");
+ SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
+ SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(aEngComp);
+ aStudyBuilder->LoadWith(aCompRefSObj, aDriver);
+ if (strcmp(aDataType, "MED") == 0) {
+ // create field or MED converter
+ CORBA::Object_var aMedObject = VISU::SObjectToObject(aTargetRefSObj);
+ SALOME_MED::FIELD_var aField = SALOME_MED::FIELD::_narrow(aMedObject);
+ if(!CORBA::is_nil(aField))
+ myInput = CreateMEDFieldConvertor(aField);
+ else
+ myInput = CreateMEDConvertor(aTargetRefSObj);
+ }
+ else
+ throw std::runtime_error("GetInput - There is no convertor for the aDataType !!!");
+ } else {
+ myFileInfo.setFile(thePrefix.c_str());
+
+ string aStudyPrefix ("");
+ if (IsMultifile())
+ aStudyPrefix = SALOMEDS_Tool::GetNameFromPath(myStudyDocument->URL());
+ if (!myFileInfo.isFile()) {
+ string aFileName = thePrefix + aStudyPrefix + "_" + myName;
+ myFileInfo.setFile(aFileName.c_str());
+ }
+ if(MYDEBUG)
+ MESSAGE("Result_i::Restore - aFileName = " << myFileInfo.filePath() << "; " << myFileInfo.isFile());
+
+ const char* aPathLatin = myFileInfo.filePath().latin1();
+ if (HDFascii::isASCII(aPathLatin)) {
+ MESSAGE("ConvertFromASCIIToHDF(" << aPathLatin << ")");
+ char* aResultPath = HDFascii::ConvertFromASCIIToHDF(aPathLatin);
+ MESSAGE("ConvertFromASCIIToHDF() DONE : " << aResultPath);
+ char* aHDFFileName = new char[strlen(aResultPath) + 19];
+ sprintf(aHDFFileName, "%shdf_from_ascii.hdf", aResultPath);
+
+ if (IsMultifile()) { // set this file as new - temporary
+ static QString aCommand;
+ aCommand.sprintf("mv %s %s%s",aHDFFileName, aResultPath, myFileInfo.baseName().latin1());
+ if (system(aCommand) == -1) {
+ if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - Can't execute the command :" << aCommand);
+ return NULL;
+ } else {
+ if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - " << aCommand);
+ }
+ myFileInfo.setFile(QString(aResultPath) + QString(myFileInfo.baseName().latin1()));
+ } else { // change current temporary file to the new: with hdf-format
+ static QString aCommand;
+ aCommand.sprintf("mv %s %s\0",aHDFFileName, myFileInfo.filePath().latin1());
+ if (system(aCommand.latin1()) == -1) {
+ if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - Can't execute the command :" << aCommand);
+ return NULL;
+ } else {
+ if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - " << aCommand);
+ }
+ SALOMEDS::ListOfFileNames_var anEmptyList = new SALOMEDS::ListOfFileNames;
+ SALOMEDS_Tool::RemoveTemporaryFiles(aResultPath, anEmptyList.in(), true);
+ }
+ mySourceId = eRestoredFile;
+ delete(aResultPath);
+ delete(aHDFFileName);
+ } else if (!IsMultifile()) {
+ mySourceId = eRestoredFile;
+ } else {
+ mySourceId = eFile;
+ }
+ if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - mySourceId = " << mySourceId);
+ myInput = CreateConvertor(myFileInfo.filePath().latin1());
+ QString aComment;
+ aComment.sprintf("myComment=%s;myType=%d;myFileName=%s;myInitFileName=%s",
+ GetComment(), VISU::TRESULT, myFileInfo.filePath().latin1(),
+ myInitFileName.c_str()); // Restoring of Python dump
+ SALOMEDS::GenericAttribute_var anAttr;
+ if (!theSObject->FindAttribute(anAttr, "AttributeComment"))
+ throw std::runtime_error("Build - There is no AttributeComment for the SObject !!!");
+ SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr);
+ aCmnt->SetValue(aComment.latin1());
}
+ bool isBuildAll = VISU::GetResourceMgr()->booleanValue("VISU", "full_med_loading", false);
+ if (isBuildAll)
+ BuildAll();
return this;
- }catch(std::runtime_error& exc){
- MESSAGE("Follow exception was accured :\n"<<exc.what());
- }catch(...){
- MESSAGE("Unknown exception was accured!");
+ } catch(std::exception& exc) {
+ INFOS("Follow exception was occured :\n"<<exc.what());
+ } catch(...) {
+ INFOS("Unknown exception was occured!!!");
}
return NULL;
}
-void VISU::Result_i::ToStream(ostrstream& theStr){
+VISU::Result_i::TInput* VISU::Result_i::GetInput() {
+ return myInput;
+}
+
+void VISU::Result_i::ToStream(std::ostringstream& theStr){
if(MYDEBUG) MESSAGE(GetComment());
Storable::DataToStream(theStr,"myName",myName.c_str());
+ Storable::DataToStream(theStr,"myInitFileName",myInitFileName.c_str());
+ Storable::DataToStream(theStr,"myCreationId",myCreationId);
}
-VISU::Storable* VISU::ResultRestore(SALOMEDS::SObject_ptr theSObject,
- const string& thePrefix, const Storable::TRestoringMap& theMap)
- throw(std::logic_error&)
+VISU::Storable*
+VISU::Result_i::Restore(SALOMEDS::SObject_ptr theSObject,
+ const string& thePrefix,
+ const Storable::TRestoringMap& theMap)
{
SALOMEDS::Study_var aStudy = theSObject->GetStudy();
- VISU::Result_i* pResult = new VISU::Result_i(aStudy);
- if(pResult == NULL) return NULL;
- return pResult->Restore(theSObject,thePrefix,theMap);
+
+ ECreationId aCreationId = ECreationId(Storable::FindValue(theMap,"myCreationId").toInt());
+ ESourceId aSourceId = eRestoredFile;
+ if(aCreationId == eImportMed || aCreationId == eImportMedField)
+ aSourceId = eRestoredComponent;
+
+ VISU::Result_i* pResult = new VISU::Result_i(aStudy,aSourceId,aCreationId);
+ if (pResult == NULL)
+ return NULL;
+
+ return pResult->Restore(theSObject,theMap,thePrefix);
}
-
-string VISU::Result_i::GetRefFatherEntry() {
+
+string VISU::Result_i::GetRefFatherEntry() {
//return QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry();
return "";
}
-string VISU::Result_i::GetEntry(){
+string VISU::Result_i::GetEntry(){
CORBA::String_var anEntry = mySObject->GetID();
return string(anEntry);
}
const SALOMEDS::SObject_var& VISU::Result_i::GetSObject() const { return mySObject;}
const SALOMEDS::Study_var& VISU::Result_i::GetStudyDocument() const { return myStudyDocument;}
const SALOMEDS::SComponent_var& VISU::Result_i::GetSComponent() const { return mySComponent;}
+std::string VISU::Result_i::GetEntry(const std::string& theComment)
+{
+ return FindEntryWithComment(myStudyDocument,GetEntry().c_str(),theComment.c_str());
+}
-VISU::Result_i::~Result_i() {
- if(MYDEBUG) MESSAGE("Result_i::~Result_i()");
+VISU::Result_i::~Result_i()
+{
+ MESSAGE("Result_i::~Result_i() - this = "<<this);
+ if (mySourceId == eRestoredFile) {
+ static QString aCommand;
+ aCommand.sprintf("rm %s",myFileInfo.filePath().latin1());
+ MESSAGE("Result_i::~Result_i - system("<<aCommand<<") = "<<system(aCommand));
+ aCommand.sprintf("rmdir --ignore-fail-on-non-empty %s",myFileInfo.dirPath().latin1());
+ MESSAGE("Result_i::~Result_i - system("<<aCommand<<") = "<<system(aCommand));
+ }
if(myInput) delete myInput;
}
+
+//=======================================================================
+//function : GetAxisInfo
+//purpose :
+//=======================================================================
+const vector< float >* Result_i::GetAxisInfo(const string& theMeshName,
+ TAxis theAxis,
+ gp_Dir& thePlaneNormal)
+{
+ const vector< float >* components = NULL;
+
+ if ( theAxis < AXIS_X || theAxis > AXIS_Z ) {
+ MESSAGE(" Bad axis index " << theAxis );
+ return components;
+ }
+
+ map< string, TGridInfo >::iterator name_info;
+ name_info = myMeshName2GridInfoMap.find( theMeshName );
+ TGridInfo * gInfo = 0;
+
+ if ( name_info != myMeshName2GridInfoMap.end() )
+ {
+ gInfo = & name_info->second;
+ }
+ else if ( myInput && IsPossible() && theAxis >= AXIS_X && theAxis <= AXIS_Z )
+ {
+ // check presence of theMeshName
+ const VISU::TMeshMap& meshMap = myInput->GetMeshMap();
+ if ( meshMap.find( theMeshName ) == meshMap.end() ) {
+ MESSAGE("No mesh named " << theMeshName );
+ return components;
+ }
+ VISU_Convertor::TOutput* vtkMesh = myInput->GetMeshOnEntity (theMeshName,
+ CELL_ENTITY);
+ if ( !vtkMesh || vtkMesh->GetNumberOfCells() == 0 ) {
+ MESSAGE( "No cells in the mesh: " << theMeshName );
+ return components;
+ }
+
+ // define axis directions and min cell size in each direction
+ const int nbAxes = 3;
+ int iAx;
+ gp_Vec axDirs[ nbAxes ];
+ float minSize[3] = { FLT_MAX, FLT_MAX, FLT_MAX };
+ bool axesComputed = false;
+ for ( vtkIdType iCell = 0; iCell < vtkMesh->GetNumberOfCells(); ++iCell )
+ {
+ vtkCell* cell = vtkMesh->GetCell( iCell );
+ int nbPnt = cell->GetNumberOfPoints();
+ if ( nbPnt != 8 )
+ continue;
+ vtkPoints * points = cell->GetPoints();
+ float* coords[ 4 ];
+ coords[0] = points->GetPoint( 0 );
+ coords[1] = points->GetPoint( 1 );
+ coords[2] = points->GetPoint( 3 );
+ coords[3] = points->GetPoint( 4 );
+ gp_Pnt p0( coords[0][0], coords[0][1], coords[0][2] );
+ for ( iAx = 0; iAx < nbAxes; ++iAx )
+ {
+ float* coo = coords[ iAx + 1 ];
+ gp_Pnt p( coo[0], coo[1], coo[2] );
+ // min size
+ float size = p0.SquareDistance( p );
+ if ( size > FLT_MIN && size < minSize[ iAx ] )
+ minSize[ iAx ] = size;
+ // axis direction
+ if ( !axesComputed ) {
+ gp_Vec dir( p0, p );
+ if ( dir.SquareMagnitude() <= DBL_MIN )
+ break;
+ axDirs[ iAx ] = dir;
+ }
+ }
+ if ( iAx == nbAxes )
+ axesComputed = true;
+ }
+ if ( !axesComputed ) {
+ MESSAGE("No good hexahedrons in the mesh: " << theMeshName );
+ return components;
+ }
+
+ // compute axes dirs
+ gInfo = & myMeshName2GridInfoMap[ theMeshName ];
+ for ( iAx = 0; iAx < nbAxes; ++iAx )
+ {
+ int iPrev = ( iAx == 0 ) ? 2 : iAx - 1;
+ int iNext = ( iAx == 2 ) ? 0 : iAx + 1;
+ gInfo->myAxis[ iAx ] = axDirs[ iPrev ] ^ axDirs[ iNext ];
+ }
+
+ // get and sort intermediate component values - projections of nodes
+ // on axis direction; define bnd box
+ set< float > comps[ 3 ];
+ Bnd_Box box;
+ vtkPoints * points = vtkMesh->GetPoints();
+ vtkIdType iP, nbP = vtkMesh->GetNumberOfPoints();
+ for ( iP = 0; iP < nbP; ++iP )
+ {
+ float* coo = points->GetPoint( iP );
+ gp_Pnt p( coo[0], coo[1], coo[2] );
+ box.Add( p );
+ for ( iAx = 0; iAx < nbAxes; ++iAx ) {
+ const gp_Dir& dir = gInfo->myAxis[ iAx ];
+ float dot = dir.XYZ() * p.XYZ();
+ comps[ iAx ].insert( dot );
+ }
+ }
+
+ // find a range of projections of bnd box corners on each axis
+ float range[3], firstValue[3];
+ double x[2],y[2],z[2];
+ box.Get(x[0],y[0],z[0],x[1],y[1],z[1]);
+ for ( iAx = 0; iAx < nbAxes; ++iAx ) {
+ set< float > bndComps;
+ const gp_Dir& dir = gInfo->myAxis[ iAx ];
+ for ( int iX = 0; iX < 2; ++iX ) {
+ for ( int iY = 0; iY < 2; ++iY ) {
+ for ( int iZ = 0; iZ < 2; ++iZ ) {
+ gp_Pnt p( x[ iX ], y[ iY ], z[ iZ ] );
+ float dot = dir.XYZ() * p.XYZ();
+ bndComps.insert( dot );
+ }
+ }
+ }
+ firstValue[ iAx ] = *bndComps.begin();
+ range[ iAx ] = *bndComps.rbegin() - *bndComps.begin();
+ }
+
+ // compute component values
+ for ( iAx = 0; iAx < nbAxes; ++iAx )
+ {
+ list< float > values;
+ int nbVals = 0;
+ set< float >& comp = comps[ iAx ];
+ set< float >::iterator val = comp.begin();
+ float bnd = -1., rng = range[ iAx ], first = firstValue[ iAx ];
+ float tol = 0.1 * sqrt( minSize[ iAx ]) / rng;
+ for ( ; val != comp.end(); ++val ) {
+ float value = ( *val - first ) / rng;
+ if ( value > bnd ) {
+ values.push_back( value );
+ bnd = value + tol;
+ nbVals++;
+ }
+ }
+ // store values in gInfo
+ vector< float >& myComp = gInfo->myComponets[ iAx ];
+ myComp.resize( nbVals );
+ list< float >::iterator v = values.begin();
+ for ( int i = 0; v != values.end(); ++v )
+ myComp[ i++ ] = *v;
+ }
+ }
+
+ // set return values
+ if ( gInfo )
+ {
+ thePlaneNormal = gInfo->myAxis[ theAxis ];
+ components = & gInfo->myComponets[ theAxis ];
+ }
+
+ return components;
+}