1 // Copyright (C) 2007-2012 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 mySComponent = mySObject->GetFatherComponent();
783 myStudyDocument = theSObject->GetStudy();
784 myStudy = VISU::GetStudy(myStudyDocument);
786 myCreationId = ECreationId(Storable::FindValue(theMap, "myCreationId").toInt());
787 mySourceId = eRestoredFile;
788 if(myCreationId == eImportMed || myCreationId == eImportMedField)
789 mySourceId = eRestoredComponent;
791 myIsBuildFields = Storable::FindValue(theMap, "myIsBuildFields", "1").toInt();
792 myIsBuildMinMax = Storable::FindValue(theMap, "myIsBuildMinMax", "1").toInt();
793 myIsBuildGroups = Storable::FindValue(theMap, "myIsBuildGroups", "1").toInt();
795 myIsBuildImmediately = true;
798 myFileName = VISU::Storable::FindValue(theMap, "myName").toLatin1().data();
800 for (int i = 0; i < myFileName.length(); i++)
802 if (myFileName[i] == ':')
806 SetInitFileName(VISU::Storable::FindValue(theMap, "myInitFileName").toLatin1().data());
808 SALOMEDS::SObject_var aRefSObj, aTargetRefSObj;
809 if (theSObject->FindSubObject(1, aRefSObj) && aRefSObj->ReferencedObject(aTargetRefSObj)) {
810 if(MYDEBUG) MESSAGE("Result_i::GetInput - There is some reference.");
811 SALOMEDS::SComponent_var aCompRefSObj = aTargetRefSObj->GetFatherComponent();
812 CORBA::String_var aDataType = aCompRefSObj->ComponentDataType();
813 myFileInfo.setFile(aDataType.in());
814 if(MYDEBUG) MESSAGE("Result_i::GetInput - aDataType = " << aDataType);
815 Engines::EngineComponent_var aEngComp =
816 Base_i::myEnginesLifeCycle->FindOrLoad_Component("FactoryServer", aDataType.in());
817 if (CORBA::is_nil(aEngComp))
818 throw std::runtime_error("Restore - There is no aEngComp for the aDataType !!!");
819 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudyDocument->NewBuilder();
820 SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(aEngComp);
821 aStudyBuilder->LoadWith(aCompRefSObj, aDriver);
822 // create field or MED converter
823 CORBA::Object_var aMedObject = VISU::SObjectToObject(aTargetRefSObj);
824 SALOME_MED::FIELD_var aField = SALOME_MED::FIELD::_narrow(aMedObject);
825 if (!CORBA::is_nil(aField)) {
826 // create field converter
827 myInput.reset(CreateMEDFieldConvertor(aField));
830 else if (strcmp(aDataType, "MED") == 0) {
831 // create MED converter
832 myInput.reset(CreateMEDConvertor(aTargetRefSObj));
836 throw std::runtime_error("GetInput - There is no convertor for the aDataType !!!");
839 myFileInfo.setFile(thePrefix.c_str());
841 std::string aStudyPrefix ("");
842 if (theIsMultiFile) {
843 CORBA::String_var anURL(GetStudyDocument()->URL());
844 aStudyPrefix = SALOMEDS_Tool::GetNameFromPath(anURL.in());
846 if (!myFileInfo.isFile()) {
847 std::string aFileName = thePrefix + aStudyPrefix + "_" + myFileName;
848 myFileInfo.setFile(aFileName.c_str());
851 MESSAGE("Result_i::Restore - aFileName = " << myFileInfo.filePath().toLatin1().data() << "; " << myFileInfo.isFile());
853 if (HDFascii::isASCII(myFileInfo.filePath().toLatin1().data())) {
854 MESSAGE("ConvertFromASCIIToHDF(" << myFileInfo.filePath().toLatin1().data() << ")");
855 char* aResultPath = HDFascii::ConvertFromASCIIToHDF(myFileInfo.filePath().toLatin1().data());
856 MESSAGE("ConvertFromASCIIToHDF() DONE : " << aResultPath);
857 char* aHDFFileName = new char[strlen(aResultPath) + 19];
858 sprintf(aHDFFileName, "%shdf_from_ascii.hdf", aResultPath);
860 if (theIsMultiFile) { // set this file as new - temporary
861 static QString aCommand;
862 aCommand.sprintf(" %s %s%s",aHDFFileName, aResultPath, myFileInfo.baseName().toLatin1().data());
863 aCommand = QDir::convertSeparators( aCommand );
864 aCommand.prepend( MOVE_COMMAND );
866 if (system(aCommand.toLatin1().data()) == -1) {
867 if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - Can't execute the command :" << aCommand.toLatin1().data());
870 if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - " << aCommand.toLatin1().data());
872 myFileInfo.setFile(QString(aResultPath) + myFileInfo.baseName());
873 } else { // change current temporary file to the new: with hdf-format
874 static QString aCommand;
875 aCommand.sprintf(" %s %s\0",aHDFFileName, myFileInfo.filePath().toLatin1().data());
876 aCommand = QDir::convertSeparators( aCommand );
877 aCommand.prepend( MOVE_COMMAND );
879 if (system(aCommand.toLatin1().data()) == -1) {
880 if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - Can't execute the command :" << aCommand.toLatin1().data());
883 if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - " << aCommand.toLatin1().data());
885 SALOMEDS::ListOfFileNames_var anEmptyList = new SALOMEDS::ListOfFileNames;
886 SALOMEDS_Tool::RemoveTemporaryFiles(aResultPath, anEmptyList.in(), true);
888 mySourceId = eRestoredFile;
890 delete(aHDFFileName);
891 } else if (!theIsMultiFile) {
892 mySourceId = eRestoredFile;
894 mySourceId = eSavedFile;
896 if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - mySourceId = " << mySourceId);
897 myInput.reset(CreateConvertor(myFileInfo.filePath().toLatin1().data()));
899 myInput->BuildEntities();
901 myInput->BuildFields();
902 myIsFieldsDone = true;
904 myInput->BuildMinMax();
905 myIsMinMaxDone = true;
909 myInput->BuildGroups();
910 myIsGroupsDone = true;
914 aComment.sprintf("myComment=%s;myFileName=%s;myInitFileName=%s",
916 myFileInfo.filePath().toLatin1().data(),
917 GetInitFileName().c_str()); // Restoring of Python dump
918 SALOMEDS::GenericAttribute_var anAttr;
919 if (!theSObject->FindAttribute(anAttr, "AttributeString"))
920 throw std::runtime_error("Build - There is no AttributeString for the SObject !!!");
921 SALOMEDS::AttributeString_var aCmnt = SALOMEDS::AttributeString::_narrow(anAttr);
922 aCmnt->SetValue(aComment.toLatin1().data());
924 bool anIsBuildAll = VISU::GetResourceMgr()->booleanValue("VISU", "full_med_loading", false);
928 } catch(std::exception& exc) {
929 INFOS("Follow exception was occured :\n"<<exc.what());
931 INFOS("Unknown exception was occured!!!");
937 //---------------------------------------------------------------
938 VISU::Result_i::PInput
940 ::GetInput(const std::string& theMeshName,
941 VISU::Entity theEntity,
942 const std::string& theFieldName,
943 CORBA::Long theTimeStampNumber)
949 //---------------------------------------------------------------
956 (myIsBuildFields? myIsFieldsDone: true) &&
957 (myIsBuildMinMax? myIsMinMaxDone: true) &&
958 (myIsBuildGroups? myIsGroupsDone: true);
965 return myIsEntitiesDone;
970 ::SetBuildFields(CORBA::Boolean theIsBuildFields,
971 CORBA::Boolean theIsCalculateMinMax)
973 myIsBuildFields = theIsBuildFields;
975 myIsBuildMinMax = theIsCalculateMinMax;
977 myIsBuildMinMax = false;
982 ::SetBuildGroups(CORBA::Boolean theIsBuildGroups)
984 myIsBuildGroups = theIsBuildGroups;
991 return myIsFieldsDone;
998 return myIsGroupsDone;
1005 return myIsMinMaxDone;
1012 return myIsPartsDone;
1016 //---------------------------------------------------------------
1017 VISU::Result::EntityNames*
1021 VISU::Result::EntityNames_var aResult = new VISU::Result::EntityNames();
1022 const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
1023 if(aMeshMap.empty())
1024 return aResult._retn();
1026 aResult->length(aMeshMap.size());
1027 VISU::TMeshMap::const_iterator anIter = aMeshMap.begin();
1028 for(size_t anId = 0; anIter != aMeshMap.end(); anIter++, anId++){
1029 const std::string& aName = anIter->first;
1030 aResult[anId] = aName.c_str();
1033 return aResult._retn();
1037 //---------------------------------------------------------------
1038 VISU::Result::Entities*
1040 ::GetEntities(const char* theMeshName)
1042 VISU::Result::Entities_var anEntities = new VISU::Result::Entities();
1043 const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
1044 if(aMeshMap.empty())
1045 return anEntities._retn();
1047 VISU::TMeshMap::const_iterator anIter = aMeshMap.find(theMeshName);
1048 if(anIter == aMeshMap.end())
1049 return anEntities._retn();
1051 const VISU::PMesh& aMesh = anIter->second;
1052 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
1053 if(aMeshOnEntityMap.empty())
1054 return anEntities._retn();
1057 anEntities->length(aMeshOnEntityMap.size());
1058 VISU::TMeshOnEntityMap::const_iterator anIter = aMeshOnEntityMap.begin();
1059 for(size_t anId = 0; anIter != aMeshOnEntityMap.end(); anIter++, anId++){
1060 const VISU::TEntity& anEntity = anIter->first;
1061 anEntities[anId] = VISU::Entity(anEntity);
1065 return anEntities._retn();
1069 //---------------------------------------------------------------
1070 VISU::Result::EntityNames*
1072 ::GetFamilies(const char* theMeshName,
1073 VISU::Entity theEntity)
1075 VISU::Result::EntityNames_var aResult = new VISU::Result::EntityNames();
1076 const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
1077 if(aMeshMap.empty())
1078 return aResult._retn();
1080 VISU::TMeshMap::const_iterator anIter = aMeshMap.find(theMeshName);
1081 if(anIter == aMeshMap.end())
1082 return aResult._retn();
1084 const VISU::PMesh& aMesh = anIter->second;
1085 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
1086 if(aMeshOnEntityMap.empty())
1087 return aResult._retn();
1090 VISU::TEntity anEntity = VISU::TEntity(theEntity);
1091 VISU::TMeshOnEntityMap::const_iterator anIter = aMeshOnEntityMap.find(anEntity);
1092 if(anIter == aMeshOnEntityMap.end())
1093 return aResult._retn();
1095 const VISU::PMeshOnEntity& aMeshOnEntity = anIter->second;
1096 const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity->myFamilyMap;
1097 if(aFamilyMap.empty())
1098 return aResult._retn();
1101 aResult->length(aFamilyMap.size());
1102 VISU::TFamilyMap::const_iterator anIter = aFamilyMap.begin();
1103 for(size_t anId = 0; anIter != aFamilyMap.end(); anIter++, anId++){
1104 const std::string& aName = anIter->first;
1105 aResult[anId] = aName.c_str();
1110 return aResult._retn();
1114 //---------------------------------------------------------------
1115 VISU::Result::EntityNames*
1117 ::GetGroups(const char* theMeshName)
1119 VISU::Result::EntityNames_var aResult = new VISU::Result::EntityNames();
1120 const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
1121 if(aMeshMap.empty())
1122 return aResult._retn();
1124 VISU::TMeshMap::const_iterator anIter = aMeshMap.find(theMeshName);
1125 if(anIter == aMeshMap.end())
1126 return aResult._retn();
1128 const VISU::PMesh& aMesh = anIter->second;
1129 const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
1130 if(aGroupMap.empty())
1131 return aResult._retn();
1134 aResult->length(aGroupMap.size());
1135 VISU::TGroupMap::const_iterator anIter = aGroupMap.begin();
1136 for(size_t anId = 0; anIter != aGroupMap.end(); anIter++, anId++){
1137 const std::string& aName = anIter->first;
1138 aResult[anId] = aName.c_str();
1142 return aResult._retn();
1146 //---------------------------------------------------------------
1147 VISU::Result::EntityNames*
1149 ::GetFields(const char* theMeshName,
1150 VISU::Entity theEntity)
1152 VISU::Result::EntityNames_var aResult = new VISU::Result::EntityNames();
1153 const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
1154 if(aMeshMap.empty())
1155 return aResult._retn();
1157 VISU::TMeshMap::const_iterator anIter = aMeshMap.find(theMeshName);
1158 if(anIter == aMeshMap.end())
1159 return aResult._retn();
1161 const VISU::PMesh& aMesh = anIter->second;
1162 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
1163 if(aMeshOnEntityMap.empty())
1164 return aResult._retn();
1167 VISU::TEntity anEntity = VISU::TEntity(theEntity);
1168 VISU::TMeshOnEntityMap::const_iterator anIter = aMeshOnEntityMap.find(anEntity);
1169 if(anIter == aMeshOnEntityMap.end())
1170 return aResult._retn();
1172 const VISU::PMeshOnEntity& aMeshOnEntity = anIter->second;
1173 const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
1174 if(aFieldMap.empty())
1175 return aResult._retn();
1178 aResult->length(aFieldMap.size());
1179 VISU::TFieldMap::const_iterator anIter = aFieldMap.begin();
1180 for(size_t anId = 0; anIter != aFieldMap.end(); anIter++, anId++){
1181 const std::string& aName = anIter->first;
1182 aResult[anId] = aName.c_str();
1187 return aResult._retn();
1191 //---------------------------------------------------------------
1192 VISU::Result::TimeStampNumbers*
1194 ::GetTimeStampNumbers(const char* theMeshName,
1195 VISU::Entity theEntity,
1196 const char* theFieldName)
1198 VISU::Result::TimeStampNumbers_var aResult = new VISU::Result::TimeStampNumbers();
1199 const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
1200 if(aMeshMap.empty())
1201 return aResult._retn();
1203 VISU::TMeshMap::const_iterator anIter = aMeshMap.find(theMeshName);
1204 if(anIter == aMeshMap.end())
1205 return aResult._retn();
1207 const VISU::PMesh& aMesh = anIter->second;
1208 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
1209 if(aMeshOnEntityMap.empty())
1210 return aResult._retn();
1213 VISU::TEntity anEntity = VISU::TEntity(theEntity);
1214 VISU::TMeshOnEntityMap::const_iterator anIter = aMeshOnEntityMap.find(anEntity);
1215 if(anIter == aMeshOnEntityMap.end())
1216 return aResult._retn();
1218 const VISU::PMeshOnEntity& aMeshOnEntity = anIter->second;
1219 const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
1220 if(aFieldMap.empty())
1221 return aResult._retn();
1224 VISU::TFieldMap::const_iterator anIter = aFieldMap.find(theFieldName);
1225 if(anIter == aFieldMap.end())
1226 return aResult._retn();
1229 const VISU::PField& aField = anIter->second;
1230 const VISU::TValField& aValField = aField->myValField;
1231 if(aValField.empty())
1232 return aResult._retn();
1235 aResult->length(aValField.size());
1236 VISU::TValField::const_iterator anIter = aValField.begin();
1237 for(size_t anId = 0; anIter != aValField.end(); anIter++, anId++){
1238 const vtkIdType& aTimeStampNumber = anIter->first;
1239 aResult[anId] = aTimeStampNumber;
1246 return aResult._retn();
1250 //---------------------------------------------------------------
1253 ::GetTimeStampValues(const char* theMeshName,
1254 VISU::Entity theEntity,
1255 const char* theFieldName)
1257 VISU::double_array_var aResult = new VISU::double_array();
1258 const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
1259 if(aMeshMap.empty())
1260 return aResult._retn();
1262 VISU::TMeshMap::const_iterator anIter = aMeshMap.find(theMeshName);
1263 if(anIter == aMeshMap.end())
1264 return aResult._retn();
1266 const VISU::PMesh& aMesh = anIter->second;
1267 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
1268 if(aMeshOnEntityMap.empty())
1269 return aResult._retn();
1272 VISU::TEntity anEntity = VISU::TEntity(theEntity);
1273 VISU::TMeshOnEntityMap::const_iterator anIter = aMeshOnEntityMap.find(anEntity);
1274 if(anIter == aMeshOnEntityMap.end())
1275 return aResult._retn();
1277 const VISU::PMeshOnEntity& aMeshOnEntity = anIter->second;
1278 const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
1279 if(aFieldMap.empty())
1280 return aResult._retn();
1283 VISU::TFieldMap::const_iterator anIter = aFieldMap.find(theFieldName);
1284 if(anIter == aFieldMap.end())
1285 return aResult._retn();
1288 const VISU::PField& aField = anIter->second;
1289 const VISU::TValField& aValField = aField->myValField;
1290 if(aValField.empty())
1291 return aResult._retn();
1294 aResult->length(aValField.size());
1295 VISU::TValField::const_iterator anIter = aValField.begin();
1296 for(size_t anId = 0; anIter != aValField.end(); anIter++, anId++){
1297 const PValForTime& aValForTime = anIter->second;
1298 aResult[anId] = aValForTime->myTime.first;
1305 return aResult._retn();
1309 //---------------------------------------------------------------
1312 ::GetNumberOfComponents(const char* theMeshName,
1313 VISU::Entity theEntity,
1314 const char* theFieldName)
1316 CORBA::Long aResult = 0;
1317 const VISU::TMeshMap& aMeshMap = GetInput()->GetMeshMap();
1318 if(aMeshMap.empty())
1321 VISU::TMeshMap::const_iterator anIter = aMeshMap.find(theMeshName);
1322 if(anIter == aMeshMap.end())
1325 const VISU::PMesh& aMesh = anIter->second;
1326 const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh->myMeshOnEntityMap;
1327 if(aMeshOnEntityMap.empty())
1331 VISU::TEntity anEntity = VISU::TEntity(theEntity);
1332 VISU::TMeshOnEntityMap::const_iterator anIter = aMeshOnEntityMap.find(anEntity);
1333 if(anIter == aMeshOnEntityMap.end())
1336 const VISU::PMeshOnEntity& aMeshOnEntity = anIter->second;
1337 const VISU::TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
1338 if(aFieldMap.empty())
1342 VISU::TFieldMap::const_iterator anIter = aFieldMap.find(theFieldName);
1343 if(anIter == aFieldMap.end())
1347 const VISU::PField& aField = anIter->second;
1348 aResult = aField->myNbComp;
1357 //---------------------------------------------------------------
1358 VISU::Result::EntityNames*
1360 ::GetPartNames(const char* theMeshName)
1362 VISU::Result::EntityNames_var aResult = new VISU::Result::EntityNames();
1363 return aResult._retn();
1367 //---------------------------------------------------------------
1368 VISU::Result::Resolutions*
1370 ::GetResolutions(const char* theMeshName,
1371 const char* thePartName)
1373 VISU::Result::Resolutions_var aResult = new VISU::Result::Resolutions();
1374 return aResult._retn();
1378 //---------------------------------------------------------------
1379 VISU::Result::Resolution
1381 ::GetResolution(const char* theMeshName,
1382 const char* thePartName)
1384 return VISU::Result::HIDDEN;
1388 //---------------------------------------------------------------
1391 ::SetResolution(const char* theMeshName,
1392 const char* thePartName,
1393 VISU::Result::Resolution theResolution)
1397 //---------------------------------------------------------------
1400 ::New(SALOMEDS::Study_ptr theStudy,
1401 const ESourceId& theSourceId,
1402 const ECreationId& theCreationId,
1403 CORBA::Boolean theIsBuildImmediately,
1404 CORBA::Boolean theIsBuildFields,
1405 CORBA::Boolean theIsBuildMinMax,
1406 CORBA::Boolean theIsBuildGroups)
1408 return new RESULT_CLASS_NAME(theStudy,
1411 theIsBuildImmediately,
1418 //---------------------------------------------------------------
1421 ::StorableEngine(SALOMEDS::SObject_ptr theSObject,
1422 const Storable::TRestoringMap& theMap,
1423 const std::string& thePrefix,
1424 CORBA::Boolean theIsMultiFile)
1426 VISU::Result_i* aResult = new RESULT_CLASS_NAME();
1427 return aResult->Restore(theSObject, theMap, thePrefix, theIsMultiFile);
1431 //---------------------------------------------------------------
1434 ::ToStream(std::ostringstream& theStr)
1436 Storable::DataToStream(theStr,"myName", GetFileName().c_str());
1437 Storable::DataToStream(theStr,"myInitFileName", GetInitFileName().c_str());
1438 Storable::DataToStream(theStr,"myCreationId", myCreationId);
1439 Storable::DataToStream(theStr,"myIsBuildFields", myIsFieldsDone);
1440 Storable::DataToStream(theStr,"myIsBuildMinMax", myIsMinMaxDone);
1441 Storable::DataToStream(theStr,"myIsBuildGroups", myIsGroupsDone);
1444 //---------------------------------------------------------------
1448 ::ExportMED(const char* theTargetFileName)
1450 static QString aCommand;
1451 const char* aTempFileName = myFileInfo.absoluteFilePath().toLatin1();
1452 aCommand.sprintf(" %s %s", aTempFileName, theTargetFileName);
1453 aCommand = QDir::convertSeparators( aCommand );
1454 aCommand.prepend( COPY_COMMAND );
1456 if(system(aCommand.toLatin1().data()) != 0) {
1457 if(MYDEBUG) MESSAGE("VISU_Gen_i::Copy - Cann't execute the command :"<<aCommand.toLatin1().data());
1464 //---------------------------------------------------------------
1467 ::GetInitFileName() const
1469 return myInitFileName;
1475 ::SetInitFileName(const std::string& theFileName)
1477 myInitFileName = theFileName;
1481 //---------------------------------------------------------------
1484 ::GetFileName() const
1486 if(GetSourceId() == eFile)
1487 return VISU::MakeFileName(myFileName, this);
1495 ::GetFileInfo() const
1500 VISU::Result_i::ECreationId
1502 ::GetCreationId() const
1504 return myCreationId;
1508 VISU::Result_i::ESourceId
1510 ::GetSourceId() const
1516 //---------------------------------------------------------------
1521 CORBA::String_var anEntry = mySObject->GetID();
1522 return anEntry.in();
1525 SALOMEDS::SObject_var
1527 ::GetSObject() const
1534 ::GetStudyDocument() const
1536 return myStudyDocument;
1546 SALOMEDS::SComponent_var
1548 ::GetSComponent() const
1550 return mySComponent;
1555 ::GetEntry(const Storable::TRestoringMap& theRestoringMap)
1557 return Storable::FindEntry(myStudyDocument,
1563 //=======================================================================
1564 //function : GetAxisInfo
1566 //=======================================================================
1567 const VISU::Result_i::TAxisInfo*
1569 ::GetAxisInfo(const string& theMeshName,
1571 gp_Dir& thePlaneNormal)
1573 const TAxisInfo* components = NULL;
1575 if ( theAxis < AXIS_X || theAxis > AXIS_Z ) {
1576 MESSAGE(" Bad axis index " << theAxis );
1580 map< string, TGridInfo >::iterator name_info;
1581 name_info = myMeshName2GridInfoMap.find( theMeshName );
1582 TGridInfo * gInfo = 0;
1584 if ( name_info != myMeshName2GridInfoMap.end() )
1586 gInfo = & name_info->second;
1588 else if ( myInput && IsPossible() && theAxis >= AXIS_X && theAxis <= AXIS_Z )
1590 // check presence of theMeshName
1591 const VISU::TMeshMap& meshMap = myInput->GetMeshMap();
1593 VISU::TMeshMap::const_iterator aIter = meshMap.find( theMeshName );
1594 if ( aIter == meshMap.end() ) {
1595 MESSAGE("No mesh named " << theMeshName );
1598 theMesh = aIter->second;
1600 VISU::PUnstructuredGridIDMapper anIDMapper = myInput->GetMeshOnEntity(theMeshName,
1602 vtkUnstructuredGrid* aMesh = anIDMapper->GetUnstructuredGridOutput();
1604 if ( !aMesh || aMesh->GetNumberOfCells() == 0 ) {
1605 MESSAGE( "No cells in the mesh: " << theMeshName );
1609 if ( !theMesh->IsStructured() || theMesh->myIsPolarType ) {
1610 // define axis directions and min cell size in each direction
1611 const int nbAxes = 3;
1613 gp_Vec axDirs[ nbAxes ];
1614 float minSize[3] = { FLT_MAX, FLT_MAX, FLT_MAX };
1615 bool axesComputed = false;
1616 for ( vtkIdType iCell = 0; iCell < aMesh->GetNumberOfCells(); ++iCell ) {
1617 vtkCell* cell = aMesh->GetCell( iCell );
1619 if (cell->GetCellType() != VTK_HEXAHEDRON &&
1620 cell->GetCellType() != VTK_QUADRATIC_HEXAHEDRON )
1622 vtkPoints * points = cell->GetPoints();
1623 vtkFloatingPointType coords[ 4 ][3];
1624 points->GetPoint( 0, coords[0] );
1625 points->GetPoint( 1, coords[1] );
1626 points->GetPoint( 3, coords[2] );
1627 points->GetPoint( 4, coords[3] );
1628 gp_Pnt p0( coords[0][0], coords[0][1], coords[0][2] );
1629 for ( iAx = 0; iAx < nbAxes; ++iAx ) {
1630 vtkFloatingPointType* coo = coords[ iAx + 1 ];
1631 gp_Pnt p( coo[0], coo[1], coo[2] );
1633 vtkFloatingPointType size = p0.SquareDistance( p );
1634 if ( size > FLT_MIN && size < minSize[ iAx ] )
1635 minSize[ iAx ] = size;
1637 if ( !axesComputed ) {
1638 gp_Vec dir( p0, p );
1639 if ( dir.SquareMagnitude() <= gp::Resolution() ) {
1642 axDirs[ iAx ] = dir;
1645 if ( iAx == nbAxes )
1646 axesComputed = true;
1648 if ( !axesComputed ) {
1649 MESSAGE("No good hexahedrons in the mesh: " << theMeshName );
1653 // compute axes dirs
1654 gInfo = & myMeshName2GridInfoMap[ theMeshName ];
1655 for ( iAx = 0; iAx < nbAxes; ++iAx ) {
1656 int iPrev = ( iAx == 0 ) ? 2 : iAx - 1;
1657 int iNext = ( iAx == 2 ) ? 0 : iAx + 1;
1658 gInfo->myAxis[ iAx ] = axDirs[ iPrev ] ^ axDirs[ iNext ];
1661 // get and sort intermediate component values - projections of nodes
1662 // on axis direction; define bnd box
1663 set< vtkFloatingPointType > comps[ 3 ];
1665 vtkPoints * points = aMesh->GetPoints();
1666 vtkIdType iP, nbP = aMesh->GetNumberOfPoints();
1667 for ( iP = 0; iP < nbP; ++iP ) {
1668 vtkFloatingPointType coo[3];
1669 points->GetPoint( iP, coo );
1670 gp_Pnt p( coo[0], coo[1], coo[2] );
1672 for ( iAx = 0; iAx < nbAxes; ++iAx ) {
1673 const gp_Dir& dir = gInfo->myAxis[ iAx ];
1674 vtkFloatingPointType dot = dir.XYZ() * p.XYZ();
1675 comps[ iAx ].insert( dot );
1679 // find a range of projections of bnd box corners on each axis
1680 vtkFloatingPointType range[3], firstValue[3];
1681 double x[2],y[2],z[2];
1682 box.Get(x[0],y[0],z[0],x[1],y[1],z[1]);
1683 for ( iAx = 0; iAx < nbAxes; ++iAx ) {
1684 set< vtkFloatingPointType > bndComps;
1685 const gp_Dir& dir = gInfo->myAxis[ iAx ];
1686 for ( int iX = 0; iX < 2; ++iX ) {
1687 for ( int iY = 0; iY < 2; ++iY ) {
1688 for ( int iZ = 0; iZ < 2; ++iZ ) {
1689 gp_Pnt p( x[ iX ], y[ iY ], z[ iZ ] );
1690 vtkFloatingPointType dot = dir.XYZ() * p.XYZ();
1691 bndComps.insert( dot );
1695 firstValue[ iAx ] = *bndComps.begin();
1696 range[ iAx ] = *bndComps.rbegin() - *bndComps.begin();
1699 // compute component values
1700 for ( iAx = 0; iAx < nbAxes; ++iAx ) {
1701 list< vtkFloatingPointType > values;
1703 set< vtkFloatingPointType >& comp = comps[ iAx ];
1704 set< vtkFloatingPointType >::iterator val = comp.begin();
1705 vtkFloatingPointType bnd = -1., rng = range[ iAx ], first = firstValue[ iAx ];
1706 vtkFloatingPointType tol = 0.1 * sqrt( minSize[ iAx ]) / rng;
1707 for ( ; val != comp.end(); ++val ) {
1708 vtkFloatingPointType value = ( *val - first ) / rng;
1709 if ( value > bnd ) {
1710 values.push_back( value );
1715 // store values in gInfo
1716 vector< vtkFloatingPointType >& myComp = gInfo->myComponets[ iAx ];
1717 myComp.resize( nbVals );
1718 list< vtkFloatingPointType >::iterator v = values.begin();
1719 for ( int i = 0; v != values.end(); ++v ){
1725 vtkIdType aMeshDim = theMesh->myDim;
1726 gInfo = & myMeshName2GridInfoMap[ theMeshName ];
1727 switch ( aMeshDim ) {
1729 gp_Dir aDir(0.0,0.0,1.0);
1730 gInfo->myAxis[ 2 ] = aDir;
1733 gp_Dir aDir(0.0,1.0,0.0);
1734 gInfo->myAxis[ 1 ] = aDir;
1737 gp_Dir aDir(1.0,0.0,0.0);
1738 gInfo->myAxis[ 0 ] = aDir;
1741 TStructuredId aStructuredId = theMesh->GetStructure();
1742 vector<vtkFloatingPointType> PointsCoords[3];
1743 vtkPoints* aPoints = aMesh->GetPoints();
1744 switch ( aMeshDim ) {
1746 TStructuredId aCoordIJK;
1747 vtkIdType nbZ = aStructuredId[2];
1748 for ( int i = 0; i < nbZ; i++ ) {
1749 aCoordIJK[2] = i + 1;
1750 vtkIdType aObjID = anIDMapper->GetObjectIDByIndexes(aCoordIJK);
1751 vtkIdType aVTKID = anIDMapper->GetNodeVTKID(aObjID);
1752 vtkFloatingPointType* aPCoord = aPoints->GetPoint(aVTKID);
1753 PointsCoords[2].push_back(aPCoord[2]);
1757 TStructuredId aCoordIJK;
1758 vtkIdType nbJ = aStructuredId[1];
1759 for ( int i = 0; i < nbJ; i++ ) {
1760 aCoordIJK[1] = i + 1;
1761 vtkIdType aObjID = anIDMapper->GetObjectIDByIndexes(aCoordIJK);
1762 vtkIdType aVTKID = anIDMapper->GetNodeVTKID(aObjID);
1763 vtkFloatingPointType* aPCoord = aPoints->GetPoint(aVTKID);
1764 PointsCoords[1].push_back(aPCoord[1]);
1768 TStructuredId aCoordIJK;
1769 vtkIdType nbI = aStructuredId[0];
1770 for ( int i = 0; i < nbI; i++ ) {
1771 aCoordIJK[0] = i + 1;
1772 vtkIdType aObjID = anIDMapper->GetObjectIDByIndexes(aCoordIJK);
1773 vtkIdType aVTKID = anIDMapper->GetNodeVTKID(aObjID);
1774 vtkFloatingPointType* aPCoord = aPoints->GetPoint(aVTKID);
1775 PointsCoords[0].push_back(aPCoord[0]);
1778 for ( int i = 0; i < aMeshDim; i++ ) {
1779 vector< vtkFloatingPointType >& myComp = gInfo->myComponets[ i ];
1780 int aSize = PointsCoords[i].size();
1782 vtkFloatingPointType aLen = PointsCoords[i][aSize-1] - PointsCoords[i][0];
1783 myComp.resize(aSize);
1785 for ( int k = 1; k < aSize; k++ ) {
1786 myComp[k]=myComp[k-1] + (PointsCoords[i][k]-PointsCoords[i][k-1])/aLen;
1793 // set return values
1795 thePlaneNormal = gInfo->myAxis[ theAxis ];
1796 components = & gInfo->myComponets[ theAxis ];
1802 SALOME_MED::MedFileInfo* VISU::Result_i::GetMEDFileInfo()
1804 SALOME_MED::MedFileInfo_var res = new SALOME_MED::MedFileInfo();
1806 QString fpath = myFileInfo.absoluteFilePath();
1807 res->fileName = fpath.toLatin1().constData();
1808 res->fileSize = myFileInfo.size();
1809 int major, minor, release;
1810 if( !MED::getMEDVersion( fpath.toLatin1().constData(), major, minor, release ) )
1818 res->release = release;