-using namespace std;
-// File: VISU_Result_i.cc
-// Created: Fri Jan 10 13:56:05 2003
-// Author: Alexey PETROV
-// <apo@ivanox.nnov.matra-dtv.fr>
+// Copyright (C) 2003 CEA/DEN, EDF R&D
+//
+//
+//
+// File : VISU_Result_i.cc
+// Author : Alexey PETROV
+// Module : VISU
+using namespace std;
#include "VISU_Result_i.hh"
#include "VISU_Convertor_impl.hxx"
#include "VISU_CorbaMedConvertor.hxx"
using namespace VISU;
#include "SALOMEDS_Tool.hxx"
+#include "HDFascii.hxx"
#include <qstring.h>
#include <qfileinfo.h>
using namespace std;
#ifdef DEBUG
-static int MYDEBUG = 1;
+static int MYDEBUG = 0;
static int MYDEBUGWITHFILES = 0;
#else
static int MYDEBUG = 0;
return tmp;
}
+QString GenerateFieldName(const string& theName, const string& theUnits){
+ static QString aName;
+ const string tmp(theUnits.size(),' ');
+ if(theUnits == "" || theUnits == tmp)
+ aName.sprintf("%s, -",theName.c_str());
+ else
+ aName.sprintf("%s, %s",theName.c_str(),theUnits.c_str());
+ aName = aName.simplifyWhiteSpace();
+ return aName.latin1();
+}
+
void CreateReference(SALOMEDS::Study_ptr theStudyDocument,
const string& theFatherEntry, const string& theRefEntry)
{
throw (std::runtime_error&)
{
if(MYDEBUG) MESSAGE("Result_i::Build");
- mySComponent = FindOrCreateVisuComponent(myStudyDocument);
- CORBA::String_var aSComponentEntry = mySComponent->GetID(), anIOR(GetID());
- string aRefFatherEntry = GetRefFatherEntry();
- QString aComment;
- aComment.sprintf("myComment=%s;myType=%d;myFileName=%s",
- GetComment(),VISU::TRESULT,myFileInfo.filePath().latin1());
- string aResultEntry = CreateAttributes(myStudyDocument,aSComponentEntry,aRefFatherEntry.c_str(),
- anIOR,myName.c_str(),"",aComment.latin1(),true);
- mySObject = myStudyDocument->FindObjectID(aResultEntry.c_str());
- if(mySObject->_is_nil()) throw std::runtime_error("Build - There is no SObject for the Result !!!");
- if(theSObject != NULL){
- CORBA::String_var aString = theSObject->GetID();
- CreateReference(myStudyDocument,aResultEntry,aString.in());
- }
const TMeshMap& aMeshMap = myInput->GetMeshMap();
if(!aMeshMap.empty()) {//apo
+ mySComponent = FindOrCreateVisuComponent(myStudyDocument);
+ CORBA::String_var aSComponentEntry = mySComponent->GetID(), anIOR(GetID());
+ string aRefFatherEntry = GetRefFatherEntry();
+ QString aComment;
+ aComment.sprintf("myComment=%s;myType=%d;myFileName=%s",
+ GetComment(),VISU::TRESULT,myFileInfo.filePath().latin1());
+ string aResultEntry = CreateAttributes(myStudyDocument,aSComponentEntry,aRefFatherEntry.c_str(),
+ anIOR,myName.c_str(),"",aComment.latin1(),true);
+ mySObject = myStudyDocument->FindObjectID(aResultEntry.c_str());
+ if(mySObject->_is_nil()) throw std::runtime_error("Build - There is no SObject for the Result !!!");
+ if(theSObject != NULL){
+ CORBA::String_var aString = theSObject->GetID();
+ CreateReference(myStudyDocument,aResultEntry,aString.in());
+ }
TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
for(; aMeshMapIter != aMeshMap.end(); aMeshMapIter++){
const string& aMeshName = aMeshMapIter->first;
const string& aFieldName = aFieldMapIter->first;
const VISU::TField& aField = aFieldMapIter->second;
const VISU::TField::TValField& aValField = aField.myValField;
+ QString aFieldNameWithUnit = ::GenerateFieldName(aFieldName,aField.myUnitNames[0]);
aComment.sprintf("myComment=FIELD;myType=%d;myMeshName=%s;myEntityId=%d;myName=%s;myNbTimeStamps=%d;myNumComponent=%d",
VISU::TFIELD,aMeshName.c_str(),anEntity,aFieldName.c_str(),aValField.size(),aField.myNbComp);
string aFieldEntry = CreateAttributes(myStudyDocument,aFieldsEntry.c_str(),aRefFatherEntry.c_str(),
- "",aFieldName.c_str(),"",aComment.latin1(),true);
+ "",aFieldNameWithUnit.latin1(),"",aComment.latin1(),true);
CreateReference(myStudyDocument,aFieldEntry,aEntity2Entry[anEntity]);
VISU::TField::TValField::const_iterator aValFieldIter = aValField.begin();
for(; aValFieldIter != aValField.end(); aValFieldIter++){
myInput = CreateConvertor(theFileName);
if(myInput == NULL) return NULL;
myFileInfo.setFile(theFileName);
- myName = ::GenerateName(myFileInfo.fileName().latin1());
- return Build();
+ myName = (const char*)(::GenerateName(myFileInfo.fileName().latin1()));
+ VISU::Storable* aStorable = Build();
+ return aStorable;
}catch(std::runtime_error& exc){
MESSAGE("Follow exception was accured :\n"<<exc.what());
}catch(...){
}
VISU::Storable* VISU::Result_i::Create(SALOMEDS::SObject_ptr theMedSObject){
- if(MYDEBUG) MESSAGE("Result_i::Create MedObject from theMedSObject");
+ if(MYDEBUG) MESSAGE("Result_i::Create MedObject from SALOMEDS::SObject_ptr");
try{
mySourceId = eComponent;
myInput = CreateMEDConvertor(theMedSObject);
if(myInput == NULL) return NULL;
string aCompDataType = GetComponentDataType(theMedSObject);
myFileInfo.setFile(aCompDataType.c_str());
- myName = ::GenerateName("aResult");
- return Build(theMedSObject);
+ myName = (const char*)(::GenerateName("aResult"));
+ VISU::Storable* aStorable = Build(theMedSObject);
+ return aStorable;
+ }catch(std::runtime_error& exc){
+ MESSAGE("Follow exception was accured :\n"<<exc.what());
+ }catch(...){
+ MESSAGE("Unknown exception was accured!");
+ }
+ return NULL;
+}
+
+VISU::Storable* VISU::Result_i::Create(SALOME_MED::FIELD_ptr theField){
+ if(MYDEBUG) MESSAGE("Result_i::Create MedObject from SALOME_MED::FIELD_ptr");
+ try{
+ mySourceId = eComponent;
+ myInput = CreateMEDFieldConvertor(theField);
+ if(myInput == NULL) return NULL;
+ string aCompDataType = "Med";
+ myFileInfo.setFile(aCompDataType.c_str());
+ myName = (const char*)(::GenerateName("aResult"));
+ VISU::Storable* aStorable = Build();
+ return aStorable;
}catch(std::runtime_error& exc){
MESSAGE("Follow exception was accured :\n"<<exc.what());
}catch(...){
mySObject = SALOMEDS::SObject::_duplicate(theSObject);
myStudyDocument = mySObject->GetStudy();
mySComponent = mySObject->GetFatherComponent();
- myName = VISU::Storable::FindValue(theMap,"myName");
+ myName = (const char*)(VISU::Storable::FindValue(theMap,"myName"));
SALOMEDS::SObject_var aRefSObj, aTargetRefSObj;
if(mySObject->FindSubObject(1,aRefSObj) && aRefSObj->ReferencedObject(aTargetRefSObj)){
mySourceId = eRestoredComponent;
}else
throw std::runtime_error("GetInput - There is no convertor for the aDataType !!!");
}else{
- mySourceId = eRestoredFile;
myFileInfo.setFile(thePrefix.c_str());
+
string aStudyPrefix(SALOMEDS_Tool::GetNameFromPath(myStudyDocument->URL()));
- string aTmpDir(SALOMEDS_Tool::GetDirFromPath(myStudyDocument->URL()));
if(!myFileInfo.isFile()){
- string aFileName = thePrefix + aStudyPrefix + "_" + myName;
+ string aFileName = thePrefix + aStudyPrefix + "_" + myName;
myFileInfo.setFile(aFileName.c_str());
}
if(MYDEBUG)
MESSAGE("Result_i::Restore - aFileName = "<<myFileInfo.filePath()<<"; "<<myFileInfo.isFile());
+
+ if (HDFascii::isASCII(myFileInfo.filePath().latin1())) {
+ char* aResultPath = HDFascii::ConvertFromASCIIToHDF(myFileInfo.filePath().latin1());
+ char* aHDFFileName = new char[strlen(aResultPath) + 19];
+ sprintf(aHDFFileName, "%shdf_from_ascii.hdf", aResultPath);
+
+ if (IsMultifile()) { // set this file as new - temporary
+ static QString aCommand;
+ aCommand.sprintf("mv %s %s%s",aHDFFileName, aResultPath, myFileInfo.baseName().latin1());
+ if(system(aCommand) == -1){
+ if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - Can't execute the command :"<<aCommand);
+ return NULL;
+ } else if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - "<<aCommand);
+ myFileInfo.setFile(QString(aResultPath)+QString(myFileInfo.baseName().latin1()));
+ } else { // change current temporary file to the new: with hdf-format
+ static QString aCommand;
+ aCommand.sprintf("mv %s %s\0",aHDFFileName, myFileInfo.filePath().latin1());
+ if(system(aCommand.latin1()) == -1) {
+ if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - Can't execute the command :"<<aCommand);
+ return NULL;
+ } else if(MYDEBUG) MESSAGE("VISU::Result_i::Restore - "<<aCommand);
+ SALOMEDS::ListOfFileNames_var anEmptyList = new SALOMEDS::ListOfFileNames;
+ SALOMEDS_Tool::RemoveTemporaryFiles(aResultPath, anEmptyList, true);
+ }
+ mySourceId = eRestoredFile;
+ delete(aResultPath);
+ delete(aHDFFileName);
+ } else if (!IsMultifile()) mySourceId = eRestoredFile;
+ else mySourceId = eFile;
+
myInput = CreateMedConvertor(myFileInfo.filePath().latin1());
QString aComment;
aComment.sprintf("myComment=%s;myType=%d;myName=%s;myFileName=%s",
throw std::runtime_error("Build - There is no AttributeComment for the SObject !!!");
SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr);
aCmnt->SetValue(aComment.latin1());
- // remove temporary file, if it's not multifile mode
- if (false || !IsMultifile()) {
- SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
- aSeq->length(1);
- aSeq[0]=(aStudyPrefix + myName).c_str();
- SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
- }
}
return this;
}catch(std::runtime_error& exc){
return myInput;
}
-void VISU::Result_i::ToStream(ostrstream& theStr){
+void VISU::Result_i::ToStream(std::ostringstream& theStr){
if(MYDEBUG) MESSAGE(GetComment());
Storable::DataToStream(theStr,"myName",myName.c_str());
}