1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // VISU OBJECT : interactive object for VISU entities implementation
24 // File : VISU_Result_i.cc
25 // Author : Alexey PETROV
28 #include "VISU_MultiResult_i.hh"
29 #include "VISU_ResultUtils.hh"
30 #include "VISU_Prs3d_i.hh"
32 #include "VISU_Convertor_impl.hxx"
33 #include "VISU_CorbaMedConvertor.hxx"
34 #include "VISU_ConvertorUtils.hxx"
35 #include "VISU_PipeLine.hxx"
37 #include "SUIT_ResourceMgr.h"
39 #include "SALOMEDS_Tool.hxx"
40 #include "HDFascii.hxx"
41 #include "Basics_Utils.hxx"
43 #include "SUIT_Session.h"
44 #include "SALOME_Event.h"
45 #include "SalomeApp_Study.h"
46 #include "SalomeApp_Application.h"
48 #include "MED_Factory.hxx"
50 #include <boost/thread/thread.hpp>
51 #include <boost/bind.hpp>
63 #include <vtkUnstructuredGrid.h>
66 #include <Bnd_Box.hxx>
69 static int MYDEBUG = 1;
71 static int MYDEBUG = 0;
78 //---------------------------------------------------------------
80 FindResult(SALOMEDS::SObject_ptr theSObject)
82 SALOMEDS::SComponent_var aSComponent = theSObject->GetFatherComponent();
83 SALOMEDS::SObject_var aFather = theSObject->GetFather();
84 CORBA::String_var aComponentID (aSComponent->GetID());
85 CORBA::String_var aFatherID (aFather->GetID());
87 while (strcmp(aComponentID, aFatherID) != 0) {
88 CORBA::Object_var anObject = SObjectToObject(aFather);
89 if (!CORBA::is_nil(anObject)) {
90 aResult = Result::_narrow(anObject);
91 if (!aResult->_is_nil()) return aResult;
93 aFather = aFather->GetFather();
94 aFatherID = aFather->GetID();
100 //---------------------------------------------------------------
102 GetResult(SALOMEDS::Study_ptr theStudy,
103 const std::string& theResultEntry)
105 Result_i* result = NULL;
106 if (!CORBA::is_nil(theStudy)) {
107 SALOMEDS::SComponent_var aSComponent = theStudy->FindComponent("VISU");
108 if (!CORBA::is_nil(aSComponent)) {
109 std::string compid = aSComponent->GetID();
110 std::string aResultEntry = theResultEntry;
111 if (theResultEntry.substr(0, compid.length()) != compid) aResultEntry = compid + theResultEntry.substr(compid.length());
112 SALOMEDS::SObject_var aSObject = theStudy->FindObjectID(aResultEntry.c_str());
113 CORBA::Object_var anObject = SObjectToObject(aSObject);
114 result = dynamic_cast<VISU::Result_i*>(GetServant(anObject).in());
121 //---------------------------------------------------------------
123 GetComponentDataType (SALOMEDS::SObject_ptr theSObject)
125 SALOMEDS::SComponent_var aCompRefSObj = theSObject->GetFatherComponent();
126 CORBA::String_var aDataType = aCompRefSObj->ComponentDataType();
127 return aDataType.in();
131 //---------------------------------------------------------------
133 CreateReference (SALOMEDS::Study_ptr theStudyDocument,
134 const string& theFatherEntry,
135 const string& theRefEntry)
137 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudyDocument->NewBuilder();
138 SALOMEDS::SObject_var aFather = theStudyDocument->FindObjectID(theFatherEntry.c_str());
139 SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(aFather);
140 SALOMEDS::SObject_var aRefSObj = theStudyDocument->FindObjectID(theRefEntry.c_str());
141 aStudyBuilder->Addreference(newObj,aRefSObj);
144 //---------------------------------------------------------------
145 // Issue 0021403. Remove a ColoredPrs3dHolder if a Result it refers to is removed
147 void RemoveHolders(VISU::Result_i* theResult)
149 CORBA::String_var resultID1 = theResult->GetID();
150 SALOMEDS::SObject_var theResSObject = theResult->GetSObject();
151 SALOMEDS::Study_var aStudyDocument = theResSObject->GetStudy();
152 SALOMEDS::SComponent_var aCompSObj = theResSObject->GetFatherComponent();
153 SALOMEDS::ChildIterator_var aChildIter = aStudyDocument->NewChildIterator(aCompSObj);
154 for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next())
156 SALOMEDS::SObject_var aChildSObject = aChildIter->Value();
157 if ( CORBA::is_nil( aChildSObject )) continue;
158 CORBA::Object_var aChildObj = aChildSObject->GetObject();
159 if ( CORBA::is_nil( aChildObj )) continue;
160 VISU::ColoredPrs3dHolder_var prsHolder = ColoredPrs3dHolder::_narrow( aChildObj );
161 if ( prsHolder->_is_nil() ) continue;
162 // check if the prsHolder refers to theResult
163 VISU::ColoredPrs3dHolder::BasicInput_var input = prsHolder->GetBasicInput();
164 CORBA::String_var resultID2 = input->myResult->GetID();
165 if ( strcmp( resultID1, resultID2 ) == 0 )
166 prsHolder->RemoveFromStudy();
170 //---------------------------------------------------------------
174 //---------------------------------------------------------------
175 const string VISU::Result_i::myComment = "RESULT";
176 const char* VISU::Result_i::GetComment() const { return myComment.c_str();}
178 //---------------------------------------------------------------
180 ::Result_i(SALOMEDS::Study_ptr theStudy,
181 const ESourceId& theSourceId,
182 const ECreationId& theCreationId,
183 CORBA::Boolean theIsBuildImmediately,
184 CORBA::Boolean theIsBuildFields,
185 CORBA::Boolean theIsBuildMinMax,
186 CORBA::Boolean theIsBuildGroups):
187 myStudyDocument(SALOMEDS::Study::_duplicate(theStudy)),
188 myCreationId(theCreationId),
189 mySourceId(theSourceId),
190 myIsBuildImmediately(theIsBuildImmediately),
191 myIsBuildFields(theIsBuildFields),
192 myIsBuildMinMax(theIsBuildMinMax),
193 myIsBuildGroups(theIsBuildGroups),
194 myIsEntitiesDone(false),
195 myIsFieldsDone(false),
196 myIsGroupsDone(false),
197 myIsMinMaxDone(false),
199 myIsBuildParts(false),
202 if(MYDEBUG) MESSAGE("Result_i::Result_i - this = "<<this);
203 myStudy = VISU::GetStudy(myStudyDocument);
207 //---------------------------------------------------------------
210 myIsEntitiesDone(false),
211 myIsFieldsDone(false),
212 myIsGroupsDone(false),
213 myIsMinMaxDone(false),
215 myIsBuildParts(false),
218 if(MYDEBUG) MESSAGE("Result_i::Result_i - this = "<<this);
222 //---------------------------------------------------------------
226 MESSAGE("Result_i::~Result_i() - this = "<<this);
227 if (GetSourceId() == eRestoredFile)
228 VISU::RemoveFile(myFileInfo.filePath().toLatin1().data());
232 //---------------------------------------------------------------
237 struct TRemoveFromStudy: public SALOME_Event
239 VISU::Result_i* myRemovable;
240 TRemoveFromStudy(VISU::Result_i* theRemovable):
241 myRemovable(theRemovable)
248 RemoveHolders(myRemovable);
249 VISU::RemoveFromStudy(myRemovable->GetSObject(),false);
250 myRemovable->UnRegister();
254 // Remove the result with all presentations and other possible sub-objects
255 ProcessVoidEvent(new TRemoveFromStudy(this));
259 //---------------------------------------------------------------
262 ::ConnectObserver(TResultObserver* theObserver,
263 boost::signalslib::connection& theConnection)
265 if(theConnection.connected())
266 theConnection.disconnect();
269 myUpdateObserverSignal.connect(boost::bind(boost::bind(&TResultObserver::UpdateFromResult,
276 //---------------------------------------------------------------
281 struct TEvent: public SALOME_Event
283 VISU::Result_i::TUpdateObserverSignal& myUpdateObserverSignal;
285 TEvent(VISU::Result_i::TUpdateObserverSignal& theUpdateObserverSignal):
286 myUpdateObserverSignal(theUpdateObserverSignal)
293 myUpdateObserverSignal();
297 ProcessVoidEvent(new TEvent(myUpdateObserverSignal));
301 //---------------------------------------------------------------
307 size_t aSize = myInput->GetSize();
308 size_t aResult = VISU_PipeLine::CheckAvailableMemory(aSize);
309 MESSAGE("Result_i::IsPossible - CheckAvailableMemory = "<<float(aSize)<<"; aResult = "<<float(aResult));
311 }catch(std::exception& exc){
312 INFOS("Follow exception was occured :\n"<<exc.what());
314 INFOS("Unknown exception was occured!");
320 //---------------------------------------------------------------
325 if(MYDEBUG) MESSAGE("Result_i::Build - myIsAllDone = "<<myIsAllDone);
331 const VISU::TMeshMap& aMeshMap = myInput->GetMeshMap();
332 VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
333 for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
334 const string& aMeshName = aMeshMapIter->first;
335 const VISU::PMesh aMesh = aMeshMapIter->second;
336 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
337 VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter;
339 aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
340 for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
341 const VISU::TEntity& anEntity = aMeshOnEntityMapIter->first;
342 const VISU::PMeshOnEntity aMeshOnEntity = aMeshOnEntityMapIter->second;
343 const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
344 VISU::TFieldMap::const_iterator aFieldMapIter = aFieldMap.begin();
345 for(; aFieldMapIter != aFieldMap.end(); aFieldMapIter++){
346 const string& aFieldName = aFieldMapIter->first;
347 const VISU::PField aField = aFieldMapIter->second;
348 const VISU::TValField& aValField = aField->myValField;
349 VISU::TValField::const_iterator aValFieldIter = aValField.begin();
350 for(; aValFieldIter != aValField.end(); aValFieldIter++){
351 int aTimeStamp = aValFieldIter->first;
353 myInput->GetTimeStampOnMesh(aMeshName,anEntity,aFieldName,aTimeStamp);
354 }catch(std::exception& exc){
355 INFOS("Follow exception was occured :\n"<<exc.what());
357 INFOS("Unknown exception was occured!!!");
362 const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
363 VISU::TGroupMap::const_iterator aGroupMapIter = aGroupMap.begin();
364 for(; aGroupMapIter != aGroupMap.end(); aGroupMapIter++){
365 const string& aGroupName = aGroupMapIter->first;
367 myInput->GetMeshOnGroup(aMeshName,aGroupName);
368 }catch(std::exception& exc){
369 INFOS("Follow exception was occured :\n"<<exc.what());
371 INFOS("Unknown exception was occured!!!");
375 const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
376 VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
377 for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
378 const string& aFamilyName = aFamilyMapIter->first;
380 myInput->GetFamilyOnEntity(aMeshName,anEntity,aFamilyName);
381 }catch(std::exception& exc){
382 INFOS("Follow exception was occured :\n"<<exc.what());
384 INFOS("Unknown exception was occured!!!");
387 //Import mesh on entity
389 myInput->GetMeshOnEntity(aMeshName,anEntity);
390 }catch(std::exception& exc){
391 INFOS("Follow exception was occured :\n"<<exc.what());
393 INFOS("Unknown exception was occured!!!");
398 }catch(std::exception& exc){
399 INFOS("Follow exception was occured :\n"<<exc.what());
401 INFOS("Unknown exception was occured!!!");
407 //---------------------------------------------------------------
410 ::Build(CORBA::Boolean theIsBuildAll,
411 CORBA::Boolean theIsAtOnce)
416 if(Build(SALOMEDS::SObject::_nil(), theIsAtOnce)){
419 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
421 SALOMEDS::GenericAttribute_var anAttr;
422 SALOMEDS::AttributePixMap_var aPixmap;
423 SALOMEDS::AttributeUserID_var aId;
425 anAttr = aStudyBuilder->FindOrCreateAttribute( mySObject, "AttributePixMap" );
426 aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
427 aPixmap ->SetPixMap("ICON_TREE_RESULT");
429 std::string auid = "AttributeUserID";
430 auid += Kernel_Utils::GetGUID(Kernel_Utils::ObjectdID);
431 anAttr = aStudyBuilder->FindOrCreateAttribute( mySObject, auid.c_str() );
432 aId = SALOMEDS::AttributeUserID::_narrow( anAttr );
433 aId ->SetValue("VISU.RESULT");
444 //---------------------------------------------------------------
445 VISU::Storable* VISU::Result_i::Build(SALOMEDS::SObject_ptr theSObject,
446 CORBA::Boolean theIsAtOnce)
454 mySComponent = FindOrCreateVisuComponent(myStudyDocument);
455 CORBA::String_var aSComponentEntry = mySComponent->GetID();
456 CORBA::String_var anIOR(GetID());
458 aComment.sprintf("myComment=%s;myFileName=%s;myInitFileName=%s",
460 myFileInfo.filePath().toLatin1().data(),
461 GetInitFileName().c_str()); // Restoring of Python dump
462 std::string aResultEntry =
463 CreateAttributes(myStudy,
464 aSComponentEntry.in(),
469 aComment.toLatin1().data(),
471 mySObject = myStudyDocument->FindObjectID(aResultEntry.c_str());
472 if(!CORBA::is_nil(theSObject)){
473 CORBA::String_var aString = theSObject->GetID();
474 CreateReference(myStudyDocument, aResultEntry, aString.in());
495 BuildFieldDataTree(this,
503 boost::thread aThread(boost::bind(boost::bind(&Result_i::BuildDataTree, this, _1),
511 //---------------------------------------------------------------
514 ::BuildDataTree(const std::string& theResultEntry)
527 boost::thread aThread(boost::bind(&BuildGroups,
537 boost::thread aThread(boost::bind(&BuildFieldDataTree,
548 //---------------------------------------------------------------
551 ::BuildAll(SALOMEDS::SObject_ptr theSObject)
553 if(MYDEBUG) MESSAGE("Result_i::Build");
557 }catch(std::exception& exc){
558 INFOS("Follow exception was occured :\n"<<exc.what());
561 INFOS("Unknown exception was occured!!!");
569 //---------------------------------------------------------------
572 ::Create(const char* theFileName)
575 myFileInfo.setFile(theFileName);
576 myFileName = myFileInfo.fileName().toLatin1().data();
579 SetInitFileName(myFileInfo.filePath().toLatin1().data());
580 SetName(VISU::GenerateName(myFileInfo.fileName().toLatin1().data()).toLatin1().data(), false);
583 if(mySourceId == eRestoredFile){
584 QString aTmpDir(SALOMEDS_Tool::GetTmpDir().c_str());
585 std::string aFileName = VISU::MakeFileName(myFileInfo.fileName().toLatin1().data(), this);
586 QString aPathToCopy(aTmpDir + aFileName.c_str());
587 if(!VISU::CopyFile(myFileInfo.absoluteFilePath().toLatin1().data(), aPathToCopy.toLatin1().data()))
590 myFileInfo.setFile(aPathToCopy);
591 myFileName = myFileInfo.fileName().toLatin1().data();
594 myInput.reset(CreateConvertor(myFileInfo.absoluteFilePath().toLatin1().data()));
597 if(myIsBuildImmediately)
598 Build(SALOMEDS::SObject::_nil());
601 }catch(std::exception& exc){
602 MSG(MYDEBUG,"Follow exception was occured in:\n"<<exc.what());
604 MSG(MYDEBUG,"Unknown exception !!!");
610 //---------------------------------------------------------------
613 ::Create(SALOMEDS::SObject_ptr theMedSObject)
615 if(MYDEBUG) MESSAGE("Result_i::Create MedObject from SALOMEDS::SObject_ptr");
617 myInput.reset(CreateMEDConvertor(theMedSObject));
623 string aCompDataType = GetComponentDataType(theMedSObject);
624 myFileInfo.setFile(aCompDataType.c_str());
625 myFileName = VISU::GenerateName("aResult").toLatin1().data();
627 SetInitFileName(aCompDataType);
628 SetName(VISU::GenerateName(myFileInfo.fileName().toLatin1().data()).toLatin1().data(), false);
630 return Build(theMedSObject);
631 }catch(std::exception& exc){
632 INFOS("Follow exception was occured :\n"<<exc.what());
634 INFOS("Unknown exception was occured!!!");
640 //---------------------------------------------------------------
643 ::Create(SALOME_MED::FIELD_ptr theField)
645 if(MYDEBUG) MESSAGE("Result_i::Create MedObject from SALOME_MED::FIELD_ptr");
647 myInput.reset(CreateMEDFieldConvertor(theField));
653 string aCompDataType = "MED";
654 myFileInfo.setFile(aCompDataType.c_str());
656 myFileName = VISU::GenerateName("aResult").toLatin1().data();
657 SetInitFileName(aCompDataType);
658 SetName(VISU::GenerateName(myFileInfo.fileName().toLatin1().data()).toLatin1().data(), false);
660 CORBA::String_var anIOR = myStudyDocument->ConvertObjectToIOR(theField);
661 SALOMEDS::SObject_var aFieldSObject = myStudyDocument->FindObjectIOR(anIOR);
663 return Build(aFieldSObject);
664 }catch(std::exception& exc){
665 INFOS("Follow exception was occured :\n"<<exc.what());
667 INFOS("Unknown exception was occured!!!");
673 //---------------------------------------------------------------
676 ::Save(SALOMEDS::SComponent_ptr theComponent,
677 const std::string& theURL,
680 TFileNames& theFileNames,
681 TFileNames& theFiles)
683 switch(GetCreationId()){
684 case Result_i::eImportFile:
685 case Result_i::eCopyAndImportFile: {
686 INITMSG(MYDEBUG, "Result::Save - this = "<<this<<"\n");
687 INITMSGA(MYDEBUG, 0, "theIsMultiFile = "<<theIsMultiFile<<"; theIsASCII = "<<theIsASCII<<"\n");
690 if (theIsMultiFile) {
691 CORBA::String_var anURL = GetStudyDocument()->URL();
692 aPrefix = SALOMEDS_Tool::GetNameFromPath(anURL.in());
695 std::string aFileName = aPrefix + "_" + GetFileName().c_str();
696 BEGMSG(MYDEBUG, "aFileName = '"<<aFileName<<"'\n");
698 std::string aFile = GetFileInfo().filePath().toLatin1().data();
699 BEGMSG(MYDEBUG, "aFile = '"<<aFile<<"'\n");
701 if(theIsMultiFile || theIsASCII){
702 std::string aPathToCopy(theURL + aFileName);
703 BEGMSG(MYDEBUG, "aPathToCopy = '"<<aPathToCopy<<"'\n");
705 if(!VISU::CopyFile(aFile, aPathToCopy))
709 HDFascii::ConvertFromHDFToASCII(const_cast<char*>(aPathToCopy.c_str()), true);
712 theFileNames.push_back(aFileName);
713 theFiles.push_back(aFile);
722 //---------------------------------------------------------------
725 ::CanCopy(SALOMEDS::SObject_ptr theObject)
727 switch(GetCreationId()){
728 case Result_i::eImportFile:
729 case Result_i::eCopyAndImportFile:
737 //---------------------------------------------------------------
740 ::CopyFrom(SALOMEDS::SObject_ptr theObject,
741 CORBA::Long& theObjectID,
742 const std::string& theTmpDir,
743 TFileNames& theFileNames)
745 if(!Storable::CopyFrom(theObject, theObjectID, theTmpDir, theFileNames))
748 SALOMEDS::Study_var aStudy = theObject->GetStudy();
749 CORBA::String_var anURL = aStudy->URL();
750 std::string aPrefix = SALOMEDS_Tool::GetNameFromPath(anURL.in());
751 std::string aFileName = aPrefix + GetFileInfo().fileName().toLatin1().data();
753 static QString aCommand;
754 std::string aFilePath = theTmpDir + aFileName;
755 aCommand.sprintf(" \"%s\" \"%s\"", GetFileInfo().filePath().toLatin1().data(), aFilePath.c_str());
756 aCommand = QDir::convertSeparators( aCommand );
757 aCommand.prepend( COPY_COMMAND );
759 if(system(aCommand.toLatin1().data()) != 0) {
760 if(MYDEBUG) MESSAGE("VISU_Gen_i::Copy - Cann't execute the command :"<<aCommand.toLatin1().data());
764 SALOMEDS::SComponent_var aSComponent = aStudy->FindComponent("VISU");
766 theFileNames.push_back(aFileName);
772 //---------------------------------------------------------------
775 ::Restore(SALOMEDS::SObject_ptr theSObject,
776 const Storable::TRestoringMap& theMap,
777 const string& thePrefix,
778 CORBA::Boolean theIsMultiFile)
780 if(MYDEBUG) MESSAGE("Result_i::Restore - " << thePrefix);
781 mySObject = SALOMEDS::SObject::_duplicate(theSObject);
782 mySObject->Register(); // Increment reference counter to stored SObject
783 mySComponent = mySObject->GetFatherComponent();
784 myStudyDocument = theSObject->GetStudy();
785 myStudy = VISU::GetStudy(myStudyDocument);
787 myCreationId = ECreationId(Storable::FindValue(theMap, "myCreationId").toInt());
788 mySourceId = eRestoredFile;
789 if(myCreationId == eImportMed || myCreationId == eImportMedField)
790 mySourceId = eRestoredComponent;
792 myIsBuildFields = Storable::FindValue(theMap, "myIsBuildFields", "1").toInt();
793 myIsBuildMinMax = Storable::FindValue(theMap, "myIsBuildMinMax", "1").toInt();
794 myIsBuildGroups = Storable::FindValue(theMap, "myIsBuildGroups", "1").toInt();
796 myIsBuildImmediately = true;
799 myFileName = VISU::Storable::FindValue(theMap, "myName").toLatin1().data();
801 for (int i = 0; i < myFileName.length(); i++)
803 if (myFileName[i] == ':')
807 SetInitFileName(VISU::Storable::FindValue(theMap, "myInitFileName").toLatin1().data());
809 SALOMEDS::SObject_var aRefSObj, aTargetRefSObj;
810 if (theSObject->FindSubObject(1, aRefSObj) && aRefSObj->ReferencedObject(aTargetRefSObj)) {
811 if(MYDEBUG) MESSAGE("Result_i::GetInput - There is some reference.");
812 SALOMEDS::SComponent_var aCompRefSObj = aTargetRefSObj->GetFatherComponent();
813 CORBA::String_var aDataType = aCompRefSObj->ComponentDataType();
814 myFileInfo.setFile(aDataType.in());
815 if(MYDEBUG) MESSAGE("Result_i::GetInput - aDataType = " << aDataType);
816 Engines::EngineComponent_var aEngComp =
817 Base_i::myEnginesLifeCycle->FindOrLoad_Component("FactoryServer", aDataType.in());
818 if (CORBA::is_nil(aEngComp))
819 throw std::runtime_error("Restore - There is no aEngComp for the aDataType !!!");
820 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
821 SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(aEngComp);
822 aStudyBuilder->LoadWith(aCompRefSObj, aDriver);
823 // create field or MED converter
824 CORBA::Object_var aMedObject = VISU::SObjectToObject(aTargetRefSObj);
825 SALOME_MED::FIELD_var aField = SALOME_MED::FIELD::_narrow(aMedObject);
826 if (!CORBA::is_nil(aField)) {
827 // create field converter
828 myInput.reset(CreateMEDFieldConvertor(aField));
831 else if (strcmp(aDataType, "MED") == 0) {
832 // create MED converter
833 myInput.reset(CreateMEDConvertor(aTargetRefSObj));
837 throw std::runtime_error("GetInput - There is no convertor for the aDataType !!!");
840 myFileInfo.setFile(thePrefix.c_str());
842 std::string aStudyPrefix ("");
843 if (theIsMultiFile) {
844 CORBA::String_var anURL(GetStudyDocument()->URL());
845 aStudyPrefix = SALOMEDS_Tool::GetNameFromPath(anURL.in());
847 if (!myFileInfo.isFile()) {
848 std::string aFileName = thePrefix + aStudyPrefix + "_" + myFileName;
849 myFileInfo.setFile(aFileName.c_str());
852 MESSAGE("Result_i::Restore - aFileName = " << myFileInfo.filePath().toLatin1().data() << "; " << myFileInfo.isFile());
854 if (HDFascii::isASCII(myFileInfo.filePath().toLatin1().data())) {
855 MESSAGE("ConvertFromASCIIToHDF(" << myFileInfo.filePath().toLatin1().data() << ")");
856 char* aResultPath = HDFascii::ConvertFromASCIIToHDF(myFileInfo.filePath().toLatin1().data());
857 MESSAGE("ConvertFromASCIIToHDF() DONE : " << aResultPath);
858 char* aHDFFileName = new char[strlen(aResultPath) + 19];
859 sprintf(aHDFFileName, "%shdf_from_ascii.hdf", aResultPath);
861 if (theIsMultiFile) { // set this file as new - temporary
862 static QString aCommand;
863 aCommand.sprintf(" \"%s\" \"%s%s\"",aHDFFileName, aResultPath, myFileInfo.baseName().toLatin1().data());
864 aCommand = QDir::convertSeparators( aCommand );
865 aCommand.prepend( MOVE_COMMAND );
867 if (system(aCommand.toLatin1().data()) == -1) {
868 if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - Can't execute the command :" << aCommand.toLatin1().data());
871 if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - " << aCommand.toLatin1().data());
873 myFileInfo.setFile(QString(aResultPath) + myFileInfo.baseName());
874 } else { // change current temporary file to the new: with hdf-format
875 static QString aCommand;
876 aCommand.sprintf(" \"%s\" \"%s\"\0",aHDFFileName, myFileInfo.filePath().toLatin1().data());
877 aCommand = QDir::convertSeparators( aCommand );
878 aCommand.prepend( MOVE_COMMAND );
880 if (system(aCommand.toLatin1().data()) == -1) {
881 if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - Can't execute the command :" << aCommand.toLatin1().data());
884 if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - " << aCommand.toLatin1().data());
886 SALOMEDS::ListOfFileNames_var anEmptyList = new SALOMEDS::ListOfFileNames;
887 SALOMEDS_Tool::RemoveTemporaryFiles(aResultPath, anEmptyList.in(), true);
889 mySourceId = eRestoredFile;
891 delete(aHDFFileName);
892 } else if (!theIsMultiFile) {
893 mySourceId = eRestoredFile;
895 mySourceId = eSavedFile;
897 if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - mySourceId = " << mySourceId);
898 myInput.reset(CreateConvertor(myFileInfo.filePath().toLatin1().data()));
900 myInput->BuildEntities();
902 myInput->BuildFields();
903 myIsFieldsDone = true;
905 myInput->BuildMinMax();
906 myIsMinMaxDone = true;
910 myInput->BuildGroups();
911 myIsGroupsDone = true;
915 aComment.sprintf("myComment=%s;myFileName=%s;myInitFileName=%s",
917 myFileInfo.filePath().toLatin1().data(),
918 GetInitFileName().c_str()); // Restoring of Python dump
919 SALOMEDS::GenericAttribute_var anAttr;
920 if (!theSObject->FindAttribute(anAttr, "AttributeString"))
921 throw std::runtime_error("Build - There is no AttributeString for the SObject !!!");
922 SALOMEDS::AttributeString_var aCmnt = SALOMEDS::AttributeString::_narrow(anAttr);
923 aCmnt->SetValue(aComment.toLatin1().data());
925 bool anIsBuildAll = VISU::GetResourceMgr()->booleanValue("VISU", "full_med_loading", false);
929 } catch(std::exception& exc) {
930 INFOS("Follow exception was occured :\n"<<exc.what());
932 INFOS("Unknown exception was occured!!!");
938 //---------------------------------------------------------------
939 VISU::Result_i::PInput
941 ::GetInput(const std::string& theMeshName,
942 VISU::Entity theEntity,
943 const std::string& theFieldName,
944 CORBA::Long theTimeStampNumber)
950 //---------------------------------------------------------------
957 (myIsBuildFields? myIsFieldsDone: true) &&
958 (myIsBuildMinMax? myIsMinMaxDone: true) &&
959 (myIsBuildGroups? myIsGroupsDone: true);
966 return myIsEntitiesDone;
971 ::SetBuildFields(CORBA::Boolean theIsBuildFields,
972 CORBA::Boolean theIsCalculateMinMax)
974 myIsBuildFields = theIsBuildFields;
976 myIsBuildMinMax = theIsCalculateMinMax;
978 myIsBuildMinMax = false;
983 ::SetBuildGroups(CORBA::Boolean theIsBuildGroups)
985 myIsBuildGroups = theIsBuildGroups;
992 return myIsFieldsDone;
999 return myIsGroupsDone;
1006 return myIsMinMaxDone;
1013 return myIsPartsDone;
1017 //---------------------------------------------------------------
1018 VISU::Result::EntityNames*
1022 VISU::Result::EntityNames_var aResult = new VISU::Result::EntityNames();
1023 const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
1024 if(aMeshMap.empty())
1025 return aResult._retn();
1027 aResult->length(aMeshMap.size());
1028 VISU::TMeshMap::const_iterator anIter = aMeshMap.begin();
1029 for(size_t anId = 0; anIter != aMeshMap.end(); anIter++, anId++){
1030 const std::string& aName = anIter->first;
1031 aResult[anId] = aName.c_str();
1034 return aResult._retn();
1038 //---------------------------------------------------------------
1039 VISU::Result::Entities*
1041 ::GetEntities(const char* theMeshName)
1043 VISU::Result::Entities_var anEntities = new VISU::Result::Entities();
1044 const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
1045 if(aMeshMap.empty())
1046 return anEntities._retn();
1048 VISU::TMeshMap::const_iterator anIter = aMeshMap.find(theMeshName);
1049 if(anIter == aMeshMap.end())
1050 return anEntities._retn();
1052 const VISU::PMesh& aMesh = anIter->second;
1053 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
1054 if(aMeshOnEntityMap.empty())
1055 return anEntities._retn();
1058 anEntities->length(aMeshOnEntityMap.size());
1059 VISU::TMeshOnEntityMap::const_iterator anIter = aMeshOnEntityMap.begin();
1060 for(size_t anId = 0; anIter != aMeshOnEntityMap.end(); anIter++, anId++){
1061 const VISU::TEntity& anEntity = anIter->first;
1062 anEntities[anId] = VISU::Entity(anEntity);
1066 return anEntities._retn();
1070 //---------------------------------------------------------------
1071 VISU::Result::EntityNames*
1073 ::GetFamilies(const char* theMeshName,
1074 VISU::Entity theEntity)
1076 VISU::Result::EntityNames_var aResult = new VISU::Result::EntityNames();
1077 const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
1078 if(aMeshMap.empty())
1079 return aResult._retn();
1081 VISU::TMeshMap::const_iterator anIter = aMeshMap.find(theMeshName);
1082 if(anIter == aMeshMap.end())
1083 return aResult._retn();
1085 const VISU::PMesh& aMesh = anIter->second;
1086 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
1087 if(aMeshOnEntityMap.empty())
1088 return aResult._retn();
1091 VISU::TEntity anEntity = VISU::TEntity(theEntity);
1092 VISU::TMeshOnEntityMap::const_iterator anIter = aMeshOnEntityMap.find(anEntity);
1093 if(anIter == aMeshOnEntityMap.end())
1094 return aResult._retn();
1096 const VISU::PMeshOnEntity& aMeshOnEntity = anIter->second;
1097 const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
1098 if(aFamilyMap.empty())
1099 return aResult._retn();
1102 aResult->length(aFamilyMap.size());
1103 VISU::TFamilyMap::const_iterator anIter = aFamilyMap.begin();
1104 for(size_t anId = 0; anIter != aFamilyMap.end(); anIter++, anId++){
1105 const std::string& aName = anIter->first;
1106 aResult[anId] = aName.c_str();
1111 return aResult._retn();
1115 //---------------------------------------------------------------
1116 VISU::Result::EntityNames*
1118 ::GetGroups(const char* theMeshName)
1120 VISU::Result::EntityNames_var aResult = new VISU::Result::EntityNames();
1121 const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
1122 if(aMeshMap.empty())
1123 return aResult._retn();
1125 VISU::TMeshMap::const_iterator anIter = aMeshMap.find(theMeshName);
1126 if(anIter == aMeshMap.end())
1127 return aResult._retn();
1129 const VISU::PMesh& aMesh = anIter->second;
1130 const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
1131 if(aGroupMap.empty())
1132 return aResult._retn();
1135 aResult->length(aGroupMap.size());
1136 VISU::TGroupMap::const_iterator anIter = aGroupMap.begin();
1137 for(size_t anId = 0; anIter != aGroupMap.end(); anIter++, anId++){
1138 const std::string& aName = anIter->first;
1139 aResult[anId] = aName.c_str();
1143 return aResult._retn();
1147 //---------------------------------------------------------------
1148 VISU::Result::EntityNames*
1150 ::GetFields(const char* theMeshName,
1151 VISU::Entity theEntity)
1153 VISU::Result::EntityNames_var aResult = new VISU::Result::EntityNames();
1154 const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
1155 if(aMeshMap.empty())
1156 return aResult._retn();
1158 VISU::TMeshMap::const_iterator anIter = aMeshMap.find(theMeshName);
1159 if(anIter == aMeshMap.end())
1160 return aResult._retn();
1162 const VISU::PMesh& aMesh = anIter->second;
1163 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
1164 if(aMeshOnEntityMap.empty())
1165 return aResult._retn();
1168 VISU::TEntity anEntity = VISU::TEntity(theEntity);
1169 VISU::TMeshOnEntityMap::const_iterator anIter = aMeshOnEntityMap.find(anEntity);
1170 if(anIter == aMeshOnEntityMap.end())
1171 return aResult._retn();
1173 const VISU::PMeshOnEntity& aMeshOnEntity = anIter->second;
1174 const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
1175 if(aFieldMap.empty())
1176 return aResult._retn();
1179 aResult->length(aFieldMap.size());
1180 VISU::TFieldMap::const_iterator anIter = aFieldMap.begin();
1181 for(size_t anId = 0; anIter != aFieldMap.end(); anIter++, anId++){
1182 const std::string& aName = anIter->first;
1183 aResult[anId] = aName.c_str();
1188 return aResult._retn();
1192 //---------------------------------------------------------------
1193 VISU::Result::TimeStampNumbers*
1195 ::GetTimeStampNumbers(const char* theMeshName,
1196 VISU::Entity theEntity,
1197 const char* theFieldName)
1199 VISU::Result::TimeStampNumbers_var aResult = new VISU::Result::TimeStampNumbers();
1200 const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
1201 if(aMeshMap.empty())
1202 return aResult._retn();
1204 VISU::TMeshMap::const_iterator anIter = aMeshMap.find(theMeshName);
1205 if(anIter == aMeshMap.end())
1206 return aResult._retn();
1208 const VISU::PMesh& aMesh = anIter->second;
1209 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
1210 if(aMeshOnEntityMap.empty())
1211 return aResult._retn();
1214 VISU::TEntity anEntity = VISU::TEntity(theEntity);
1215 VISU::TMeshOnEntityMap::const_iterator anIter = aMeshOnEntityMap.find(anEntity);
1216 if(anIter == aMeshOnEntityMap.end())
1217 return aResult._retn();
1219 const VISU::PMeshOnEntity& aMeshOnEntity = anIter->second;
1220 const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
1221 if(aFieldMap.empty())
1222 return aResult._retn();
1225 VISU::TFieldMap::const_iterator anIter = aFieldMap.find(theFieldName);
1226 if(anIter == aFieldMap.end())
1227 return aResult._retn();
1230 const VISU::PField& aField = anIter->second;
1231 const VISU::TValField& aValField = aField->myValField;
1232 if(aValField.empty())
1233 return aResult._retn();
1236 aResult->length(aValField.size());
1237 VISU::TValField::const_iterator anIter = aValField.begin();
1238 for(size_t anId = 0; anIter != aValField.end(); anIter++, anId++){
1239 const vtkIdType& aTimeStampNumber = anIter->first;
1240 aResult[anId] = aTimeStampNumber;
1247 return aResult._retn();
1251 //---------------------------------------------------------------
1254 ::GetTimeStampValues(const char* theMeshName,
1255 VISU::Entity theEntity,
1256 const char* theFieldName)
1258 VISU::double_array_var aResult = new VISU::double_array();
1259 const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
1260 if(aMeshMap.empty())
1261 return aResult._retn();
1263 VISU::TMeshMap::const_iterator anIter = aMeshMap.find(theMeshName);
1264 if(anIter == aMeshMap.end())
1265 return aResult._retn();
1267 const VISU::PMesh& aMesh = anIter->second;
1268 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
1269 if(aMeshOnEntityMap.empty())
1270 return aResult._retn();
1273 VISU::TEntity anEntity = VISU::TEntity(theEntity);
1274 VISU::TMeshOnEntityMap::const_iterator anIter = aMeshOnEntityMap.find(anEntity);
1275 if(anIter == aMeshOnEntityMap.end())
1276 return aResult._retn();
1278 const VISU::PMeshOnEntity& aMeshOnEntity = anIter->second;
1279 const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
1280 if(aFieldMap.empty())
1281 return aResult._retn();
1284 VISU::TFieldMap::const_iterator anIter = aFieldMap.find(theFieldName);
1285 if(anIter == aFieldMap.end())
1286 return aResult._retn();
1289 const VISU::PField& aField = anIter->second;
1290 const VISU::TValField& aValField = aField->myValField;
1291 if(aValField.empty())
1292 return aResult._retn();
1295 aResult->length(aValField.size());
1296 VISU::TValField::const_iterator anIter = aValField.begin();
1297 for(size_t anId = 0; anIter != aValField.end(); anIter++, anId++){
1298 const PValForTime& aValForTime = anIter->second;
1299 aResult[anId] = aValForTime->myTime.first;
1306 return aResult._retn();
1310 //---------------------------------------------------------------
1313 ::GetNumberOfComponents(const char* theMeshName,
1314 VISU::Entity theEntity,
1315 const char* theFieldName)
1317 CORBA::Long aResult = 0;
1318 const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
1319 if(aMeshMap.empty())
1322 VISU::TMeshMap::const_iterator anIter = aMeshMap.find(theMeshName);
1323 if(anIter == aMeshMap.end())
1326 const VISU::PMesh& aMesh = anIter->second;
1327 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
1328 if(aMeshOnEntityMap.empty())
1332 VISU::TEntity anEntity = VISU::TEntity(theEntity);
1333 VISU::TMeshOnEntityMap::const_iterator anIter = aMeshOnEntityMap.find(anEntity);
1334 if(anIter == aMeshOnEntityMap.end())
1337 const VISU::PMeshOnEntity& aMeshOnEntity = anIter->second;
1338 const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
1339 if(aFieldMap.empty())
1343 VISU::TFieldMap::const_iterator anIter = aFieldMap.find(theFieldName);
1344 if(anIter == aFieldMap.end())
1348 const VISU::PField& aField = anIter->second;
1349 aResult = aField->myNbComp;
1358 //---------------------------------------------------------------
1359 VISU::Result::EntityNames*
1361 ::GetPartNames(const char* theMeshName)
1363 VISU::Result::EntityNames_var aResult = new VISU::Result::EntityNames();
1364 return aResult._retn();
1368 //---------------------------------------------------------------
1369 VISU::Result::Resolutions*
1371 ::GetResolutions(const char* theMeshName,
1372 const char* thePartName)
1374 VISU::Result::Resolutions_var aResult = new VISU::Result::Resolutions();
1375 return aResult._retn();
1379 //---------------------------------------------------------------
1380 VISU::Result::Resolution
1382 ::GetResolution(const char* theMeshName,
1383 const char* thePartName)
1385 return VISU::Result::HIDDEN;
1389 //---------------------------------------------------------------
1392 ::SetResolution(const char* theMeshName,
1393 const char* thePartName,
1394 VISU::Result::Resolution theResolution)
1398 //---------------------------------------------------------------
1401 ::New(SALOMEDS::Study_ptr theStudy,
1402 const ESourceId& theSourceId,
1403 const ECreationId& theCreationId,
1404 CORBA::Boolean theIsBuildImmediately,
1405 CORBA::Boolean theIsBuildFields,
1406 CORBA::Boolean theIsBuildMinMax,
1407 CORBA::Boolean theIsBuildGroups)
1409 return new RESULT_CLASS_NAME(theStudy,
1412 theIsBuildImmediately,
1419 //---------------------------------------------------------------
1422 ::StorableEngine(SALOMEDS::SObject_ptr theSObject,
1423 const Storable::TRestoringMap& theMap,
1424 const std::string& thePrefix,
1425 CORBA::Boolean theIsMultiFile)
1427 VISU::Result_i* aResult = new RESULT_CLASS_NAME();
1428 return aResult->Restore(theSObject, theMap, thePrefix, theIsMultiFile);
1432 //---------------------------------------------------------------
1435 ::ToStream(std::ostringstream& theStr)
1437 Storable::DataToStream(theStr,"myName", GetFileName().c_str());
1438 Storable::DataToStream(theStr,"myInitFileName", GetInitFileName().c_str());
1439 Storable::DataToStream(theStr,"myCreationId", myCreationId);
1440 Storable::DataToStream(theStr,"myIsBuildFields", myIsFieldsDone);
1441 Storable::DataToStream(theStr,"myIsBuildMinMax", myIsMinMaxDone);
1442 Storable::DataToStream(theStr,"myIsBuildGroups", myIsGroupsDone);
1445 //---------------------------------------------------------------
1449 ::ExportMED(const char* theTargetFileName)
1451 static QString aCommand;
1452 const char* aTempFileName = myFileInfo.absoluteFilePath().toLatin1();
1453 aCommand.sprintf(" \"%s\" \"%s\"", aTempFileName, theTargetFileName);
1454 aCommand = QDir::convertSeparators( aCommand );
1455 aCommand.prepend( COPY_COMMAND );
1457 if(system(aCommand.toLatin1().data()) != 0) {
1458 if(MYDEBUG) MESSAGE("VISU_Gen_i::Copy - Cann't execute the command :"<<aCommand.toLatin1().data());
1465 //---------------------------------------------------------------
1468 ::GetInitFileName() const
1470 return myInitFileName;
1476 ::SetInitFileName(const std::string& theFileName)
1478 myInitFileName = theFileName;
1482 //---------------------------------------------------------------
1485 ::GetFileName() const
1487 if(GetSourceId() == eFile)
1488 return VISU::MakeFileName(myFileName, this);
1496 ::GetFileInfo() const
1501 VISU::Result_i::ECreationId
1503 ::GetCreationId() const
1505 return myCreationId;
1509 VISU::Result_i::ESourceId
1511 ::GetSourceId() const
1517 //---------------------------------------------------------------
1522 CORBA::String_var anEntry = mySObject->GetID();
1523 return anEntry.in();
1526 SALOMEDS::SObject_var
1528 ::GetSObject() const
1535 ::GetStudyDocument() const
1537 return myStudyDocument;
1547 SALOMEDS::SComponent_var
1549 ::GetSComponent() const
1551 return mySComponent;
1556 ::GetEntry(const Storable::TRestoringMap& theRestoringMap)
1558 return Storable::FindEntry(myStudyDocument,
1564 //=======================================================================
1565 //function : GetAxisInfo
1567 //=======================================================================
1568 const VISU::Result_i::TAxisInfo*
1570 ::GetAxisInfo(const string& theMeshName,
1572 gp_Dir& thePlaneNormal)
1574 const TAxisInfo* components = NULL;
1576 if ( theAxis < AXIS_X || theAxis > AXIS_Z ) {
1577 MESSAGE(" Bad axis index " << theAxis );
1581 map< string, TGridInfo >::iterator name_info;
1582 name_info = myMeshName2GridInfoMap.find( theMeshName );
1583 TGridInfo * gInfo = 0;
1585 if ( name_info != myMeshName2GridInfoMap.end() )
1587 gInfo = & name_info->second;
1589 else if ( myInput && IsPossible() && theAxis >= AXIS_X && theAxis <= AXIS_Z )
1591 // check presence of theMeshName
1592 const VISU::TMeshMap& meshMap = myInput->GetMeshMap();
1594 VISU::TMeshMap::const_iterator aIter = meshMap.find( theMeshName );
1595 if ( aIter == meshMap.end() ) {
1596 MESSAGE("No mesh named " << theMeshName );
1599 theMesh = aIter->second;
1601 VISU::PUnstructuredGridIDMapper anIDMapper = myInput->GetMeshOnEntity(theMeshName,
1603 vtkUnstructuredGrid* aMesh = anIDMapper->GetUnstructuredGridOutput();
1605 if ( !aMesh || aMesh->GetNumberOfCells() == 0 ) {
1606 MESSAGE( "No cells in the mesh: " << theMeshName );
1610 if ( !theMesh->IsStructured() || theMesh->myIsPolarType ) {
1611 // define axis directions and min cell size in each direction
1612 const int nbAxes = 3;
1614 gp_Vec axDirs[ nbAxes ];
1615 float minSize[3] = { FLT_MAX, FLT_MAX, FLT_MAX };
1616 bool axesComputed = false;
1617 for ( vtkIdType iCell = 0; iCell < aMesh->GetNumberOfCells(); ++iCell ) {
1618 vtkCell* cell = aMesh->GetCell( iCell );
1620 if (cell->GetCellType() != VTK_HEXAHEDRON &&
1621 cell->GetCellType() != VTK_QUADRATIC_HEXAHEDRON )
1623 vtkPoints * points = cell->GetPoints();
1624 double coords[ 4 ][3];
1625 points->GetPoint( 0, coords[0] );
1626 points->GetPoint( 1, coords[1] );
1627 points->GetPoint( 3, coords[2] );
1628 points->GetPoint( 4, coords[3] );
1629 gp_Pnt p0( coords[0][0], coords[0][1], coords[0][2] );
1630 for ( iAx = 0; iAx < nbAxes; ++iAx ) {
1631 double* coo = coords[ iAx + 1 ];
1632 gp_Pnt p( coo[0], coo[1], coo[2] );
1634 double size = p0.SquareDistance( p );
1635 if ( size > FLT_MIN && size < minSize[ iAx ] )
1636 minSize[ iAx ] = size;
1638 if ( !axesComputed ) {
1639 gp_Vec dir( p0, p );
1640 if ( dir.SquareMagnitude() <= gp::Resolution() ) {
1643 axDirs[ iAx ] = dir;
1646 if ( iAx == nbAxes )
1647 axesComputed = true;
1649 if ( !axesComputed ) {
1650 MESSAGE("No good hexahedrons in the mesh: " << theMeshName );
1654 // compute axes dirs
1655 gInfo = & myMeshName2GridInfoMap[ theMeshName ];
1656 for ( iAx = 0; iAx < nbAxes; ++iAx ) {
1657 int iPrev = ( iAx == 0 ) ? 2 : iAx - 1;
1658 int iNext = ( iAx == 2 ) ? 0 : iAx + 1;
1659 gInfo->myAxis[ iAx ] = axDirs[ iPrev ] ^ axDirs[ iNext ];
1662 // get and sort intermediate component values - projections of nodes
1663 // on axis direction; define bnd box
1664 set< double > comps[ 3 ];
1666 vtkPoints * points = aMesh->GetPoints();
1667 vtkIdType iP, nbP = aMesh->GetNumberOfPoints();
1668 for ( iP = 0; iP < nbP; ++iP ) {
1670 points->GetPoint( iP, coo );
1671 gp_Pnt p( coo[0], coo[1], coo[2] );
1673 for ( iAx = 0; iAx < nbAxes; ++iAx ) {
1674 const gp_Dir& dir = gInfo->myAxis[ iAx ];
1675 double dot = dir.XYZ() * p.XYZ();
1676 comps[ iAx ].insert( dot );
1680 // find a range of projections of bnd box corners on each axis
1681 double range[3], firstValue[3];
1682 double x[2],y[2],z[2];
1683 box.Get(x[0],y[0],z[0],x[1],y[1],z[1]);
1684 for ( iAx = 0; iAx < nbAxes; ++iAx ) {
1685 set< double > bndComps;
1686 const gp_Dir& dir = gInfo->myAxis[ iAx ];
1687 for ( int iX = 0; iX < 2; ++iX ) {
1688 for ( int iY = 0; iY < 2; ++iY ) {
1689 for ( int iZ = 0; iZ < 2; ++iZ ) {
1690 gp_Pnt p( x[ iX ], y[ iY ], z[ iZ ] );
1691 double dot = dir.XYZ() * p.XYZ();
1692 bndComps.insert( dot );
1696 firstValue[ iAx ] = *bndComps.begin();
1697 range[ iAx ] = *bndComps.rbegin() - *bndComps.begin();
1700 // compute component values
1701 for ( iAx = 0; iAx < nbAxes; ++iAx ) {
1702 list< double > values;
1704 set< double >& comp = comps[ iAx ];
1705 set< double >::iterator val = comp.begin();
1706 double bnd = -1., rng = range[ iAx ], first = firstValue[ iAx ];
1707 double tol = 0.1 * sqrt( minSize[ iAx ]) / rng;
1708 for ( ; val != comp.end(); ++val ) {
1709 double value = ( *val - first ) / rng;
1710 if ( value > bnd ) {
1711 values.push_back( value );
1716 // store values in gInfo
1717 vector< double >& myComp = gInfo->myComponets[ iAx ];
1718 myComp.resize( nbVals );
1719 list< double >::iterator v = values.begin();
1720 for ( int i = 0; v != values.end(); ++v ){
1726 vtkIdType aMeshDim = theMesh->myDim;
1727 gInfo = & myMeshName2GridInfoMap[ theMeshName ];
1728 switch ( aMeshDim ) {
1730 gp_Dir aDir(0.0,0.0,1.0);
1731 gInfo->myAxis[ 2 ] = aDir;
1734 gp_Dir aDir(0.0,1.0,0.0);
1735 gInfo->myAxis[ 1 ] = aDir;
1738 gp_Dir aDir(1.0,0.0,0.0);
1739 gInfo->myAxis[ 0 ] = aDir;
1742 TStructuredId aStructuredId = theMesh->GetStructure();
1743 vector<double> PointsCoords[3];
1744 vtkPoints* aPoints = aMesh->GetPoints();
1745 switch ( aMeshDim ) {
1747 TStructuredId aCoordIJK;
1748 vtkIdType nbZ = aStructuredId[2];
1749 for ( int i = 0; i < nbZ; i++ ) {
1750 aCoordIJK[2] = i + 1;
1751 vtkIdType aObjID = anIDMapper->GetObjectIDByIndexes(aCoordIJK);
1752 vtkIdType aVTKID = anIDMapper->GetNodeVTKID(aObjID);
1753 double* aPCoord = aPoints->GetPoint(aVTKID);
1754 PointsCoords[2].push_back(aPCoord[2]);
1758 TStructuredId aCoordIJK;
1759 vtkIdType nbJ = aStructuredId[1];
1760 for ( int i = 0; i < nbJ; i++ ) {
1761 aCoordIJK[1] = i + 1;
1762 vtkIdType aObjID = anIDMapper->GetObjectIDByIndexes(aCoordIJK);
1763 vtkIdType aVTKID = anIDMapper->GetNodeVTKID(aObjID);
1764 double* aPCoord = aPoints->GetPoint(aVTKID);
1765 PointsCoords[1].push_back(aPCoord[1]);
1769 TStructuredId aCoordIJK;
1770 vtkIdType nbI = aStructuredId[0];
1771 for ( int i = 0; i < nbI; i++ ) {
1772 aCoordIJK[0] = i + 1;
1773 vtkIdType aObjID = anIDMapper->GetObjectIDByIndexes(aCoordIJK);
1774 vtkIdType aVTKID = anIDMapper->GetNodeVTKID(aObjID);
1775 double* aPCoord = aPoints->GetPoint(aVTKID);
1776 PointsCoords[0].push_back(aPCoord[0]);
1779 for ( int i = 0; i < aMeshDim; i++ ) {
1780 vector< double >& myComp = gInfo->myComponets[ i ];
1781 int aSize = PointsCoords[i].size();
1783 double aLen = PointsCoords[i][aSize-1] - PointsCoords[i][0];
1784 myComp.resize(aSize);
1786 for ( int k = 1; k < aSize; k++ ) {
1787 myComp[k]=myComp[k-1] + (PointsCoords[i][k]-PointsCoords[i][k-1])/aLen;
1794 // set return values
1796 thePlaneNormal = gInfo->myAxis[ theAxis ];
1797 components = & gInfo->myComponets[ theAxis ];
1803 SALOME_MED::MedFileInfo* VISU::Result_i::GetMEDFileInfo()
1805 SALOME_MED::MedFileInfo_var res = new SALOME_MED::MedFileInfo();
1807 QString fpath = myFileInfo.absoluteFilePath();
1808 res->fileName = fpath.toLatin1().constData();
1809 res->fileSize = myFileInfo.size();
1810 int major, minor, release;
1811 if( !MED::getMEDVersion( fpath.toLatin1().constData(), major, minor, release ) )
1819 res->release = release;