if ( objectBrowser() )
objectBrowser()->openLevels();
+ updateObjectBrowser( true );
+
emit studyOpened();
}
#include <QFileInfo>
#include <QDir>
+#include <cstring>
#ifdef WIN32
#include <time.h>
{
int aNbModules = 0;
std::map<std::string, ListOfFiles>::const_iterator it;
+ std::map<std::string, std::string>::const_iterator it1;
for (it = myMap.begin(); it != myMap.end(); ++it)
aNbModules++;
unsigned char** aBuffer = new unsigned char*[aNbModules];
long* aBufferSize = new long[aNbModules];
char** aModuleName = new char*[aNbModules];
+ char** aTree = new char*[aNbModules];
if(aBuffer == NULL || aBufferSize == NULL || aModuleName == NULL)
return false;
i++;
}
int n = i;
+
+ i = 0;
+ for ( it1 = myMapTree.begin(); it1 != myMapTree.end(); ++it1 ) {
+ aFileBufferSize += 4; //Add 4 bytes: a length of the object tree
+ aTree[i] = const_cast<char*>( it1->second.c_str() );
+ aFileBufferSize += strlen( aTree[i] ) + 1;
+ i++;
+ }
unsigned char* aFileBuffer = new unsigned char[aFileBufferSize];
if(aFileBuffer == NULL)
aCurrentPos += 4;
int aBufferNameSize = 0;
+ int aTreeSize = 0;
for (i = 0; i < n; i++) {
aBufferNameSize = strlen(aModuleName[i])+1;
//Initialize 4 bytes of the buffer by 0
//Copy the module buffer to the buffer
memcpy((aFileBuffer + aCurrentPos), aBuffer[i], aBufferSize[i]);
aCurrentPos += aBufferSize[i];
+
+ //Initialize 4 bytes of the buffer by 0
+ memset((aFileBuffer + aCurrentPos), 0, 4);
+ aTreeSize = strlen(aTree[i]) + 1;
+ //Copy the length of the object tree
+ memcpy((aFileBuffer + aCurrentPos), &aTreeSize, ((sizeof(int) > 4) ? : sizeof(int)));
+ aCurrentPos += 4;
+ //Copy the object tree to the buffer
+ memcpy((aFileBuffer + aCurrentPos), aTree[i], aTreeSize);
+ aCurrentPos += aTreeSize;
}
#ifdef WIN32
delete[] aBufferSize;
delete[] aModuleName;
delete[] aFileBuffer;
+ delete[] aTree;
return true;
}
memcpy(&aBufferSize, (aFileBuffer + aCurrentPos), ((sizeof(long) > 8) ? 8 : sizeof(long)));
aCurrentPos += 8;
unsigned char *aBuffer = new unsigned char[aBufferSize];
-
+
//Put a buffer for current module to aBuffer
- memcpy(aBuffer, (aFileBuffer + aCurrentPos), aBufferSize);
+ memcpy(aBuffer, (aFileBuffer + aCurrentPos), aBufferSize);
aCurrentPos += aBufferSize;
+ //Put a length of the object tree buffer to aTreeSize
+ int aTreeSize;
+ memcpy(&aTreeSize, (aFileBuffer + aCurrentPos), ((sizeof(int) > 4) ? 4 : sizeof(int)));
+ aCurrentPos += 4;
+ char *aTree = new char[aTreeSize];
+
+ //Put an object tree for current module to aTree
+ memcpy(aTree, (aFileBuffer + aCurrentPos), aTreeSize);
+ aCurrentPos += aTreeSize;
+
// Put buffer to aListOfFiles and set to myMap
ListOfFiles aListOfFiles = PutStreamToFiles(aBuffer, aBufferSize, isMultiFile);
SetListOfFiles(aModuleName, aListOfFiles);
+ // Set the object tree to myMapTree
+ std::string aTmpTree(aTree);
+ SetTree(aModuleName, aTmpTree);
+
delete[] aModuleName;
delete[] aBuffer;
+ delete[] aTree;
}
delete[] aFileBuffer;
{
std::string aName (theModuleName);
myMap[aName] = theListOfFiles;
+
+}
+
+/*!
+ Sets the object tree for module with name 'theModuleName'
+*/
+void LightApp_Driver::SetTree( const std::string& theModuleName, const std::string& theTree )
+{
+ myMapTree[theModuleName] = theTree;
+}
+
+/*!
+ Gets the object tree for module with name 'theModuleName'
+*/
+QString LightApp_Driver::GetTree( const std::string& theModuleName )
+{
+ if ( myMapTree.count( theModuleName ) ) {
+ QString aTree( myMapTree[theModuleName].c_str() );
+ return aTree;
+ }
+ return QString();
}
/*!
aDirString.ChangeAll('|','/');
return aDirString.ToCString();
}
-
#include "vector"
#include "map"
+#include <QString>
+
#ifdef WIN32
#pragma warning( disable:4251 )
#endif
virtual void ClearDriverContents();
+ QString GetTree (const std::string& theModuleName);
+ void SetTree (const std::string& theModuleName, const std::string& theTree);
+
protected:
void PutFilesToStream(const std::string& theModuleName, unsigned char*& theBuffer,
long& theBufferSize, bool theNamesOnly = false);
protected:
typedef std::map<std::string, ListOfFiles> MapOfListOfFiles;
MapOfListOfFiles myMap;
+ typedef std::map<std::string, std::string> MapTrees;
+ MapTrees myMapTree;
std::string myTmpDir;
private:
hdf_dataset->WriteOnDisk(aBuffer); //Save the stream in the HDF file
hdf_dataset->CloseOnDisk();
hdf_dataset = 0; //will be deleted by hdf_sco_group destructor
+
+ if ( myMapTree.count( aName ) ) {
+ char* aTree = const_cast<char*>( myMapTree[ aName ].c_str() );
+ aHDFSize[0] = strlen(aTree)+1;
+
+ hdf_dataset = new HDFdataset ("TREE_STREAM", hdf_sco_group, HDF_STRING, aHDFSize, 1);
+ hdf_dataset->CreateOnDisk();
+ hdf_dataset->WriteOnDisk(aTree); //Save the stream of tree in the HDF file
+ hdf_dataset->CloseOnDisk();
+ hdf_dataset = 0; //will be deleted by hdf_sco_group destructor
+ }
// store multifile state
aHDFSize[0] = 2;
hdf_dataset = 0;
}
+ // Read the Tree
+ char* aStreamTree = NULL;
+ int aTreeStreamSize = 0;
+
+ if (hdf_sco_group->ExistInternalObject("TREE_STREAM")) {
+ HDFdataset *hdf_dataset = new HDFdataset("TREE_STREAM", hdf_sco_group);
+ hdf_dataset->OpenOnDisk();
+ aTreeStreamSize = hdf_dataset->GetSize();
+ aStreamTree = new char[aTreeStreamSize];
+ if (aStreamTree == NULL) {
+ isError = true;
+ } else {
+ hdf_dataset->ReadFromDisk(aStreamTree);
+ }
+
+ hdf_dataset->CloseOnDisk();
+ hdf_dataset = 0;
+ }
+
HDFdataset *multifile_hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group);
multifile_hdf_dataset->OpenOnDisk();
multifile_hdf_dataset->ReadFromDisk(aMultifileState);
delete [] aStreamFile;
}
+ if (aStreamTree != NULL) {
+ // Set buffer to to myMapTree
+ std::string aTree(aStreamTree);
+ SetTree(mapEntryName[name], aTree);
+
+ delete [] aStreamTree;
+ }
+
hdf_sco_group->CloseOnDisk();
}
}
--- /dev/null
+// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "LightApp_IDataObject.h"
+
+#define ENTRY "entry"
+#define NAME "name"
+#define OBJECT_NODE "objectNode"
+#define ROOT_NODE "rootNode"
+
+/*!
+ \class LightApp_IDataObject
+ \brief Base data object class to build the object tree in Object Browser.
+*/
+
+/*!
+ \brief Constructor.
+ \param parent parent data object
+*/
+LightApp_IDataObject::LightApp_IDataObject( SUIT_DataObject* parent )
+: CAM_DataObject( parent ),
+ LightApp_DataObject( parent ),
+ myName( "" ),
+ myEntry( "" )
+{
+}
+
+/*!
+ \brief Destructor.
+*/
+LightApp_IDataObject::~LightApp_IDataObject()
+{
+}
+
+/*!
+ \brief Set the data object name.
+*/
+void LightApp_IDataObject::setName( const QString& theName )
+{
+ myName = theName;
+}
+
+/*!
+ \brief Set the data object ID.
+*/
+void LightApp_IDataObject::setEntry( const QString& theEntry )
+{
+ myEntry = theEntry;
+}
+
+/*!
+ \brief Return the data object name.
+*/
+QString LightApp_IDataObject::name() const
+{
+ return myName;
+}
+
+/*!
+ \brief Return the data object name.
+*/
+QString LightApp_IDataObject::entry() const
+{
+ return myEntry;
+}
+
+QString LightApp_IDataObject::GetTreeDoc( CAM_DataObject* theRoot )
+{
+
+ QDomDocument aDoc;
+ QDomElement treeRoot = aDoc.createElement( ROOT_NODE );
+ if ( dumpObject( theRoot, treeRoot ) )
+ {
+ aDoc.appendChild( treeRoot );
+ dumpTree( theRoot, treeRoot );
+ }
+ return aDoc.toString();
+}
+
+bool LightApp_IDataObject::dumpObject( SUIT_DataObject* objNode, QDomElement& treeNode )
+{
+ if( objNode != 0 ) {
+ LightApp_DataObject* obj = dynamic_cast<LightApp_DataObject*>( objNode );
+ treeNode.setAttribute( ENTRY, obj->entry() );
+ treeNode.setAttribute( NAME, obj->name() );
+ return true;
+ }
+ return false;
+}
+
+void LightApp_IDataObject::dumpTree( SUIT_DataObject* currentNode, QDomElement& currentRoot )
+{
+ for( int i=0; i < currentNode->childCount(); i++ ) {
+ QDomElement treeChild = currentRoot.ownerDocument().createElement( OBJECT_NODE );
+ SUIT_DataObject* obj = currentNode->childObject( i );
+ dumpObject( obj, treeChild );
+ currentRoot.appendChild( treeChild );
+ dumpTree( obj, treeChild );
+ }
+}
+
+void LightApp_IDataObject::BuildITree( SUIT_DataObject* theRoot, const QString& theTree )
+{
+ QDomDocument aDoc;
+ if( aDoc.setContent( theTree ) ) {
+ QDomElement aRoot = aDoc.documentElement();
+ LightApp_IDataObject* obj = new LightApp_IDataObject();
+ BuildNode( aRoot, *obj );
+ theRoot->appendChild( obj );
+ BuildIModuleTree( aRoot, *obj );
+ }
+}
+
+void LightApp_IDataObject::BuildNode( const QDomElement& treeNode, LightApp_IDataObject& objNode )
+{
+ QString aName = treeNode.attribute( NAME );
+ objNode.setName( aName );
+ QString aEntry = treeNode.attribute( ENTRY );
+ objNode.setEntry( aEntry );
+}
+
+void LightApp_IDataObject::BuildIModuleTree( const QDomElement& currentRoot, LightApp_IDataObject& currentNode )
+{
+ for( QDomElement treeChild = currentRoot.firstChildElement(); !treeChild.isNull();
+ treeChild = treeChild.nextSiblingElement() ) {
+ LightApp_IDataObject* obj = new LightApp_IDataObject();
+ BuildNode( treeChild, *obj );
+ currentNode.appendChild( obj );
+ BuildIModuleTree( treeChild, *obj );
+ }
+}
--- /dev/null
+// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+#ifndef LightApp_IDATAOBJECT_H
+#define LightApp_IDATAOBJECT_H
+
+#include <LightApp_DataObject.h>
+#include <SUIT_DataObject.h>
+#include <QDomDocument>
+#include <QDomElement>
+#include <QDomNode>
+
+class LIGHTAPP_EXPORT LightApp_IDataObject : public LightApp_DataObject
+{
+
+public:
+ LightApp_IDataObject( SUIT_DataObject* = 0 );
+ virtual ~LightApp_IDataObject();
+
+ virtual QString name() const;
+ virtual QString entry() const;
+
+ void setName( const QString& );
+ void setEntry( const QString& );
+ static QString GetTreeDoc( CAM_DataObject* theRoot );
+ static void BuildITree( SUIT_DataObject* theRoot, const QString& theTree = 0 );
+
+protected:
+ static bool dumpObject( SUIT_DataObject* objNode, QDomElement& treeNode );
+ static void dumpTree( SUIT_DataObject* currentNode, QDomElement& currentRoot );
+ static void BuildNode( const QDomElement& treeNode, LightApp_IDataObject& objNode );
+ static void BuildIModuleTree( const QDomElement& currentRoot, LightApp_IDataObject& currentNode );
+
+
+private:
+ QString myName;
+ QString myEntry;
+};
+
+#endif // LightApp_IDATAOBJECT_H
#include "LightApp_Application.h"
#include "LightApp_DataModel.h"
#include "LightApp_DataObject.h"
+#include "LightApp_IDataObject.h"
#include "LightApp_HDFDriver.h"
#include "SUIT_ResourceMgr.h"
return false;
setRoot( new LightApp_RootObject( this ) ); // create myRoot
-
+
+ //create object tree for all modules
+ CAM_Application* app = dynamic_cast<CAM_Application*>( application() );
+ QStringList listOfModules;
+ app->modules( listOfModules, false );
+
+ for ( QStringList::Iterator it = listOfModules.begin(); it != listOfModules.end(); ++it )
+ LightApp_IDataObject::BuildITree( root(), myDriver->GetTree( ( app->moduleName( (*it) ) ).toStdString() ) );
+
// update loaded data models: call open() and update() on them.
ModelList dm_s;
dataModels( dm_s );
aModel->saveAs( theFileName, this, listOfFiles );
if ( !listOfFiles.isEmpty() )
saveModuleData(aModel->module()->name(), listOfFiles);
-
+ myDriver->SetTree(aModel->module()->name().toStdString(),LightApp_IDataObject::GetTreeDoc(aModel->root()).toStdString());
// Remove files if necessary. File is removed if it was in the list of files before
// saving and it is not contained in the list after saving. This provides correct
// removing previous temporary files. These files are not removed before saving
myDriver->ClearDriverContents();
QStringList listOfFiles;
QListIterator<CAM_DataModel*> itList( list );
+
while ( itList.hasNext() ) {
LightApp_DataModel* aModel = (LightApp_DataModel*)itList.next();
if ( !aModel ) continue;
listOfFiles.clear();
aModel->save( listOfFiles );
saveModuleData(aModel->module()->name(), listOfFiles);
+ myDriver->SetTree(aModel->module()->name().toStdString(),LightApp_IDataObject::GetTreeDoc(aModel->root()).toStdString());
}
bool res = saveStudyData(studyName());
LightApp_Driver.h \
LightApp_EventFilter.h \
LightApp_HDFDriver.h \
+ LightApp_IDataObject.h \
LightApp_Module.h \
LightApp_ModuleAction.h \
LightApp_ModuleDlg.h \
LightApp_Driver.cxx \
LightApp_EventFilter.cxx \
LightApp_HDFDriver.cxx \
+ LightApp_IDataObject.cxx \
LightApp_Module.cxx \
LightApp_ModuleAction.cxx \
LightApp_ModuleDlg.cxx \