From: srn Date: Thu, 17 Mar 2005 07:55:14 +0000 (+0000) Subject: Dump Python X-Git-Tag: T_22_03_05~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4426c0668808739b735f02ef2742fa996aaeb8a9;p=modules%2Fvisu.git Dump Python --- diff --git a/src/ENGINE/VISU_Engine_i.cc b/src/ENGINE/VISU_Engine_i.cc index 0edb9acc..03ddbf9f 100644 --- a/src/ENGINE/VISU_Engine_i.cc +++ b/src/ENGINE/VISU_Engine_i.cc @@ -351,4 +351,11 @@ namespace VISU{ return myVisuGen->PasteInto(theStream,theObjectID,theObject); } + Engines::TMPFile* VISU_Gen_i::DumpPython(CORBA::Object_ptr theStudy, + CORBA::Boolean theIsPublished, + CORBA::Boolean& theIsValidScript) + { + return myVisuGen->DumpPython(theStudy, theIsPublished, theIsValidScript); + } + }; diff --git a/src/ENGINE/VISU_Engine_i.hh b/src/ENGINE/VISU_Engine_i.hh index 8ad9db0f..86c135ca 100644 --- a/src/ENGINE/VISU_Engine_i.hh +++ b/src/ENGINE/VISU_Engine_i.hh @@ -131,6 +131,12 @@ namespace VISU{ SALOMEDS::SObject_ptr PasteInto(const SALOMEDS::TMPFile& theStream, CORBA::Long theObjectID, SALOMEDS::SObject_ptr theObject); + + // inherited methods from Engines::Component + virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy, + CORBA::Boolean theIsPublished, + CORBA::Boolean& theIsValidScript); + }; }; diff --git a/src/VISU_I/Makefile.in b/src/VISU_I/Makefile.in index 1489eb26..24f947b6 100644 --- a/src/VISU_I/Makefile.in +++ b/src/VISU_I/Makefile.in @@ -23,7 +23,8 @@ LIB_SRC = VISUConfig.cc VISU_Gen_i.cc VISU_Result_i.cc \ VISU_IsoSurfaces_i.cc VISU_DeformedShape_i.cc \ VISU_CutPlanes_i.cc VISU_CutLines_i.cc \ VISU_Vectors_i.cc VISU_StreamLines_i.cc \ - VISU_TimeAnimation.cxx VISU_CorbaMedConvertor.cxx + VISU_TimeAnimation.cxx VISU_CorbaMedConvertor.cxx \ + VISU_DumpPython.cc LIB_MOC = VISU_TimeAnimation.h diff --git a/src/VISU_I/VISUConfig.cc b/src/VISU_I/VISUConfig.cc index c137e26f..ee36c44f 100644 --- a/src/VISU_I/VISUConfig.cc +++ b/src/VISU_I/VISUConfig.cc @@ -93,7 +93,7 @@ namespace VISU{ } void Storable::StrToMap(const QString& theStr, VISU::Storable::TRestoringMap& theMap){ - if(0 && MYDEBUG) MESSAGE("Storable::StrToMap : string="<> there is no value for "<> there is no value for ") + theArg); + if(isFind != NULL) + *isFind = false; static QString BAD_VALUE("NULL"); return BAD_VALUE; } - if(isFind != NULL) *isFind = true; + + if(isFind != NULL) + *isFind = true; + return i->second; } diff --git a/src/VISU_I/VISUConfig.hh b/src/VISU_I/VISUConfig.hh index ca83125f..1d80e7cb 100644 --- a/src/VISU_I/VISUConfig.hh +++ b/src/VISU_I/VISUConfig.hh @@ -106,7 +106,7 @@ namespace VISU{ typedef std::map TCallbackMap; static void Registry(const char* theComment, TStorableEngine theEngine); static Storable* Create(SALOMEDS::SObject_ptr, const std::string& thePrefix, const std::string& theString); - static const QString& FindValue(const TRestoringMap& theMap, const std::string& theArg, bool* isFind = NULL); + static QString FindValue(const TRestoringMap& theMap, const std::string& theArg, bool* isFind = NULL); static void StrToMap(const QString& theStr, VISU::Storable::TRestoringMap& theMap); static SALOMEDS::SObject_ptr GetResultSO(SALOMEDS::SObject_ptr theSObject); static void DataToStream(std::ostringstream& theStr, const QString& theName, const QString& theVal); diff --git a/src/VISU_I/VISU_DumpPython.cc b/src/VISU_I/VISU_DumpPython.cc new file mode 100644 index 00000000..0b5fd9f8 --- /dev/null +++ b/src/VISU_I/VISU_DumpPython.cc @@ -0,0 +1,1191 @@ +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// File : VISU_DumpPython.cc +// Author : Alexey PETROV +// Module : VISU + +#include "VISU_Gen_i.hh" +#include "VISU_Result_i.hh" +#include "VISU_PrsObject_i.hh" + +#include "VISU_Prs3d_i.hh" +#include "VISU_Mesh_i.hh" +#include "VISU_ScalarMap_i.hh" +#include "VISU_IsoSurfaces_i.hh" +#include "VISU_DeformedShape_i.hh" +#include "VISU_CutPlanes_i.hh" +#include "VISU_CutLines_i.hh" +#include "VISU_Vectors_i.hh" +#include "VISU_StreamLines_i.hh" +#include "VISU_Table_i.hh" + +#include "utilities.h" + +#include +#include +#include + +#include +#include + +//#define COUT + +using namespace std; + +namespace VISU{ + static std::string PREFIX(" "); + + typedef std::map TName2EntryMap; + typedef std::map TEntry2NameMap; + + inline + std::string + GenerateName(std::string theName, + SALOMEDS::SObject_ptr theSObject, + TName2EntryMap& theName2EntryMap, + TEntry2NameMap& theEntry2NameMap, + char theSuffix) + { + if(theName2EntryMap.find(theName) != theName2EntryMap.end()){ + theName = GenerateName(theName + theSuffix, theSObject, theName2EntryMap, theEntry2NameMap, theSuffix); + }else{ + CORBA::String_var anID = theSObject->GetID(); + theName2EntryMap[theName] = anID.in(); + theEntry2NameMap[anID.in()] = theName; + //cout<<"GenerateName - "< "<GetName(); + + std::string aName = QString(aString.in()).simplifyWhiteSpace().latin1(); + + //replace_if(aName.begin(),aName.end(),not1(ptr_fun(isxdigit)),'_'); + replace_if(aName.begin(),aName.end(),TReplacePredicate(),'_'); + + return aName; + } + + inline + std::string + GenerateName(SALOMEDS::SObject_ptr theSObject, + TName2EntryMap& theName2EntryMap, + TEntry2NameMap& theEntry2NameMap) + { + std::string aName = GetName(theSObject); + + return GenerateName(aName,theSObject,theName2EntryMap,theEntry2NameMap,'X'); + } + + + //=========================================================================== + typedef void (*TDumpToPython)(SALOMEDS::Study_ptr theStudy, + CORBA::Boolean theIsPublished, + CORBA::Boolean& theIsValidScript, + SALOMEDS::SObject_ptr theSObject, + std::ostream& theStr, + TName2EntryMap& theName2EntryMap, + TEntry2NameMap& theEntry2NameMap, + std::string theArgumentName, + std::string thePrefix); + + + void + DumpToPython(SALOMEDS::Study_ptr theStudy, + CORBA::Boolean theIsPublished, + CORBA::Boolean& theIsValidScript, + SALOMEDS::SObject_ptr theSObject, + std::ostream& theStr, + TName2EntryMap& theName2EntryMap, + TEntry2NameMap& theEntry2NameMap, + std::string theArgumentName, + std::string thePrefix); + + + //=========================================================================== + std::string + ScalarMapToPython(SALOMEDS::SObject_ptr theSObject, + VISU::ScalarMap_i* theServant, + std::ostream& theStr, + std::string& theName, + const std::string& theConstructorName, + const std::string& theArgumentName, + std::string thePrefix) + { + std::string aParam; + switch(theServant->GetEntity()){ + case NODE: + aParam = "VISU.NODE"; + break; + case EDGE: + aParam = "VISU.EDGE"; + break; + case FACE: + aParam = "VISU.FACE"; + break; + case CELL: + aParam = "VISU.CELL"; + break; + } + + theStr<GetMeshName()<<"'"<< + ","<GetFieldName()<<"'"<< + ","<GetIteration()<< + ")"<GetScalarMode()<<")"<GetScaling()){ + case LINEAR: + aParam = "VISU.LINEAR"; + break; + case LOGARITHMIC: + aParam = "VISU.LOGARITHMIC"; + break; + } + theStr<GetMin()<<","<GetMax()<<")"<GetBarOrientation()){ + case ScalarMap::HORIZONTAL: + aParam = "VISU.ScalarMap.HORIZONTAL"; + break; + case ScalarMap::VERTICAL: + aParam = "VISU.ScalarMap.VERTICAL"; + break; + } + theStr<GetPosX()<<","<GetPosY()<<")"<GetWidth()<<","<GetHeight()<<")"<GetNbColors()<<")"<GetLabels()<<")"<GetTitle()<<"')"<GetScale()<<")"<IsColored()<<")"<GetColor(); + theStr< + void + TableAttrToPython(SALOMEDS::Study_ptr theStudy, + CORBA::Boolean theIsPublished, + CORBA::Boolean& theIsValidScript, + SALOMEDS::SObject_ptr theSObject, + TTableAttr theTableAttr, + const std::string& theAttrName, + std::ostream& theStr, + TName2EntryMap& theName2EntryMap, + TEntry2NameMap& theEntry2NameMap, + std::string theArgumentName, + std::string thePrefix) + { + SALOMEDS::GenericAttribute_var anAttr; + SALOMEDS::SObject_var aFatherSObject = theSObject->GetFather(); + if(aFatherSObject->FindAttribute(anAttr,"AttributeComment")){ + SALOMEDS::AttributeComment_var aComment = + SALOMEDS::AttributeComment::_narrow(anAttr); + CORBA::String_var aValue = aComment->Value(); + Storable::TRestoringMap aMap; + Storable::StrToMap(aValue.in(),aMap); + bool anIsExist; + QString aMethodName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist); + if(anIsExist){ + if(strcmp(aMethodName.latin1(),"ImportTables") == 0){ + return; + } + } + } + + std::string aSObjectName = GetName(theSObject); + theStr<GetTitle(); + theStr<GetNbColumns(); + theStr<GetNbRows(); + theStr<HasValue(i,j)){ + CORBA::Double aValue = theTableAttr->GetValue(i,j); + theStr<GetRowTitles(); + SALOMEDS::StringSeq_var aRowUnits = theTableAttr->GetRowUnits(); + for(CORBA::Long j = 1; j <= aNbRows; j++){ + theStr<GetColumnTitles(); + for(CORBA::Long i = 1; i <= aNbColumns; i++){ + theStr<FindAttribute(anAttr,"AttributeIOR")){ + theStr<NewChildIterator(theSObject); + for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){ + SALOMEDS::SObject_var aSObject = aChildItet->Value(); + DumpToPython(theStudy, + theIsPublished, + theIsValidScript, + aSObject, + theStr, + theName2EntryMap, + theEntry2NameMap, + theArgumentName, + thePrefix); + } + } + + + //=========================================================================== + void + DumpTableAttrToPython(SALOMEDS::Study_ptr theStudy, + CORBA::Boolean theIsPublished, + CORBA::Boolean& theIsValidScript, + SALOMEDS::SObject_ptr theSObject, + std::ostream& theStr, + TName2EntryMap& theName2EntryMap, + TEntry2NameMap& theEntry2NameMap, + std::string theArgumentName, + std::string thePrefix) + { + SALOMEDS::GenericAttribute_var anAttr; + if(theSObject->FindAttribute(anAttr,"AttributeTableOfInteger")){ + SALOMEDS::AttributeTableOfInteger_var aTableAttr = + SALOMEDS::AttributeTableOfInteger::_narrow(anAttr); + + TableAttrToPython(theStudy, + theIsPublished, + theIsValidScript, + theSObject, + aTableAttr, + "AttributeTableOfInteger", + theStr, + theName2EntryMap, + theEntry2NameMap, + theArgumentName, + thePrefix); + + }else if(theSObject->FindAttribute(anAttr,"AttributeTableOfReal")){ + SALOMEDS::AttributeTableOfReal_var aTableAttr = + SALOMEDS::AttributeTableOfReal::_narrow(anAttr); + + TableAttrToPython(theStudy, + theIsPublished, + theIsValidScript, + theSObject, + aTableAttr, + "AttributeTableOfReal", + theStr, + theName2EntryMap, + theEntry2NameMap, + theArgumentName, + thePrefix); + } + } + + + //=========================================================================== + void + NewSObjectDumpToPython(SALOMEDS::Study_ptr theStudy, + CORBA::Boolean theIsPublished, + CORBA::Boolean& theIsValidScript, + SALOMEDS::SObject_ptr theSObject, + TDumpToPython theDumpToPython, + std::ostream& theStr, + TName2EntryMap& theName2EntryMap, + TEntry2NameMap& theEntry2NameMap, + std::string theArgumentName, + std::string thePrefix) + { + SALOMEDS::StudyBuilder_var aBuilder = theStudy->NewBuilder(); + std::string aName = GenerateName(theSObject,theName2EntryMap,theEntry2NameMap); + theStr<GetID(); + + VISU::VISUType aType = aBase->GetType(); + switch(aType){ + case VISU::TRESULT: + if(Result_i* aServant = dynamic_cast(GetServant(anObj).in())){ + std::string aFileName = aServant->GetFileName(); + Result_i::ECreationId anId = aServant->GetCreationId(); + if(anId == Result_i::eImportFile || anId == Result_i::eCopyAndImportFile){ + switch(anId){ + case Result_i::eImportFile: + theStr<FindSubObject(1,aRefSObj)){ + SALOMEDS::SObject_var aTargetRefSObj; + if(aRefSObj->ReferencedObject(aTargetRefSObj)){ + CORBA::String_var aString = aTargetRefSObj->GetName(); + theStr<(GetServant(anObj).in())){ + VISU::Entity anEntity = aServant->GetEntity(); + const std::string& aSubMeshName = aServant->GetSubMeshName(); + if(anEntity >= 0){ + std::string aParam; + switch(anEntity){ + case NODE: + aParam = "VISU.NODE"; + break; + case EDGE: + aParam = "VISU.EDGE"; + break; + case FACE: + aParam = "VISU.FACE"; + break; + case CELL: + aParam = "VISU.CELL"; + break; + } + + if(aSubMeshName == "") + theStr<GetMeshName()<<"'"<< + ","<GetMeshName()<<"'"<< + ","<GetMeshName()<<"'"<< + ",'"<GetNodeColor(); + theStr<GetLinkColor(); + theStr<GetPresentationType()){ + case POINT: + aParam = "VISU.POINT"; + break; + case WIREFRAME: + aParam = "VISU.WIREFRAME"; + break; + case SHADED: + aParam = "VISU.SHADED"; + break; + case INSIDEFRAME: + aParam = "VISU.INSIDEFRAME"; + break; + case SURFACEFRAME: + aParam = "VISU.SURFACEFRAME"; + break; + case SHRINK: + aParam = "VISU.SHRINK"; + break; + } + theStr<(GetServant(anObj).in())){ + thePrefix = ScalarMapToPython(theSObject,aServant,theStr,aName,"ScalarMapOnField",theArgumentName,thePrefix); + theStr<(GetServant(anObj).in())){ + thePrefix = DeformedShapeToPython(theSObject,aServant,theStr,aName,"DeformedShapeOnField",theArgumentName,thePrefix); + theStr<(GetServant(anObj).in())){ + thePrefix = DeformedShapeToPython(theSObject,aServant,theStr,aName,"StreamLinesOnField",theArgumentName,thePrefix); + + std::string aParam; + switch(aServant->GetDirection()){ + case StreamLines::FORWARD: + aParam = "VISU.StreamLines.FORWARD"; + break; + case StreamLines::BACKWARD: + aParam = "VISU.StreamLines.BACKWARD"; + break; + case StreamLines::BOTH: + aParam = "VISU.StreamLines.BOTH"; + break; + } + + theStr<GetSource(); + if(!CORBA::is_nil(aPrs3d)){ + if(Prs3d_i* aServant3d = dynamic_cast(GetServant(aPrs3d).in())){ + SALOMEDS::SObject_var aSObject = aServant3d->GetSObject(); + CORBA::String_var anID = aSObject->GetID(); + std::string anArg = theEntry2NameMap[anID.in()]; + theStr<GetIntegrationStep()<<","<< + aServant->GetPropagationTime()<<","<< + aServant->GetStepLength()<<","<< + "aPrs3d"<<","<< + aServant->GetUsedPoints()<<","<< + aParam<< + ")"<(GetServant(anObj).in())){ + thePrefix = DeformedShapeToPython(theSObject,aServant,theStr,aName,"VectorsOnField",theArgumentName,thePrefix); + + theStr<GetLineWidth()<<")"<GetGlyphType()){ + case Vectors::ARROW: + aParam = "VISU.Vectors.ARROW"; + break; + case Vectors::CONE2: + aParam = "VISU.Vectors.CONE2"; + break; + case Vectors::CONE6: + aParam = "VISU.Vectors.CONE6"; + break; + case Vectors::NONE: + aParam = "VISU.Vectors.NONE"; + break; + } + theStr<GetGlyphPos()){ + case Vectors::CENTER: + aParam = "VISU.Vectors.CENTER"; + break; + case Vectors::TAIL: + aParam = "VISU.Vectors.TAIL"; + break; + case Vectors::HEAD: + aParam = "VISU.Vectors.HEAD"; + break; + } + theStr<(GetServant(anObj).in())){ + thePrefix = ScalarMapToPython(theSObject,aServant,theStr,aName,"IsoSurfacesOnField",theArgumentName,thePrefix); + theStr<GetNbSurfaces()<<")"<(GetServant(anObj).in())){ + thePrefix = ScalarMapToPython(theSObject,aServant,theStr,aName,"CutPlanesOnField",theArgumentName,thePrefix); + + std::string aParam; + switch(aServant->GetOrientationType()){ + case CutPlanes::XY: + aParam = "VISU.CutPlanes.XY"; + break; + case CutPlanes::YZ: + aParam = "VISU.CutPlanes.YZ"; + break; + case CutPlanes::ZX: + aParam = "VISU.CutPlanes.ZX"; + break; + } + theStr<GetRotateX()<<","<GetRotateY()<<")"<GetDisplacement()<<")"<GetNbPlanes(); + theStr<IsDefault(anId)) + theStr<GetPlanePosition(anId)<<")"<(GetServant(anObj).in())){ + thePrefix = ScalarMapToPython(theSObject,aServant,theStr,aName,"CutLinesOnField",theArgumentName,thePrefix); + + std::string aParam; + switch(aServant->GetOrientationType()){ + case CutPlanes::XY: + aParam = "VISU.CutPlanes.XY"; + break; + case CutPlanes::YZ: + aParam = "VISU.CutPlanes.YZ"; + break; + case CutPlanes::ZX: + aParam = "VISU.CutPlanes.ZX"; + break; + } + theStr<GetRotateX()<<","<GetRotateY()<<")"<GetOrientationType2()){ + case CutPlanes::XY: + aParam = "VISU.CutPlanes.XY"; + break; + case CutPlanes::YZ: + aParam = "VISU.CutPlanes.YZ"; + break; + case CutPlanes::ZX: + aParam = "VISU.CutPlanes.ZX"; + break; + } + theStr<GetRotateX2()<<","<GetRotateY2()<<")"<GetDisplacement()<<")"<GetDisplacement2()<<")"<IsDefault()) + theStr<GetBasePlanePosition()<<")"<GetNbLines(); + theStr<IsDefaultPosition(anId)) + theStr<GetLinePosition(anId)<<")"<(GetServant(anObj).in())){ + theStr<GetHRow()<< + ","<GetVRow()<< + ")"<GetTitle()<<"')"<GetColor(); + theStr<GetMarker()){ + case Curve::NONE: + aParam = "VISU.Curve.NONE"; + break; + case Curve::CIRCLE: + aParam = "VISU.Curve.CIRCLE"; + break; + case Curve::RECTANGLE: + aParam = "VISU.Curve.RECTANGLE"; + break; + case Curve::DIAMOND: + aParam = "VISU.Curve.DIAMOND"; + break; + case Curve::DTRIANGLE: + aParam = "VISU.Curve.DTRIANGLE"; + break; + case Curve::UTRIANGLE: + aParam = "VISU.Curve.UTRIANGLE"; + break; + case Curve::LTRIANGLE: + aParam = "VISU.Curve.LTRIANGLE"; + break; + case Curve::RTRIANGLE: + aParam = "VISU.Curve.RTRIANGLE"; + break; + case Curve::CROSS: + aParam = "VISU.Curve.CROSS"; + break; + case Curve::XCROSS: + aParam = "VISU.Curve.XCROSS"; + break; + } + theStr<GetLine()){ + case Curve::VOIDLINE: + aParam = "VISU.Curve.VOIDLINE"; + break; + case Curve::SOLIDLINE: + aParam = "VISU.Curve.SOLIDLINE"; + break; + case Curve::DASHLINE: + aParam = "VISU.Curve.DASHLINE"; + break; + case Curve::DOTLINE: + aParam = "VISU.Curve.DOTLINE"; + break; + case Curve::DASHDOTLINE: + aParam = "VISU.Curve.DASHDOTLINE"; + break; + case Curve::DASHDOTDOTLINE: + aParam = "VISU.Curve.DASHDOTDOTLINE"; + break; + } + theStr<GetLineWidth()<<")"<(GetServant(anObj).in())){ + SALOMEDS::SObject_var aSObject = aServant->GetSObject(); + SALOMEDS::GenericAttribute_var anAttr; + if(theSObject->FindAttribute(anAttr,"AttributeComment")){ + using namespace SALOMEDS; + AttributeComment_var aComment = AttributeComment::_narrow(anAttr); + CORBA::String_var aValue = aComment->Value(); + Storable::TRestoringMap aMap; + Storable::StrToMap(aValue.in(),aMap); + bool anIsExist; + QString aSourceId = VISU::Storable::FindValue(aMap,"mySourceId",&anIsExist); + if(anIsExist){ + if(strcmp(aSourceId.latin1(),"CutLines") == 0){ + theStr<Tag(); + theStr<FindAttribute(anAttr,"AttributeComment")){ + SALOMEDS::AttributeComment_var aComment = + SALOMEDS::AttributeComment::_narrow(anAttr); + CORBA::String_var aValue = aComment->Value(); + Storable::TRestoringMap aMap; + Storable::StrToMap(aValue.in(),aMap); + bool anIsExist; + QString aTypeName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist); + if(anIsExist){ + if(strcmp(aTypeName.latin1(),"ImportTables") == 0){ + QString aFileName = VISU::Storable::FindValue(aMap,"myFileName",&anIsExist); + if(anIsExist){ + std::string aName = GenerateName(theSObject,theName2EntryMap,theEntry2NameMap); + theStr<ReferencedObject(aTargetRefSObj)){ + CORBA::Object_var anObj = SObjectToObject(aTargetRefSObj); + if(CORBA::is_nil(anObj)) + return; + + VISU::Base_var aBase = VISU::Base::_narrow(anObj); + if(CORBA::is_nil(aBase)) + return; + + if(aBase->GetType() == VISU::TCURVE){ + CORBA::String_var anID = aTargetRefSObj->GetID(); + std::string anArg = theEntry2NameMap[anID.in()]; + theStr<NewChildIterator(theSObject); + for(aChildItet->InitEx(false); aChildItet->More(); aChildItet->Next()){ + SALOMEDS::SObject_var aSObject = aChildItet->Value(); + CORBA::Object_var anObj = SObjectToObject(aSObject); + if(CORBA::is_nil(anObj)) + continue; + + VISU::Base_var aBase = VISU::Base::_narrow(anObj); + if(CORBA::is_nil(aBase)) + continue; + + if(aBase->GetType() == VISU::TCONTAINER){ + theStr<NewChildIterator(aSObject); + for(aCurveIter->InitEx(false); aCurveIter->More(); aCurveIter->Next()){ + SALOMEDS::SObject_var aRefSObj = aCurveIter->Value(); + DumpCurveToPython(theStudy,theIsPublished,theIsValidScript,aRefSObj,theStr,theName2EntryMap,theEntry2NameMap,theArgumentName,aPrefix); + } + + theStr<GetStudy(); + + //CORBA::Boolean anIsValidScript; + //Engines::TMPFile_var aDump = DumpPython(aStudy,false,anIsValidScript); + SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent); for (; itBig->More(); itBig->Next()) { SALOMEDS::SObject_var gotBranch = itBig->Value(); CORBA::Object_var anObj = SObjectToObject(gotBranch); if(CORBA::is_nil(anObj)) continue; if(Result_i* pResult = dynamic_cast(GetServant(anObj).in())){ - const Result_i::TSourceId& aSourceId = pResult->GetSourceId(); - if(aSourceId == Result_i::eFile || aSourceId == Result_i::eRestoredFile){ + switch(pResult->GetCreationId()){ + case Result_i::eImportFile: + case Result_i::eCopyAndImportFile: { const QFileInfo& aFileInfo = pResult->GetFileInfo(); QString aPrefix(""); if (isMultiFile) aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL()).c_str(); QString aFileName = aPrefix + "_" + (pResult->GetName()).c_str(); static QString aCommand; aCommand.sprintf("cp %s %s%s",aFileInfo.filePath().latin1(),aTmpDir.ToCString(),aFileName.latin1()); - + int aRes = system(aCommand); if(aRes){ if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Cann't execute the command :"<URL()).c_str(); @@ -297,7 +304,7 @@ namespace VISU{ HDFascii::ConvertFromHDFToASCII(strdup((aTmpDir + aString).ToCString()), true); aFileNames.Append(aString); - } + }} } } SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0); @@ -377,7 +384,9 @@ namespace VISU{ return Result::_nil(); Mutex mt(myMutex); aFileInfo.setFile(theFileName); - Result_i* pResult = new Result_i(myStudyDocument); + Result_i* pResult = new Result_i(myStudyDocument, + Result_i::eFile, + Result_i::eImportFile); if(pResult->Create(theFileName) != NULL) return pResult->_this(); else{ @@ -392,7 +401,9 @@ namespace VISU{ Mutex mt(myMutex); VISU::Result_var aResult; aFileInfo.setFile(theFileName); - Result_i* pResult = new Result_i(myStudyDocument,Result_i::eRestoredFile); + Result_i* pResult = new Result_i(myStudyDocument, + Result_i::eRestoredFile, + Result_i::eCopyAndImportFile); if(pResult->Create(theFileName) != NULL) aResult = pResult->_this(); return aResult._retn(); @@ -402,7 +413,9 @@ namespace VISU{ if(myStudyDocument->GetProperties()->IsLocked()) return Result::_nil(); Mutex mt(myMutex); - Result_i* pResult = new Result_i(myStudyDocument); + Result_i* pResult = new Result_i(myStudyDocument, + Result_i::eComponent, + Result_i::eImportMed); if(pResult->Create(theMedSObject) != NULL) return pResult->_this(); else{ @@ -415,7 +428,9 @@ namespace VISU{ if(myStudyDocument->GetProperties()->IsLocked()) return Result::_nil(); Mutex mt(myMutex); - Result_i* pResult = new Result_i(myStudyDocument); + Result_i* pResult = new Result_i(myStudyDocument, + Result_i::eComponent, + Result_i::eImportMedField); if(pResult->Create(theField) != NULL) return pResult->_this(); else{ @@ -639,11 +654,11 @@ namespace VISU{ Result_var aResultObj = Result::_narrow(anObj); if(!aResultObj->_is_nil()){ if(Result_i* pResult = dynamic_cast(GetServant(aResultObj).in())){ - const Result_i::TSourceId& aSourceId = pResult->GetSourceId(); - if(aSourceId == Result_i::eComponent || aSourceId == Result_i::eRestoredComponent) - if((pResult->GetFileInfo()).filePath() == "MED") - return false; - return true; + switch(pResult->GetCreationId()){ + case Result_i::eImportFile: + case Result_i::eCopyAndImportFile: + return true; + } } } } diff --git a/src/VISU_I/VISU_Gen_i.hh b/src/VISU_I/VISU_Gen_i.hh index 7869cd6c..d5f71d52 100644 --- a/src/VISU_I/VISU_Gen_i.hh +++ b/src/VISU_I/VISU_Gen_i.hh @@ -98,13 +98,20 @@ namespace VISU{ virtual void DeleteResult(Result_ptr theResult); virtual void DeletePrs3d(Prs3d_ptr thePrs3d); - // inherited methods from SALOMEDS::Driver + // inherited methods from Engines::Component + virtual + Engines::TMPFile* + DumpPython(CORBA::Object_ptr theStudy, + CORBA::Boolean theIsPublished, + CORBA::Boolean& theIsValidScript); + virtual SALOMEDS::TMPFile* Save(SALOMEDS::SComponent_ptr theComponent, const char* theURL, bool isMultiFile); virtual SALOMEDS::TMPFile* SaveASCII(SALOMEDS::SComponent_ptr theComponent, const char* theURL, bool isMultiFile); + virtual bool Load(SALOMEDS::SComponent_ptr, const SALOMEDS::TMPFile &, const char* theURL, diff --git a/src/VISU_I/VISU_Mesh_i.hh b/src/VISU_I/VISU_Mesh_i.hh index 5ae8a364..d299ac66 100644 --- a/src/VISU_I/VISU_Mesh_i.hh +++ b/src/VISU_I/VISU_Mesh_i.hh @@ -81,6 +81,10 @@ namespace VISU{ static int IsPossible(Result_i* theResult, const char* theMeshName, const char* theGroupName); virtual Storable* Create(const char* theMeshName, const char* theGroupName); + const std::string& GetMeshName() const { return myMeshName;} + VISU::Entity GetEntity() const { return VISU::Entity(myEntity);} + const string& GetSubMeshName() const { return mySubMeshName;} + virtual void ToStream(std::ostringstream& theStr); virtual const char* GetComment() const; diff --git a/src/VISU_I/VISU_Result_i.cc b/src/VISU_I/VISU_Result_i.cc index d4e1ee61..6aea4e45 100644 --- a/src/VISU_I/VISU_Result_i.cc +++ b/src/VISU_I/VISU_Result_i.cc @@ -126,14 +126,15 @@ string GetComponentDataType(SALOMEDS::SObject_ptr theSObject){ const string VISU::Result_i::myComment = "RESULT"; const char* VISU::Result_i::GetComment() const { return myComment.c_str();} -VISU::Result_i::Result_i(SALOMEDS::Study_ptr theStudy, const TSourceId& aSourceId) { - myStudyDocument = SALOMEDS::Study::_duplicate(theStudy); - mySourceId = aSourceId; - myInput = NULL; - myIsDone = 0; - CORBA::String_var aName = theStudy->Name(); - MESSAGE("Result_i::Result_i - this = "<GetSize(); bool aResult = VISU_PipeLine::CheckAvailableMemory(aSize); @@ -157,7 +161,10 @@ int VISU::Result_i::IsPossible(){ } -CORBA::Boolean VISU::Result_i::BuildAll(){ +CORBA::Boolean +VISU::Result_i:: +BuildAll() +{ if(MYDEBUG) MESSAGE("Result_i::Build - myIsDone = "<NewBuilder(); aStudyBuilder->NewCommand(); // There is a transaction @@ -425,21 +435,25 @@ VISU::Storable* VISU::Result_i::Build(SALOMEDS::SObject_ptr theSObject) return this; } -VISU::Storable* VISU::Result_i::Create(const char* theFileName){ + +VISU::Storable* +VISU::Result_i:: +Create(const char* theFileName) +{ try{ myFileInfo.setFile(theFileName); myInitFileName = myFileInfo.filePath().latin1(); myName = ::GenerateName(myFileInfo.fileName()).latin1(); - if(GetSourceId() == eRestoredFile){ - auto_ptr aTmpDir((char*)SALOMEDS_Tool::GetTmpDir().c_str()); + if(mySourceId == eRestoredFile){ + std::string aTmpDir(SALOMEDS_Tool::GetTmpDir()); static QString aCommand; - aCommand.sprintf("cp %s %s",myFileInfo.absFilePath().latin1(),aTmpDir.get()); + aCommand.sprintf("cp %s %s",myFileInfo.absFilePath().latin1(),aTmpDir.c_str()); if(system(aCommand) == -1){ MESSAGE("Create - Can't execute the command :"<ConvertObjectToIOR(theField); SALOMEDS::SObject_var aFieldSObject = myStudyDocument->FindObjectIOR(anIOR); + VISU::Storable* aStorable = Build(aFieldSObject); return aStorable; }catch(std::exception& exc){ @@ -493,8 +522,12 @@ VISU::Storable* VISU::Result_i::Create(SALOME_MED::FIELD_ptr theField){ return NULL; } -VISU::Storable* VISU::Result_i::Restore(SALOMEDS::SObject_ptr theSObject, - const Storable::TRestoringMap& theMap, const string& thePrefix) + +VISU::Storable* +VISU::Result_i:: +Restore(SALOMEDS::SObject_ptr theSObject, + const Storable::TRestoringMap& theMap, + const string& thePrefix) { if(MYDEBUG) MESSAGE("Result_i::Restore - "<FindSubObject(1,aRefSObj) && aRefSObj->ReferencedObject(aTargetRefSObj)){ - mySourceId = eRestoredComponent; if(MYDEBUG) MESSAGE("Result_i::GetInput - There is some reference."); SALOMEDS::SComponent_var aCompRefSObj = aTargetRefSObj->GetFatherComponent(); CORBA::String_var aDataType = aCompRefSObj->ComponentDataType(); @@ -595,14 +627,25 @@ void VISU::Result_i::ToStream(std::ostringstream& theStr){ if(MYDEBUG) MESSAGE(GetComment()); Storable::DataToStream(theStr,"myName",myName.c_str()); Storable::DataToStream(theStr,"myInitFileName",myInitFileName.c_str()); + Storable::DataToStream(theStr,"myCreationId",myCreationId); } -VISU::Storable* VISU::Result_i::Restore(SALOMEDS::SObject_ptr theSObject, - const string& thePrefix, const Storable::TRestoringMap& theMap) +VISU::Storable* +VISU::Result_i::Restore(SALOMEDS::SObject_ptr theSObject, + const string& thePrefix, + const Storable::TRestoringMap& theMap) { SALOMEDS::Study_var aStudy = theSObject->GetStudy(); - VISU::Result_i* pResult = new VISU::Result_i(aStudy); - if(pResult == NULL) return NULL; + + ECreationId aCreationId = ECreationId(Storable::FindValue(theMap,"myCreationId").toInt()); + ESourceId aSourceId = eRestoredFile; + if(aCreationId == eImportMed || aCreationId == eImportMedField) + aSourceId = eRestoredComponent; + + VISU::Result_i* pResult = new VISU::Result_i(aStudy,aSourceId,aCreationId); + if(pResult == NULL) + return NULL; + return pResult->Restore(theSObject,theMap,thePrefix); } @@ -626,7 +669,7 @@ std::string VISU::Result_i::GetEntry(const std::string& theComment) VISU::Result_i::~Result_i() { MESSAGE("Result_i::~Result_i() - this = "<GetFather(); + if(aFatherSObject->FindAttribute(anAttr,"AttributeComment")){ + SALOMEDS::AttributeComment_var aCommentAttr = + SALOMEDS::AttributeComment::_narrow(anAttr); + CORBA::String_var aValue = aCommentAttr->Value(); + Storable::TRestoringMap aMap; + Storable::StrToMap(aValue.in(),aMap); + bool anIsExist; + QString aMethodName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist); + if(anIsExist){ + if(strcmp(aMethodName.latin1(),"ImportTables") == 0){ + aComment.sprintf("myComment=%s;myType=%d;mySourceId=TableFile",GetComment(),VISU::TTABLE); + } + } + } + } + + // create SObject and set attributes string anEntry = CreateAttributes( myStudy, SO->GetID(),//SComponent->GetID(), "", @@ -1120,11 +1141,20 @@ SALOMEDS::SObject_var VISU::ImportTables(const char* theFileName, SALOMEDS::Stud SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder(); SALOMEDS::SComponent_var theSComponent = VISU::FindOrCreateVisuComponent(theStudy); SALOMEDS::SObject_var aFileObject = aStudyBuilder->NewObject(theSComponent); + SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aFileObject, "AttributeName"); SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr); QFileInfo aFileInfo(theFileName); aName->SetValue(aFileInfo.fileName().latin1()); + + anAttr = aStudyBuilder->FindOrCreateAttribute(aFileObject, "AttributeComment"); + SALOMEDS::AttributeComment_var aComment = SALOMEDS::AttributeComment::_narrow(anAttr); + QString aString; + aString.sprintf("myComment=ImportTables;myFileName=%s", + aFileInfo.absFilePath().latin1()); + aComment->SetValue(aString.latin1()); + for(int i = 0, iEnd = aTableCont.size(); i < iEnd; i++){ const TTable2D& aTable2D = aTableCont[i]; SALOMEDS::SObject_var aRealObject = aStudyBuilder->NewObject(aFileObject); diff --git a/src/VISU_I/VISU_Table_i.hh b/src/VISU_I/VISU_Table_i.hh index 1d00478b..72067232 100644 --- a/src/VISU_I/VISU_Table_i.hh +++ b/src/VISU_I/VISU_Table_i.hh @@ -66,6 +66,9 @@ namespace VISU{ public: virtual Storable* Create(); + + SALOMEDS::SObject_var GetSObject() const { return mySObj;} + virtual Storable* Restore( const Storable::TRestoringMap& theMap, SALOMEDS::SObject_ptr SO); static Storable* Restore(SALOMEDS::SObject_ptr theSObject, const string& thePrefix, const Storable::TRestoringMap& theMap); @@ -124,6 +127,10 @@ namespace VISU{ public: virtual Storable* Create(); + + int GetHRow() const { return myHRow;} + int GetVRow() const { return myVRow;} + virtual Storable* Restore( const Storable::TRestoringMap& theMap, SALOMEDS::SObject_ptr theSO); static Storable* Restore(SALOMEDS::SObject_ptr theSObject,