Launcher \
LifeCycleCORBA \
LifeCycleCORBA_SWIG \
+ TOOLSDS \
Notebook \
SALOMEDSClient \
- TOOLSDS \
SALOMEDSImpl \
SALOMEDS \
ModuleGenerator \
salomeinclude_HEADERS = \
SALOME_Parameter.hxx \
SALOME_Notebook.hxx \
+ SALOME_NotebookDriver.hxx \
SALOME_Eval.hxx \
SALOME_EvalExpr.hxx \
SALOME_EvalParser.hxx \
-I$(srcdir)/../SALOMELocalTrace \
-I$(srcdir)/../Basics \
-I$(srcdir)/../Utils \
+ -I$(srcdir)/../TOOLSDS \
-I$(top_builddir)/idl \
@CORBA_CXXFLAGS@ @CORBA_INCLUDES@
# This local variable defines the list of dependant libraries common to all target in this package.
-COMMON_LIBS =
+COMMON_LIBS = ../TOOLSDS/libTOOLSDS.la
#LDFLAGS+= -lSalomeGenericObj -lSalomeLifeCycleCORBA
libSalomeNotebook_la_SOURCES = \
SALOME_Parameter.cxx \
SALOME_Notebook.cxx \
+ SALOME_NotebookDriver.cxx \
SALOME_EvalExpr.cxx \
SALOME_EvalParser.cxx \
SALOME_EvalSet.cxx \
#include <SALOME_Notebook.hxx>
#include <SALOME_Parameter.hxx>
-SALOME_Notebook::SALOME_Notebook( SALOMEDS::Study_ptr theStudy )
+SALOME_Notebook::SALOME_Notebook( PortableServer::POA_ptr thePOA, SALOMEDS::Study_ptr theStudy )
+: SALOME::GenericObj_i( thePOA )
{
myStudy = SALOMEDS::Study::_duplicate( theStudy );
}
void SALOME_Notebook::SetToUpdate( SALOME::ParameterizedObject_ptr theObj )
{
- printf( "SetToUpdate: %s\n", GetKey( theObj ).c_str() );
+ //printf( "SetToUpdate: %s\n", GetKey( theObj ).c_str() );
SALOME::Parameter_ptr aParam = SALOME::Parameter::_narrow( theObj );
if( !CORBA::is_nil( aParam ) )
*uit = tmp;
}
+ /*
uit = myToUpdate.begin(); ulast = myToUpdate.end();
for( ; uit!=ulast; uit++ )
printf( "To update: %s\n", (*uit).key().c_str() );
+ */
}
void SALOME_Notebook::Update()
{
- printf( "Update\n" );
+ //printf( "Update\n" );
std::list< KeyHelper > aPostponedUpdate;
std::list<KeyHelper>::const_iterator it = myToUpdate.begin(), last = myToUpdate.end();
for( ; it!=last; it++ )
{
std::string aKey = (*it).key();
- printf( "key = %s\n", aKey.c_str() );
+ //printf( "key = %s\n", aKey.c_str() );
SALOME::ParameterizedObject_ptr anObj = FindObject( aKey );
if( CORBA::is_nil( anObj ) )
aPostponedUpdate.push_back( *it );
myParams.erase( theParamName );
}
+SALOME::StringList* SALOME_Notebook::Params()
+{
+ return 0;
+}
+
SALOME::Parameter_ptr SALOME_Notebook::Param( const char* theParamName )
{
//printf( "Param, name = %s\n", theParamName );
bool SALOME_Notebook::AddParam( SALOME_Parameter* theParam )
{
std::string anEntry = theParam->GetEntry();
+ if( !CheckParamName( anEntry ) )
+ return false;
+
//printf( "Add param: %s\n", anEntry.c_str() );
std::map< std::string, SALOME_Parameter* >::const_iterator it = myParams.find( anEntry );
{
return myKey == theKey;
}
+
+void SALOME_Notebook::Save( const char* theFileName )
+{
+ //printf( "SALOME_Notebook::Save into %s\n", theFileName );
+
+ FILE* aFile = fopen( theFileName, "w" );
+
+ fprintf( aFile, "\n\nnotebook\n" );
+
+ //1. Save dependencies
+ fprintf( aFile, "Dependencies\n" );
+ std::map< std::string, std::list<std::string> >::const_iterator dit = myDeps.begin(), dlast = myDeps.end();
+ for( ; dit!=dlast; dit++ )
+ {
+ fprintf( aFile, "%s -> ", dit->first.c_str() );
+ std::list<std::string>::const_iterator it = dit->second.begin(), last = dit->second.end();
+ for( ; it!=last; it++ )
+ fprintf( aFile, "%s ", it->c_str() );
+ fprintf( aFile, "\n" );
+ }
+
+ //2. Save parameters
+ fprintf( aFile, "Parameters\n" );
+ std::map< std::string, SALOME_Parameter* >::const_iterator pit = myParams.begin(), plast = myParams.end();
+ for( ; pit!=plast; pit++ )
+ {
+ fprintf( aFile, pit->second->Save().c_str() );
+ fprintf( aFile, "\n" );
+ }
+
+ //3. Save update list
+ fprintf( aFile, "Update\n" );
+ std::list< KeyHelper >::const_iterator uit = myToUpdate.begin(), ulast = myToUpdate.end();
+ for( ; uit!=ulast; uit++ )
+ {
+ fprintf( aFile, uit->key().c_str() );
+ fprintf( aFile, "\n" );
+ }
+
+ fclose( aFile );
+}
+
+CORBA::Boolean SALOME_Notebook::Load( const char* theFileName )
+{
+ return false;
+}
+
+bool SALOME_Notebook::CheckParamName( const std::string& theParamName ) const
+{
+ int len = theParamName.length();
+ if( len == 0 )
+ return false;
+
+ SALOME_EvalExpr anExpr( theParamName );
+ return anExpr.parser()->isMonoParam();
+}
class SALOME_Notebook : public virtual POA_SALOME::Notebook, public virtual SALOME::GenericObj_i
{
public:
- SALOME_Notebook( SALOMEDS::Study_ptr theStudy );
+ SALOME_Notebook( PortableServer::POA_ptr thePOA, SALOMEDS::Study_ptr theStudy );
virtual CORBA::Boolean AddDependency( SALOME::ParameterizedObject_ptr theObj, SALOME::ParameterizedObject_ptr theRef );
virtual void RemoveDependency( SALOME::ParameterizedObject_ptr theObj, SALOME::ParameterizedObject_ptr theRef );
virtual CORBA::Boolean AddValue( const char* theName, CORBA::Double theValue );
virtual void Remove( const char* theParamName );
virtual SALOME::Parameter_ptr Param( const char* theParamName );
+ virtual SALOME::StringList* Params();
+
+ virtual void Save( const char* theFileName );
+ virtual CORBA::Boolean Load( const char* theFileName );
SALOME_Parameter* ParamPtr( const char* theParamName ) const;
bool AddDependencies( SALOME_Parameter* theParam );
bool AddDependency( const std::string& theObjKey, const std::string& theRefKey );
void ClearDependencies( const std::string& theObjKey );
+ bool CheckParamName( const std::string& theParamName ) const;
private:
std::string GetKey( SALOME::ParameterizedObject_ptr theObj );
--- /dev/null
+
+#include <SALOME_NotebookDriver.hxx>
+#include <SALOMEDS_Tool.hxx>
+#include <stdio.h>
+
+SALOME_NotebookDriver::SALOME_NotebookDriver()
+{
+}
+
+SALOME_NotebookDriver::~SALOME_NotebookDriver()
+{
+}
+
+std::string SALOME_NotebookDriver::GetFileName( SALOMEDS::SComponent_ptr theComponent, bool isMultiFile ) const
+{
+ // Prepare a file name to open
+ std::string aNameWithExt;
+ if( isMultiFile )
+ aNameWithExt = SALOMEDS_Tool::GetNameFromPath( theComponent->GetStudy()->URL() ).c_str();
+ aNameWithExt += "_Notebook.dat";
+ return aNameWithExt;
+}
+
+SALOMEDS::TMPFile* SALOME_NotebookDriver::Save( SALOMEDS::SComponent_ptr theComponent, const char* theURL, bool isMultiFile )
+{
+ SALOMEDS::TMPFile_var aStreamFile;
+
+ // Get a temporary directory to store a file
+ std::string aTmpDir = isMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
+
+ // Create a list to store names of created files
+ SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
+ aSeq->length( 1 );
+
+ std::string aNameWithExt = GetFileName( theComponent, isMultiFile );
+ aSeq[0] = CORBA::string_dup( aNameWithExt.c_str() );
+
+ // Build a full file name of temporary file
+ std::string aFullName = std::string( aTmpDir.c_str() ) + aNameWithExt;
+
+ // Save Notebook component into this file
+ theComponent->GetStudy()->GetNotebook()->Save( aFullName.c_str() );
+
+ // Convert a file to the byte stream
+ aStreamFile = SALOMEDS_Tool::PutFilesToStream( aTmpDir.c_str(), aSeq.in(), isMultiFile );
+
+ // Remove the created file and tmp directory
+ if( !isMultiFile )
+ SALOMEDS_Tool::RemoveTemporaryFiles( aTmpDir.c_str(), aSeq.in(), true );
+
+ // Return the created byte stream
+ return aStreamFile._retn();
+}
+
+SALOMEDS::TMPFile* SALOME_NotebookDriver::SaveASCII( SALOMEDS::SComponent_ptr theComponent, const char* theURL, bool isMultiFile )
+{
+ SALOMEDS::TMPFile_var aStreamFile = Save( theComponent, theURL, isMultiFile );
+ return aStreamFile._retn();
+}
+
+CORBA::Boolean SALOME_NotebookDriver::Load( SALOMEDS::SComponent_ptr theComponent, const SALOMEDS::TMPFile& theStream,
+ const char* theURL, bool isMultiFile )
+{
+ // Get a temporary directory for a file
+ std::string aTmpDir = isMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
+
+ // Convert the byte stream theStream to a file and place it in tmp directory
+ SALOMEDS::ListOfFileNames_var aSeq =
+ SALOMEDS_Tool::PutStreamToFiles( theStream, aTmpDir.c_str(), isMultiFile );
+
+ // Prepare a file name to open
+ std::string aNameWithExt = GetFileName( theComponent, isMultiFile );
+ std::string aFullName = std::string( aTmpDir.c_str() ) + aNameWithExt;
+
+ // Open document
+ if( !theComponent->GetStudy()->GetNotebook()->Load( aFullName.c_str() ) )
+ return false;
+
+ // Remove the created file and tmp directory
+ if( !isMultiFile )
+ SALOMEDS_Tool::RemoveTemporaryFiles( aTmpDir.c_str(), aSeq.in(), true );
+
+ return true;
+}
+
+CORBA::Boolean SALOME_NotebookDriver::LoadASCII( SALOMEDS::SComponent_ptr theComponent, const SALOMEDS::TMPFile& theStream,
+ const char* theURL, bool isMultiFile )
+{
+ return Load( theComponent, theStream, theURL, isMultiFile );
+}
+
+void SALOME_NotebookDriver::Close( SALOMEDS::SComponent_ptr theComponent )
+{
+}
+
+char* SALOME_NotebookDriver::ComponentDataType()
+{
+ return CORBA::string_dup( "NOTEBOOK" );
+}
+
+char* SALOME_NotebookDriver::IORToLocalPersistentID( SALOMEDS::SObject_ptr theSObject, const char* theIOR,
+ CORBA::Boolean isMultiFile, CORBA::Boolean isASCII )
+{
+ return 0;
+}
+
+char* SALOME_NotebookDriver::LocalPersistentIDToIOR( SALOMEDS::SObject_ptr theSObject, const char* theLocalPersistentID,
+ CORBA::Boolean isMultiFile, CORBA::Boolean isASCII )
+{
+ return 0;
+}
+
+bool SALOME_NotebookDriver::CanPublishInStudy( CORBA::Object_ptr theIOR )
+{
+ return false;
+}
+
+SALOMEDS::SObject_ptr SALOME_NotebookDriver::PublishInStudy( SALOMEDS::Study_ptr theStudy, SALOMEDS::SObject_ptr theSObject,
+ CORBA::Object_ptr theObject, const char* theName )
+{
+ SALOMEDS::SObject_var aRes;
+ return aRes._retn();
+}
+
+CORBA::Boolean SALOME_NotebookDriver::CanCopy( SALOMEDS::SObject_ptr theObject )
+{
+ return false;
+}
+
+SALOMEDS::TMPFile* SALOME_NotebookDriver::CopyFrom ( SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID )
+{
+ return 0;
+}
+
+CORBA::Boolean SALOME_NotebookDriver::CanPaste ( const char* theComponentName, CORBA::Long theObjectID )
+{
+ return false;
+}
+
+SALOMEDS::SObject_ptr SALOME_NotebookDriver::PasteInto( const SALOMEDS::TMPFile& theStream, CORBA::Long theObjectID,
+ SALOMEDS::SObject_ptr theObject )
+{
+ SALOMEDS::SObject_var aRes;
+ return aRes._retn();
+}
--- /dev/null
+
+#ifndef SALOME_NOTEBOOK_DRIVER_HEADER
+#define SALOME_NOTEBOOK_DRIVER_HEADER
+
+#include CORBA_SERVER_HEADER(SALOMEDS)
+#include <string>
+
+class SALOME_NotebookDriver : public POA_SALOMEDS::Driver
+{
+public:
+ SALOME_NotebookDriver();
+ virtual ~SALOME_NotebookDriver();
+
+ 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 CORBA::Boolean Load ( SALOMEDS::SComponent_ptr theComponent, const SALOMEDS::TMPFile& theStream,
+ const char* theURL, bool isMultiFile );
+ virtual CORBA::Boolean LoadASCII( SALOMEDS::SComponent_ptr theComponent, const SALOMEDS::TMPFile& theStream,
+ const char* theURL, bool isMultiFile );
+ virtual void Close ( SALOMEDS::SComponent_ptr theComponent );
+
+ virtual char* ComponentDataType();
+ virtual char* IORToLocalPersistentID( SALOMEDS::SObject_ptr theSObject, const char* theIOR,
+ CORBA::Boolean isMultiFile, CORBA::Boolean isASCII );
+ virtual char* LocalPersistentIDToIOR( SALOMEDS::SObject_ptr theSObject, const char* theLocalPersistentID,
+ CORBA::Boolean isMultiFile, CORBA::Boolean isASCII );
+
+ virtual bool CanPublishInStudy ( CORBA::Object_ptr theIOR );
+ virtual SALOMEDS::SObject_ptr PublishInStudy ( SALOMEDS::Study_ptr theStudy, SALOMEDS::SObject_ptr theSObject,
+ CORBA::Object_ptr theObject, const char* theName );
+
+ virtual CORBA::Boolean CanCopy ( SALOMEDS::SObject_ptr theObject );
+ virtual SALOMEDS::TMPFile* CopyFrom ( SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID );
+ virtual CORBA::Boolean CanPaste ( const char* theComponentName, CORBA::Long theObjectID );
+ virtual SALOMEDS::SObject_ptr PasteInto( const SALOMEDS::TMPFile& theStream, CORBA::Long theObjectID,
+ SALOMEDS::SObject_ptr theObject );
+
+protected:
+ std::string GetFileName( SALOMEDS::SComponent_ptr theComponent, bool isMultiFile ) const;
+};
+
+#endif
{
return myIsCalculable ? myExpr.parser()->parameters() : SALOME_StringList();
}
+
+std::string SALOME_Parameter::Save() const
+{
+ char buf[256];
+ sprintf( buf, "%s %i %i ", myName.c_str(), (int)myIsAnonimous, (int)myIsCalculable );
+ std::string aRes = buf;
+ if( myIsCalculable )
+ aRes += myExpr.expression();
+ else
+ {
+ sprintf( buf, "%i %s", myResult.type(), myResult.toString().c_str() );
+ aRes += buf;
+ }
+ return aRes;
+}
+
+SALOME_Parameter* SALOME_Parameter::Load( const std::string& theData )
+{
+ return 0;
+}
SALOME_StringList Dependencies() const;
+ std::string Save() const;
+ static SALOME_Parameter* Load( const std::string& theData );
+
private:
SALOME_Notebook* myNotebook;
std::string myName;
#include "SALOMEDS_SComponent_i.hxx"
#include "SALOMEDS_Study_i.hxx"
#include "SALOMEDS.hxx"
+#include <SALOME_NotebookDriver.hxx>
#include <stdlib.h>
using namespace std;
// SALOMEDS_DriverFactory
//###############################################################################################################
+SALOMEDS_DriverFactory_i::SALOMEDS_DriverFactory_i(CORBA::ORB_ptr theORB)
+{
+ _orb = CORBA::ORB::_duplicate(theORB);
+ _name_service = new SALOME_NamingService(_orb);
+
+ SALOME_NotebookDriver* aDriver = new SALOME_NotebookDriver();
+ myNotebookDriver = aDriver->_this();
+}
+
+SALOMEDS_DriverFactory_i::~SALOMEDS_DriverFactory_i()
+{
+ delete _name_service;
+}
+
SALOMEDSImpl_Driver* SALOMEDS_DriverFactory_i::GetDriverByType(const string& theComponentType)
{
CORBA::Object_var obj;
string aFactoryType;
- if (theComponentType == "SUPERV") aFactoryType = "SuperVisionContainer";
- else aFactoryType = "FactoryServer";
+ if (theComponentType == "SUPERV")
+ aFactoryType = "SuperVisionContainer";
+ else
+ aFactoryType = "FactoryServer";
SALOMEDS::unlock();
obj = SALOME_LifeCycleCORBA(_name_service).FindOrLoad_Component(aFactoryType.c_str(), theComponentType.c_str());
SALOMEDS::lock();
- if (CORBA::is_nil(obj)) {
+ if (CORBA::is_nil(obj))
+ {
obj = SALOME_LifeCycleCORBA(_name_service).FindOrLoad_Component("FactoryServerPy", theComponentType.c_str());
}
- if (!CORBA::is_nil(obj)) {
+ if (!CORBA::is_nil(obj))
+ {
SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(obj);
return new SALOMEDS_Driver_i(aDriver, _orb);
}
public:
- SALOMEDS_DriverFactory_i(CORBA::ORB_ptr theORB)
- {
- _orb = CORBA::ORB::_duplicate(theORB);
- _name_service = new SALOME_NamingService(_orb);
- }
+ SALOMEDS_DriverFactory_i(CORBA::ORB_ptr theORB);
- ~SALOMEDS_DriverFactory_i()
- {
- delete _name_service;
- }
+ ~SALOMEDS_DriverFactory_i();
virtual SALOMEDSImpl_Driver* GetDriverByType(const std::string& theComponentType);
virtual SALOMEDSImpl_Driver* GetDriverByIOR(const std::string& theIOR);
+
+private:
+ SALOMEDS::Driver_var myNotebookDriver;
};
#endif
SALOMEDS_Study_i *Study_servant = SALOMEDS_Study_i::GetStudyServant(aStudyImpl, _orb);
PortableServer::ObjectId_var servantid = _poa->activate_object(Study_servant); // to use poa registered in _mapOfPOA
SALOMEDS::Study_var Study = Study_servant->_this();
-
+
// Register study in the naming service
// Path to acces the study
if(!_name_service->Change_Directory("/Study"))
_mapOfPOA[Study->StudyId()] = _poa;
+ Study->GetNotebook();
+
return Study._retn();
}
if(!_name_service->Change_Directory("/Study")) MESSAGE( "Unable to access the study directory" )
else _name_service->Register(Study, CORBA::string_dup(aStudyImpl->Name().c_str()));
+ Study->GetNotebook();
+
return Study._retn();
}
#include "SALOMEDSImpl_ChildIterator.hxx"
#include "SALOMEDSImpl_IParameters.hxx"
+#include <SALOME_NotebookDriver.hxx>
+
#include "DF_Label.hxx"
#include "DF_Attribute.hxx"
{
if( CORBA::is_nil( myNotebook ) )
{
- SALOME_Notebook* aNb = new SALOME_Notebook( _this() );
+ SALOME_Notebook* aNb = new SALOME_Notebook( _default_POA(), _this() );
myNotebook = aNb->_this();
+
+ //Creation of default component for the Notebook
+ SALOMEDS::GenericAttribute_var anAttr;
+ SALOMEDS::StudyBuilder_var aStudyBuilder = NewBuilder();
+ SALOMEDS::SComponent_var aNotebookComponent = aStudyBuilder->NewComponent( "NOTEBOOK" );
+
+ anAttr = aStudyBuilder->FindOrCreateAttribute( aNotebookComponent, "AttributeName" );
+ SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow( anAttr );
+ aName->SetValue( "Notebook" );
+ aName->Destroy();
+
+ anAttr = aStudyBuilder->FindOrCreateAttribute( aNotebookComponent, "AttributePixMap" );
+ SALOMEDS::AttributePixMap_var aPixMap = SALOMEDS::AttributePixMap::_narrow( anAttr );
+ aPixMap->SetPixMap( "ICON_OBJBROWSER_Notebook" );
+ aPixMap->Destroy();
+
+ SALOME_NotebookDriver* aDriver = new SALOME_NotebookDriver();
+ SALOMEDS::Driver_var aDriverVar = aDriver->_this();
+ aStudyBuilder->DefineComponentInstance( aNotebookComponent, aDriverVar._retn() );
}
- return myNotebook._retn();
+ return SALOME::Notebook::_duplicate( myNotebook );
}