X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FVISU_I%2FVISU_Gen_i.cc;h=4801ceeef3c7abd026389d9abb8ae7f135e36580;hb=a7e9d108adf9283e24d85357125a07022f409d3a;hp=c31b72141c8d69d4548cf302386b83f8ec4fabb2;hpb=1470190682148c950f0c1a941034e9e2b6c10318;p=modules%2Fvisu.git diff --git a/src/VISU_I/VISU_Gen_i.cc b/src/VISU_I/VISU_Gen_i.cc index c31b7214..4801ceee 100644 --- a/src/VISU_I/VISU_Gen_i.cc +++ b/src/VISU_I/VISU_Gen_i.cc @@ -1,256 +1,154 @@ -// Copyright (C) 2003 CEA/DEN, EDF R&D +// 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. // -// File : VISU_Gen_i.cc file -// Author : Alexey Petrov +// 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_Gen_i.cc +// Author : Alexey PETROV // Module : VISU -// $Header: -using namespace std; #include "VISU_Gen_i.hh" #include "VISU_Result_i.hh" -#include "VISU_Convertor.hxx" #include "VISU_PrsObject_i.hh" #include "VISU_ViewManager_i.hh" -#include "VISU_TimeAnimation.h" + +#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_Plot3D_i.hh" #include "VISU_Table_i.hh" +#include "VISU_TimeAnimation.h" + +#include "VISU_Actor.h" #include "HDFascii.hxx" #include "SALOMEDS_Tool.hxx" -#include -#include -#include -#include -#include -#include +#include "SALOMEDSClient_AttributeName.hxx" +#include "SALOMEDSClient_AttributePixMap.hxx" + +#include "SUIT_Session.h" +#include "SalomeApp_Study.h" +#include "SalomeApp_Application.h" +#include "LightApp_SelectionMgr.h" +#include "SVTK_ViewModel.h" +#include "SVTK_ViewWindow.h" +#include "SALOME_Event.hxx" +#include "SALOME_ListIO.hxx" +#include "SALOME_ListIteratorOfListIO.hxx" + +#include "utilities.h" + +// IDL Headers +#include #include CORBA_SERVER_HEADER(SALOME_Session) #include CORBA_SERVER_HEADER(SALOME_ModuleCatalog) +// QT Includes #include #include + +// VTK Includes +#include +#include + +// OCCT Includes +#include +#include + +// STL Includes +#include + +#include "Utils_ExceptHandlers.hxx" + +using namespace std; + static QFileInfo aFileInfo; -#ifdef DEBUG -static int MYDEBUG = 0; +#ifdef _DEBUG_ +static int MYDEBUG = 1; #else static int MYDEBUG = 0; #endif -#include - -//static int IS_LOADED = (cout<<"\n----------------- VisuEngine_factory is loaded -----------------\n", 1); -extern "C" { - PortableServer::ObjectId * - VISUEngine_factory(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, PortableServer::ObjectId * contId, - const char *instanceName, const char *interfaceName) - { - if(MYDEBUG) MESSAGE("VisuEngine_factory : "<getId() ; - } - VISU::VISU_Gen_ptr - GetVisuGen(CORBA::ORB_ptr theORB, PortableServer::POA_ptr thePOA, - SALOME_NamingService* theNamingService, QMutex* theMutex) - { - if(MYDEBUG) MESSAGE("extern \"C\" GetVisuGen"); - VISU::VISU_Gen_i *aVISU_Gen = new VISU::VISU_Gen_i(theORB,thePOA,theNamingService,theMutex); - return VISU::VISU_Gen::_duplicate(aVISU_Gen->_this()); - //return aVISU_Gen->_this(); - } +UNEXPECT_CATCH(SalomeException, SALOME::SALOME_Exception); + +extern "C" VISU::VISU_Gen_ptr GetImpl(CORBA::ORB_ptr theORB, + PortableServer::POA_ptr thePOA, + SALOME_NamingService* theNamingService, + QMutex* theMutex) +{ + if(MYDEBUG) MESSAGE("extern \"C\" GetImpl"); + VISU::VISU_Gen_i *aVISU_Gen = new VISU::VISU_Gen_i(theORB,thePOA,theNamingService,theMutex); + //return VISU::VISU_Gen::_duplicate(aVISU_Gen->_this()); + return aVISU_Gen->_this(); } namespace VISU{ - //=========================================================================== - //apo - static QMutex VISUMutex; - QMutex* Base_i::myMutex = NULL; //apo - &VISUMutex; - CORBA::ORB_var Base_i::myOrb; - PortableServer::POA_var Base_i::myPOA; - SALOME_NamingService* Base_i::myNamingService; - SALOME_LifeCycleCORBA* Base_i::myEnginesLifeCycle; - VISU_Gen_i* Base_i::myVisuGenImpl; - VISU_Gen_var Base_i::GetVisuGenInter() { return myVisuGenImpl->_this();} - Base_i::~Base_i() {} - char* Base_i::GetID(){ - //CORBA::Object_var anObject = _this(); - //return CORBA::string_dup(myOrb->object_to_string(anObject)); - return CORBA::string_dup(myOrb->object_to_string(_this())); - } - //=========================================================================== - static int mySCnt = 0; - static int myQCnt = 0; - static int myIsBatchMode = 0; + static string VisuTmpDir; - static int QApp_Counter = 0; - static int Session_Counter = 0; - static int COUNTER = 0; + static CORBA::Boolean myIsMultiFile; + const CORBA::Boolean IsMultifile() { return myIsMultiFile;} - Mutex::Mutex(QMutex* theMutex, QApplication* theQApp, int theDelay) : - myQApp(theQApp), isQAppLocked(theQApp->locked()), myDelay(theDelay), - myMutex(theMutex), isSessionLocked(theMutex->locked()) - { - if(MYDEBUG) MESSAGE("Mutex::Mutex : "<<(!isQAppLocked && !myQCnt)<<" "<<(!isSessionLocked && !mySCnt)); - if(!myIsBatchMode && isQAppLocked) myIsBatchMode++; - if(!isSessionLocked && !mySCnt) { myMutex->lock();}; mySCnt++; - if(!isQAppLocked && !myQCnt) { - myQApp->lock(); - myQApp->syncX(); - }; - myQCnt++; - } - Mutex::~Mutex(){ - myQCnt--; - if(!isQAppLocked && !myQCnt) { - myQApp->flushX(); - //if(myDelay > 0) - myQApp->processEvents(myDelay+3); - myQApp->unlock(); - } - mySCnt--; if(!isSessionLocked && !mySCnt) { myMutex->unlock();} - if(MYDEBUG) MESSAGE("Mutex::~Mutex : "<<(!isQAppLocked && !myQCnt)<<" "<<(!isSessionLocked && !mySCnt)); - } //=========================================================================== - static Storable::TCallbackMap VisuStoreMap; - string Storable::ToString(){ - ostringstream strOut; - Storable::DataToStream( strOut, "myComment", GetComment() ); - ToStream(strOut); - strOut< aRet(strOut.str()); - return strOut.str(); - } + _PTR(SComponent) ClientFindOrCreateVisuComponent (_PTR(Study) theStudyDocument) + { + _PTR(SComponent) aSComponent = theStudyDocument->FindComponent("VISU"); + if (!aSComponent) { + _PTR(StudyBuilder) aStudyBuilder = theStudyDocument->NewBuilder(); + aStudyBuilder->NewCommand(); + int aLocked = theStudyDocument->GetProperties()->IsLocked(); + if (aLocked) theStudyDocument->GetProperties()->SetLocked(false); + aSComponent = aStudyBuilder->NewComponent("VISU"); + _PTR(GenericAttribute) anAttr = + aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName"); + _PTR(AttributeName) aName (anAttr); - void Storable::Registry(const char* theComment, TStorableEngine theEngine) - throw(std::logic_error&) - { - if(!VisuStoreMap.insert(TCallbackMap::value_type(theComment,theEngine)).second){ - if(MYDEBUG) MESSAGE("Storable::Registry >> dupliacte registring !!!"); - throw std::logic_error("Storable::Registry >> dupliacte registring !!!"); - } + CORBA::ORB_var anORB = Base_i::GetORB(); + SALOME_NamingService *NamingService = new SALOME_NamingService( anORB ); + CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog"); + SALOME_ModuleCatalog::ModuleCatalog_var Catalogue = + SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN); + SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "VISU" ); + if (!Comp->_is_nil()) { + aName->SetValue(Comp->componentusername()); } - void RegistryStorable() throw(std::logic_error&) { - //Storable::Registry(View3D_i::myComment.c_str(),&View3DRestore); - Storable::Registry(Result_i::myComment.c_str(),&ResultRestore); - Storable::Registry(Mesh_i::myComment.c_str(),&MeshRestore); - Storable::Registry(ScalarMap_i::myComment.c_str(),&ScalarMapRestore); - Storable::Registry(DeformedShape_i::myComment.c_str(),&DeformedShapeRestore); - Storable::Registry(CutPlanes_i::myComment.c_str(),&CutPlanesRestore); - Storable::Registry(CutLines_i::myComment.c_str(),&CutLinesRestore); - Storable::Registry(IsoSurfaces_i::myComment.c_str(),&IsoSurfacesRestore); - Storable::Registry(StreamLines_i::myComment.c_str(),&StreamLinesRestore); - Storable::Registry(Vectors_i::myComment.c_str(),&VectorsRestore); - Storable::Registry(Table_i::myComment.c_str(),&TableRestore); - Storable::Registry(Curve_i::myComment.c_str(),&CurveRestore); - Storable::Registry(Container_i::myComment.c_str(),&ContainerRestore); - } + anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap"); + _PTR(AttributePixMap) aPixmap (anAttr); + aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" ); - void Storable::StrToMap(const QString& theStr, VISU::Storable::TRestoringMap& theMap){ - if(0 && MYDEBUG) MESSAGE("Storable::StrToMap : string="<_this(); + aStudyBuilder->DefineComponentInstance(aSComponent, aVisuGen->GetID()); + if (aLocked) theStudyDocument->GetProperties()->SetLocked(true); + aStudyBuilder->CommitCommand(); } + return aSComponent; } - void Storable::DataToStream(ostringstream& theStr, const QString& theName, const QString& theVal) { - QString output = ( !theName.isNull() ? theName : QString("") ) - + QString( "=" ) - + ( !theVal.isNull() ? theVal : QString("") ); - theStr<GetID()); - //aMap.insert(TRestoringMap::value_type("ResultID", strdup(aResultID))); - bool isExist; - QString aComment = VISU::Storable::FindValue(aMap,"myComment",&isExist); - if ( isExist ) { - TCallbackMap::const_iterator i = VisuStoreMap.find(aComment.latin1()); - if(MYDEBUG) MESSAGE("Storable::Create - "<second)(theSObject,thePrefix,aMap); - } - }catch(std::logic_error& exc){ - MESSAGE("Follow exception was accured :\n"<> there is no value for "<> there is no value for ") + theArg); - static QString BAD_VALUE("NULL"); - return BAD_VALUE; - } - if(isFind != NULL) *isFind = true; - return i->second; - } - //=========================================================================== - PortableServer::Servant GetServant(CORBA::Object_ptr theObject){ - PortableServer::POA_ptr aPOA = Base_i::GetPOA(); - if(CORBA::is_nil(theObject)) - if(MYDEBUG) MESSAGE("GetServant - CORBA::is_nil(theObject)"); - return aPOA->reference_to_servant(theObject); - } - //=========================================================================== - CORBA::Object_var SObjectToObject(SALOMEDS::SObject_ptr theSObject){ - SALOMEDS::GenericAttribute_var anAttr; - CORBA::Object_var anObj; - try{ - if(theSObject->FindAttribute(anAttr, "AttributeIOR")){ - SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - CORBA::String_var aValue = anIOR->Value(); - CORBA::ORB_ptr anORB = Base_i::GetORB(); - if(strcmp(aValue,"") != 0) - anObj = anORB->string_to_object(aValue); - } - }catch(...){ - MESSAGE("SObjectToObject - Unknown exception was accured!"); - } - return anObj; - } - //=========================================================================== SALOMEDS::SComponent_var FindOrCreateVisuComponent(SALOMEDS::Study_ptr theStudyDocument){ SALOMEDS::SComponent_var aSComponent = theStudyDocument->FindComponent("VISU"); if (aSComponent->_is_nil()) { @@ -258,11 +156,11 @@ namespace VISU{ aStudyBuilder->NewCommand(); int aLocked = theStudyDocument->GetProperties()->IsLocked(); if (aLocked) theStudyDocument->GetProperties()->SetLocked(false); - aSComponent = aStudyBuilder->NewComponent("VISU"); + aSComponent = aStudyBuilder->NewComponent("VISU"); SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributeName"); SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr); - //NRI aName->SetValue("Visu"); + //NRI aName->SetValue("Visu"); CORBA::ORB_var anORB = Base_i::GetORB(); SALOME_NamingService *NamingService = new SALOME_NamingService( anORB ); CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog"); @@ -275,111 +173,41 @@ namespace VISU{ anAttr = aStudyBuilder->FindOrCreateAttribute(aSComponent, "AttributePixMap"); SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr); aPixmap->SetPixMap( "ICON_OBJBROWSER_Visu" ); - - VISU_Gen_var aVisuGen = Base_i::GetVisuGenInter(); + + VISU_Gen_var aVisuGen = Base_i::GetVisuGenImpl()->_this(); aStudyBuilder->DefineComponentInstance(aSComponent,aVisuGen); if (aLocked) theStudyDocument->GetProperties()->SetLocked(true); aStudyBuilder->CommitCommand(); } return aSComponent; } - //=========================================================================== - string FindEntryWithComment(SALOMEDS::Study_ptr theStudyDocument, const char* theStartEntry, - const char* theComment, int IsAllLevels) - { - if(0 && MYDEBUG) MESSAGE("FindEntryWithComment - '"<NewChildIterator(theStudyDocument->FindObjectID(theStartEntry)); - anIter->InitEx(IsAllLevels); - SALOMEDS::SObject_var aFieldSO; - for(;anIter->More();anIter->Next()) { - SALOMEDS::GenericAttribute_var anAttr; - if (anIter->Value()->FindAttribute(anAttr,"AttributeComment")) { - SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr); - CORBA::String_var aString = aCmnt->Value(); - string aValue(aString); - if (aValue == theComment) { - aFieldSO = anIter->Value(); - aString = aFieldSO->GetID(); - aValue = aString; - return aValue; - } - } - } - return ""; - } - //=========================================================================== - string CreateAttributes(SALOMEDS::Study_ptr theStudyDocument, - const char* theFatherEntry, const char* theRefFatherEntry, - const char* theIOR, const char* theName, - const char* thePersistentRef, const char* theComment, - CORBA::Boolean theCreateNew) - { - if(0 && MYDEBUG) - MESSAGE("CreateAttributes - theName = "<SetValue(theIOR); - anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName"); - SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr); - aName->SetValue(theName); - anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributePersistentRef"); - SALOMEDS::AttributePersistentRef_var aPRef = SALOMEDS::AttributePersistentRef::_narrow(anAttr); - aPRef->SetValue(thePersistentRef); - anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeComment"); - SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr); - aCmnt->SetValue(theComment); - if(strcmp(theRefFatherEntry,"") != 0){ - SALOMEDS::SObject_var aRefFather = theStudyDocument->FindObjectID(theRefFatherEntry); - SALOMEDS::SObject_var anObj = aStudyBuilder->NewObject(aRefFather); - aStudyBuilder->Addreference(anObj,newObj); - } - CORBA::String_var anEntry = newObj->GetID(); - string aRet(anEntry); - if(0 && MYDEBUG) MESSAGE("CreateAttributes - anEntry = "<activate_object(_thisObj); - SALOME_NamingService aNamingService(orb); - CORBA::Object_ptr anObject = aNamingService.Resolve("/Kernel/Session"); - SALOME::Session_var aSession = SALOME::Session::_narrow(anObject); - //aSession->GetInterface(); - Engines::Component_var aComponent = aSession->GetVisuComponent(); - myVisuGen = VISU::VISU_Gen::_narrow(aComponent); + + void RegistryStorable() { + Storable::Registry(Result_i::myComment.c_str(),&(Result_i::Restore)); + Storable::Registry(Mesh_i::myComment.c_str(),&(Restore)); + Storable::Registry(ScalarMap_i::myComment.c_str(),&(Restore)); + Storable::Registry(DeformedShape_i::myComment.c_str(),&(Restore)); + Storable::Registry(CutPlanes_i::myComment.c_str(),&(Restore)); + Storable::Registry(CutLines_i::myComment.c_str(),&(Restore)); + Storable::Registry(IsoSurfaces_i::myComment.c_str(),&(Restore)); + Storable::Registry(StreamLines_i::myComment.c_str(),&(Restore)); + Storable::Registry(Plot3D_i::myComment.c_str(),&(Restore)); + Storable::Registry(Vectors_i::myComment.c_str(),&(Restore)); + Storable::Registry(Table_i::myComment.c_str(),&(Table_i::Restore)); + Storable::Registry(Curve_i::myComment.c_str(),&(Curve_i::Restore)); + Storable::Registry(Container_i::myComment.c_str(),&(Container_i::Restore)); } - VISU_Gen_i::VISU_Gen_i(CORBA::ORB_ptr theORB, PortableServer::POA_ptr thePOA, + + //=========================================================================== + VISU_Gen_i::VISU_Gen_i(CORBA::ORB_ptr theORB, PortableServer::POA_ptr thePOA, SALOME_NamingService* theNamingService, QMutex* theMutex) : Engines_Component_i() { if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : "<GetOpenStudies(); if(aListOfOpenStudies->length() > 0) { CORBA::String_var aStudyName = aListOfOpenStudies[0]; - aFileInfo.setFile(aStudyName.in()); - myStudyDocument = aStudyManager->GetStudyByName(aFileInfo.baseName()); - }else{ + //aFileInfo.setFile(aStudyName.in()); + myStudyDocument = aStudyManager->GetStudyByName(aStudyName/*aFileInfo.baseName()*/); + }else if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : there is no opened study in StudyManager !!!"); - } - - Base_i::myPOA->activate_object(this); } VISU_Gen_i::~VISU_Gen_i(){ if(MYDEBUG) MESSAGE("VISU_Gen_i::~VISU_Gen_i"); } //=========================================================================== - bool VISU_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent, - const SALOMEDS::TMPFile & theStream, - const char* theURL, - bool isMultiFile) + CORBA::Boolean VISU_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent, + const SALOMEDS::TMPFile & theStream, + const char* theURL, + bool isMultiFile) { - if(MYDEBUG) MESSAGE("VISU_Gen_i::Load - myMutex = "<GetStudy(); - SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); - TCollection_AsciiString aTmpDir = - isMultiFile?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir(); - VisuSComponent = SALOMEDS::SComponent::_duplicate(theComponent); - VisuTmpDir = aTmpDir.ToCString(); - SALOMEDS::ListOfFileNames_var aSeq = - SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.ToCString(),isMultiFile); - myIsMultiFile = isMultiFile; - return true; - } - return myVisuGen->Load(theComponent,theStream,theURL,isMultiFile); + Mutex mt(myMutex); + SALOMEDS::Study_var aStudy = theComponent->GetStudy(); + SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); + const char* aDir = isMultiFile? theURL: SALOMEDS_Tool::GetTmpDir().c_str(); + TCollection_AsciiString aTmpDir(const_cast(aDir)); + VisuTmpDir = aTmpDir.ToCString(); + SALOMEDS::ListOfFileNames_var aSeq = + SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.ToCString(),isMultiFile); + myIsMultiFile = isMultiFile; + return true; } - bool VISU_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent, - const SALOMEDS::TMPFile & theStream, - const char* theURL, - bool isMultiFile) { + CORBA::Boolean VISU_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent, + const SALOMEDS::TMPFile & theStream, + const char* theURL, + bool isMultiFile) + { return Load(theComponent, theStream, theURL, isMultiFile); } char* VISU_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject, const char* aLocalPersistentID, CORBA::Boolean isMultiFile, - CORBA::Boolean isASCII) { - if(myMutex){ - CORBA::String_var aString(""); - if(strcmp(aLocalPersistentID,"") != 0) { - Mutex mt(myMutex,qApp); - Storable* aStorable = - Storable::Create(theSObject,VisuTmpDir.c_str(),aLocalPersistentID); - if(aStorable != NULL) aString = aStorable->GetID(); - } - return aString._retn(); + CORBA::Boolean isASCII) + { + CORBA::String_var aString(""); + if(strcmp(aLocalPersistentID,"") != 0) { + Mutex mt(myMutex); + Storable* aStorable = + Storable::Create(theSObject,VisuTmpDir.c_str(),aLocalPersistentID); + if(aStorable != NULL) aString = aStorable->GetID(); } - return myVisuGen->LocalPersistentIDToIOR(theSObject, aLocalPersistentID, isMultiFile, isASCII); + return aString._retn(); } //=========================================================================== SALOMEDS::TMPFile* VISU_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent, - const char* theURL, - bool isMultiFile) + const char* theURL, + bool isMultiFile) { - if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - myMutex = "<GetStudy(); - 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; - Result_i* pResult = dynamic_cast(GetServant(anObj)); - if(pResult && abs(pResult->GetSourceId()) == Result_i::eFile){ + Mutex mt(myMutex); + const char* aDir = isMultiFile? theURL: SALOMEDS_Tool::GetTmpDir().c_str(); + TCollection_AsciiString aTmpDir(const_cast(aDir)); + if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<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())){ + switch(pResult->GetCreationId()){ + case Result_i::eImportFile: + case Result_i::eCopyAndImportFile: { const QFileInfo& aFileInfo = pResult->GetFileInfo(); - QString aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL()); + 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()); - if(system(aCommand) == -1){ + + int aRes = system(aCommand); + if(aRes){ if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Cann't execute the command :"< 0){ - SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames; - aSeq->length(aFileNames.Length()); - for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--) - aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString()); - aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile); - if(!isMultiFile) - SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true); + }} } - return aStreamFile._retn(); } - return myVisuGen->Save(theComponent,theURL,isMultiFile); + SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0); + if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.Length() - "< 0){ + SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames; + aSeq->length(aFileNames.Length()); + for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--) + aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString()); + aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile); + if(!isMultiFile) + SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true); + } + return aStreamFile._retn(); } SALOMEDS::TMPFile* VISU_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent, - const char* theURL, - bool isMultiFile) { - if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - myMutex = "<GetStudy(); - 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; - Result_i* pResult = dynamic_cast(GetServant(anObj)); - if(pResult && abs(pResult->GetSourceId()) == Result_i::eFile){ + const char* theURL, + bool isMultiFile) + { + Mutex mt(myMutex); + const char* aDir = isMultiFile? theURL: SALOMEDS_Tool::GetTmpDir().c_str(); + TCollection_AsciiString aTmpDir(const_cast(aDir)); + if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<GetStudy(); + 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())){ + switch(pResult->GetCreationId()){ + case Result_i::eImportFile: + case Result_i::eCopyAndImportFile: { const QFileInfo& aFileInfo = pResult->GetFileInfo(); - QString aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL()); + 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()); - - if(system(aCommand) == -1){ - if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Cann't execute the command :"< 0){ - SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames; - aSeq->length(aFileNames.Length()); - for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--) - aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString()); - aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile); - if(!isMultiFile) - SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true); + }} } - return aStreamFile._retn(); } - return myVisuGen->Save(theComponent,theURL,isMultiFile); + SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0); + if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.Length() - "< 0){ + SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames; + aSeq->length(aFileNames.Length()); + for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--) + aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString()); + aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile); + if(!isMultiFile) + SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true); + } + return aStreamFile._retn(); } char* VISU_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject, const char* IORString, CORBA::Boolean isMultiFile, - CORBA::Boolean isASCII) { - if(MYDEBUG) MESSAGE("VISU_Gen_i::IORToLocalPersistentID - myMutex = "<string_to_object(aString); - if(!CORBA::is_nil(anObj)){ - Storable* pStorable = dynamic_cast(GetServant(anObj)); - if(pStorable != NULL){ - Mutex mt(myMutex,qApp); - aString = pStorable->ToString().c_str(); - return aString._retn(); - } + CORBA::Boolean isASCII) + { + CORBA::String_var aString(IORString); + if(strcmp(IORString,"") != 0){ + CORBA::ORB_ptr anORB = GetORB(); + CORBA::Object_var anObj = anORB->string_to_object(aString); + if(!CORBA::is_nil(anObj)){ + if(Storable* pStorable = dynamic_cast(GetServant(anObj).in())){ + Mutex mt(myMutex); + aString = pStorable->ToString().c_str(); + return aString._retn(); } } - return aString._retn(); } - return myVisuGen->IORToLocalPersistentID(theSObject, IORString, isMultiFile, isASCII); + return aString._retn(); } - void VISU_Gen_i::SetCurrentStudy(SALOMEDS::Study_ptr theStudy){ - //if(MYDEBUG) MESSAGE("VISU_Gen_i::SetCurrentStudy : "<<(!theStudy->_is_nil())); - if(myMutex) + char* VISU_Gen_i::GetID(){ + return Base_i::GetID(); + } + + void VISU_Gen_i::SetCurrentStudy (SALOMEDS::Study_ptr theStudy) + { + class TEvent: public SALOME_Event { + std::string myStudyName; + public: + TEvent(const std::string theStudyName):myStudyName(theStudyName) + {} + virtual void Execute() + { + bool isActive = false; + SUIT_Session* aSession = SUIT_Session::session(); + QPtrList anApplications = aSession->applications(); + QPtrListIterator anIter (anApplications); + SUIT_Application* aFirstApp = anIter.current(); + while (SUIT_Application* anApp = anIter.current()) { + ++anIter; + if (SUIT_Study* aSStudy = anApp->activeStudy()) { + if (SalomeApp_Study* aStudy = dynamic_cast(aSStudy)) { + if (_PTR(Study) aCStudy = aStudy->studyDS()) { + MESSAGE("There is an application with active study : StudyId = " + << aCStudy->StudyId() << "; Name = '" << aCStudy->Name() << "'"); + if (myStudyName == aCStudy->Name()) { + isActive = true; + break; + } + } + } + } + } + if (!isActive) { + MESSAGE("!!! anApp->onLoadDoc(myStudyName) !!!"); + // Has to be loaded in an empty or in a new application + SalomeApp_Application* anApp = dynamic_cast(aFirstApp); + anApp->onLoadDoc(myStudyName.c_str()); + } + } + }; + + if (!CORBA::is_nil(theStudy)) + { + CORBA::String_var aName = theStudy->Name(); + std::string aStudyName (aName.in()); + MESSAGE("StudyId = " << theStudy->StudyId() << "; Name = '" << aName.in() << "'"); myStudyDocument = SALOMEDS::Study::_duplicate(theStudy); - else - myVisuGen->SetCurrentStudy(theStudy); + + ProcessVoidEvent(new TEvent(aStudyName)); + } else { + MESSAGE("CORBA::is_nil(theStudy)"); + } } + SALOMEDS::Study_ptr VISU_Gen_i::GetCurrentStudy(){ - if(MYDEBUG) MESSAGE("VISU_Gen_i::GetCurrentStudy : "<GetCurrentStudy(); + return SALOMEDS::Study::_duplicate(myStudyDocument); } + ViewManager_ptr VISU_Gen_i::GetViewManager(){ - //omni_mutex aMutex; - //omni_mutex_lock aMutexLock(aMutex); - if(MYDEBUG) MESSAGE("VISU_Gen_i::GetViewManager : "<_this()); - } - return myVisuGen->GetViewManager(); + Mutex mt(myMutex); + ViewManager_i * aViewManager = new ViewManager_i(myStudyDocument); + return ViewManager::_duplicate(aViewManager->_this()); } SALOMEDS::SObject_ptr VISU_Gen_i::ImportTables(const char* theFileName){ - if(myMutex){ - if(myStudyDocument->GetProperties()->IsLocked()) return SALOMEDS::SObject::_nil(); - Mutex mt(myMutex,qApp); - SALOMEDS::SObject_var aRes = VISU::ImportTables(theFileName,myStudyDocument); - return aRes._retn(); - } - return myVisuGen->ImportTables(theFileName); + if(myStudyDocument->GetProperties()->IsLocked()) + return SALOMEDS::SObject::_nil(); + Mutex mt(myMutex); + SALOMEDS::SObject_var aRes = VISU::ImportTables(theFileName,myStudyDocument); + return aRes._retn(); + } + + CORBA::Boolean VISU_Gen_i::ExportTableToFile(SALOMEDS::SObject_ptr theTable, + const char* theFileName) + { + return VISU::ExportTableToFile(theTable, theFileName); } Result_ptr VISU_Gen_i::ImportFile(const char* theFileName){ - if(myMutex){ - if(myStudyDocument->GetProperties()->IsLocked()) return Result::_nil(); - Mutex mt(myMutex,qApp); - aFileInfo.setFile(theFileName); - Result_i* pResult = new Result_i(myStudyDocument); - if(pResult->Create(theFileName) != NULL) - return Result::_duplicate(pResult->_this()); + if(myStudyDocument->GetProperties()->IsLocked()) return Result::_nil(); + Mutex mt(myMutex); + aFileInfo.setFile(theFileName); + Result_i* pResult = new Result_i(myStudyDocument, + Result_i::eFile, + Result_i::eImportFile); + if(pResult->Create(theFileName) != NULL) + return pResult->_this(); + else{ + pResult->_remove_ref(); + return VISU::Result::_nil(); } - return myVisuGen->ImportFile(theFileName); } - Result_ptr VISU_Gen_i::ImportMed(SALOMEDS::SObject_ptr theMedSObject){ - if(MYDEBUG) MESSAGE("VISU_Gen_i::ImportMed : "<GetProperties()->IsLocked()) return Result::_nil(); - Mutex mt(myMutex,qApp); - Result_i* pResult = new Result_i(myStudyDocument); - if(pResult->Create(theMedSObject) != NULL) - return Result::_duplicate(pResult->_this()); + Result_ptr VISU_Gen_i::CopyAndImportFile(const char* theFileName){ + if(myStudyDocument->GetProperties()->IsLocked()) + return Result::_nil(); + Mutex mt(myMutex); + VISU::Result_var aResult; + aFileInfo.setFile(theFileName); + Result_i* pResult = new Result_i(myStudyDocument, + Result_i::eRestoredFile, + Result_i::eCopyAndImportFile); + if(pResult->Create(theFileName) != NULL) + aResult = pResult->_this(); + return aResult._retn(); + } + + Result_ptr VISU_Gen_i::ImportMed (SALOMEDS::SObject_ptr theMedSObject) + { + if (myStudyDocument->GetProperties()->IsLocked()) return Result::_nil(); + Mutex mt(myMutex); + Result_i* pResult = new Result_i(myStudyDocument, + Result_i::eComponent, + Result_i::eImportMed); + if (pResult->Create(theMedSObject) != NULL) { + return pResult->_this(); + } else { + pResult->_remove_ref(); + return VISU::Result::_nil(); } - return myVisuGen->ImportMed(theMedSObject); } - Result_ptr VISU_Gen_i::ImportMedField(SALOME_MED::FIELD_ptr theField){ - if(MYDEBUG) MESSAGE("VISU_Gen_i::ImportMedField : "<GetProperties()->IsLocked()) return Result::_nil(); - Mutex mt(myMutex,qApp); - Result_i* pResult = new Result_i(myStudyDocument); - if(pResult->Create(theField) != NULL) - return Result::_duplicate(pResult->_this()); + Result_ptr VISU_Gen_i::ImportMedField (SALOME_MED::FIELD_ptr theField) + { + if (myStudyDocument->GetProperties()->IsLocked()) return Result::_nil(); + Mutex mt(myMutex); + Result_i* pResult = new Result_i(myStudyDocument, + Result_i::eComponent, + Result_i::eImportMedField); + if (pResult->Create(theField) != NULL) { + return pResult->_this(); + } else { + pResult->_remove_ref(); + return VISU::Result::_nil(); } - return myVisuGen->ImportMedField(theField); } - Mesh_ptr VISU_Gen_i::MeshOnEntity(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity){ - if(MYDEBUG) MESSAGE("VISU_Gen_i::MeshOnEntity : "<GetProperties()->IsLocked()) return Mesh::_nil(); - Mutex mt(myMutex,qApp); - Result_i* pResult = dynamic_cast(GetServant(theResult)); - Mesh_i* aPresent = new Mesh_i(pResult); - if(aPresent->Create(theMeshName,theEntity) != NULL) - return Mesh::_duplicate(aPresent->_this()); + Mesh_ptr VISU_Gen_i::MeshOnEntity(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity) + { + if(myStudyDocument->GetProperties()->IsLocked()) return Mesh::_nil(); + Mutex mt(myMutex); + if(Result_i* pResult = dynamic_cast(GetServant(theResult).in())){ + Mesh_i* aPresent = new Mesh_i(pResult); + if(aPresent->Create(theMeshName,theEntity) != NULL) + return aPresent->_this(); + else{ + aPresent->_remove_ref(); + } } - return myVisuGen->MeshOnEntity(theResult,theMeshName,theEntity); + return VISU::Mesh::_nil(); } - Mesh_ptr VISU_Gen_i::FamilyMeshOnEntity(Result_ptr theResult, const char* theMeshName, - VISU::Entity theEntity, - const char* theFamilyName){ - if(MYDEBUG) MESSAGE("VISU_Gen_i::FamilyMeshOnEntity : "<GetProperties()->IsLocked()) return Mesh::_nil(); - Mutex mt(myMutex,qApp); - Result_i* pResult = dynamic_cast(GetServant(theResult)); - Mesh_i* aPresent = new Mesh_i(pResult); - if(aPresent->Create(theMeshName,theEntity,theFamilyName) != NULL) - return Mesh::_duplicate(aPresent->_this()); + Mesh_ptr VISU_Gen_i::FamilyMeshOnEntity(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFamilyName) + { + if(myStudyDocument->GetProperties()->IsLocked()) return Mesh::_nil(); + Mutex mt(myMutex); + if(Result_i* pResult = dynamic_cast(GetServant(theResult).in())){ + Mesh_i* aPresent = new Mesh_i(pResult); + if(aPresent->Create(theMeshName,theEntity,theFamilyName) != NULL) + return aPresent->_this(); + else{ + aPresent->_remove_ref(); + } } - return myVisuGen->FamilyMeshOnEntity(theResult,theMeshName,theEntity,theFamilyName); + return VISU::Mesh::_nil(); } - Mesh_ptr VISU_Gen_i::GroupMesh(Result_ptr theResult, const char* theMeshName, - const char* theGroupName){ - if(MYDEBUG) MESSAGE("VISU_Gen_i::GroupMesh : "<GetProperties()->IsLocked()) return Mesh::_nil(); - Mutex mt(myMutex,qApp); - Result_i* pResult = dynamic_cast(GetServant(theResult)); - Mesh_i* aPresent = new Mesh_i(pResult); - if(aPresent->Create(theMeshName,theGroupName) != NULL) - return Mesh::_duplicate(aPresent->_this()); + Mesh_ptr VISU_Gen_i::GroupMesh(Result_ptr theResult, + const char* theMeshName, + const char* theGroupName) + { + if(myStudyDocument->GetProperties()->IsLocked()) return Mesh::_nil(); + Mutex mt(myMutex); + if(Result_i* pResult = dynamic_cast(GetServant(theResult).in())){ + Mesh_i* aPresent = new Mesh_i(pResult); + if(aPresent->Create(theMeshName,theGroupName) != NULL) + return aPresent->_this(); + else{ + aPresent->_remove_ref(); + } } - return myVisuGen->GroupMesh(theResult,theMeshName,theGroupName); + return VISU::Mesh::_nil(); } - ScalarMap_ptr VISU_Gen_i::ScalarMapOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, CORBA::Double theIteration){ - if(MYDEBUG) MESSAGE("VISU_Gen_i::ScalarMapOnField : "<GetProperties()->IsLocked()) return ScalarMap::_nil(); - Mutex mt(myMutex,qApp); - Result_i* pResult = dynamic_cast(GetServant(theResult)); - if(ScalarMap_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){ - ScalarMap_i* aPresent = new ScalarMap_i(pResult); - if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL){ - //Base_i::myPOA->activate_object(aPresent); - //aPresent->_remove_ref(); - return aPresent->_this(); - } - } - return ScalarMap::_nil(); - } - return myVisuGen->ScalarMapOnField(theResult,theMeshName,theEntity,theFieldName,theIteration); + ScalarMap_ptr VISU_Gen_i::ScalarMapOnField(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration) + { + return Prs3dOnField(theResult,theMeshName,theEntity,theFieldName,theIteration,true)._retn(); } - DeformedShape_ptr VISU_Gen_i::DeformedShapeOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, CORBA::Double theIteration){ - if(MYDEBUG) MESSAGE("VISU_Gen_i::DeformedShapeOnField : "<GetProperties()->IsLocked()) return DeformedShape::_nil(); - Mutex mt(myMutex,qApp); - Result_i* pResult = dynamic_cast(GetServant(theResult)); - if(DeformedShape_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){ - DeformedShape_i* aPresent = new DeformedShape_i(pResult); - if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL) - return DeformedShape::_duplicate(aPresent->_this()); - } - return DeformedShape::_nil(); - } - return myVisuGen->DeformedShapeOnField(theResult,theMeshName,theEntity,theFieldName,theIteration); + DeformedShape_ptr VISU_Gen_i::DeformedShapeOnField(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration) + { + return Prs3dOnField(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn(); } - Vectors_ptr VISU_Gen_i::VectorsOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, CORBA::Double theIteration){ - if(MYDEBUG) MESSAGE("VISU_Gen_i::VectorsOnField : "<GetProperties()->IsLocked()) return Vectors::_nil(); - Mutex mt(myMutex,qApp); - Result_i* pResult = dynamic_cast(GetServant(theResult)); - if(Vectors_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){ - Vectors_i* aPresent = new Vectors_i(pResult); - if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL) - return Vectors::_duplicate(aPresent->_this()); - } - return Vectors::_nil(); - } - return myVisuGen->VectorsOnField(theResult,theMeshName,theEntity,theFieldName,theIteration); + Vectors_ptr VISU_Gen_i::VectorsOnField(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration) + { + return Prs3dOnField(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn(); } - IsoSurfaces_ptr VISU_Gen_i::IsoSurfacesOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, CORBA::Double theIteration){ - if(MYDEBUG) MESSAGE("VISU_Gen_i::IsoSurfacesOnField : "<GetProperties()->IsLocked()) return IsoSurfaces::_nil(); - Mutex mt(myMutex,qApp); - Result_i* pResult = dynamic_cast(GetServant(theResult)); - if(IsoSurfaces_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){ - IsoSurfaces_i* aPresent = new IsoSurfaces_i(pResult); - if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL) - return IsoSurfaces::_duplicate(aPresent->_this()); - } - return IsoSurfaces::_nil(); - } - return myVisuGen->IsoSurfacesOnField(theResult,theMeshName,theEntity,theFieldName,theIteration); + IsoSurfaces_ptr VISU_Gen_i::IsoSurfacesOnField(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration) + { + return Prs3dOnField(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn(); } - StreamLines_ptr VISU_Gen_i::StreamLinesOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, CORBA::Double theIteration){ - if(MYDEBUG) MESSAGE("VISU_Gen_i::StreamLinesOnField : "<GetProperties()->IsLocked()) return StreamLines::_nil(); - Mutex mt(myMutex,qApp); - Result_i* pResult = dynamic_cast(GetServant(theResult)); - if(StreamLines_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){ - StreamLines_i* aPresent = new StreamLines_i(pResult); - if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL) - return StreamLines::_duplicate(aPresent->_this()); - } - return StreamLines::_nil(); - } - return myVisuGen->StreamLinesOnField(theResult,theMeshName,theEntity,theFieldName,theIteration); + StreamLines_ptr VISU_Gen_i::StreamLinesOnField(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration) + { + return Prs3dOnField(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn(); } - CutPlanes_ptr VISU_Gen_i::CutPlanesOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, CORBA::Double theIteration){ - if(MYDEBUG) MESSAGE("VISU_Gen_i::CutPlanesOnField : "<GetProperties()->IsLocked()) return CutPlanes::_nil(); - Mutex mt(myMutex,qApp); - Result_i* pResult = dynamic_cast(GetServant(theResult)); - if(CutPlanes_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){ - CutPlanes_i* aPresent = new CutPlanes_i(pResult); - if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL) - return CutPlanes::_duplicate(aPresent->_this()); - } - return CutPlanes::_nil(); - } - return myVisuGen->CutPlanesOnField(theResult,theMeshName,theEntity,theFieldName,theIteration); + Plot3D_ptr VISU_Gen_i::Plot3DOnField(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration) + { + return Prs3dOnField(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn(); } - CutLines_ptr VISU_Gen_i::CutLinesOnField(Result_ptr theResult, const char* theMeshName, VISU::Entity theEntity, - const char* theFieldName, CORBA::Double theIteration){ - if(MYDEBUG) MESSAGE("VISU_Gen_i::CutLinesOnField : "<GetProperties()->IsLocked()) return CutLines::_nil(); - Mutex mt(myMutex,qApp); - Result_i* pResult = dynamic_cast(GetServant(theResult)); - if(CutLines_i::IsPossible(pResult,theMeshName,theEntity,theFieldName,theIteration)){ - CutLines_i* aPresent = new CutLines_i(pResult); - if(aPresent->Create(theMeshName,theEntity,theFieldName,theIteration) != NULL) - return CutLines::_duplicate(aPresent->_this()); - } - return CutLines::_nil(); - } - return myVisuGen->CutLinesOnField(theResult,theMeshName,theEntity,theFieldName,theIteration); + CutPlanes_ptr VISU_Gen_i::CutPlanesOnField(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration) + { + return Prs3dOnField(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn(); + } + + CutLines_ptr VISU_Gen_i::CutLinesOnField(Result_ptr theResult, + const char* theMeshName, + VISU::Entity theEntity, + const char* theFieldName, + CORBA::Double theIteration) + { + return Prs3dOnField(theResult,theMeshName,theEntity,theFieldName,theIteration)._retn(); } Table_ptr VISU_Gen_i::CreateTable(const char* theTableEntry){ - if(MYDEBUG) MESSAGE("VISU_Gen_i::CreateTable : "<GetProperties()->IsLocked()) return Table::_nil(); - Mutex mt(myMutex,qApp); - Table_i* aPresent = new Table_i(myStudyDocument,theTableEntry); - if(aPresent->Create() != NULL) - return Table::_duplicate(aPresent->_this()); + if(myStudyDocument->GetProperties()->IsLocked()) return Table::_nil(); + Mutex mt(myMutex); + Table_i* pPresent = new Table_i(myStudyDocument,theTableEntry); + if(pPresent->Create() != NULL) + return pPresent->_this(); + else{ + pPresent->_remove_ref(); + return VISU::Table::_nil(); } - return myVisuGen->CreateTable(theTableEntry); } - Curve_ptr VISU_Gen_i::CreateCurve(Table_ptr theTable, CORBA::Long theHRow, CORBA::Long theVRow){ - if(MYDEBUG) MESSAGE("VISU_Gen_i::CreateCurve : "<GetProperties()->IsLocked()) return Curve::_nil(); - Mutex mt(myMutex,qApp); - PortableServer::POA_ptr aPOA = GetPOA(); - Table_i* pTable = dynamic_cast(aPOA->reference_to_servant(theTable)); - Curve_i* aPresent = new Curve_i(myStudyDocument,pTable,theHRow,theVRow); - if(aPresent->Create() != NULL) { - return Curve::_duplicate(aPresent->_this()); - } + Curve_ptr VISU_Gen_i::CreateCurve(Table_ptr theTable, + CORBA::Long theHRow, + CORBA::Long theVRow) + { + if(myStudyDocument->GetProperties()->IsLocked()) return Curve::_nil(); + Mutex mt(myMutex); + PortableServer::POA_ptr aPOA = GetPOA(); + Table_i* pTable = dynamic_cast(aPOA->reference_to_servant(theTable)); + Curve_i* pPresent = new Curve_i(myStudyDocument,pTable,theHRow,theVRow); + if(pPresent->Create() != NULL) + return pPresent->_this(); + else{ + pPresent->_remove_ref(); + return VISU::Curve::_nil(); } - return myVisuGen->CreateCurve(theTable,theHRow,theVRow); } + Container_ptr VISU_Gen_i::CreateContainer(){ - if(MYDEBUG) MESSAGE("VISU_Gen_i::CreateContainer : "<GetProperties()->IsLocked()) return Container::_nil(); - Mutex mt(myMutex,qApp); - Container_i* aPresent = new Container_i(myStudyDocument); - if(aPresent->Create() != NULL) { - return Container::_duplicate(aPresent->_this()); - } + if(myStudyDocument->GetProperties()->IsLocked()) return Container::_nil(); + Mutex mt(myMutex); + Container_i* pPresent = new Container_i(myStudyDocument); + if(pPresent->Create() != NULL) + return pPresent->_this(); + else{ + pPresent->_remove_ref(); + return VISU::Container::_nil(); } - return myVisuGen->CreateContainer(); } Animation_ptr VISU_Gen_i::CreateAnimation(View3D_ptr theView3D){ - if(myMutex){ - if(myStudyDocument->GetProperties()->IsLocked()) return Animation::_nil(); - Mutex mt(myMutex,qApp); - if(MYDEBUG) MESSAGE("VISU_Gen_i::CreateAnimation : "<_this()); - } - return myVisuGen->CreateAnimation(theView3D); + if(myStudyDocument->GetProperties()->IsLocked()) + return Animation::_nil(); + Mutex mt(myMutex); + if(VISU_TimeAnimation_i* anAnim = new VISU_TimeAnimation_i(myStudyDocument,theView3D)){ + return anAnim->_this(); + }else + return VISU::Animation::_nil(); } - void VISU_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent){ - if(MYDEBUG) MESSAGE("VISU_Gen_i::Close : "<GetStudy(); - if(!aStudy->_is_nil()){ - SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent); - for (int i = 0; itBig->More(); itBig->Next(),i++) { - SALOMEDS::SObject_var gotBranch = itBig->Value(); - if(MYDEBUG) MESSAGE("VISU_Gen_i::Close : itBig->Next() = "<(GetServant(anObj)); - if(!pResult) continue; - if(pResult->GetSourceId() == Result_i::eRestoredFile){ //Try remove its file and directory - const QFileInfo& aFileInfo = pResult->GetFileInfo(); - static QString aCommand; - aCommand.sprintf("rm %s",aFileInfo.filePath().latin1()); - if(system(aCommand) != -1 && MYDEBUG) MESSAGE("VISU_Gen_i::Close - "<(GetServant(myResult).in())) { + SALOMEDS::SObject_var aSObject = aResult->GetSObject(); + VISU::RemoveFromStudy(aSObject, + false, // not only attribute + true); // destroy sub-objects + + //jfa tmp:if (QAD_Desktop* aDesktop = QAD_Application::getDesktop()) + //jfa tmp: if (QAD_Study* aStudy = aDesktop->findStudy(aStudyDocument)) + //jfa tmp: aStudy->updateObjBrowser(); //update Object browser } + + myResult->Destroy(); } + }; + + if (myStudyDocument->GetProperties()->IsLocked()) return; - } - myVisuGen->Close(theComponent); + Mutex mt(myMutex); // jfa ??? + + ProcessVoidEvent(new TEvent(theResult)); + } + + void VISU_Gen_i::DeletePrs3d (Prs3d_ptr thePrs3d) + { + class TEvent: public SALOME_Event { + Prs3d_ptr myPrs3d; + public: + TEvent(Prs3d_ptr thePrs3d): myPrs3d(thePrs3d) {} + virtual void Execute() { + myPrs3d->RemoveFromStudy(); + + //update Object browser + /*jfa tmp:if (QAD_Desktop* aDesktop = QAD_Application::getDesktop()) { + if (Prs3d_i* aPrs3d = dynamic_cast(GetServant(myPrs3d).in())) { + SALOMEDS::SObject_var aSObject = aPrs3d->GetSObject(); + SALOMEDS::Study_var aStudyDocument = aSObject->GetStudy(); + if (QAD_Study* aStudy = aDesktop->findStudy(aStudyDocument)) + aStudy->updateObjBrowser(); + } + }*/ + + myPrs3d->Destroy(); + } + }; + + if (myStudyDocument->GetProperties()->IsLocked()) + return; + Mutex mt(myMutex); // jfa ??? + + ProcessVoidEvent(new TEvent(thePrs3d)); + } + + void VISU_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent){ } char* VISU_Gen_i::ComponentDataType(){ @@ -912,176 +799,181 @@ namespace VISU{ SALOMEDS::SObject_ptr VISU_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, SALOMEDS::SObject_ptr theSObject, CORBA::Object_ptr theObject, - const char* theName) - throw (SALOME::SALOME_Exception) + const char* theName) + throw (SALOME::SALOME_Exception) { + Unexpect aCatch(SalomeException); if(MYDEBUG) MESSAGE("VISU_Gen_i::PublishInStudy : "<(GetServant(theObject)); - if (!aResultObj) return aResultSO._retn(); - const QFileInfo& aFileInfo = aResultObj->GetFileInfo(); - CORBA::String_var anEntry = aResultObj->Create(aFileInfo.filePath().latin1())->GetID(); - aResultSO = theStudy->FindObjectID(anEntry); - return aResultSO._retn(); - } - return myVisuGen->PublishInStudy(theStudy, theSObject, theObject, theName); + Mutex mt(myMutex); + SALOMEDS::SObject_var aResultSO; + Result_i* aResultObj = dynamic_cast(GetServant(theObject).in()); + if (!aResultObj) return aResultSO._retn(); + const QFileInfo& aFileInfo = aResultObj->GetFileInfo(); + CORBA::String_var anEntry = aResultObj->Create(aFileInfo.filePath().latin1())->GetID(); + aResultSO = theStudy->FindObjectID(anEntry); + return aResultSO._retn(); } - + CORBA::Boolean VISU_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) { - if(0 && MYDEBUG) MESSAGE("VISU_Gen_i::CanCopy : "<FindAttribute(anAttr, "AttributeIOR")) return false; - try { - SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - CORBA::String_var aValue = anIOR->Value(); - if(strcmp(aValue,"") != 0){ - CORBA::Object_ptr anObj = GetORB()->string_to_object(aValue); - if (!CORBA::is_nil(anObj)){ - Result_var aResultObj = Result::_narrow(anObj); - if(!aResultObj->_is_nil()){ - Result_i* pResult = dynamic_cast(GetServant(aResultObj)); - if(pResult != NULL){ - if(abs(pResult->GetSourceId()) > Result_i::eFile) - if((pResult->GetFileInfo()).filePath() == "MED") return false; + Mutex mt(myMutex); + SALOMEDS::GenericAttribute_var anAttr; + if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false; + try { + SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); + CORBA::String_var aValue = anIOR->Value(); + if(strcmp(aValue,"") != 0){ + CORBA::Object_ptr anObj = GetORB()->string_to_object(aValue); + if (!CORBA::is_nil(anObj)){ + Result_var aResultObj = Result::_narrow(anObj); + if(!aResultObj->_is_nil()){ + if(Result_i* pResult = dynamic_cast(GetServant(aResultObj).in())){ + switch(pResult->GetCreationId()){ + case Result_i::eImportFile: + case Result_i::eCopyAndImportFile: return true; } } } } - } catch (...) { - MESSAGE("Unknown exception was accured!"); } - return false; + }catch(std::exception& exc){ + INFOS("Follow exception was occured :\n"<CanCopy(theObject); + return false; } SALOMEDS::TMPFile* VISU_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) { - if(MYDEBUG) MESSAGE("VISU_Gen_i::CopyFrom : "<FindAttribute(anAttr,"AttributeIOR")) return NULL; - SALOMEDS::AttributeIOR_var anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr); - CORBA::Object_var aCorbaObj; - try { - aCorbaObj = GetORB()->string_to_object(anIORAttr->Value()); - } catch(...) { - aStreamFile->length(1); - aStreamFile[0] = strdup("E")[0]; - return aStreamFile._retn(); - } - if (CORBA::is_nil(aCorbaObj)) { - return NULL; - } + SALOMEDS::GenericAttribute_var anAttr; + if (!theObject->FindAttribute(anAttr,"AttributeIOR")) return NULL; + SALOMEDS::AttributeIOR_var anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr); + CORBA::Object_var aCorbaObj; + try { + aCorbaObj = GetORB()->string_to_object(anIORAttr->Value()); + } catch(...) { + aStreamFile->length(1); + aStreamFile[0] = strdup("E")[0]; + return aStreamFile._retn(); + } + if (CORBA::is_nil(aCorbaObj)) { + return NULL; + } + + Storable* pStorable = dynamic_cast(GetServant(aCorbaObj).in()); + if (!pStorable) { + return NULL; + } + + string aTmpDir = SALOMEDS_Tool::GetTmpDir(); + string aCopyPersist = aTmpDir + "copy_persistent"; + + ofstream stmOut2(aCopyPersist.c_str(),ios::out); + string aStr = pStorable->ToString().c_str(); + stmOut2<(GetServant(aCorbaObj)); - if (!pStorable) { + if (Result_i* aResultObj = dynamic_cast(aPOA->reference_to_servant(aCorbaObj))) { + string aFileName = string(SALOMEDS_Tool::GetNameFromPath(theObject->GetStudy()->URL())) + "_"; + if(strlen(aFileName.c_str()) == 1) aFileName=""; + const QFileInfo& aFileInfo = aResultObj->GetFileInfo(); + aFileName += aFileInfo.fileName().latin1(); + static QString aCommand; + string aFullFileName = aTmpDir + aFileName; + aCommand.sprintf("cp %s %s", + aFileInfo.filePath().latin1(), + aFullFileName.c_str()); + if(system(aCommand) == -1) { + if(MYDEBUG) MESSAGE("VISU_Gen_i::Copy - Cann't execute the command :"<ToString().c_str(); - ofstream stmOut2((string(aTmpDir) + string("copy_persistent")).c_str(),ios::out); - stmOut2<(aPOA->reference_to_servant(aCorbaObj)); - if (aResultObj) { - string aFileName = string(SALOMEDS_Tool::GetNameFromPath(theObject->GetStudy()->URL())) + "_"; - const QFileInfo& aFileInfo = aResultObj->GetFileInfo(); - aFileName += aFileInfo.fileName().latin1(); - static QString aCommand; - aCommand.sprintf("cp %s %s", - aFileInfo.filePath().latin1(), - (string(aTmpDir) + aFileName).c_str()); - if(system(aCommand) == -1) { - if(MYDEBUG) MESSAGE("VISU_Gen_i::Copy - Cann't execute the command :"<length(2); + aSeq[0] = "copy_persistent"; + aSeq[1] = aFileName.c_str(); + } else { + aSeq->length(1); + aSeq[0] = "copy_persistent"; + } - aSeq->length(2); - aSeq[0] = "copy_persistent"; - aSeq[1] = aFileName.c_str(); - } else { - aSeq->length(1); - aSeq[0] = "copy_persistent"; - } - aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir, aSeq.in(), false); - SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aSeq.in(), true); + aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), false); + SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true); - // Assign an ID = 1 the the type VISU::Result - theObjectID = 1; - return aStreamFile._retn(); - } - return myVisuGen->CopyFrom(theObject, theObjectID); + // Assign an ID = 1 the the type VISU::Result + theObjectID = 1; + + + SALOMEDS::SComponent_var aSComponent = theObject->GetStudy()->FindComponent("VISU"); + return aStreamFile._retn(); } CORBA::Boolean VISU_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) { // The VISU component can paste only objects copied by VISU component // and with the object type = 1 - if(0 && MYDEBUG) MESSAGE("VISU_Gen_i::CanPaste : "<length() > 1) aFileName += aSeq[1].in(); - Storable* aStorable = Storable::Create(theObject,aFileName,aString); - - SALOMEDS::ListOfFileNames_var aSeqToRm = new SALOMEDS::ListOfFileNames; - aSeqToRm->length(1); - aSeqToRm[0] = "copy_persistent"; - SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aSeqToRm.in(), true); - - SALOMEDS::SComponent_var aComponent = theObject->GetFatherComponent(); - SALOMEDS::Study_var aStudy = theObject->GetStudy(); - SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); - CORBA::String_var aComponentID(aComponent->GetID()), aSObjID(theObject->GetID()); - if (strcmp(aComponentID, aSObjID) == 0) //create the new result SObject - aResultSO = aStudyBuilder->NewObject(aComponent); - else - aResultSO = SALOMEDS::SObject::_duplicate(theObject); - SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR"); - SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - CORBA::String_var anIORValue(aStorable->GetID()); - anIOR->SetValue(anIORValue); + SALOMEDS::SObject_ptr theObject) + { + Mutex mt(myMutex); + SALOMEDS::SObject_var aResultSO; + if (theObjectID != 1) return aResultSO._retn(); + + string aTmpDir = SALOMEDS_Tool::GetTmpDir(); + SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), false); + + ifstream stmIn((aTmpDir + string("copy_persistent")).c_str()); + stmIn.seekg(0, ios::end); + int aLength = stmIn.tellg(); + stmIn.seekg(0, ios::beg); + char* aString = new char[aLength+1]; + stmIn.read(aString, aLength); + aString[aLength] = 0; + myIsMultiFile = false; + + string aFileName(aTmpDir); + string aBasicFileName; + if(aSeq->length() > 1) { + aBasicFileName = aSeq[1].in(); + aFileName += aBasicFileName; } - return myVisuGen->PasteInto(theStream,theObjectID,theObject); - } -}; + SALOMEDS::SComponent_var aComponent = theObject->GetFatherComponent(); + SALOMEDS::Study_var aStudy = theObject->GetStudy(); + SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); + CORBA::String_var aComponentID(aComponent->GetID()), aSObjID(theObject->GetID()); + + if (strcmp(aComponentID, aSObjID) == 0) //create the new result SObject + aResultSO = aStudyBuilder->NewObject(aComponent); + else + aResultSO = SALOMEDS::SObject::_duplicate(theObject); + + //Just for Result::Restore to find the Comment attribute :( + SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment"); + + Storable* aStorable = Storable::Create(aResultSO,aFileName,aString); + + SALOMEDS::ListOfFileNames_var aSeqToRm = new SALOMEDS::ListOfFileNames; + aSeqToRm->length(1); + aSeqToRm[0] = "copy_persistent"; + + SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeqToRm.in(), true); + + anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR"); + SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); + CORBA::String_var anIORValue(aStorable->GetID()); + anIOR->SetValue(anIORValue); + return aResultSO._retn(); + } +}