From: smh Date: Thu, 26 May 2005 12:30:00 +0000 (+0000) Subject: SMH: Merge with development version = NEW GUI, POLY_WORK, OCC_development_02, BR_Lyfe... X-Git-Tag: smh_26_05~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=023451bb80fcc805d6891debdb140c4619b30820;p=modules%2Fkernel.git SMH: Merge with development version = NEW GUI, POLY_WORK, OCC_development_02, BR_LyfeCycle, HEAD --- diff --git a/examples/slots.brep b/examples/slots.brep new file mode 100755 index 000000000..9d0b0084b --- /dev/null +++ b/examples/slots.brep @@ -0,0 +1,257 @@ +DBRep_DrawableShape + +CASCADE Topology V1, (c) Matra-Datavision +Locations 10 +1 + 1 0 0 0 + 0 1 0 0 + 0 0 1 0 +1 + 1 -0 0 -0 + 0 1 0 0 + -0 0 1 -0 +1 + 1 0 0 0 + 0 1 0 0 + 0 0 1 100 +2 2 1 3 1 0 +1 + 1 0 0 -0 + 0 1 0 -0 + 0 0 1 -32 +2 2 1 3 1 5 1 0 +2 5 -1 3 -1 2 -1 0 +2 3 -1 2 -1 0 +1 + -0.5 -0.866025403784439 0 0 +0.866025403784439 -0.5 0 0 + 0 0 1 0 +1 + -0.5 0.866025403784438 0 0 +-0.866025403784438 -0.5 0 0 + 0 0 1 0 +Curve2ds 0 +Curves 8 +1 -110 -10 100 -0 -0 -1 +1 110 -10 100 -0 -0 -1 +1 -110 -10 0 1 0 0 +1 110 10 100 -0 -0 -1 +1 110 -10 0 0 1 0 +1 -110 10 100 -0 -0 -1 +1 110 10 0 -1 0 0 +1 -110 10 0 0 -1 -0 +Polygon3D 0 +PolygonOnTriangulations 17 +2 3 4 +p 3.20000002 1 0 32 +2 1 2 +p 3.20000002 1 0 32 +2 2 4 +p 22.00000002 1 0 220 +2 1 3 +p 22.00000002 1 0 220 +2 1 2 +p 22.00000002 1 0 220 +2 3 4 +p 3.20000002 1 0 32 +2 1 2 +p 12.80000008 1 0 32 +2 2 4 +p 3.20000002 1 0 20 +2 1 3 +p 3.20000002 1 0 20 +2 2 3 +p 8.00000008 1 0 20 +2 1 2 +p 3.20000002 1 0 32 +2 2 4 +p 22.00000002 1 0 220 +2 1 3 +p 22.00000002 1 0 220 +2 3 4 +p 22.00000002 1 0 220 +2 1 3 +p 3.20000002 1 0 20 +2 2 4 +p 3.20000002 1 0 20 +2 4 1 +p 8.00000008 1 0 20 +Surfaces 5 +1 -110 -10 100 0 -1 0 1 0 0 -0 0 1 +1 110 -10 100 1 0 0 -0 1 0 0 -0 1 +1 110 10 100 0 1 -0 -1 0 0 0 0 1 +1 -110 10 100 -1 -0 0 0 -1 -0 0 0 1 +1 -110 -10 100 0 0 -1 -1 0 -0 0 1 0 +Triangulations 5 +4 2 1 0 +-110 -10 100 -110 -10 68 110 -10 100 110 -10 68 0 0 0 -32 220 0 220 -32 1 2 3 4 3 2 +4 2 1 0 +-110 10 100 -110 10 68 -110 -10 100 -110 -10 68 0 0 0 -32 20 0 20 -32 1 2 3 4 3 2 +4 2 1 0 +110 -10 100 110 -10 68 110 10 100 110 10 68 0 0 0 -32 20 0 20 -32 1 2 3 4 3 2 +4 2 1 0 +-110 -10 100 110 -10 100 110 10 100 -110 10 100 0 0 -220 0 -220 20 0 20 3 2 1 1 4 3 +4 2 1 0 +110 10 100 110 10 68 -110 10 100 -110 10 68 0 0 0 -32 220 0 220 -32 1 2 3 4 3 2 + +TShapes 25 +Ve +1e-07 +-110 -10 0 +0 0 + +0101101 +* +Ed + 1e-07 1 1 0 +1 1 0 0 32 +6 1 2 0 +0 + +0101000 ++25 4 -25 6 * +Ve +1e-07 +110 -10 0 +0 0 + +0101101 +* +Ed + 1e-07 1 1 0 +1 2 0 0 32 +6 2 3 0 +0 + +0101000 ++23 4 -23 6 * +Ed + 1e-07 1 1 0 +1 3 0 0 220 +6 3 1 7 +6 4 1 8 +6 5 4 8 +0 + +0101000 ++25 0 -23 0 * +Wi + +0101000 ++24 0 -22 0 -21 4 +21 6 * +Fa +0 1e-07 1 0 +2 1 +0101000 ++20 0 * +Ve +1e-07 +110 10 0 +0 0 + +0101101 +* +Ed + 1e-07 1 1 0 +1 4 0 0 32 +6 6 3 0 +6 7 5 0 +0 + +0101000 ++18 4 -18 6 * +Ed + 1e-07 1 1 0 +1 5 0 0 20 +6 8 3 7 +6 9 3 8 +6 10 4 8 +0 + +0101000 ++23 0 -18 0 * +Wi + +0101000 ++22 0 -17 0 -16 4 +16 6 * +Fa +0 1e-07 2 0 +2 3 +0101000 ++15 0 * +Ve +1e-07 +-110 10 0 +0 0 + +0101101 +* +Ed + 1e-07 1 1 0 +1 6 0 0 32 +6 11 2 0 +0 + +0101000 ++13 4 -13 6 * +Ed + 1e-07 1 1 0 +1 7 0 0 220 +6 12 5 7 +6 13 5 8 +6 14 4 8 +0 + +0101000 ++18 0 -13 0 * +Wi + +0101000 ++17 0 -12 0 -11 4 +11 6 * +Fa +0 1e-07 3 0 +2 5 +0101000 ++10 0 * +Ed + 1e-07 1 1 0 +1 8 0 0 20 +6 15 2 8 +6 16 2 7 +6 17 4 8 +0 + +0101000 ++13 0 -25 0 * +Wi + +0101000 ++12 0 -24 0 -8 4 +8 6 * +Fa +0 1e-07 4 0 +2 2 +0101000 ++7 0 * +Wi + +0101100 ++21 0 +16 0 +11 0 +8 0 * +Fa +0 1e-07 5 0 +2 4 +0101000 +-5 4 * +Sh + +0101000 +-19 0 -14 0 -9 0 -6 0 +4 0 -4 5 * +So + +0100000 +-3 0 * +Co + +0100000 ++2 1 +2 9 +2 10 * + ++1 0 \ No newline at end of file diff --git a/resources/Plugin.in b/resources/Plugin.in new file mode 100755 index 000000000..3d4fad5e5 --- /dev/null +++ b/resources/Plugin.in @@ -0,0 +1,10 @@ +! Description of available plugins +! ******************************** +! +a148e300-5740-11d1-a904-080036aaa103.Location: FWOSPlugin +! +! standard attribute drivers plugin +! +ad696000-5b34-11d1-b5ba-00a0c9064368.Location: @CAS_STDPLUGIN@ +ad696001-5b34-11d1-b5ba-00a0c9064368.Location: @CAS_STDPLUGIN@ +ad696002-5b34-11d1-b5ba-00a0c9064368.Location: @CAS_STDPLUGIN@ diff --git a/salome_adm/unix/config_files/check_msg2qm.m4 b/salome_adm/unix/config_files/check_msg2qm.m4 new file mode 100755 index 000000000..63c3af848 --- /dev/null +++ b/salome_adm/unix/config_files/check_msg2qm.m4 @@ -0,0 +1,48 @@ +# Check availability of Salome's KERNEL binary distribution +# +# Author : Jerome Roy (CEA, 2003) +# + +AC_DEFUN([CHECK_MSG2QM],[ + +AC_CHECKING(for msg2qm) + +msg2qm_ok=no + +AC_ARG_WITH(msg2qm, + [ --with-msg2qm=DIR root directory path of MSG2QM installation], + MSG2QM_DIR="$withval",MSG2QM_DIR="") + +if test "x$MSG2QM_DIR" == "x" ; then + +# no --with-MSG2QM-dir option used + + if test "x$MSG2QM_ROOT" != "x" ; then + + # MSG2QM_ROOT environment variable defined + MSG2QM_DIR=$MSG2QM_ROOT + + else + + # search MSG2QM binaries in PATH variable + AC_PATH_PROG(TEMP, mgs2qm) + if test "x$TEMP" != "x" ; then + MSG2QM_BIN_DIR=`dirname $TEMP` + MSG2QM_DIR=`dirname $MSG2QM_BIN_DIR` + fi + + fi +# +fi + +if test -f ${MSG2QM_DIR}/msg2qm ; then + msg2qm_ok=yes + AC_MSG_RESULT(Using MSG2QM executable in ${MSG2QM_DIR}) +else + AC_MSG_WARN("Cannot find MSG2QM executable") +fi + +AC_MSG_RESULT(for MSG2QM: $msg2qm_ok) + +])dnl + diff --git a/src/Container/Container_init_python.cxx b/src/Container/Container_init_python.cxx new file mode 100644 index 000000000..7a4e58527 --- /dev/null +++ b/src/Container/Container_init_python.cxx @@ -0,0 +1,58 @@ +// SALOME Container : implementation of container and engine for Kernel +// +// 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 : Container_init_python.cxx +// Author : Paul RASCLE, EDF +// Module : KERNEL +// $Header$ + +#include "Container_init_python.hxx" + +#include "utilities.h" +using namespace std; + +PyThreadState *KERNEL_PYTHON::_gtstate = 0; +PyObject *KERNEL_PYTHON::salome_shared_modules_module = NULL; +PyInterpreterState *KERNEL_PYTHON::_interp = NULL; + +void KERNEL_PYTHON::init_python(int argc, char **argv) +{ + if (Py_IsInitialized()) + { + MESSAGE("Python already initialized"); + SCRUTE(KERNEL_PYTHON::_gtstate); + return; + } + MESSAGE("================================================================="); + MESSAGE("Python Initialization..."); + MESSAGE("================================================================="); + Py_SetProgramName(argv[0]); + Py_Initialize(); // Initialize the interpreter + PySys_SetArgv(argc, argv); + KERNEL_PYTHON::_interp = PyThreadState_Get()->interp; + PyEval_InitThreads(); // Create (and acquire) the interpreter lock + ASSERT(!KERNEL_PYTHON::_gtstate); + KERNEL_PYTHON::_gtstate = PyEval_SaveThread(); // Release global thread state + SCRUTE(KERNEL_PYTHON::_gtstate); +} + diff --git a/src/Container/Container_init_python.hxx b/src/Container/Container_init_python.hxx new file mode 100644 index 000000000..acaef6307 --- /dev/null +++ b/src/Container/Container_init_python.hxx @@ -0,0 +1,66 @@ +// SALOME Container : implementation of container and engine for Kernel +// +// 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 : Container_init_python.hxx +// Author : Paul RASCLE, EDF +// Module : KERNEL +// $Header$ + +#ifndef _CONTAINER_INIT_PYTHON_HXX_ +#define _CONTAINER_INIT_PYTHON_HXX_ + +#include // must be before Python.h ! +#include + + +// next two MACRO must be used together only once inside a block +// ------------------------------------------------------------- +// protect a sequence of Python calls: +// - Python lock must be acquired for these calls +// - new Python thread state allows multi thread use of the sequence: +// - Python may release the lock within the sequence, so multiple +// thread execution of the sequence may occur. +// - For that case, each sequence call must use a specific Python +// thread state. +// - There is no need of C Lock protection of the sequence. + +#define Py_ACQUIRE_NEW_THREAD \ + PyEval_AcquireLock(); \ + PyThreadState *myTstate = PyThreadState_New(KERNEL_PYTHON::_interp); \ + PyThreadState *myoldTstate = PyThreadState_Swap(myTstate); + +#define Py_RELEASE_NEW_THREAD \ + PyEval_ReleaseThread(myTstate); \ + PyThreadState_Delete(myTstate); + +struct KERNEL_PYTHON +{ + static PyThreadState *_gtstate; + static PyObject *salome_shared_modules_module; + static PyInterpreterState *_interp; + + static void init_python(int argc, char **argv); + +}; + +#endif diff --git a/src/Container/SALOME_Container.py b/src/Container/SALOME_Container.py new file mode 100644 index 000000000..befd9a173 --- /dev/null +++ b/src/Container/SALOME_Container.py @@ -0,0 +1,107 @@ +#! /usr/bin/env python +# +# SALOME Container : implementation of container and engine for Kernel +# +# 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 : SALOME_Container.py +# Author : Paul RASCLE, EDF +# Module : SALOME +# $Header$ + +import os +import sys +import string +from omniORB import CORBA, PortableServer +# import SALOMEDS before other SALOME modules +# (if not, incomplete import done by SALOME module: no load of SALOMEDS_attributes) +import SALOMEDS +import Engines, Engines__POA +reload(Engines) +reload(Engines__POA) +from SALOME_NamingServicePy import * +from SALOME_ComponentPy import * + +from SALOME_utilities import * +from Utils_Identity import getShortHostName + +#============================================================================= + +#define an implementation of the container interface + +class SALOME_Container_i: + _orb = None + _poa = None + _containerName = "" + _naming_service = None + + #------------------------------------------------------------------------- + + def __init__(self ,containerName, containerIORStr): + MESSAGE( "SALOME_Container_i::__init__" ) + self._orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID) + self._poa = self._orb.resolve_initial_references("RootPOA") + self._containerName = containerName + #self._naming_service = SALOME_NamingServicePy_i(self._orb) + self._container = self._orb.string_to_object(containerIORStr) + + #------------------------------------------------------------------------- + + def import_component(self, componentName): + MESSAGE( "SALOME_Container_i::import_component" ) + ret=0 + try: + print "try import ",componentName + __import__(componentName) + print "import ",componentName," successful" + ret=1 + except: + import traceback + traceback.print_exc() + print "import ",componentName," not possible" + return ret + + #------------------------------------------------------------------------- + + def create_component_instance(self, componentName, instanceName, studyId): + MESSAGE( "SALOME_Container_i::create_component_instance" ) + comp_iors="" + try: + component=__import__(componentName) + factory=getattr(component,componentName) + comp_i=factory(self._orb, + self._poa, + self._container, + self._containerName, + instanceName, + componentName) + + MESSAGE( "SALOME_Container_i::create_component_instance : OK") + comp_o = comp_i._this() + comp_iors = self._orb.object_to_string(comp_o) + except: + import traceback + traceback.print_exc() + MESSAGE( "SALOME_Container_i::create_component_instance : NOT OK") + return comp_iors + + diff --git a/src/Container/SALOME_ContainerManagerServer.cxx b/src/Container/SALOME_ContainerManagerServer.cxx new file mode 100644 index 000000000..77297a412 --- /dev/null +++ b/src/Container/SALOME_ContainerManagerServer.cxx @@ -0,0 +1,39 @@ +#include "SALOME_ContainerManager.hxx" +#include "utilities.h" + +int main(int argc, char* argv[]) +{ + PortableServer::POA_var root_poa; + PortableServer::POAManager_var pman; + CORBA::Object_var obj; + + CORBA::ORB_var orb = CORBA::ORB_init( argc , argv ) ; + try{ + obj = orb->resolve_initial_references("RootPOA"); + if(!CORBA::is_nil(obj)) + root_poa = PortableServer::POA::_narrow(obj); + if(!CORBA::is_nil(root_poa)) + pman = root_poa->the_POAManager(); + } + catch(CORBA::COMM_FAILURE&){ + MESSAGE( "Container: CORBA::COMM_FAILURE: Unable to contact the Naming Service" ); + } + try{ + SALOME_ContainerManager *cmServ=new SALOME_ContainerManager(orb); + pman->activate(); + orb->run(); + }catch(CORBA::SystemException&){ + MESSAGE("Caught CORBA::SystemException."); + }catch(PortableServer::POA::WrongPolicy&){ + MESSAGE("Caught CORBA::WrongPolicyException."); + }catch(PortableServer::POA::ServantAlreadyActive&){ + MESSAGE("Caught CORBA::ServantAlreadyActiveException"); + }catch(CORBA::Exception&){ + MESSAGE("Caught CORBA::Exception."); + }catch(std::exception& exc){ + MESSAGE("Caught std::exception - "<" + CSO.GetID() + " " + t_name[1] + t_RefSO = CSO.ReferencedObject() + if t_RefSO[0] == 1: + RefSO = t_RefSO[1] + ofs = 1 + a = "" + while ofs <= offset: + a = a + " " + ofs = ofs +1 + print a + ">" + RefSO.GetID() + DumpComponent(Study, CSO, offset+2) + + #-------------------------------------------------------------------------- + +def DumpStudy(Study): + itcomp = Study.NewComponentIterator() + while itcomp.More(): + SC = itcomp.Value() + itcomp.Next() + name = SC.ComponentDataType() + print "-> ComponentDataType is " + name + DumpComponent(Study, SC, 1) + + + #-------------------------------------------------------------------------- + +# initialise the ORB +orb = CORBA.ORB_init([''], CORBA.ORB_ID) + +# create an LifeCycleCORBA instance +lcc = LifeCycleCORBA(orb) + +# create an SALOMEGUI_Swig instance +sg = SALOMEGUI_Swig() + +#create an naming service instance +naming_service = SALOME_NamingServicePy_i(orb) + +# get active study name and id +myStudyName = sg.getActiveStudyName() +print myStudyName + +myStudyId = sg.getActiveStudyId() +print myStudyId + +# get Study Manager reference +obj = naming_service.Resolve('myStudyManager') +myStudyManager = obj._narrow(SALOMEDS.StudyManager) + +# get active study +myStudy = myStudyManager.GetStudyByName(myStudyName) diff --git a/src/KERNEL_PY/batchmode_salome.py b/src/KERNEL_PY/batchmode_salome.py new file mode 100755 index 000000000..389791622 --- /dev/null +++ b/src/KERNEL_PY/batchmode_salome.py @@ -0,0 +1,269 @@ +# Copyright (C) 2003 CEA/DEN, EDF R&D +# +# +# +# File : batchmode_salome.py +# Module : SALOME + +import salome_shared_modules + +from omniORB import CORBA +from LifeCycleCORBA import * +import SALOMEDS +from SALOME_NamingServicePy import * + +#-------------------------------------------------------------------------- + +def ImportComponentGUI(ComponentName): + libName = "lib" + ComponentName + "_Swig" + command = "from " + libName + " import *" + exec ( command ) + constructor = ComponentName + "GUI_Swig()" + command = "gui = " + constructor + exec ( command ) + return gui + + #-------------------------------------------------------------------------- + +def SalomeGUIgetAllSelected(self): + selNumber = self.SelectedCount() + listSelected = [] + for i in range(selNumber): + listSelected.append(self.getSelected(i)) + return listSelected + #-------------------------------------------------------------------------- + +def generateName(prefix = None): + import whrandom; + int = whrandom.randint(1,1000); + if prefix is None: + return "Study" + str(int) + else : + return prefix + str(int) + +#WITHOUTIHMfrom libSALOME_Swig import * +###from SalomePyQt import * +#WITHOUTIHMclass SalomeGUI(SALOMEGUI_Swig): + #WITHOUTIHMgetAllSelected = SalomeGUIgetAllSelected + + #WITHOUTIHMdef getDesktop(self) : +# return SalomePyQt.getDesktop() + #WITHOUTIHMreturn None + + #WITHOUTIHMdef getSelection(self) : +# return SalomePyQt.getSelection() + #WITHOUTIHMreturn None + + #-------------------------------------------------------------------------- + +def IDToObject(id): + myObj = None + mySO = myStudy.FindObjectID(id); + if mySO is not None: + ok, anAttr = mySO.FindAttribute("AttributeIOR") + if ok: + AtIOR = anAttr._narrow(SALOMEDS.AttributeIOR) + if AtIOR.Value() != "": + myObj = orb.string_to_object(AtIOR.Value()) + return myObj + +def ObjectToSObject(obj): + mySO = None + if obj is not None: + ior = orb.object_to_string(obj) + if ior != "": + mySO = myStudy.FindObjectIOR(ior) + return mySO + +def ObjectToID(obj): + mySO = ObjectToSObject(obj) + if mySO: + return mySO.GetID() + return "" + +def IDToSObject(id): + mySO = myStudy.FindObjectID(id); + return mySO + + #-------------------------------------------------------------------------- + +def PersistentPresentation(theStudy, theSO, theWithID): + # put the sobject's content (with subchildren) to the string + aResult = "" + attrs = theSO.GetAllAttributes() + aLen = len(attrs) + anUncopied = 0 + for a in range(0,aLen): + attr = attrs[a] + if isinstance(attr,SALOMEDS._objref_AttributeTreeNode): + anUncopied += 1 + elif isinstance(attr,SALOMEDS._objref_AttributeTarget): + anUncopied += 1 + elif isinstance(attr,SALOMEDS._objref_AttributeReal) or \ + isinstance(attr,SALOMEDS._objref_AttributeInteger) or \ + isinstance(attr,SALOMEDS._objref_AttributeName) or \ + isinstance(attr,SALOMEDS._objref_AttributeComment) or \ + isinstance(attr,SALOMEDS._objref_AttributePersistentRef) or \ + isinstance(attr,SALOMEDS._objref_AttributeLocalID) or \ + isinstance(attr,SALOMEDS._objref_AttributeUserID): + aResult += " attribute value: " + str(attr.Value()) + elif isinstance(attr,SALOMEDS._objref_AttributeIOR): + aResult += " attribute: IOR" + elif isinstance(attr,SALOMEDS._objref_AttributeSequenceOfReal) or \ + isinstance(attr,SALOMEDS._objref_AttributeSequenceOfInteger): + aResult += " Sequence: " + str(attr.CorbaSequence()) + elif isinstance(attr,SALOMEDS._objref_AttributeDrawable): + aResult += " Drawable: " + str(attr.IsDrawable()) + elif isinstance(attr,SALOMEDS._objref_AttributeSelectable): + aResult += " Selectable: " + str(attr.IsSelectable()) + elif isinstance(attr,SALOMEDS._objref_AttributeExpandable): + aResult += " Expandable: " + str(attr.IsExpandable()) + elif isinstance(attr,SALOMEDS._objref_AttributeOpened): + aResult += " Opened: " + str(attr.IsOpened()) + elif isinstance(attr,SALOMEDS._objref_AttributeTextColor): + aResult += " TextColor: " + str(attr.TextColor()) + elif isinstance(attr,SALOMEDS._objref_AttributeTextHighlightColor): + aResult += " TextHighlightColor: " + str(attr.TextHighlightColor()) + elif isinstance(attr,SALOMEDS._objref_AttributePixMap): + aResult += " PixMap: " + str(attr.GetPixMap()) + elif isinstance(attr,SALOMEDS._objref_AttributeTableOfInteger) or \ + isinstance(attr,SALOMEDS._objref_AttributeTableOfReal): + aResult += " Table with title: " + attr.GetTitle() + elif isinstance(attr,SALOMEDS._objref_AttributePythonObject): + aResult += " PythonObject: " + attr.GetObject() + + if theWithID: + aResult = "sobject: " + theSO.GetID() + " nbattrs: " + str(aLen - anUncopied) + aResult + '\n' + else: + aResult = " nbattrs: " + str(aLen - anUncopied) + aResult + '\n' + anIter = theStudy.NewChildIterator(theSO) + while anIter.More(): + aResult += PersistentPresentation(theStudy, anIter.Value(), theWithID) + anIter.Next() + return aResult + + #-------------------------------------------------------------------------- + +def GetTree(theSO): + # returns the document list tree (as list) + aResult = [theSO.GetID()] + anIter = myStudy.NewChildIterator(theSO) + while anIter.More(): + aResult += GetTree(anIter.Value()) + anIter.Next() + return aResult + + #-------------------------------------------------------------------------- + +def CheckCopyPaste(theSO, theInfo ,theComponentPaste): + aRoot = theSO + while aRoot.GetID() != "0:": + aRoot = aRoot.GetFather() + aTree = GetTree(aRoot) + aStudyPersist = PersistentPresentation(myStudy, aRoot, 1) + + if not myStudyManager.CanCopy(theSO): + raise RuntimeError, " for "+theInfo+" returns false" + + if not myStudyManager.Copy(theSO): + raise RuntimeError, " for "+theInfo+" returns false" + + + if not myStudyManager.CanPaste(theSO): + raise RuntimeError, " for "+theInfo+" returns false" + + # check: before paste study is not changed check + if aStudyPersist != PersistentPresentation(myStudy, aRoot, 1): + raise RuntimeError, "Study is changed before Paste calling for "+theInfo + + aSObj = theSO + if theComponentPaste: + aSObj = theSO.GetFatherComponent() + theInfo = theInfo + "(paste for component)" + if myStudyManager.Paste(aSObj) == None: + raise RuntimeError, " for "+theInfo+" returns None object" + aNewTree = GetTree(aRoot) + aLen = len(aTree) + for a in range(0,aLen): + if aTree[a] != aNewTree[a]: + return myStudy.FindObjectID(aNewTree[a]) + + if aLen < len(aNewTree): + return myStudy.FindObjectID(aNewTree[aLen]) + + raise RuntimeError, "After Copy calling the tree is not changed" + + #-------------------------------------------------------------------------- +def FindFileInDataDir(filename): + import os + datadir = os.getenv("DATA_DIR") + if datadir is not None: + import string + dirs = string.split(datadir, ":") + for dir in dirs: + file = dir + "/" + filename + if os.path.exists(file): + return file; + datadir = os.getenv("KERNEL_ROOT_DIR") + "/examples/" + file = datadir + filename + if os.path.exists(file): + return file; + + return None + +#-------------------------------------------------------------------------- +# initialise the ORB +orb = None + +step = 0 +while step < 100 and orb is None: + orb = CORBA.ORB_init([''], CORBA.ORB_ID) + step = step + 1 + time.sleep(4) + +if orb is None: + print "Warning: ORB has not been initialized !!!" + +# create an LifeCycleCORBA instance +lcc = LifeCycleCORBA(orb) + +step = 0 +while step < 100 and lcc._catalog is None: + lcc = LifeCycleCORBA(orb) + step = step + 1 + time.sleep(4) + +if lcc._catalog is None: + print "Warning: LifeCycleCORBA object is incomplete !!!" + +#create a naming service instance +naming_service = SALOME_NamingServicePy_i(orb) + +# get Study Manager reference +obj = None + +step = 0 +while step < 100 and obj == None: + obj = naming_service.Resolve('myStudyManager') + step = step + 1 + time.sleep(4) + +myStudyManager = obj._narrow(SALOMEDS.StudyManager) + +if myStudyManager is None: + print "Warning: SALOMEDS.StudyManager has not been created !!!" + +# create new study +aListOfOpenStudies = myStudyManager.GetOpenStudies(); +myStudy = None; +if len(aListOfOpenStudies) == 0 : + myStudy = myStudyManager.NewStudy("Study1") +else: + myStudyName = aListOfOpenStudies[0] + myStudy = myStudyManager.GetStudyByName(myStudyName) + +myStudyName = myStudy._get_Name() + +myStudyId = myStudy._get_StudyId() +print myStudyId + diff --git a/src/KERNEL_PY/import_hook.py b/src/KERNEL_PY/import_hook.py new file mode 100755 index 000000000..79725c627 --- /dev/null +++ b/src/KERNEL_PY/import_hook.py @@ -0,0 +1,109 @@ +""" +This module replaces the standard import mechanism with one +that filters some imports that can't be done more than once. + +This is related to the multi study feature that is implemented +by using the Python multi interpreter feature. +Some modules register objects or classes by calling modules +implemented in C. These operations can't be done multiple times. +So it's very important to control these imports. + +Examples: + - PyQt : import qt calls a C module to register classes + - OmniORB : import *_idl calls a C module to register CORBA interfaces + +Usage: + - First import the module : import import_hook. This module will + replace the original importer mechanism + + - Next register the module names or pattern names to filter out:: + import_hook.register_name("a") + import_hook.register_pattern(pattern) + + where pattern is a function with one parameter, the module name + to be imported, that returns true or false depending if this module is + to be filtered or not. + + - Then it's done + +IMPORTANT : Every subinterpretor has its own import_hook module. import_hook is not shared among subinterpretors. +The mechanism only works if shared_imported and pattern are shared between all subinterpretors. +This is done by calling init_shared_modules(). + +""" +import sys, imp, __builtin__ + +# Keep in shared_imported a copy of dictionnary modules +# that need to be imported only once in multi-study context +shared_imported={} + +# patterns contains functions that returns 1 or 0 depending if +# the module name (argument) must be filtered out or not +# These functions are added by calling register_pattern +patterns=[] + +original_import=__builtin__.__import__ + +def register_name(name): + if shared_imported.has_key(name):return + shared_imported[name]=None + +def register_pattern(pattern): + patterns.append(pattern) + +def is_shared(name): + if shared_imported.has_key(name):return 1 + for pattern in patterns: + if pattern(name) : return 1 + return 0 + +def get_shared_imported(name): + return shared_imported.get(name) + +def set_shared_imported(name,module): + shared_imported[name]=module + #print "Module %s shared registered" % name,module + +def get_shared_imported_with_copy(name): + module_dict= shared_imported.get(name) + m=imp.new_module(name) + m.__dict__.update(module_dict) + return m +def set_shared_imported_with_copy(name,module): + shared_imported[name]=module.__dict__.copy() + #print "Module %s shared registered" % name + +def import_hook(name, globals=None, locals=None, fromlist=None): + #print "import_hook",name,fromlist + module=get_shared_imported(name) + if module: + sys.modules[name]=module + return module + + module= original_import(name, globals, locals, fromlist) + + if is_shared(name): + set_shared_imported(name,module) + return module + +original_reload=__builtin__.reload + +def reload_hook(module): + if is_shared(module.__name__): + return module + return original_reload(module) + +__builtin__.__import__=import_hook +# Reload is not replaced +#__builtin__.reload=reload_hook + +def init_shared_modules(shared_module): + global shared_imported, patterns + shared_imported=shared_module.shared_imported + patterns= shared_module.patterns + for k,v in shared_imported.items(): + if v is not None:sys.modules[k]=v + shared_imported["salome_shared_modules"]=shared_module + import salome_shared_modules + for m in salome_shared_modules.list_modules: + m.init_shared_modules() diff --git a/src/KERNEL_PY/kernel_shared_modules.py b/src/KERNEL_PY/kernel_shared_modules.py new file mode 100755 index 000000000..bcdd46381 --- /dev/null +++ b/src/KERNEL_PY/kernel_shared_modules.py @@ -0,0 +1,104 @@ +""" + +""" +import import_hook + +import glob,os,sys,string,imp + +from import_hook import register_name +from import_hook import register_pattern + +register_name("qt") +register_pattern(lambda(x):x.endswith("_idl")) + +register_name("omniORB") +import omniORB + +# Modify omniORB to use right sys.modules dictionnary +# with multi-interpreter feature +# openModule and newModule are functions of omniORB/__init__.py module +# modified to register modules to share +# Function to return a Python module for the required IDL module name +def openModule(mname, fname=None): + # Salome modification start + import sys + # Salome modification end + + if mname == "CORBA": + mod = sys.modules["omniORB.CORBA"] + elif sys.modules.has_key(mname): + mod = sys.modules[mname] + else: + mod = newModule(mname) + + # Salome modification start + import_hook.set_shared_imported(mname,mod) + # Salome modification end + + + if not hasattr(mod, "__doc__") or mod.__doc__ is None: + mod.__doc__ = "omniORB IDL module " + mname + "\n\n" + \ + "Generated from:\n\n" + + if fname is not None: + mod.__doc__ = mod.__doc__ + " " + fname + "\n" + + return mod + +# Function to create a new module, and any parent modules which do not +# already exist +def newModule(mname): + # Salome modification start + import sys + # Salome modification end + + mlist = string.split(mname, ".") + current = "" + mod = None + + for name in mlist: + current = current + name + + if sys.modules.has_key(current): + mod = sys.modules[current] + else: + newmod = imp.new_module(current) + if mod: setattr(mod, name, newmod) + sys.modules[current] = mod = newmod + + current = current + "." + + return mod +# Replace openModule and newModule by modified ones +# to take into account the sys.modules that matches +# the right one (multi-interpreter feature) +omniORB.openModule=openModule +omniORB.newModule=newModule + +# BE CAREFUL +# Engines, SALOME, SALOMEDS must be imported in that order because : +# Engines imports SALOME_Component_idl +# SALOME imports SALOME_Session_idl and SALOME_Exception_idl which imports SALOME_Component_idl +# and SALOMEDS imports SALOMEDS_idl and SALOMEDS_Attributes_idl which imports SALOME_Exception_idl +# If SALOME is imported before Engines, that module would not be completely imported +import Engines +import SALOME +import SALOMEDS +import SALOME_ModuleCatalog + +def init_shared_modules(): + """ + This function initializes shared modules that need to be + """ + # EDF-CCAR: + # Problem with omniORB : omniORB creates a C Python module named _omnipy + # this module has sub-modules : omni_func, ... + # _omnipy is quite a package but import with Python sub-interpreters does not seem to work + # To make it work we need to add those sub-modules in sys.modules + import sys + import _omnipy + sys.modules["_omnipy.omni_func"]=_omnipy.omni_func + sys.modules["_omnipy.poa_func"]=_omnipy.poa_func + sys.modules["_omnipy.poamanager_func"]=_omnipy.poamanager_func + sys.modules["_omnipy.orb_func"]=_omnipy.orb_func + diff --git a/src/KERNEL_PY/salome.py b/src/KERNEL_PY/salome.py new file mode 100755 index 000000000..e8d5d5bac --- /dev/null +++ b/src/KERNEL_PY/salome.py @@ -0,0 +1,63 @@ +# 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 : salome.py +# Author : Paul RASCLE, EDF +# Module : SALOME +# $Header$ + +from salome_kernel import * +from salome_study import * +from salome_iapp import * + +salome_initial=1 +def salome_init(theStudyId=0): + """ + Performs only once SALOME general purpose intialisation for scripts. + optional argument : theStudyId + When in embedded interpreter inside IAPP, theStudyId is not used + When used without GUI (external interpreter) + 0 : create a new study (default). + n (>0) : try connection to study with Id = n, or create a new one + if study not found. + If study creation, its Id may be different from theStudyId ! + Provides: + orb reference to CORBA + lcc a LifeCycleCorba instance + naming_service a naming service instance + cm reference to the container manager + sg access to SALOME GUI (when linked with IAPP GUI) + myStudyManager the study manager + myStudyId active study identifier + myStudy active study itself (CORBA reference) + myStudyName active study name + """ + global salome_initial + global orb, lcc, naming_service, cm + global sg + global myStudyManager, myStudyId, myStudy, myStudyName + + if salome_initial: + salome_initial=0 + sg = salome_iapp_init() + orb, lcc, naming_service, cm = salome_kernel_init() + myStudyManager, myStudyId, myStudy, myStudyName =salome_study_init(theStudyId) + diff --git a/src/KERNEL_PY/salome_ComponentGUI.py b/src/KERNEL_PY/salome_ComponentGUI.py new file mode 100644 index 000000000..617c88218 --- /dev/null +++ b/src/KERNEL_PY/salome_ComponentGUI.py @@ -0,0 +1,56 @@ +# 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 : salome.py +# Author : Paul RASCLE, EDF +# Module : SALOME +# $Header$ + + +# to replace some function from _SWIG, outside GUI + +# --- From GeometryGUI_SWIG + + #-------------------------------------------------------------------------- + +def getIndexTopology(aSubId, aMainId): + return 0 + + #-------------------------------------------------------------------------- + +def getShapeTypeString(aSubId): + return "SubShape" + + #-------------------------------------------------------------------------- + +# --- From SMESHGUI_SWIG + + #-------------------------------------------------------------------------- + +def Init(studyId): + return + + #-------------------------------------------------------------------------- + +def SetName(objId, name): + return + + #-------------------------------------------------------------------------- diff --git a/src/KERNEL_PY/salome_iapp.py b/src/KERNEL_PY/salome_iapp.py new file mode 100644 index 000000000..befa0d075 --- /dev/null +++ b/src/KERNEL_PY/salome_iapp.py @@ -0,0 +1,74 @@ +# 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 : salome_iapp.py +# Author : Paul RASCLE, EDF +# Module : SALOME +# $Header$ + +from libSALOME_Swig import * +import salome_ComponentGUI + + #-------------------------------------------------------------------------- + +IN_SALOME_GUI=0 + +def ImportComponentGUI(ComponentName): + if IN_SALOME_GUI: + libName = "lib" + ComponentName + "_Swig" + command = "from " + libName + " import *" + exec ( command ) + constructor = ComponentName + "_Swig()" + command = "gui = " + constructor + exec ( command ) + return gui + else: + print "Warning: ImportComponentGUI(",ComponentName,") outside GUI !" + print "calls to GUI methods may crash..." + return salome_ComponentGUI + + #-------------------------------------------------------------------------- + +def SalomeGUIgetAllSelected(self): + selNumber = self.SelectedCount() + listSelected = [] + for i in range(selNumber): + listSelected.append(self.getSelected(i)) + return listSelected + +class SalomeGUI(SALOMEGUI_Swig): + getAllSelected = SalomeGUIgetAllSelected + + #-------------------------------------------------------------------------- + +salome_iapp_initial = 1 + +def salome_iapp_init(): + global salome_iapp_initial + global sg,IN_SALOME_GUI + + if salome_iapp_initial: + salome_iapp_initial=0 + + # create a SALOMEGUI_Swig instance + sg = SalomeGUI() + IN_SALOME_GUI=sg.hasDesktop() + return sg diff --git a/src/KERNEL_PY/salome_kernel.py b/src/KERNEL_PY/salome_kernel.py new file mode 100644 index 000000000..40fe9e124 --- /dev/null +++ b/src/KERNEL_PY/salome_kernel.py @@ -0,0 +1,55 @@ +# 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 : salome_kernel.py +# Author : Paul RASCLE, EDF +# Module : SALOME +# $Header$ + +from omniORB import CORBA +from LifeCycleCORBA import * +from SALOME_NamingServicePy import * +from SALOME_utilities import * +import Engines + +salome_kernel_initial=1 + +def salome_kernel_init(): + global salome_kernel_initial + global orb, lcc, naming_service, cm + + if salome_kernel_initial: + salome_kernel_initial = 0 + + # initialise the ORB + orb = CORBA.ORB_init([''], CORBA.ORB_ID) + + # create a LifeCycleCORBA instance + lcc = LifeCycleCORBA(orb) + + #create a naming service instance + naming_service = SALOME_NamingServicePy_i(orb) + + # get Container Manager + obj = naming_service.Resolve('/ContainerManager') + cm = obj._narrow(Engines.ContainerManager) + + return orb, lcc, naming_service, cm diff --git a/src/KERNEL_PY/salome_shared_modules.py b/src/KERNEL_PY/salome_shared_modules.py new file mode 100755 index 000000000..f74680985 --- /dev/null +++ b/src/KERNEL_PY/salome_shared_modules.py @@ -0,0 +1,92 @@ +# 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 : salome_shared_modules.py +# Module : SALOME + +from SALOME_utilities import * + +""" +This module with help of import_hook and *_shared_modules +filters imports when using the embedded Python interpretor. + +Some imports can't be done more than once. +This is related to the multi study feature that is implemented +by using the Python multi interpreter feature. +Some modules register objects or classes by calling modules +implemented in C. These operations can't be done multiple times. +So it's very important to control these imports. + +Examples: + - PyQt : import qt calls a C module to register classes + - OmniORB : import *_idl calls a C module to register CORBA interfaces + +Usage: + - First : the module salome_shared_modules is imported by main Python interpretor. + It will keep a dictionnary and a list that are shared among all + the subinterpretors and imports import_hook module that replaces + the standard import mechanism par one that prevents more than one import + for some modules identified by name (call register_name) or by a + validator (call register_pattern). + + Calls to register_name and register_pattern are done in modules named *_shared_modules + that could be found in the path SALOMEPATH + +""" +import glob,os,sys + +import import_hook +# shared_imported, patterns, register_name, register_pattern +# will be shared by all Python sub interpretors +from import_hook import shared_imported +from import_hook import patterns +from import_hook import register_name +from import_hook import register_pattern + +register_name("salome_shared_modules") + +# Get the SALOMEPATH if set or else use KERNEL_ROOT_DIR that should be set. +salome_path=os.environ.get("SALOMEPATH",os.getenv("KERNEL_ROOT_DIR")) + +list_modules=[] + +# Import all *_shared_modules in the path and store them in list_modules +path=salome_path.split(":") +for rep in path: + # Import all *_shared_modules in rep + for f in glob.glob(os.path.join(rep,"lib","python"+sys.version[:3],"site-packages","salome","shared_modules","*_shared_modules.py")): + try: + name=os.path.splitext(os.path.basename(f))[0] + register_name(name) + m=__import__(name) + list_modules.append(m) + except: + pass + +# +# If shared modules have been imported before installing import mechanism +# we add them to shared_imported +# +for name,module in sys.modules.items(): + if import_hook.is_shared(name) and shared_imported.get(name) is None: + #print "Module shared added to shared_imported: ",name + shared_imported[name]=module + diff --git a/src/KERNEL_PY/salome_study.py b/src/KERNEL_PY/salome_study.py new file mode 100644 index 000000000..f643e844b --- /dev/null +++ b/src/KERNEL_PY/salome_study.py @@ -0,0 +1,323 @@ +# 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 : salome_study.py +# Author : Paul RASCLE, EDF +# Module : SALOME +# $Header$ + +import salome_kernel +import SALOMEDS +import salome_iapp + +#-------------------------------------------------------------------------- + +def DumpComponent(Study, SO, offset): + it = Study.NewChildIterator(SO) + Builder = Study.NewBuilder() + while it.More(): + CSO = it.Value() + it.Next() + anAttr = Builder.FindOrCreateAttribute(CSO, "AttributeName") + AtName = anAttr._narrow(SALOMEDS.AttributeName) + t_name = AtName.Value() + if t_name[0] == 1: + ofs = 1 + a = "" + while ofs <= offset: + a = a + "--" + ofs = ofs +1 + MESSAGE( a + ">" + str(CSO.GetID()) + " " + str(t_name[1]) ) + t_RefSO = CSO.ReferencedObject() + if t_RefSO[0] == 1: + RefSO = t_RefSO[1] + ofs = 1 + a = "" + while ofs <= offset: + a = a + " " + ofs = ofs +1 + MESSAGE( a + ">" + str(RefSO.GetID()) ) + DumpComponent(Study, CSO, offset+2) + + #-------------------------------------------------------------------------- + +def DumpStudy(Study): + itcomp = Study.NewComponentIterator() + while itcomp.More(): + SC = itcomp.Value() + itcomp.Next() + name = SC.ComponentDataType() + MESSAGE( "-> ComponentDataType is " + name ) + DumpComponent(Study, SC, 1) + + + #-------------------------------------------------------------------------- + +def IDToObject(id): + myObj = None + mySO = myStudy.FindObjectID(id); + if mySO is not None: + ok, anAttr = mySO.FindAttribute("AttributeIOR") + if ok: + AtIOR = anAttr._narrow(SALOMEDS.AttributeIOR) + if AtIOR.Value() != "": + myObj = orb.string_to_object(AtIOR.Value()) + return myObj + +def ObjectToSObject(obj): + mySO = None + if obj is not None: + ior = orb.object_to_string(obj) + if ior != "": + mySO = myStudy.FindObjectIOR(ior) + return mySO + +def ObjectToID(obj): + mySO = ObjectToSObject(obj) + if mySO: + return mySO.GetID() + return "" + +def IDToSObject(id): + mySO = myStudy.FindObjectID(id); + return mySO + + #-------------------------------------------------------------------------- + +def generateName(prefix = None): + import whrandom; + int = whrandom.randint(1,1000); + if prefix is None: + return "Study" + str(int) + else : + return prefix + str(int) + + #-------------------------------------------------------------------------- + +def PersistentPresentation(theStudy, theSO, theWithID): + # put the sobject's content (with subchildren) to the string + aResult = "" + attrs = theSO.GetAllAttributes() + aLen = len(attrs) + anUncopied = 0 + for a in range(0,aLen): + attr = attrs[a] + if isinstance(attr,SALOMEDS._objref_AttributeTreeNode): + anUncopied += 1 + elif isinstance(attr,SALOMEDS._objref_AttributeTarget): + anUncopied += 1 + elif isinstance(attr,SALOMEDS._objref_AttributeReal) or \ + isinstance(attr,SALOMEDS._objref_AttributeInteger) or \ + isinstance(attr,SALOMEDS._objref_AttributeName) or \ + isinstance(attr,SALOMEDS._objref_AttributeComment) or \ + isinstance(attr,SALOMEDS._objref_AttributePersistentRef) or \ + isinstance(attr,SALOMEDS._objref_AttributeLocalID) or \ + isinstance(attr,SALOMEDS._objref_AttributeUserID): + aResult += " attribute value: " + str(attr.Value()) + elif isinstance(attr,SALOMEDS._objref_AttributeIOR): + aResult += " attribute: IOR" + elif isinstance(attr,SALOMEDS._objref_AttributeSequenceOfReal) or \ + isinstance(attr,SALOMEDS._objref_AttributeSequenceOfInteger): + aResult += " Sequence: " + str(attr.CorbaSequence()) + elif isinstance(attr,SALOMEDS._objref_AttributeDrawable): + aResult += " Drawable: " + str(attr.IsDrawable()) + elif isinstance(attr,SALOMEDS._objref_AttributeSelectable): + aResult += " Selectable: " + str(attr.IsSelectable()) + elif isinstance(attr,SALOMEDS._objref_AttributeExpandable): + aResult += " Expandable: " + str(attr.IsExpandable()) + elif isinstance(attr,SALOMEDS._objref_AttributeOpened): + aResult += " Opened: " + str(attr.IsOpened()) + elif isinstance(attr,SALOMEDS._objref_AttributeTextColor): + aResult += " TextColor: " + str(attr.TextColor()) + elif isinstance(attr,SALOMEDS._objref_AttributeTextHighlightColor): + aResult += " TextHighlightColor: " + str(attr.TextHighlightColor()) + elif isinstance(attr,SALOMEDS._objref_AttributePixMap): + aResult += " PixMap: " + str(attr.GetPixMap()) + elif isinstance(attr,SALOMEDS._objref_AttributeTableOfInteger) or \ + isinstance(attr,SALOMEDS._objref_AttributeTableOfReal): + aResult += " Table with title: " + attr.GetTitle() + elif isinstance(attr,SALOMEDS._objref_AttributePythonObject): + aResult += " PythonObject: " + attr.GetObject() + + if theWithID: + aResult = "sobject: " + theSO.GetID() + " nbattrs: " + str(aLen - anUncopied) + aResult + '\n' + else: + aResult = " nbattrs: " + str(aLen - anUncopied) + aResult + '\n' + anIter = theStudy.NewChildIterator(theSO) + while anIter.More(): + aResult += PersistentPresentation(theStudy, anIter.Value(), theWithID) + anIter.Next() + return aResult + + #-------------------------------------------------------------------------- + +def GetTree(theSO): + # returns the document list tree (as list) + aResult = [theSO.GetID()] + anIter = myStudy.NewChildIterator(theSO) + while anIter.More(): + aResult += GetTree(anIter.Value()) + anIter.Next() + return aResult + + #-------------------------------------------------------------------------- + +def CheckCopyPaste(theSO, theInfo ,theComponentPaste): + aRoot = theSO + while aRoot.GetID() != "0:": + aRoot = aRoot.GetFather() + aTree = GetTree(aRoot) + aStudyPersist = PersistentPresentation(myStudy, aRoot, 1) + + if not myStudyManager.CanCopy(theSO): + raise RuntimeError, " for "+theInfo+" returns false" + + if not myStudyManager.Copy(theSO): + raise RuntimeError, " for "+theInfo+" returns false" + + + if not myStudyManager.CanPaste(theSO): + raise RuntimeError, " for "+theInfo+" returns false" + + # check: before paste study is not changed check + if aStudyPersist != PersistentPresentation(myStudy, aRoot, 1): + raise RuntimeError, "Study is changed before Paste calling for "+theInfo + + aSObj = theSO + if theComponentPaste: + aSObj = theSO.GetFatherComponent() + theInfo = theInfo + "(paste for component)" + if myStudyManager.Paste(aSObj) == None: + raise RuntimeError, " for "+theInfo+" returns None object" + aNewTree = GetTree(aRoot) + aLen = len(aTree) + for a in range(0,aLen): + if aTree[a] != aNewTree[a]: + return myStudy.FindObjectID(aNewTree[a]) + + if aLen < len(aNewTree): + return myStudy.FindObjectID(aNewTree[aLen]) + + raise RuntimeError, "After Copy calling the tree is not changed" + + #-------------------------------------------------------------------------- + +def FindFileInDataDir(filename): + import os + datadir = os.getenv("DATA_DIR") + if datadir is not None: + import string + dirs = string.split(datadir, ":") + for dir in dirs: + file = dir + "/" + filename + if os.path.exists(file): + return file; + datadir = os.getenv("KERNEL_ROOT_DIR") + "/examples/" + file = datadir + filename + if os.path.exists(file): + return file; + + return None + + #-------------------------------------------------------------------------- + +salome_study_ID = -1 + +def getActiveStudy(theStudyId=0): + global salome_study_ID + + print "getActiveStudy" + sg = salome_iapp.salome_iapp_init() + if salome_study_ID == -1: + if sg.hasDesktop(): + print "---in gui" + salome_study_ID = sg.getActiveStudyId() + else: + print "---outside gui" + if theStudyId: + aStudy=myStudyManager.GetStudyByID(theStudyId) + if aStudy: + print "connection to existing study ", theStudyId + salome_study_ID = theStudyId + if salome_study_ID == -1: + salome_study_ID = createNewStudy() + print"--- Study Id ", salome_study_ID + return salome_study_ID + + #-------------------------------------------------------------------------- + +def createNewStudy(): + print "createNewStudy" + i=1 + aStudyName = "noName" + nameAlreadyInUse = 1 + listOfOpenStudies = myStudyManager.GetOpenStudies() + print listOfOpenStudies + while nameAlreadyInUse: + aStudyName = "extStudy_%d"%i + if aStudyName not in listOfOpenStudies: + nameAlreadyInUse=0 + else: + i = i+1 + + theStudy = myStudyManager.NewStudy(aStudyName) + theStudyId = theStudy._get_StudyId() + print aStudyName, theStudyId + return theStudyId + + #-------------------------------------------------------------------------- + +salome_study_initial = 1 + +def salome_study_init(theStudyId=0): + """ + Performs only once study creation or connection. + optional argument : theStudyId + When in embedded interpreter inside IAPP, theStudyId is not used + When used without GUI (external interpreter) + 0 : create a new study (default). + n (>0) : try connection to study with Id = n, or create a new one + if study not found. + """ + + global salome_study_initial + global myStudyManager, myStudyId, myStudy, myStudyName + global orb, lcc, naming_service, cm + + if salome_study_initial: + salome_study_initial = 0 + + orb, lcc, naming_service, cm = salome_kernel.salome_kernel_init() + + # get Study Manager reference + print "looking for studyManager ..." + obj = naming_service.Resolve('myStudyManager') + myStudyManager = obj._narrow(SALOMEDS.StudyManager) + print "studyManager found" + + # get active study Id, ref and name + myStudyId = getActiveStudy(theStudyId) + print "myStudyId",myStudyId + myStudy = myStudyManager.GetStudyByID(myStudyId) + myStudyName = myStudy._get_Name() + + return myStudyManager, myStudyId, myStudy, myStudyName + diff --git a/src/KERNEL_PY/salome_test.py b/src/KERNEL_PY/salome_test.py new file mode 100755 index 000000000..a1e63a6cc --- /dev/null +++ b/src/KERNEL_PY/salome_test.py @@ -0,0 +1,486 @@ +# SALOME SALOME_SWIG : binding of C++ implementation and Python +# +# Copyright (C) 2003 CEA/DEN, EDF R&D +# +# +# +# File : salome_test.py +# Module : SALOME + +print "Test the application loading GEOM, SMESH, VISU, MED, components and doing some" +print "operation within the components." + +import salome +from salome import sg +import SALOMEDS +import os + +import SALOME_ModuleCatalog + +print "======================================================================" +print " Get Catalog " +print "======================================================================" +obj = salome.naming_service.Resolve('Kernel/ModulCatalog') +catalog = obj._narrow(SALOME_ModuleCatalog.ModuleCatalog) + +print "======================================================================" +print " Create Study " +print "======================================================================" + +comp = catalog.GetComponent("GEOM") +if comp is None: + raise RuntimeError,"Component GEOM not found in Module Catalog." + +import geompy + +print "=================================" +print " create AttributeReal " +print "=================================" +A = geompy.myBuilder.FindOrCreateAttribute(geompy.father, "AttributeReal") +if A == None : + raise RuntimeError, "Can't create AttributeReal attribute" +A = A._narrow(SALOMEDS.AttributeReal) +A.SetValue(0.0001) +if A.Value() != 0.0001: + raise RuntimeError, "Error : wrong value of AttributeReal" + +print +print " =========== Test Geometry ==========================" +print + +print "===================================" +print " define a box" +print "===================================" + +box = geompy.MakeBox(0., 0., 0., 100., 200., 300.) +idbox = geompy.addToStudy(box,"box") + +print +print "============= Test SMESH =============================" +print + +import StdMeshers + +comp = catalog.GetComponent("SMESH") +if comp is None: + raise RuntimeError,"Component SMESH not found in Module Catalog." + +comp = catalog.GetComponent("MED") +if comp is None: + raise RuntimeError,"Component MED not found in Module Catalog." + +import SMESH + +geom = salome.lcc.FindOrLoadComponent("FactoryServer", "GEOM") +myBuilder = salome.myStudy.NewBuilder() + +smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH") +smeshgui = salome.ImportComponentGUI("SMESH") +smeshgui.Init(salome.myStudyId); + +ShapeTypeCompSolid = 1 +ShapeTypeSolid = 2 +ShapeTypeShell = 3 +ShapeTypeFace = 4 +ShapeTypeWire = 5 +ShapeTypeEdge = 6 +ShapeTypeVertex = 7 + +# ---- define a box + +box = geompy.MakeBox(0., 0., 0., 100., 200., 300.) +idbox = geompy.addToStudy(box,"box") + +# ---- add first face of box in study + +subShapeList=geompy.SubShapeAll(box,ShapeTypeFace) +face=subShapeList[0] +name = geompy.SubShapeName(face, box) +print name +idface=geompy.addToStudyInFather(box,face,name) + +# ---- add shell from box in study + +subShellList=geompy.SubShapeAll(box,ShapeTypeShell) +shell = subShellList[0] +name = geompy.SubShapeName(shell, box) +print name +idshell=geompy.addToStudyInFather(box,shell,name) + +# ---- add first edge of face in study + +edgeList = geompy.SubShapeAll(face,ShapeTypeEdge) +edge=edgeList[0]; +name = geompy.SubShapeName(edge, face) +print name +idedge=geompy.addToStudyInFather(face,edge,name) + + +# ---- SMESH + +# ---- create Hypothesis + +print "-------------------------- create Hypothesis" +print "-------------------------- LocalLength" +hypLen1 = smesh.CreateHypothesis( "LocalLength", "libStdMeshersEngine.so" ) +hypLen1.SetLength(100) +print hypLen1.GetName() +print hypLen1.GetId() +print hypLen1.GetLength() + +smeshgui.SetName(salome.ObjectToID(hypLen1), "Local_Length_100") + +print "-------------------------- NumberOfSegments" +hypNbSeg1= smesh.CreateHypothesis( "NumberOfSegments", "libStdMeshersEngine.so" ) +hypNbSeg1.SetNumberOfSegments(7) +print hypNbSeg1.GetName() +print hypNbSeg1.GetId() +print hypNbSeg1.GetNumberOfSegments() + +smeshgui.SetName(salome.ObjectToID(hypNbSeg1), "NumberOfSegments_7") + +print "-------------------------- MaxElementArea" +hypArea1 = smesh.CreateHypothesis( "MaxElementArea", "libStdMeshersEngine.so" ) +hypArea1.SetMaxElementArea(2500) +print hypArea1.GetName() +print hypArea1.GetId() +print hypArea1.GetMaxElementArea() + +smeshgui.SetName(salome.ObjectToID(hypArea1), "MaxElementArea_2500") + +print "-------------------------- MaxElementArea" +hypArea2 = smesh.CreateHypothesis( "MaxElementArea", "libStdMeshersEngine.so" ) +hypArea2.SetMaxElementArea(500) +print hypArea2.GetName() +print hypArea2.GetId() +print hypArea2.GetMaxElementArea() + +smeshgui.SetName(salome.ObjectToID(hypArea2), "MaxElementArea_500") + +print "-------------------------- Regular_1D" +algoReg = smesh.CreateHypothesis( "Regular_1D", "libStdMeshersEngine.so" ) +listHyp=algoReg.GetCompatibleHypothesis() +for hyp in listHyp: + print hyp +print algoReg.GetName() +print algoReg.GetId() + +smeshgui.SetName(salome.ObjectToID(algoReg), "Regular_1D" ) + +print "-------------------------- MEFISTO_2D" +algoMef = smesh.CreateHypothesis( "MEFISTO_2D", "libStdMeshersEngine.so" ) +listHyp=algoMef.GetCompatibleHypothesis() +for hyp in listHyp: + print hyp +print algoMef.GetName() +print algoMef.GetId() + +smeshgui.SetName(salome.ObjectToID(algoMef), "MEFISTO_2D" ) + +# ---- add hypothesis to box + +print "-------------------------- add hypothesis to box" +box=salome.IDToObject(idbox) +mesh = smesh.CreateMesh(box) + +smeshgui.SetName( salome.ObjectToID(mesh), "MeshBox" ); + +ret=mesh.AddHypothesis(box,algoReg) +print ret +ret=mesh.AddHypothesis(box,algoMef) +print ret + + +ret=mesh.AddHypothesis(box,hypNbSeg1) +print ret +ret=mesh.AddHypothesis(box,hypArea1) +print ret + + +# ---- add hypothesis to edge + +print "-------------------------- add hypothesis to edge" +edge=salome.IDToObject(idedge) +submesh=mesh.GetSubMesh(edge, "SubMeshEdge") + +ret=mesh.AddHypothesis(edge,algoReg) +print ret +ret=mesh.AddHypothesis(edge,hypLen1) +print ret + +print "-------------------------- add hypothesis to face" +face=salome.IDToObject(idface) +submesh = mesh.GetSubMesh(face, "SubMeshFace") + +ret=mesh.AddHypothesis(face,hypArea2) +print ret + +smesh.Compute(mesh, box) +sg.updateObjBrowser(1); + +print +print "============= Test Supervisor =============================" +print + +comp = catalog.GetComponent("SUPERV") +if comp is None: + raise RuntimeError,"Component SUPERV not found in Module Catalog." + +from SuperV import * +import SALOMEDS +myStudy = salome.myStudy +myBuilder = myStudy.NewBuilder() + +SuperVision = lcc.FindOrLoadComponent("SuperVisionContainer","SUPERV") +father = myStudy.FindComponent("SUPERV") +if father is None: + father = myBuilder.NewComponent("SUPERV") + A1 = myBuilder.FindOrCreateAttribute(father, "AttributeName"); + FName = A1._narrow(SALOMEDS.AttributeName) + FName.SetValue( salome.sg.getComponentUserName("SUPERV") ) + A2 = myBuilder.FindOrCreateAttribute(father, "AttributePixMap"); + aPixmap = A2._narrow(SALOMEDS.AttributePixMap); + aPixmap.SetPixMap( "ICON_OBJBROWSER_Supervision" ); + myBuilder.DefineComponentInstance(father,SuperVision) + +def addStudy(ior): + dataflow = SuperVision.getStreamGraph(ior) + name=dataflow.Name() + itr = myStudy.NewChildIterator(father) + while itr.More(): + item=itr.Value() + res,A=item.FindAttribute("AttributeName") + if res: + aName = A._narrow(SALOMEDS.AttributeName) + if aName.Value() == name : + print myBuilder.FindOrCreateAttribute(item, "AttributeIOR") + A = myBuilder.FindOrCreateAttribute(item, "AttributeIOR") + print "A = ", A + if A is not None : + #res,A = myBuilder.FindOrCreateAttribute(item, "AttributeIOR") + anIOR = A._narrow(SALOMEDS.AttributeIOR); + print "anIOR.SetValue(dataflow.getIOR())" + anIOR.SetValue(dataflow.getIOR()) + return + itr.Next() + obj = myBuilder.NewObject(father) + A=myBuilder.FindOrCreateAttribute(obj, "AttributeName") + aName=A._narrow(SALOMEDS.AttributeName) + aName.SetValue(name) + A=myBuilder.FindOrCreateAttribute(obj, "AttributeIOR") + anIOR = A._narrow(SALOMEDS.AttributeIOR) + anIOR.SetValue(dataflow.getIOR()) + +import os +dir= os.getenv("SUPERV_ROOT_DIR") +if dir == None: + raise RuntimeError, "SUPERV_ROOT_DIR is not defined" +xmlfile = dir +"/examples/GraphGeomEssai.xml" +print "Load dataflow from the file : " +print xmlfile +print + +myGraph = StreamGraph ( xmlfile ) + +# This DataFlow is "valid" : no loop, correct links between Nodes etc... +print "myGraph.IsValid() = ", myGraph.IsValid() + +# Get Nodes +myGraph.PrintNodes() + +# This DataFlow is "executable" : all pending Ports are defined with Datas +print myGraph.IsExecutable() + +# Starts only execution of that DataFlow and gets control immediatly +print myGraph.Run() + +# That DataFlow is running ==> 0 (false) +print myGraph.IsDone() + +# Events of execution : +aStatus,aNode,anEvent,aState = myGraph.Event() +while aStatus : + print aNode.Thread(),aNode.SubGraph(),aNode.Name(),anEvent,aState + aStatus,aNode,anEvent,aState = myGraph.Event() +print "myGraph.IsDone() = ",myGraph.IsDone() + +# Wait for Completion (but it is already done after event loop ...) +print "Done : ",myGraph.DoneW() + +print " " +#print "Type : print myGraph.IsDone()" +#print " If execution is finished ==> 1 (true)" +res=myGraph.IsDone() +if res != 1: + raise RuntimeError, "myGraph.Run() is not done" + +print " " +print "Type : myGraph.PrintPorts()" +print " to see input and output values of the graph" +myGraph.PrintPorts() + +# Export will create newsupervisionexample.xml and the corresponding .py file +tmpdir=os.getenv("TmpDir") +if tmpdir is None: + tmpdir="/tmp" +file = tmpdir + "/newsupervisionexample" +print "--------------\n"+file+"\n--------------\n" +myGraph.Export(file) + +ior = salome.orb.object_to_string(myGraph.G) +addStudy(ior) + +GraphName = myGraph.Name() +print "Befor save ", +#nodes = myGraph.Nodes() +nodes = myGraph.G.Nodes().FNodes +length_bs = len(nodes) +print "ListOfNodes length = ", length_bs +names=[] +for node in nodes: + names.append(node.Name()) +print names + +# Graph creation +GraphInLines = StreamGraph( 'GraphInLines' ) +GraphInLines.SetName( 'GraphInLines' ) +GraphInLines.SetAuthor( '' ) +GraphInLines.SetComment( '' ) +GraphInLines.Coords( 0 , 0 ) + +# Creation of InLine Nodes +PyAdd = [] +PyAdd.append( 'def Add(a,b) : ' ) +PyAdd.append( ' return a+b ' ) +PyAdd.append( '' ) +Add = GraphInLines.INode( 'Add' , PyAdd ) +Add.InPort( 'a' , 'long' ) +Add.InPort( 'b' , 'long' ) +Add.OutPort( 'f' , 'long' ) +Add.SetName( 'Add' ) +Add.SetAuthor( '' ) +Add.SetComment( 'Python function' ) +Add.Coords( 351 , 77 ) +PySub = [] +PySub.append( 'def Sub(a,b) : ' ) +PySub.append( ' return a-b ' ) +PySub.append( '' ) +Sub = GraphInLines.INode( 'Sub' , PySub ) +Sub.InPort( 'a' , 'long' ) +Sub.InPort( 'b' , 'long' ) +Sub.OutPort( 'f' , 'long' ) +Sub.SetName( 'Sub' ) +Sub.SetAuthor( '' ) +Sub.SetComment( 'Python function' ) +Sub.Coords( 86 , 333 ) +PyMul = [] +PyMul.append( 'def Mul(a,b) : ' ) +PyMul.append( ' return a*b ' ) +Mul = GraphInLines.INode( 'Mul' , PyMul ) +Mul.InPort( 'a' , 'long' ) +Mul.InPort( 'b' , 'long' ) +Mul.OutPort( 'Result' , 'long' ) +Mul.SetName( 'Mul' ) +Mul.SetAuthor( '' ) +Mul.SetComment( 'Python function' ) +Mul.Coords( 616 , 247 ) + +# Creation of intermediate Output variables and of Control Links +Addf = Add.Port( 'f' ) +Mula = GraphInLines.Link( Addf , Mul.Port( 'a' ) ) +Mula.AddCoord( 1 , 570 , 356 ) +Mula.AddCoord( 2 , 570 , 186 ) +Subf = Sub.Port( 'f' ) +Mulb = GraphInLines.Link( Subf , Mul.Port( 'b' ) ) +Mulb.AddCoord( 1 , 282 , 376 ) +Mulb.AddCoord( 2 , 282 , 442 ) +Addb = GraphInLines.Link( Subf , Add.Port( 'b' ) ) +Addb.AddCoord( 1 , 283 , 209 ) +Addb.AddCoord( 2 , 283 , 374 ) +Addb.AddCoord( 3 , 283 , 442 ) + +# Creation of Input datas +Adda = Add.Input( 'a' , 1) +Suba = Sub.Input( 'a' , 3) +Subb = Sub.Input( 'b' , 4) + +# Creation of Output variables +MulResult = Mul.Port( 'Result' ) + +GraphInLines.Run() + +GraphInLines.DoneW() + +GraphInLines.PrintPorts() + +sg.updateObjBrowser(1); + +print +print "============= Test VISU and MED =============================" +print + +comp = catalog.GetComponent("VISU") +if comp is None: + raise RuntimeError,"Component VISU not found in Module Catalog." + +import sys +import SALOMEDS +import SALOME +import SALOME_MED +import VISU + +import visu_gui + +medFileName = "pointe.med" +medFile = os.getenv('KERNEL_ROOT_DIR') + '/examples/' + medFileName +print "Load ", medFile + +studyCurrent = salome.myStudyName + +med_comp = salome.lcc.FindOrLoadComponent("FactoryServer", "MED") +myVisu = salome.lcc.FindOrLoadComponent("FactoryServer", "VISU") + +try: + if os.access(medFile, os.R_OK) : + if not os.access(medFile, os.W_OK) : + import random + medFileNew = "/tmp/" + str(random.randint(0,1000000)) + "_" + medFileName + print " -- Copy " + medFile + " to " + medFileNew + os.system("cp "+ medFile + " " + medFileNew) + medFile = medFileNew + os.system("chmod 755 " + medFile) + + if os.access(medFile, os.W_OK) : + med_comp.readStructFileWithFieldType(medFile,studyCurrent) + med_obj = visu_gui.visu.getMedObjectFromStudy() + print "med_obj - ", med_obj + + myField1 = visu_gui.visu.getFieldObjectFromStudy(2,1) + aMeshName = "maa1" + anEntity = VISU.NODE + aTimeStampId = -1 + + myResult1 = myVisu.ImportMedField(myField1) + aMesh1 = myVisu.MeshOnEntity(myResult1, aMeshName, anEntity); + + aScalarMap1= myVisu.ScalarMapOnField(myResult1, aMeshName, anEntity, myField1.getName(), aTimeStampId) + + myResult2 = myVisu.ImportFile(medFile); + aMesh2 = myVisu.MeshOnEntity(myResult2, aMeshName, anEntity); + + aTimeStampId = 3 + aScalarMap2= myVisu.ScalarMapOnField(myResult2, aMeshName, anEntity, myField1.getName(), aTimeStampId) + + sg.updateObjBrowser(0) + else : print "We have no permission to rewrite medFile, so readStructFileWithFieldType can't open this file"; + else : print "We have no permission to read medFile, it will not be opened"; + +except: + if sys.exc_type == SALOME.SALOME_Exception : + print "There is no permission to read " + medFile + else : + print sys.exc_type + print sys.exc_value + print sys.exc_traceback + +sg.updateObjBrowser(1); diff --git a/src/SALOMEDSClient/Makefile.in b/src/SALOMEDSClient/Makefile.in new file mode 100644 index 000000000..c3c92b5e2 --- /dev/null +++ b/src/SALOMEDSClient/Makefile.in @@ -0,0 +1,55 @@ +# File : Makefile.in +# Author : Sergey RUIN +# Module : SALOME + +top_srcdir=@top_srcdir@ +top_builddir=../.. +srcdir=@srcdir@ +VPATH=.:@srcdir@:@top_srcdir@/idl:$(top_srcdir)/idl + + +@COMMENCE@ + +EXPORT_HEADERS= SALOMEDSClient_definitions.hxx \ + SALOMEDSClient_AttributeComment.hxx \ + SALOMEDSClient_AttributeDrawable.hxx \ + SALOMEDSClient_AttributeExpandable.hxx \ + SALOMEDSClient_AttributeExternalFileDef.hxx \ + SALOMEDSClient_AttributeFileType.hxx \ + SALOMEDSClient_AttributeFlags.hxx \ + SALOMEDSClient_AttributeGraphic.hxx \ + SALOMEDSClient_AttributeIOR.hxx \ + SALOMEDSClient_AttributeInteger.hxx \ + SALOMEDSClient_AttributeLocalID.hxx \ + SALOMEDSClient_AttributeName.hxx \ + SALOMEDSClient_AttributeOpened.hxx \ + SALOMEDSClient_AttributePersistentRef.hxx \ + SALOMEDSClient_AttributePixMap.hxx \ + SALOMEDSClient_AttributePythonObject.hxx \ + SALOMEDSClient_AttributeReal.hxx \ + SALOMEDSClient_AttributeSelectable.hxx \ + SALOMEDSClient_AttributeSequenceOfInteger.hxx \ + SALOMEDSClient_AttributeSequenceOfReal.hxx \ + SALOMEDSClient_AttributeStudyProperties.hxx \ + SALOMEDSClient_AttributeTableOfInteger.hxx \ + SALOMEDSClient_AttributeTableOfReal.hxx \ + SALOMEDSClient_AttributeTableOfString.hxx \ + SALOMEDSClient_AttributeTarget.hxx \ + SALOMEDSClient_AttributeTextColor.hxx \ + SALOMEDSClient_AttributeTextHighlightColor.hxx \ + SALOMEDSClient_AttributeTreeNode.hxx \ + SALOMEDSClient_AttributeUserID.hxx \ + SALOMEDSClient_ChildIterator.hxx \ + SALOMEDSClient_GenericAttribute.hxx \ + SALOMEDSClient_SComponent.hxx \ + SALOMEDSClient_SComponentIterator.hxx \ + SALOMEDSClient_SObject.hxx \ + SALOMEDSClient_Study.hxx \ + SALOMEDSClient_StudyBuilder.hxx \ + SALOMEDSClient_StudyManager.hxx \ + SALOMEDSClient_UseCaseBuilder.hxx \ + SALOMEDSClient_UseCaseIterator.hxx \ + SALOMEDSClient.hxx + +@CONCLUDE@ + diff --git a/src/SALOMEDSClient/SALOMEDSClient.hxx b/src/SALOMEDSClient/SALOMEDSClient.hxx new file mode 100644 index 000000000..e64da148c --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient.hxx @@ -0,0 +1,44 @@ +#ifndef SALOMEDSCLIENT_HXX +#define SALOMEDSCLIENT_HXX + +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_AttributeComment.hxx" +#include "SALOMEDSClient_AttributeDrawable.hxx" +#include "SALOMEDSClient_AttributeExpandable.hxx" +#include "SALOMEDSClient_AttributeExternalFileDef.hxx" +#include "SALOMEDSClient_AttributeFileType.hxx" +#include "SALOMEDSClient_AttributeFlags.hxx" +#include "SALOMEDSClient_AttributeGraphic.hxx" +#include "SALOMEDSClient_AttributeIOR.hxx" +#include "SALOMEDSClient_AttributeInteger.hxx" +#include "SALOMEDSClient_AttributeLocalID.hxx" +#include "SALOMEDSClient_AttributeName.hxx" +#include "SALOMEDSClient_AttributeOpened.hxx" +#include "SALOMEDSClient_AttributePersistentRef.hxx" +#include "SALOMEDSClient_AttributePixMap.hxx" +#include "SALOMEDSClient_AttributePythonObject.hxx" +#include "SALOMEDSClient_AttributeReal.hxx" +#include "SALOMEDSClient_AttributeSelectable.hxx" +#include "SALOMEDSClient_AttributeSequenceOfInteger.hxx" +#include "SALOMEDSClient_AttributeSequenceOfReal.hxx" +#include "SALOMEDSClient_AttributeStudyProperties.hxx" +#include "SALOMEDSClient_AttributeTableOfInteger.hxx" +#include "SALOMEDSClient_AttributeTableOfReal.hxx" +#include "SALOMEDSClient_AttributeTableOfString.hxx" +#include "SALOMEDSClient_AttributeTarget.hxx" +#include "SALOMEDSClient_AttributeTextColor.hxx" +#include "SALOMEDSClient_AttributeTextHighlightColor.hxx" +#include "SALOMEDSClient_AttributeTreeNode.hxx" +#include "SALOMEDSClient_AttributeUserID.hxx" +#include "SALOMEDSClient_ChildIterator.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" +#include "SALOMEDSClient_SComponent.hxx" +#include "SALOMEDSClient_SComponentIterator.hxx" +#include "SALOMEDSClient_SObject.hxx" +#include "SALOMEDSClient_Study.hxx" +#include "SALOMEDSClient_StudyBuilder.hxx" +#include "SALOMEDSClient_StudyManager.hxx" +#include "SALOMEDSClient_UseCaseBuilder.hxx" +#include "SALOMEDSClient_UseCaseIterator.hxx" + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeComment.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeComment.hxx new file mode 100644 index 000000000..2f01b00c7 --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeComment.hxx @@ -0,0 +1,19 @@ +// File : SALOMEDSClient_AttributeComment.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef SALOMEDSClient_AttributeComment_HeaderFile +#define SALOMEDSClient_AttributeComment_HeaderFile + +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" +#include + +class SALOMEDSClient_AttributeComment: public virtual SALOMEDSClient_GenericAttribute +{ +public: + virtual std::string Value() = 0; + virtual void SetValue(const std::string& value) = 0; +}; + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeDrawable.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeDrawable.hxx new file mode 100644 index 000000000..b5d424af8 --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeDrawable.hxx @@ -0,0 +1,18 @@ +// File : SALOMEDSClient_AttributeDrawable.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef SALOMEDSClient_AttributeDrawable_HeaderFile +#define SALOMEDSClient_AttributeDrawable_HeaderFile + +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" + +class SALOMEDSClient_AttributeDrawable: public virtual SALOMEDSClient_GenericAttribute +{ +public: + virtual bool IsDrawable() = 0; + virtual void SetDrawable(bool value) = 0; +}; + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeExpandable.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeExpandable.hxx new file mode 100644 index 000000000..e16aa10cd --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeExpandable.hxx @@ -0,0 +1,21 @@ +// File : SALOMEDSClient_AttributeExpandable.hxx +// Author : Sergey RUIN +// Module : SALOME +// $Header: + +#ifndef SALOMEDSClient_AttributeExpandable_HeaderFile +#define SALOMEDSClient_AttributeExpandable_HeaderFile + +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" + +class SALOMEDSClient_AttributeExpandable: public virtual SALOMEDSClient_GenericAttribute +{ +public: + virtual bool IsExpandable() = 0; + virtual void SetExpandable(bool value) = 0; +}; + + + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeExternalFileDef.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeExternalFileDef.hxx new file mode 100644 index 000000000..c2b6bba76 --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeExternalFileDef.hxx @@ -0,0 +1,21 @@ +// File : SALOMEDSClient_AttributeExternalFileDef.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef SALOMEDSClient_AttributeExternalFileDef_HeaderFile +#define SALOMEDSClient_AttributeExternalFileDef_HeaderFile + +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" +#include + +class SALOMEDSClient_AttributeExternalFileDef: public virtual SALOMEDSClient_GenericAttribute +{ +public: + virtual std::string Value() = 0; + virtual void SetValue(const std::string& value) = 0; +}; + + + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeFileType.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeFileType.hxx new file mode 100644 index 000000000..cc2077398 --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeFileType.hxx @@ -0,0 +1,22 @@ +// File : SALOMEDSClient_AttributeFileType.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef SALOMEDSClient_AttributeFileType_HeaderFile +#define SALOMEDSClient_AttributeFileType_HeaderFile + +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" +#include + +class SALOMEDSClient_AttributeFileType: public virtual SALOMEDSClient_GenericAttribute +{ +public: + virtual std::string Value() = 0; + virtual void SetValue(const std::string& value) = 0; + +}; + + + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeFlags.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeFlags.hxx new file mode 100644 index 000000000..712fd2f0d --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeFlags.hxx @@ -0,0 +1,24 @@ +// File : SALOMEDSClient_AttributeFlags.hxx +// Author : Sergey RUIN +// Module : SALOME +// $Header: + +#ifndef SALOMEDSClient_AttributeFlags_HeaderFile +#define SALOMEDSClient_AttributeFlags_HeaderFile + +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" + +class SALOMEDSClient_AttributeFlags: public virtual SALOMEDSClient_GenericAttribute +{ +public: + + virtual int GetFlags() = 0; + virtual void SetFlags(int theFlags) = 0; + + virtual bool Get(int theFlag) = 0; + virtual void Set(int theFlag, bool theValue) = 0; + +}; + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeGraphic.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeGraphic.hxx new file mode 100644 index 000000000..3de00de92 --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeGraphic.hxx @@ -0,0 +1,21 @@ +// File : SALOMEDSClient_AttributeFlags.hxx +// Author : Sergey RUIN +// Module : SALOME +// $Header: + +#ifndef SALOMEDSClient_AttributeGraphic_HeaderFile +#define SALOMEDSClient_AttributeGraphic_HeaderFile + +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" + +class SALOMEDSClient_AttributeGraphic: public virtual SALOMEDSClient_GenericAttribute +{ +public: + + virtual void SetVisibility(int theViewId, bool theValue) = 0; + virtual bool GetVisibility(int theViewId) = 0; + +}; + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeIOR.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeIOR.hxx new file mode 100644 index 000000000..920f97f30 --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeIOR.hxx @@ -0,0 +1,22 @@ +// File : SALOMEDSClient_AttributeIOR.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef SALOMEDSClient_AttributeIOR_HeaderFile +#define SALOMEDSClient_AttributeIOR_HeaderFile + +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" +#include + +class SALOMEDSClient_AttributeIOR: public virtual SALOMEDSClient_GenericAttribute +{ +public: + + virtual std::string Value() = 0; + virtual void SetValue(const std::string& value) = 0; + +}; + + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeInteger.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeInteger.hxx new file mode 100644 index 000000000..1b177df19 --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeInteger.hxx @@ -0,0 +1,21 @@ +// File : SALOMEDSClient_AttributeInteger.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef SALOMEDSClient_AttributeInteger_HeaderFile +#define SALOMEDSClient_AttributeInteger_HeaderFile + +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" + +class SALOMEDSClient_AttributeInteger: public virtual SALOMEDSClient_GenericAttribute +{ +public: + + virtual int Value() = 0; + virtual void SetValue(int value) = 0; +}; + + + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeLocalID.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeLocalID.hxx new file mode 100644 index 000000000..705b490c7 --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeLocalID.hxx @@ -0,0 +1,22 @@ +// File : SALOMEDSClient_AttributeLocalID.hxx +// Author : Sergey RUIN +// Module : SALOME +// $Header: + +#ifndef SALOMEDSClient_AttributeLocalID_HeaderFile +#define SALOMEDSClient_AttributeLocalID_HeaderFile + +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" + +class SALOMEDSClient_AttributeLocalID: public virtual SALOMEDSClient_GenericAttribute +{ +public: + virtual int Value() = 0; + virtual void SetValue(int value) = 0; + +}; + + + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeName.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeName.hxx new file mode 100644 index 000000000..1d19e84c5 --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeName.hxx @@ -0,0 +1,25 @@ +// File : SALOMEDSClient_AttributeName.hxx +// Author : Sergey RUIN +// Module : SALOME +// $Header: + +#ifndef SALOMEDSClient_AttributeName_HeaderFile +#define SALOMEDSClient_AttributeName_HeaderFile + +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" +#include + +class SALOMEDSClient_AttributeName: public virtual SALOMEDSClient_GenericAttribute +{ +public: + + virtual std::string Value() = 0; + virtual void SetValue(const std::string& value) = 0; + +}; + + + + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeOpened.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeOpened.hxx new file mode 100644 index 000000000..fb9266d99 --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeOpened.hxx @@ -0,0 +1,22 @@ +// File : SALOMEDSClient_AttributeOpened.hxx +// Author : Sergey RUIN +// Module : SALOME +// $Header: + +#ifndef SALOMEDSClient_AttributeOpened_HeaderFile +#define SALOMEDSClient_AttributeOpened_HeaderFile + +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" + +class SALOMEDSClient_AttributeOpened: public virtual SALOMEDSClient_GenericAttribute +{ +public: + + virtual bool IsOpened() = 0; + virtual void SetOpened(bool value) = 0; +}; + + + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributePersistentRef.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributePersistentRef.hxx new file mode 100644 index 000000000..6efa09cdc --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributePersistentRef.hxx @@ -0,0 +1,23 @@ +// File : SALOMEDSClient_AttributePersistentRef.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef SALOMEDSClient_AttributePersistentRef_HeaderFile +#define SALOMEDSClient_AttributePersistentRef_HeaderFile + +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" +#include + +class SALOMEDSClient_AttributePersistentRef: public virtual SALOMEDSClient_GenericAttribute +{ +public: + + virtual std::string Value() = 0; + virtual void SetValue(const std::string& value) = 0; + +}; + + + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributePixMap.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributePixMap.hxx new file mode 100644 index 000000000..530380ea2 --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributePixMap.hxx @@ -0,0 +1,23 @@ +// File : SALOMEDSClient_AttributePixMap.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef SALOMEDSClient_AttributePixMap_HeaderFile +#define SALOMEDSClient_AttributePixMap_HeaderFile + +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" +#include + +class SALOMEDSClient_AttributePixMap: public virtual SALOMEDSClient_GenericAttribute +{ +public: + + virtual bool HasPixMap() = 0; + virtual std::string GetPixMap() = 0; + virtual void SetPixMap(const std::string& value) = 0; + +}; + + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributePythonObject.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributePythonObject.hxx new file mode 100644 index 000000000..ee0318bcd --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributePythonObject.hxx @@ -0,0 +1,25 @@ +// File : SALOMEDSClient_AttributePythonObject.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef SALOMEDSClient_AttributePythonObject_HeaderFile +#define SALOMEDSClient_AttributePythonObject_HeaderFile + +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" +#include + +class SALOMEDSClient_AttributePythonObject: public virtual SALOMEDSClient_GenericAttribute +{ +public: + + virtual void SetObject(const std::string& theSequence, bool IsScript) = 0; + virtual std::string GetObject() = 0; + virtual bool IsScript() = 0; + +}; + + + + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeReal.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeReal.hxx new file mode 100644 index 000000000..e5360aa2b --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeReal.hxx @@ -0,0 +1,20 @@ +// File : SALOMEDSClient_AttributeReal.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef SALOMEDSClient_AttributeReal_HeaderFile +#define SALOMEDSClient_AttributeReal_HeaderFile + +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" + +class SALOMEDSClient_AttributeReal: public virtual SALOMEDSClient_GenericAttribute +{ +public: + + virtual double Value() = 0; + virtual void SetValue(double value) = 0; +}; + + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeSelectable.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeSelectable.hxx new file mode 100644 index 000000000..257860e51 --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeSelectable.hxx @@ -0,0 +1,22 @@ +// File : SALOMEDSClient_AttributeSelectable.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef SALOMEDSClient_AttributeSelectable_HeaderFile +#define SALOMEDSClient_AttributeSelectable_HeaderFile + +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" + +class SALOMEDSClient_AttributeSelectable: public virtual SALOMEDSClient_GenericAttribute +{ +public: + + virtual bool IsSelectable() = 0; + virtual void SetSelectable(bool value) = 0; + +}; + + + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeSequenceOfInteger.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeSequenceOfInteger.hxx new file mode 100644 index 000000000..4fbd4587d --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeSequenceOfInteger.hxx @@ -0,0 +1,26 @@ +// File : SALOMEDSClient_AttributeSequenceOfInteger.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef SALOMEDSClient_AttributeSequenceOfInteger_HeaderFile +#define SALOMEDSClient_AttributeSequenceOfInteger_HeaderFile + +#include +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" + +class SALOMEDSClient_AttributeSequenceOfInteger: public virtual SALOMEDSClient_GenericAttribute +{ +public: + + virtual void Assign(const std::vector& other) = 0; + virtual std::vector CorbaSequence() = 0; + virtual void Add(int value) = 0; + virtual void Remove(int index) = 0; + virtual void ChangeValue(int index, int value) = 0; + virtual int Value(int index) = 0; + virtual int Length() = 0; + +}; + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeSequenceOfReal.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeSequenceOfReal.hxx new file mode 100644 index 000000000..e30df3bde --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeSequenceOfReal.hxx @@ -0,0 +1,28 @@ +// File : SALOMEDSClient_AttributeSequenceOfSequenceOfReal.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef SALOMEDSClient_AttributeSequenceOfSequenceOfReal_HeaderFile +#define SALOMEDSClient_AttributeSequenceOfSequenceOfReal_HeaderFile + +#include +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" + +class SALOMEDSClient_AttributeSequenceOfReal: public virtual SALOMEDSClient_GenericAttribute +{ +public: + + virtual void Assign(const std::vector& other) = 0; + virtual std::vector CorbaSequence() = 0; + virtual void Add(double value) = 0; + virtual void Remove(int index) = 0; + virtual void ChangeValue(int index, double value) = 0; + virtual double Value(int index) = 0; + virtual int Length() = 0; + +}; + + + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeStudyProperties.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeStudyProperties.hxx new file mode 100644 index 000000000..db7c35d36 --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeStudyProperties.hxx @@ -0,0 +1,45 @@ +// File : SALOMEDSClient_AttributeStudyProperties.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef SALOMEDSClient_AttributeStudyProperties_HeaderFile +#define SALOMEDSClient_AttributeStudyProperties_HeaderFile + +#include +#include +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" + +class SALOMEDSClient_AttributeStudyProperties: public virtual SALOMEDSClient_GenericAttribute +{ +public: + + virtual void SetUserName(const std::string& theName) = 0; + virtual std::string GetUserName() = 0; + virtual void SetCreationDate(int theMinute, int theHour, int theDay, int theMonth, int theYear) = 0; + virtual bool GetCreationDate(int& theMinute, int& theHour, int& theDay, int& theMonth, int& theYear) = 0; + virtual void SetCreationMode(const std::string& theMode) = 0; + virtual std::string GetCreationMode() = 0; + virtual void SetModified(int theModified) = 0; + virtual bool IsModified() = 0; + virtual int GetModified() = 0; + virtual void SetLocked(bool theLocked) = 0; + virtual bool IsLocked() = 0; + virtual void SetModification(const std::string& theName, + int theMinute, + int theHour, + int theDay, + int theMonth, + int theYear) = 0; + virtual void GetModificationsList(std::vector& theNames, + std::vector& theMinutes, + std::vector& theHours, + std::vector& theDays, + std::vector& theMonths, + std::vector& theYears, + bool theWithCreator) = 0; + +}; + + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeTableOfInteger.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeTableOfInteger.hxx new file mode 100644 index 000000000..2bdeb301c --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeTableOfInteger.hxx @@ -0,0 +1,48 @@ +// File : SALOMEDSClient_AttributeTableOfInteger.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef SALOMEDSClient_AttributeTableOfInteger_HeaderFile +#define SALOMEDSClient_AttributeTableOfInteger_HeaderFile + +#include +#include +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" + +class SALOMEDSClient_AttributeTableOfInteger: public virtual SALOMEDSClient_GenericAttribute +{ + +public: + + virtual void SetTitle(const std::string& theTitle) = 0; + virtual std::string GetTitle() = 0; + virtual void SetRowTitle(int theIndex, const std::string& theTitle) = 0; + virtual void SetRowTitles(const std::vector& theTitles) = 0; + virtual std::vector GetRowTitles() = 0; + virtual void SetColumnTitle(int theIndex, const std::string& theTitle) = 0; + virtual void SetColumnTitles(const std::vector& theTitles) = 0; + virtual std::vector GetColumnTitles() = 0; + + virtual void SetRowUnit(int theIndex, const std::string& theUnit) = 0; + virtual void SetRowUnits(const std::vector& theUnits) = 0; + virtual std::vector GetRowUnits() = 0; + + virtual int GetNbRows() = 0; + virtual int GetNbColumns() = 0; + virtual void AddRow(const std::vector& theData) = 0; + virtual void SetRow(int theRow, const std::vector& theData) = 0; + virtual std::vector GetRow(int theRow) = 0; + virtual void AddColumn(const std::vector& theData) = 0; + virtual void SetColumn(int theColumn, const std::vector& theData) = 0; + virtual std::vector GetColumn(int theColumn) = 0; + virtual void PutValue(int theValue, int theRow, int theColumn) = 0; + virtual bool HasValue(int theRow, int theColumn) = 0; + virtual int GetValue(int theRow, int theColumn) = 0; + + virtual std::vector GetRowSetIndices(int theRow) = 0; + virtual void SetNbColumns(int theNbColumns) = 0; + +}; + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeTableOfReal.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeTableOfReal.hxx new file mode 100644 index 000000000..22df706c4 --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeTableOfReal.hxx @@ -0,0 +1,47 @@ +// File : SALOMEDSClient_AttributeTableOfReal.hxx +// Author : Michael Ponikarov +// Module : SALOME + +#ifndef SALOMEDSClient_AttributeTableOfReal_HeaderFile +#define SALOMEDSClient_AttributeTableOfReal_HeaderFile + +#include +#include +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" + +class SALOMEDSClient_AttributeTableOfReal: public virtual SALOMEDSClient_GenericAttribute +{ + +public: + + virtual void SetTitle(const std::string& theTitle) = 0; + virtual std::string GetTitle() = 0; + virtual void SetRowTitle(int theIndex, const std::string& theTitle) = 0; + virtual void SetRowTitles(const std::vector& theTitles) = 0; + virtual std::vector GetRowTitles() = 0; + virtual void SetColumnTitle(int theIndex, const std::string& theTitle) = 0; + virtual void SetColumnTitles(const std::vector& theTitles) = 0; + virtual std::vector GetColumnTitles() = 0; + virtual void SetRowUnit(int theIndex, const std::string& theUnit) = 0; + virtual void SetRowUnits(const std::vector& theUnits) = 0; + virtual std::vector GetRowUnits() = 0; + + virtual int GetNbRows() = 0; + virtual int GetNbColumns() = 0; + virtual void AddRow(const std::vector& theData) = 0; + virtual void SetRow(int theRow, const std::vector& theData) = 0; + virtual std::vector GetRow(int theRow) = 0; + virtual void AddColumn(const std::vector& theData) = 0; + virtual void SetColumn(int theColumn, const std::vector& theData) = 0; + virtual std::vector GetColumn(int theColumn) = 0; + virtual void PutValue(double theValue, int theRow, int theColumn) = 0; + virtual bool HasValue(int theRow, int theColumn) = 0; + virtual double GetValue(int theRow, int theColumn) = 0; + + virtual std::vector GetRowSetIndices(int theRow) = 0; + virtual void SetNbColumns(int theNbColumns) = 0; + +}; + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeTableOfString.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeTableOfString.hxx new file mode 100644 index 000000000..ddb7b69da --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeTableOfString.hxx @@ -0,0 +1,47 @@ +// File : SALOMEDSClient_AttributeTableOfString.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef SALOMEDSClient_AttributeTableOfString_HeaderFile +#define SALOMEDSClient_AttributeTableOfString_HeaderFile + +#include +#include +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" + +class SALOMEDSClient_AttributeTableOfString: public virtual SALOMEDSClient_GenericAttribute +{ +public: + + virtual void SetTitle(const std::string& theTitle) = 0; + virtual std::string GetTitle() = 0; + virtual void SetRowTitle(int theIndex, const std::string& theTitle) = 0; + virtual void SetRowTitles(const std::vector& theTitles) = 0; + virtual std::vector GetRowTitles() = 0; + virtual void SetColumnTitle(int theIndex, const std::string& theTitle) = 0; + virtual void SetColumnTitles(const std::vector& theTitles) = 0; + virtual std::vector GetColumnTitles() = 0; + + virtual void SetRowUnit(int theIndex, const std::string& theUnit) = 0; + virtual void SetRowUnits(const std::vector& theUnits) = 0; + virtual std::vector GetRowUnits() = 0; + + virtual int GetNbRows() = 0; + virtual int GetNbColumns() = 0; + virtual void AddRow(const std::vector& theData) = 0; + virtual void SetRow(int theRow, const std::vector& theData) = 0; + virtual std::vector GetRow(int theRow) = 0; + virtual void AddColumn(const std::vector& theData) = 0; + virtual void SetColumn(int theColumn, const std::vector& theData) = 0; + virtual std::vector GetColumn(int theColumn) = 0; + virtual void PutValue(const std::string& theValue, int theRow, int theColumn) = 0; + virtual bool HasValue(int theRow, int theColumn) = 0; + virtual std::string GetValue(int theRow, int theColumn) = 0; + + virtual std::vector GetRowSetIndices(int theRow) = 0; + virtual void SetNbColumns(int theNbColumns) = 0; + +}; + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeTarget.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeTarget.hxx new file mode 100644 index 000000000..bb221ed5c --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeTarget.hxx @@ -0,0 +1,21 @@ +// File : SALOMEDSClient_AttributeTarget.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef SALOMEDSClient_AttributeTarget_HeaderFile +#define SALOMEDSClient_AttributeTarget_HeaderFile + +#include +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_SObject.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" + +class SALOMEDSClient_AttributeTarget: public virtual SALOMEDSClient_GenericAttribute +{ +public: + virtual void Add(const _PTR(SObject)& theObject) = 0; + virtual std::vector<_PTR(SObject)> Get() = 0; + virtual void Remove(const _PTR(SObject)& theObject) = 0; +}; + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeTextColor.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeTextColor.hxx new file mode 100644 index 000000000..84f722cc0 --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeTextColor.hxx @@ -0,0 +1,23 @@ +// File : SALOMEDSClient_AttributeTextColor.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef SALOMEDSClient_AttributeTextColor_HeaderFile +#define SALOMEDSClient_AttributeTextColor_HeaderFile + +#include +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" +#include "SALOMEDSClient_definitions.hxx" + +class SALOMEDSClient_AttributeTextColor: public virtual SALOMEDSClient_GenericAttribute +{ +public: + + virtual STextColor TextColor() = 0; + virtual void SetTextColor(STextColor value) = 0; + +}; + + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeTextHighlightColor.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeTextHighlightColor.hxx new file mode 100644 index 000000000..ecc03a7ab --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeTextHighlightColor.hxx @@ -0,0 +1,21 @@ +// File : SALOMEDSClient_AttributeTextHighlightColor.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef SALOMEDSClient_AttributeTextHighlightColor_HeaderFile +#define SALOMEDSClient_AttributeTextHighlightColor_HeaderFile + +#include +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" +#include "SALOMEDSClient_definitions.hxx" + +class SALOMEDSClient_AttributeTextHighlightColor: public virtual SALOMEDSClient_GenericAttribute +{ +public: + virtual STextColor TextHighlightColor() = 0; + virtual void SetTextHighlightColor(STextColor value) = 0; +}; + + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeTreeNode.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeTreeNode.hxx new file mode 100644 index 000000000..8cfe7715b --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeTreeNode.hxx @@ -0,0 +1,43 @@ +// File : SALOMEDSClient_AttributeTreeNode.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef SALOMEDSClient_AttributeTreeNode_HeaderFile +#define SALOMEDSClient_AttributeTreeNode_HeaderFile + +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" + +class SALOMEDSClient_AttributeTreeNode +{ +public: + + virtual void SetFather(const _PTR(AttributeTreeNode)& value) = 0; + virtual bool HasFather() = 0; + virtual _PTR(AttributeTreeNode) GetFather() = 0; + virtual void SetPrevious(const _PTR(AttributeTreeNode)& value) = 0; + virtual bool HasPrevious() = 0; + virtual _PTR(AttributeTreeNode) GetPrevious() = 0; + virtual void SetNext(const _PTR(AttributeTreeNode)& value) = 0; + virtual bool HasNext() = 0; + virtual _PTR(AttributeTreeNode) GetNext() = 0; + virtual void SetFirst(const _PTR(AttributeTreeNode)& value) = 0; + virtual bool HasFirst() = 0; + virtual _PTR(AttributeTreeNode) GetFirst() = 0; + virtual void SetTreeID(const std::string& value) = 0; + virtual std::string GetTreeID() = 0; + virtual void Append(const _PTR(AttributeTreeNode)& value) = 0; + virtual void Prepend(const _PTR(AttributeTreeNode)& value) = 0; + virtual void InsertBefore(const _PTR(AttributeTreeNode)& value) = 0; + virtual void InsertAfter(const _PTR(AttributeTreeNode)& value) = 0; + virtual void Remove() = 0; + virtual int Depth() = 0; + virtual bool IsRoot() = 0; + virtual bool IsDescendant(const _PTR(AttributeTreeNode)& value) = 0; + virtual bool IsFather(const _PTR(AttributeTreeNode)& value) = 0; + virtual bool IsChild(const _PTR(AttributeTreeNode)& value) = 0; + virtual std::string Label() = 0; + +}; + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeUserID.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeUserID.hxx new file mode 100644 index 000000000..6e9007065 --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeUserID.hxx @@ -0,0 +1,24 @@ +// File : SALOMEDSClient_AttributeUserID.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef SALOMEDSClient_AttributeUserID_HeaderFile +#define SALOMEDSClient_AttributeUserID_HeaderFile + +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" +#include + +class SALOMEDSClient_AttributeUserID: public virtual SALOMEDSClient_GenericAttribute +{ +public: + + virtual std::string Value() = 0; + virtual void SetValue(const std::string& value) = 0; + +}; + + + + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_ChildIterator.hxx b/src/SALOMEDSClient/SALOMEDSClient_ChildIterator.hxx new file mode 100644 index 000000000..6fa372013 --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_ChildIterator.hxx @@ -0,0 +1,22 @@ +// File : SALOMEDSClient_ChildIterator.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef __SALOMEDSClient_CHILDITERATOR_H__ +#define __SALOMEDSClient_CHILDITERATOR_H__ + +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_SObject.hxx" + +class SALOMEDSClient_ChildIterator +{ +public: + virtual ~SALOMEDSClient_ChildIterator() {} + + virtual void Init() = 0; + virtual void InitEx(bool) = 0; + virtual bool More() = 0; + virtual void Next() = 0; + virtual _PTR(SObject) Value() = 0; +}; +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_GenericAttribute.hxx b/src/SALOMEDSClient/SALOMEDSClient_GenericAttribute.hxx new file mode 100644 index 000000000..4d1f23482 --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_GenericAttribute.hxx @@ -0,0 +1,23 @@ +// File : SALOMEDSClient__GenericAttribute.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef _GENERICCLIENT_ATTRIBUTE_HXX_ +#define _GENERICCLIENT_ATTRIBUTE_HXX_ + +#include +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_SObject.hxx" + +class SALOMEDSClient_GenericAttribute +{ +public: + virtual ~SALOMEDSClient_GenericAttribute() {} + + virtual void CheckLocked() = 0; + virtual std::string Type() = 0; + virtual std::string GetClassType() = 0; + virtual _PTR(SObject) GetSObject() = 0; +}; + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_SComponent.hxx b/src/SALOMEDSClient/SALOMEDSClient_SComponent.hxx new file mode 100644 index 000000000..dc2a5c054 --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_SComponent.hxx @@ -0,0 +1,21 @@ +// File : SALOMEDSClient_SComponent.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef __SALOMEDSCLIENT_SCOMPONENT_H__ +#define __SALOMEDSCLIENT_SCOMPONENT_H__ + +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_SObject.hxx" +#include + +class SALOMEDSClient_SComponent: public virtual SALOMEDSClient_SObject +{ +public: + virtual ~SALOMEDSClient_SComponent() {} + + virtual std::string ComponentDataType() = 0; + virtual bool ComponentIOR(std::string& theID) = 0; + +}; +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_SComponentIterator.hxx b/src/SALOMEDSClient/SALOMEDSClient_SComponentIterator.hxx new file mode 100644 index 000000000..40cd3cec6 --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_SComponentIterator.hxx @@ -0,0 +1,22 @@ +// File : SALOMEDSClient_SComponentIterator.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef __SALOMEDSClient_SCOMPONENTITERATOR_H__ +#define __SALOMEDSClient_SCOMPONENTITERATOR_H__ + +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_SComponent.hxx" + +class SALOMEDSClient_SComponentIterator +{ +public: + virtual ~SALOMEDSClient_SComponentIterator() {} + + virtual void Init() = 0; + virtual bool More() = 0; + virtual void Next() = 0; + virtual _PTR(SComponent) Value() = 0; +}; + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_SObject.hxx b/src/SALOMEDSClient/SALOMEDSClient_SObject.hxx new file mode 100644 index 000000000..7bc4e7af6 --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_SObject.hxx @@ -0,0 +1,40 @@ +// File : SALOMEDSClient_SObject.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef __SALOMEDSCLIENT_SOBJECT_H__ +#define __SALOMEDSCLIENT_SOBJECT_H__ + +// std C++ headers +#include +#include + +#include "SALOMEDSClient_definitions.hxx" + +class SALOMEDSClient_Study; +class SALOMEDSClient_SComponent; +class SALOMEDSClient_GenericAttribute; + +class SALOMEDSClient_SObject +{ +public: + virtual ~SALOMEDSClient_SObject() {} + + virtual std::string GetID() = 0; + virtual _PTR(SComponent) GetFatherComponent() = 0; + virtual _PTR(SObject) GetFather() = 0; + virtual bool FindAttribute(_PTR(GenericAttribute)& anAttribute, const std::string& aTypeOfAttribute) = 0; + virtual bool ReferencedObject(_PTR(SObject)& theObject) = 0; + virtual bool FindSubObject(int theTag, _PTR(SObject)& theObject) = 0; + virtual _PTR(Study) GetStudy() = 0; + virtual std::string Name() = 0; + virtual void Name(const std::string& theName) = 0; + virtual std::vector<_PTR(GenericAttribute)> GetAllAttributes() = 0; + virtual std::string GetName() = 0; + virtual std::string GetComment() = 0; + virtual std::string GetIOR() = 0; + virtual int Tag() = 0; + virtual int Depth() = 0; +}; + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_Study.hxx b/src/SALOMEDSClient/SALOMEDSClient_Study.hxx new file mode 100644 index 000000000..2140d3322 --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_Study.hxx @@ -0,0 +1,67 @@ +// File : SALOMEDSClient_Study.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef __SALOMEDSClient_STUDY_H__ +#define __SALOMEDSClient_STUDY_H__ + +#include +#include + +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_SComponentIterator.hxx" +#include "SALOMEDSClient_StudyBuilder.hxx" +#include "SALOMEDSClient_SObject.hxx" +#include "SALOMEDSClient_SComponent.hxx" +#include "SALOMEDSClient_UseCaseBuilder.hxx" +#include "SALOMEDSClient_AttributeStudyProperties.hxx" +#include "SALOMEDSClient_ChildIterator.hxx" + +class SALOMEDSClient_Study +{ + +public: + virtual ~SALOMEDSClient_Study() {} + + virtual std::string GetPersistentReference() = 0; + virtual std::string GetTransientReference() = 0; + virtual bool IsEmpty() = 0; + virtual _PTR(SComponent) FindComponent (const std::string& aComponentName) = 0; + virtual _PTR(SComponent) FindComponentID(const std::string& aComponentID) = 0; + virtual _PTR(SObject) FindObject(const std::string& anObjectName) = 0; + virtual std::vector<_PTR(SObject)> FindObjectByName( const std::string& anObjectName, const std::string& aComponentName ) = 0; + virtual _PTR(SObject) FindObjectID(const std::string& anObjectID) = 0; + virtual _PTR(SObject) CreateObjectID(const std::string& anObjectID) = 0; + virtual _PTR(SObject) FindObjectIOR(const std::string& anObjectIOR) = 0; + virtual _PTR(SObject) FindObjectByPath(const std::string& thePath) = 0; + virtual std::string GetObjectPath(const _PTR(SObject)& theSO) = 0; + virtual void SetContext(const std::string& thePath) = 0; + virtual std::string GetContext() = 0; + virtual std::vector GetObjectNames(const std::string& theContext) = 0; + virtual std::vector GetDirectoryNames(const std::string& theContext) = 0; + virtual std::vector GetFileNames(const std::string& theContext) = 0; + virtual std::vector GetComponentNames(const std::string& theContext) = 0; + virtual _PTR(ChildIterator) NewChildIterator(const _PTR(SObject)& theSO) = 0; + virtual _PTR(SComponentIterator) NewComponentIterator() = 0; + virtual _PTR(StudyBuilder) NewBuilder() = 0; + virtual std::string Name() = 0; + virtual void Name(const std::string& name) = 0; + virtual bool IsSaved() = 0; + virtual void IsSaved(bool save) = 0; + virtual bool IsModified() = 0; + virtual std::string URL() = 0; + virtual void URL(const std::string& url) = 0; + virtual int StudyId() = 0; + virtual void StudyId(int id) = 0; + virtual std::vector<_PTR(SObject)> FindDependances(const _PTR(SObject)& theSO) = 0; + virtual _PTR(AttributeStudyProperties) GetProperties() = 0; + virtual std::string GetLastModificationDate() = 0; + virtual std::vector GetModificationsDate() = 0; + virtual _PTR(UseCaseBuilder) GetUseCaseBuilder() = 0; + virtual void Close() = 0; + virtual void EnableUseCaseAutoFilling(bool isEnabled) = 0; + virtual bool DumpStudy(const std::string& thePath, const std::string& theBaseName, bool isPublished) = 0; +}; + + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_StudyBuilder.hxx b/src/SALOMEDSClient/SALOMEDSClient_StudyBuilder.hxx new file mode 100644 index 000000000..9066fb451 --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_StudyBuilder.hxx @@ -0,0 +1,53 @@ +// File : SALOMEDSClient_StudyBuilder.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef __SALOMEDSClient_STUDYBUILDER_H__ +#define __SALOMEDSClient_STUDYBUILDER_H__ + +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_SObject.hxx" +#include "SALOMEDSClient_SComponent.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" +#include + +class SALOMEDSClient_StudyBuilder +{ +public: + virtual ~SALOMEDSClient_StudyBuilder() {} + + virtual _PTR(SComponent) NewComponent(const std::string& ComponentDataType) = 0; + virtual void DefineComponentInstance (const _PTR(SComponent)&, const std::string& ComponentIOR) = 0; + virtual void RemoveComponent(const _PTR(SComponent)& theSCO) = 0; + virtual _PTR(SObject) NewObject(const _PTR(SObject)& theFatherObject) = 0; + virtual _PTR(SObject) NewObjectToTag(const _PTR(SObject)& theFatherObject, int theTag) = 0; + virtual void AddDirectory(const std::string& thePath) = 0; + virtual void LoadWith(const _PTR(SComponent)& theSCO, const std::string& theIOR) = 0; + virtual void Load(const _PTR(SObject)& theSCO) = 0; + virtual void RemoveObject(const _PTR(SObject)& theSO) = 0; + virtual void RemoveObjectWithChildren(const _PTR(SObject)& theSO) = 0; + virtual _PTR(GenericAttribute) FindOrCreateAttribute(const _PTR(SObject)& theSO, const std::string& aTypeOfAttribute) = 0; + virtual bool FindAttribute(const _PTR(SObject)& theSO, + _PTR(GenericAttribute)& theAttribute, + const std::string& aTypeOfAttribute) = 0; + virtual void RemoveAttribute(const _PTR(SObject)& theSO, const std::string& aTypeOfAttribute) = 0; + virtual void Addreference(const _PTR(SObject)& me, const _PTR(SObject)& thereferencedObject) = 0; + virtual void RemoveReference(const _PTR(SObject)& me) = 0; + virtual void SetGUID(const _PTR(SObject)& theSO, const std::string& theGUID) = 0; + virtual bool IsGUID(const _PTR(SObject)& theSO, const std::string& theGUID) = 0; + virtual void NewCommand() = 0; + virtual void CommitCommand()= 0; + virtual bool HasOpenCommand() = 0; + virtual void AbortCommand() = 0; + virtual void Undo() = 0; + virtual void Redo() = 0; + virtual bool GetAvailableUndos() = 0; + virtual bool GetAvailableRedos() = 0; + virtual int UndoLimit() = 0; + virtual void UndoLimit(int theLimit) = 0; + virtual void SetName(const _PTR(SObject)& theSO, const std::string& theValue) = 0; + virtual void SetComment(const _PTR(SObject)& theSO, const std::string& theValue) = 0; + virtual void SetIOR(const _PTR(SObject)& theSO, const std::string& theValue) = 0; +}; + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_StudyManager.hxx b/src/SALOMEDSClient/SALOMEDSClient_StudyManager.hxx new file mode 100644 index 000000000..9e50d0a87 --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_StudyManager.hxx @@ -0,0 +1,36 @@ +// File : SALOMEDSClient_StudyManager.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef __SALOMEDSClient_STUDYMANAGER_H__ +#define __SALOMEDSClient_STUDYMANAGER_H__ + +#include +#include + +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_Study.hxx" + +class SALOMEDSClient_StudyManager +{ +public: + virtual ~SALOMEDSClient_StudyManager() {} + + virtual _PTR(Study) NewStudy(const std::string& study_name) = 0; + virtual _PTR(Study) Open(const std::string& theStudyUrl) = 0; + virtual void Close(const _PTR(Study)& theStudy) = 0; + virtual void Save(const _PTR(Study)& theStudy, bool theMultiFile) = 0; + virtual void SaveASCII(const _PTR(Study)& theStudy, bool theMultiFile) = 0; + virtual void SaveAs(const std::string& theUrl, const _PTR(Study)& theStudy, bool theMultiFile) = 0; + virtual void SaveAsASCII(const std::string& theUrl, const _PTR(Study)& theStudy, bool theMultiFile) = 0; + virtual std::vector GetOpenStudies() = 0; + virtual _PTR(Study) GetStudyByName(const std::string& theStudyName) = 0; + virtual _PTR(Study) GetStudyByID(int theStudyID) = 0; + virtual bool CanCopy(const _PTR(SObject)& theSO) = 0; + virtual bool Copy(const _PTR(SObject)& theSO) = 0; + virtual bool CanPaste(const _PTR(SObject)& theSO) = 0; + virtual _PTR(SObject) Paste(const _PTR(SObject)& theSO) = 0; + +}; + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_UseCaseBuilder.hxx b/src/SALOMEDSClient/SALOMEDSClient_UseCaseBuilder.hxx new file mode 100644 index 000000000..e535f06cb --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_UseCaseBuilder.hxx @@ -0,0 +1,35 @@ +// File : SALOMEDSClient_UseCaseBuilder.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef __SALOMEDSClient_USECaseBuilder_H__ +#define __SALOMEDSClient_USECaseBuilder_H__ + +#include +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_UseCaseIterator.hxx" +#include "SALOMEDSClient_SObject.hxx" + +class SALOMEDSClient_UseCaseBuilder +{ +public: + virtual ~SALOMEDSClient_UseCaseBuilder() {} + + virtual bool Append(const _PTR(SObject)& theObject) = 0; + virtual bool Remove(const _PTR(SObject)& theObject) = 0; + virtual bool AppendTo(const _PTR(SObject)& theFather, _PTR(SObject) theObject) = 0; + virtual bool InsertBefore(const _PTR(SObject)& theFirst, _PTR(SObject) theNext) = 0; + virtual bool SetCurrentObject(const _PTR(SObject)& theObject) = 0; + virtual bool SetRootCurrent() = 0; + virtual bool HasChildren(const _PTR(SObject)& theObject) = 0; + virtual bool IsUseCase(const _PTR(SObject)& theObject) = 0; + virtual bool SetName(const std::string& theName) = 0; + virtual _PTR(SObject) GetCurrentObject() = 0; + virtual std::string GetName() = 0; + virtual _PTR(SObject) AddUseCase(const std::string& theName) = 0; + virtual _PTR(UseCaseIterator) GetUseCaseIterator(const _PTR(SObject)& anObject) = 0; + +}; + + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_UseCaseIterator.hxx b/src/SALOMEDSClient/SALOMEDSClient_UseCaseIterator.hxx new file mode 100644 index 000000000..41376b52b --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_UseCaseIterator.hxx @@ -0,0 +1,23 @@ +// File : SALOMEDSClient_UseCaseIterator.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef __SALOMEDSClient_USECASEITERATOR_H__ +#define __SALOMEDSClient_USECASEITERATOR_H__ + +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_SObject.hxx" + +class SALOMEDSClient_UseCaseIterator +{ + +public: + virtual ~SALOMEDSClient_UseCaseIterator() {} + + virtual void Init(bool) = 0; + virtual bool More() = 0; + virtual void Next() = 0; + virtual _PTR(SObject) Value() = 0; +}; + +#endif diff --git a/src/SALOMEDSClient/SALOMEDSClient_definitions.hxx b/src/SALOMEDSClient/SALOMEDSClient_definitions.hxx new file mode 100644 index 000000000..2176ff1d3 --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_definitions.hxx @@ -0,0 +1,50 @@ +#ifndef SALOMEDSCLIENT_DEF_HXX +#define SALOMEDSCLIENT_DEF_HXX + +#include + +template class clt_shared_ptr: public boost::shared_ptr +{ +public: + clt_shared_ptr() {} + + template + explicit clt_shared_ptr(Y * p) + { + reset(p); + } + + template + clt_shared_ptr(clt_shared_ptr const & r): + boost::shared_ptr(r,boost::detail::dynamic_cast_tag()) + {} + + template + clt_shared_ptr & operator=(clt_shared_ptr const & r) + { + clt_shared_ptr(r).swap(*this); + return *this; + } + + template clt_shared_ptr& operator()(Y * p) // Y must be complete + { + if(T* pt = dynamic_cast(p)) + boost::shared_ptr::reset(pt); + else + boost::throw_exception(std::bad_cast()); + return *this; + } + +}; + +#define _PTR(Class) clt_shared_ptr +#define _CAST(Class, shared_ptr_Obj) dynamic_cast(shared_ptr_Obj.get()) + +struct STextColor +{ + double R; + double G; + double B; +}; + +#endif diff --git a/src/SALOMEDSImpl/Makefile.in b/src/SALOMEDSImpl/Makefile.in new file mode 100644 index 000000000..f448f8588 --- /dev/null +++ b/src/SALOMEDSImpl/Makefile.in @@ -0,0 +1,133 @@ +# File : Makefile.in +# Author : Sergey RUIN +# Module : SALOME + +top_srcdir=@top_srcdir@ +top_builddir=../.. +srcdir=@srcdir@ +VPATH=.:@srcdir@:@top_srcdir@/idl:$(top_srcdir)/idl + + +@COMMENCE@ + +EXPORT_HEADERS= \ + SALOMEDSImpl_Attributes.hxx \ + SALOMEDSImpl_SObject.hxx \ + SALOMEDSImpl_SComponent.hxx \ + SALOMEDSImpl_Driver.hxx \ + SALOMEDSImpl_Callback.hxx \ + SALOMEDSImpl_ChildIterator.hxx \ + SALOMEDSImpl_GenericAttribute.hxx \ + SALOMEDSImpl_AttributeIOR.hxx \ + SALOMEDSImpl_AttributeExternalFileDef.hxx \ + SALOMEDSImpl_AttributeFileType.hxx \ + SALOMEDSImpl_AttributePersistentRef.hxx \ + SALOMEDSImpl_AttributeSequenceOfReal.hxx \ + SALOMEDSImpl_AttributeSequenceOfInteger.hxx \ + SALOMEDSImpl_AttributeDrawable.hxx \ + SALOMEDSImpl_AttributeSelectable.hxx \ + SALOMEDSImpl_AttributeExpandable.hxx \ + SALOMEDSImpl_AttributeOpened.hxx \ + SALOMEDSImpl_AttributeFlags.hxx \ + SALOMEDSImpl_AttributeGraphic.hxx \ + SALOMEDSImpl_AttributeTextColor.hxx \ + SALOMEDSImpl_AttributeTextHighlightColor.hxx \ + SALOMEDSImpl_AttributePixMap.hxx \ + SALOMEDSImpl_AttributeLocalID.hxx \ + SALOMEDSImpl_AttributeTarget.hxx \ + SALOMEDSImpl_AttributeTableOfInteger.hxx \ + SALOMEDSImpl_AttributeTableOfReal.hxx \ + SALOMEDSImpl_AttributeTableOfString.hxx \ + SALOMEDSImpl_AttributeStudyProperties.hxx \ + SALOMEDSImpl_AttributePythonObject.hxx \ + SALOMEDSImpl_AttributeReal.hxx \ + SALOMEDSImpl_AttributeInteger.hxx \ + SALOMEDSImpl_AttributeUserID.hxx \ + SALOMEDSImpl_AttributeTreeNode.hxx \ + SALOMEDSImpl_AttributeName.hxx \ + SALOMEDSImpl_AttributeComment.hxx \ + SALOMEDSImpl_AttributeReference.hxx \ + SALOMEDSImpl_UseCaseBuilder.hxx \ + SALOMEDSImpl_UseCaseIterator.hxx \ + SALOMEDSImpl_SComponentIterator.hxx \ + SALOMEDSImpl_StudyBuilder.hxx \ + SALOMEDSImpl_Study.hxx \ + SALOMEDSImpl_StudyManager.hxx \ + SALOMEDSImpl_OCAFApplication.hxx \ + SALOMEDSImpl_ChildNodeIterator.hxx \ + +LIB_CLIENT_IDL = +LIB_SERVER_IDL = + +# Executables targets +BIN = testDS +BIN_SRC = +BIN_CLIENT_IDL = +BIN_SERVER_IDL = + +# Libraries targets + +LIB = libSalomeDSImpl.la +LIB_SRC = SALOMEDSImpl_Tool.cxx \ + SALOMEDSImpl_Callback.cxx \ + SALOMEDSImpl_StudyHandle.cxx \ + SALOMEDSImpl_GenericAttribute.cxx \ + SALOMEDSImpl_SObject.cxx \ + SALOMEDSImpl_SComponent.cxx \ + SALOMEDSImpl_ChildIterator.cxx \ + SALOMEDSImpl_OCAFApplication.cxx \ + SALOMEDSImpl_AttributeIOR.cxx \ + SALOMEDSImpl_AttributeExternalFileDef.cxx \ + SALOMEDSImpl_AttributeFileType.cxx \ + SALOMEDSImpl_AttributePersistentRef.cxx \ + SALOMEDSImpl_AttributeSequenceOfReal.cxx \ + SALOMEDSImpl_AttributeSequenceOfInteger.cxx \ + SALOMEDSImpl_AttributeDrawable.cxx \ + SALOMEDSImpl_AttributeSelectable.cxx \ + SALOMEDSImpl_AttributeExpandable.cxx \ + SALOMEDSImpl_AttributeOpened.cxx \ + SALOMEDSImpl_AttributeFlags.cxx \ + SALOMEDSImpl_AttributeGraphic.cxx \ + SALOMEDSImpl_AttributeTextColor.cxx \ + SALOMEDSImpl_AttributeTextHighlightColor.cxx \ + SALOMEDSImpl_AttributePixMap.cxx \ + SALOMEDSImpl_AttributeLocalID.cxx \ + SALOMEDSImpl_AttributeTarget.cxx \ + SALOMEDSImpl_AttributeTableOfInteger.cxx \ + SALOMEDSImpl_AttributeTableOfReal.cxx \ + SALOMEDSImpl_AttributeTableOfString.cxx \ + SALOMEDSImpl_AttributeStudyProperties.cxx \ + SALOMEDSImpl_AttributePythonObject.cxx \ + SALOMEDSImpl_AttributeReal.cxx \ + SALOMEDSImpl_AttributeInteger.cxx \ + SALOMEDSImpl_AttributeUserID.cxx \ + SALOMEDSImpl_AttributeTreeNode.cxx \ + SALOMEDSImpl_AttributeName.cxx \ + SALOMEDSImpl_AttributeComment.cxx \ + SALOMEDSImpl_AttributeReference.cxx \ + SALOMEDSImpl_ChildNodeIterator.cxx \ + SALOMEDSImpl_UseCaseBuilder.cxx \ + SALOMEDSImpl_UseCaseIterator.cxx \ + SALOMEDSImpl_SComponentIterator.cxx \ + SALOMEDSImpl_StudyBuilder.cxx \ + SALOMEDSImpl_Study.cxx \ + SALOMEDSImpl_StudyManager.cxx + + + +CPPFLAGS+=$(OCC_INCLUDES) $(HDF5_INCLUDES) +CXXFLAGS+=$(OCC_CXXFLAGS) +LDFLAGS+= $(HDF5_LIBS) -lSalomeHDFPersist $(CAS_LDPATH) -lTKCAF -lTKBO -lTKStdSchema -lTKernel + +# _CS_gbo_090604 Ajout Spécifique Calibre 3, pour l'utilisation de la version 5.12 de la bibliothèque OCC. +# La bibliothèque OCC5.12 a été compilée sur Calibre 3 avec l'extention Xmu (impossible de compiler sans). +# On est donc obligé ici, pour permettre l'édition de lien avec les bibliothèques OCC, de spécifier le +# chemin d'accès aux bibliothèques Xmu +# +LDXMUFLAGS= -L/usr/X11R6/lib -lXmu +LDFLAGS+=$(LDXMUFLAGS) + + +@CONCLUDE@ + + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeComment.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeComment.cxx new file mode 100644 index 000000000..ee3950094 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeComment.cxx @@ -0,0 +1,83 @@ +// File : SALOMEDSImpl_AttributeComment.cxx +// Author : Sergey RUIN +// Module : SALOME + +using namespace std; +#include "SALOMEDSImpl_AttributeComment.hxx" + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeComment, SALOMEDSImpl_GenericAttribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeComment, SALOMEDSImpl_GenericAttribute ) + +//======================================================================= +//function : GetID +//purpose : +//======================================================================= +const Standard_GUID& SALOMEDSImpl_AttributeComment::GetID () +{ + static Standard_GUID CommentID ("7AF2F7CC-1CA2-4476-BE95-8ACC996BC7B9"); + return CommentID; +} + +Handle(SALOMEDSImpl_AttributeComment) SALOMEDSImpl_AttributeComment::Set (const TDF_Label& L, + const TCollection_ExtendedString& Val) +{ + Handle(SALOMEDSImpl_AttributeComment) A; + if (!L.FindAttribute(SALOMEDSImpl_AttributeComment::GetID(), A)) { + A = new SALOMEDSImpl_AttributeComment(); + L.AddAttribute(A); + } + + A->SetValue(Val); + return A; +} + +//======================================================================= +//function : SetValue +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeComment::SetValue (const TCollection_ExtendedString& S) +{ + CheckLocked(); + + if(myString == S) return; + + Backup(); + + myString = S; +} + + +//======================================================================= +//function : ID +//purpose : +//======================================================================= +const Standard_GUID& SALOMEDSImpl_AttributeComment::ID () const { return GetID(); } + +//======================================================================= +//function : NewEmpty +//purpose : +//======================================================================= +Handle(TDF_Attribute) SALOMEDSImpl_AttributeComment::NewEmpty () const +{ + return new SALOMEDSImpl_AttributeComment(); +} + +//======================================================================= +//function : Restore +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeComment::Restore(const Handle(TDF_Attribute)& with) +{ + myString = Handle(SALOMEDSImpl_AttributeComment)::DownCast (with)->Value (); +} + +//======================================================================= +//function : Paste +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributeComment::Paste (const Handle(TDF_Attribute)& into, + const Handle(TDF_RelocationTable)& RT) const +{ + Handle(SALOMEDSImpl_AttributeComment)::DownCast (into)->SetValue(myString); +} diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeComment.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeComment.hxx new file mode 100644 index 000000000..86c5aee80 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeComment.hxx @@ -0,0 +1,51 @@ +// File : SALOMEDSImpl_AttributeIOR.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef _SALOMEDSImpl_AttributeComment_HeaderFile +#define _SALOMEDSImpl_AttributeComment_HeaderFile + +#include +#include +#include +#include +#include +#include +#include "SALOMEDSImpl_GenericAttribute.hxx" + +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_AttributeComment, SALOMEDSImpl_GenericAttribute ) + +class SALOMEDSImpl_AttributeComment : public SALOMEDSImpl_GenericAttribute +{ +private: + + TCollection_ExtendedString myString; + +public: + +Standard_EXPORT static const Standard_GUID& GetID() ; + +Standard_EXPORT SALOMEDSImpl_AttributeComment() :SALOMEDSImpl_GenericAttribute("AttributeComment") {} + +Standard_EXPORT static Handle(SALOMEDSImpl_AttributeComment) Set(const TDF_Label& L, const TCollection_ExtendedString& Val); +Standard_EXPORT void SetValue (const TCollection_ExtendedString& S); +Standard_EXPORT TCollection_ExtendedString Value() const { return myString; } + +Standard_EXPORT virtual TCollection_AsciiString Save() { return myString; } +Standard_EXPORT virtual void Load(const TCollection_AsciiString& theValue) { myString = theValue; } + +Standard_EXPORT const Standard_GUID& ID() const; +Standard_EXPORT void Restore(const Handle(TDF_Attribute)& with) ; +Standard_EXPORT Handle_TDF_Attribute NewEmpty() const; +Standard_EXPORT void Paste(const Handle(TDF_Attribute)& into,const Handle(TDF_RelocationTable)& RT) const; + +Standard_EXPORT ~SALOMEDSImpl_AttributeComment() {} + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_AttributeComment ) +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeDrawable.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeDrawable.cxx new file mode 100644 index 000000000..31a94b518 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeDrawable.cxx @@ -0,0 +1,103 @@ +// File : SALOMEDSImpl_AttributeDrawable.cxx +// Author : Sergey RUIN +// Module : SALOME + +using namespace std; +#include "SALOMEDSImpl_AttributeDrawable.hxx" + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeDrawable, SALOMEDSImpl_GenericAttribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeDrawable, SALOMEDSImpl_GenericAttribute ) + +//======================================================================= +//function : GetID +//purpose : +//======================================================================= +const Standard_GUID& SALOMEDSImpl_AttributeDrawable::GetID () +{ + static Standard_GUID SALOMEDSImpl_AttributeDrawableID ("12837184-8F52-11d6-A8A3-0001021E8C7F"); + return SALOMEDSImpl_AttributeDrawableID; +} + + +//======================================================================= +//function : Set +//purpose : +//======================================================================= + +Handle(SALOMEDSImpl_AttributeDrawable) SALOMEDSImpl_AttributeDrawable::Set (const TDF_Label& L, + const Standard_Integer value) +{ + Handle(SALOMEDSImpl_AttributeDrawable) A; + if (!L.FindAttribute(SALOMEDSImpl_AttributeDrawable::GetID(),A)) { + A = new SALOMEDSImpl_AttributeDrawable(); + L.AddAttribute(A); + } + + A->SetDrawable (value); + return A; +} + + +//======================================================================= +//function : constructor +//purpose : +//======================================================================= +SALOMEDSImpl_AttributeDrawable::SALOMEDSImpl_AttributeDrawable() +:SALOMEDSImpl_GenericAttribute("AttributeDrawable") +{ + myValue = 0; +} + +//======================================================================= +//function : SetDrawable +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeDrawable::SetDrawable(const Standard_Integer theValue) +{ + CheckLocked(); + + Backup(); + + (theValue!=0)?myValue=1:myValue=0; +} + + +//======================================================================= +//function : ID +//purpose : +//======================================================================= + +const Standard_GUID& SALOMEDSImpl_AttributeDrawable::ID () const { return GetID(); } + + +//======================================================================= +//function : NewEmpty +//purpose : +//======================================================================= + +Handle(TDF_Attribute) SALOMEDSImpl_AttributeDrawable::NewEmpty () const +{ + return new SALOMEDSImpl_AttributeDrawable(); +} + +//======================================================================= +//function : Restore +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributeDrawable::Restore(const Handle(TDF_Attribute)& with) +{ + myValue = Handle(SALOMEDSImpl_AttributeDrawable)::DownCast (with)->IsDrawable (); +} + +//======================================================================= +//function : Paste +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributeDrawable::Paste (const Handle(TDF_Attribute)& into, + const Handle(TDF_RelocationTable)& RT) const +{ + Handle(SALOMEDSImpl_AttributeDrawable)::DownCast (into)->SetDrawable (myValue); +} + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeDrawable.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeDrawable.hxx new file mode 100644 index 000000000..4ae08511c --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeDrawable.hxx @@ -0,0 +1,48 @@ +// File : SALOMEDSImpl_AttributeDrawable.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef _SALOMEDSImpl_AttributeDrawable_HeaderFile +#define _SALOMEDSImpl_AttributeDrawable_HeaderFile + +#include +#include +#include +#include +#include +#include "SALOMEDSImpl_GenericAttribute.hxx" + +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_AttributeDrawable, SALOMEDSImpl_GenericAttribute ) + + +class SALOMEDSImpl_AttributeDrawable : public SALOMEDSImpl_GenericAttribute +{ +private: +Standard_Integer myValue; + +public: +Standard_EXPORT virtual TCollection_AsciiString Save() { return (myValue == 0)?(char*)"0":(char*)"1"; } +Standard_EXPORT virtual void Load(const TCollection_AsciiString& theValue) { (theValue == "0")?myValue=0:myValue=1; } + +Standard_EXPORT static const Standard_GUID& GetID() ; +Standard_EXPORT static Handle_SALOMEDSImpl_AttributeDrawable Set(const TDF_Label& label,const Standard_Integer value) ; + +Standard_EXPORT void SetDrawable(const Standard_Integer theValue); +Standard_EXPORT Standard_Integer IsDrawable() const { return myValue; } +Standard_EXPORT SALOMEDSImpl_AttributeDrawable(); +Standard_EXPORT const Standard_GUID& ID() const; +Standard_EXPORT void Restore(const Handle(TDF_Attribute)& with) ; +Standard_EXPORT Handle_TDF_Attribute NewEmpty() const; +Standard_EXPORT void Paste(const Handle(TDF_Attribute)& into,const Handle(TDF_RelocationTable)& RT) const; +Standard_EXPORT ~SALOMEDSImpl_AttributeDrawable() {} + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_AttributeDrawable ) + +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeExpandable.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeExpandable.cxx new file mode 100644 index 000000000..0216a575c --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeExpandable.cxx @@ -0,0 +1,102 @@ +// File : SALOMEDSImpl_AttributeExpandable.cxx +// Author : Sergey RUIN +// Module : SALOME + +using namespace std; +#include "SALOMEDSImpl_AttributeExpandable.hxx" + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeExpandable, SALOMEDSImpl_GenericAttribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeExpandable, SALOMEDSImpl_GenericAttribute ) + +//======================================================================= +//function : GetID +//purpose : +//======================================================================= +const Standard_GUID& SALOMEDSImpl_AttributeExpandable::GetID () +{ + static Standard_GUID SALOMEDSImpl_AttributeExpandableID ("12837185-8F52-11d6-A8A3-0001021E8C7F"); + return SALOMEDSImpl_AttributeExpandableID; +} + + + +//======================================================================= +//function : Set +//purpose : +//======================================================================= +Handle(SALOMEDSImpl_AttributeExpandable) SALOMEDSImpl_AttributeExpandable::Set (const TDF_Label& L, + const Standard_Integer value) +{ + Handle(SALOMEDSImpl_AttributeExpandable) A; + if (!L.FindAttribute(SALOMEDSImpl_AttributeExpandable::GetID(),A)) { + A = new SALOMEDSImpl_AttributeExpandable(); + L.AddAttribute(A); + } + + A->SetExpandable(value); + return A; +} + + +//======================================================================= +//function : constructor +//purpose : +//======================================================================= +SALOMEDSImpl_AttributeExpandable::SALOMEDSImpl_AttributeExpandable() +:SALOMEDSImpl_GenericAttribute("AttributeExpandable") +{ + myValue = 0; +} + +//======================================================================= +//function : SetExpandable +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeExpandable::SetExpandable(const Standard_Integer theValue) +{ + CheckLocked(); + + Backup(); + + (theValue!=0)?myValue=1:myValue=0; +} + +//======================================================================= +//function : ID +//purpose : +//======================================================================= + +const Standard_GUID& SALOMEDSImpl_AttributeExpandable::ID () const { return GetID(); } + + +//======================================================================= +//function : NewEmpty +//purpose : +//======================================================================= + +Handle(TDF_Attribute) SALOMEDSImpl_AttributeExpandable::NewEmpty () const +{ + return new SALOMEDSImpl_AttributeExpandable(); +} + +//======================================================================= +//function : Restore +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributeExpandable::Restore(const Handle(TDF_Attribute)& with) +{ + myValue = Handle(SALOMEDSImpl_AttributeExpandable)::DownCast (with)->IsExpandable (); +} + +//======================================================================= +//function : Paste +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributeExpandable::Paste (const Handle(TDF_Attribute)& into, + const Handle(TDF_RelocationTable)& RT) const +{ + Handle(SALOMEDSImpl_AttributeExpandable)::DownCast (into)->SetExpandable (myValue); +} + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeExpandable.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeExpandable.hxx new file mode 100644 index 000000000..a31cf02d5 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeExpandable.hxx @@ -0,0 +1,47 @@ +// File : SALOMEDSImpl_AttributeExpandable.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef _SALOMEDSImpl_AttributeExpandable_HeaderFile +#define _SALOMEDSImpl_AttributeExpandable_HeaderFile + +#include +#include +#include +#include +#include +#include "SALOMEDSImpl_GenericAttribute.hxx" + +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_AttributeExpandable, SALOMEDSImpl_GenericAttribute ) + + +class SALOMEDSImpl_AttributeExpandable : public SALOMEDSImpl_GenericAttribute +{ +private: +Standard_Integer myValue; + +public: + +Standard_EXPORT virtual TCollection_AsciiString Save() { return (myValue == 0)?(char*)"0":(char*)"1"; } +Standard_EXPORT virtual void Load(const TCollection_AsciiString& theValue) { (theValue == "0")?myValue=0:myValue=1; } + +Standard_EXPORT static const Standard_GUID& GetID() ; +Standard_EXPORT static Handle_SALOMEDSImpl_AttributeExpandable Set(const TDF_Label& label,const Standard_Integer value) ; +Standard_EXPORT SALOMEDSImpl_AttributeExpandable(); +Standard_EXPORT void SetExpandable(const Standard_Integer value); +Standard_EXPORT int IsExpandable() const { return myValue; } +Standard_EXPORT const Standard_GUID& ID() const; +Standard_EXPORT void Restore(const Handle(TDF_Attribute)& with) ; +Standard_EXPORT Handle_TDF_Attribute NewEmpty() const; +Standard_EXPORT void Paste(const Handle(TDF_Attribute)& into,const Handle(TDF_RelocationTable)& RT) const; +Standard_EXPORT ~SALOMEDSImpl_AttributeExpandable() {} + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_AttributeExpandable ) +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeExternalFileDef.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeExternalFileDef.cxx new file mode 100644 index 000000000..29e743acb --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeExternalFileDef.cxx @@ -0,0 +1,102 @@ +// File : SALOMEDSImpl_AttributeExternalFileDef.cxx +// Author : Sergey RUIN +// Module : SALOME + +#include "SALOMEDSImpl_AttributeExternalFileDef.hxx" + +using namespace std; + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeExternalFileDef, SALOMEDSImpl_GenericAttribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeExternalFileDef, SALOMEDSImpl_GenericAttribute ) + +//======================================================================= +//function : GetID +//purpose : +//======================================================================= +const Standard_GUID& SALOMEDSImpl_AttributeExternalFileDef::GetID () +{ + static Standard_GUID SALOMEDSImpl_AttributeExternalFileDefID ("7123AD4C-ACDB-4e3a-8FDC-70EA164D2CBE"); + return SALOMEDSImpl_AttributeExternalFileDefID; +} + +//======================================================================= +//function : Set +//purpose : +//======================================================================= +Handle(SALOMEDSImpl_AttributeExternalFileDef) +SALOMEDSImpl_AttributeExternalFileDef::Set (const TDF_Label& L, const TCollection_ExtendedString& S) +{ + + Handle(SALOMEDSImpl_AttributeExternalFileDef) A; + if (!L.FindAttribute(SALOMEDSImpl_AttributeExternalFileDef::GetID(),A)) { + A = new SALOMEDSImpl_AttributeExternalFileDef(); + L.AddAttribute(A); + } + + A->SetValue (S); + return A; +} + + +//======================================================================= +//function : constructor +//purpose : +//======================================================================= +SALOMEDSImpl_AttributeExternalFileDef::SALOMEDSImpl_AttributeExternalFileDef() +:SALOMEDSImpl_GenericAttribute("AttributeExternalFileDef") +{ +} + +//======================================================================= +//function : SetValue +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeExternalFileDef::SetValue (const TCollection_ExtendedString& S) +{ + CheckLocked(); + + if(myString == S) return; + + Backup(); + + myString = S; +} + + + +//======================================================================= +//function : ID +//purpose : +//======================================================================= +const Standard_GUID& SALOMEDSImpl_AttributeExternalFileDef::ID () const { return GetID(); } + + +//======================================================================= +//function : NewEmpty +//purpose : +//======================================================================= +Handle(TDF_Attribute) SALOMEDSImpl_AttributeExternalFileDef::NewEmpty () const +{ + return new SALOMEDSImpl_AttributeExternalFileDef(); +} + +//======================================================================= +//function : Restore +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeExternalFileDef::Restore(const Handle(TDF_Attribute)& with) +{ + myString = Handle(SALOMEDSImpl_AttributeExternalFileDef)::DownCast (with)->Value (); +} + +//======================================================================= +//function : Paste +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeExternalFileDef::Paste (const Handle(TDF_Attribute)& into, + const Handle(TDF_RelocationTable)& RT) const +{ + Handle(SALOMEDSImpl_AttributeExternalFileDef) anAttr = Handle(SALOMEDSImpl_AttributeExternalFileDef)::DownCast(into); + anAttr->SetValue(myString); +} + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeExternalFileDef.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeExternalFileDef.hxx new file mode 100644 index 000000000..6e74704ca --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeExternalFileDef.hxx @@ -0,0 +1,44 @@ + +#ifndef _SALOMEDSImpl_AttributeExternalFileDef_HeaderFile +#define _SALOMEDSImpl_AttributeExternalFileDef_HeaderFile + +#include +#include +#include +#include +#include +#include "SALOMEDSImpl_GenericAttribute.hxx" + +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_AttributeExternalFileDef, SALOMEDSImpl_GenericAttribute ) + +class SALOMEDSImpl_AttributeExternalFileDef : public SALOMEDSImpl_GenericAttribute +{ +private: + + TCollection_ExtendedString myString; + +public: +Standard_EXPORT static const Standard_GUID& GetID() ; +Standard_EXPORT static Handle_SALOMEDSImpl_AttributeExternalFileDef Set(const TDF_Label& label, + const TCollection_ExtendedString& Name); +Standard_EXPORT SALOMEDSImpl_AttributeExternalFileDef(); +Standard_EXPORT void SetValue(const TCollection_ExtendedString& value); +Standard_EXPORT TCollection_ExtendedString Value() const { return myString; } +Standard_EXPORT const Standard_GUID& ID() const; +Standard_EXPORT void Restore(const Handle(TDF_Attribute)& with) ; +Standard_EXPORT Handle_TDF_Attribute NewEmpty() const; +Standard_EXPORT void Paste(const Handle(TDF_Attribute)& into,const Handle(TDF_RelocationTable)& RT) const; +Standard_EXPORT ~SALOMEDSImpl_AttributeExternalFileDef() {} + +Standard_EXPORT virtual TCollection_AsciiString Save() { return myString; } +Standard_EXPORT virtual void Load(const TCollection_AsciiString& theValue) { myString = theValue; } + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_AttributeExternalFileDef ) +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeFileType.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeFileType.cxx new file mode 100644 index 000000000..d880e387e --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeFileType.cxx @@ -0,0 +1,107 @@ +// File : SALOMEDSImpl_AttributeFileType.cxx +// Author : Sergey RUIN +// Module : SALOME + +#include "SALOMEDSImpl_AttributeFileType.hxx" + +using namespace std; + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeFileType, SALOMEDSImpl_GenericAttribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeFileType, SALOMEDSImpl_GenericAttribute ) + +//======================================================================= +//function : GetID +//purpose : +//======================================================================= + +const Standard_GUID& SALOMEDSImpl_AttributeFileType::GetID () +{ + static Standard_GUID SALOMEDSImpl_AttributeFileTypeID ("0181B525-3F15-4ab2-9DE3-5E2F54B5F340"); + return SALOMEDSImpl_AttributeFileTypeID; +} + + + +//======================================================================= +//function : Set +//purpose : +//======================================================================= + +Handle(SALOMEDSImpl_AttributeFileType) SALOMEDSImpl_AttributeFileType::Set (const TDF_Label& L, + const TCollection_ExtendedString& S) +{ + + Handle(SALOMEDSImpl_AttributeFileType) A; + if (!L.FindAttribute(SALOMEDSImpl_AttributeFileType::GetID(),A)) { + A = new SALOMEDSImpl_AttributeFileType(); + L.AddAttribute(A); + } + + A->SetValue (S); + return A; +} + + +//======================================================================= +//function : constructor +//purpose : +//======================================================================= +SALOMEDSImpl_AttributeFileType::SALOMEDSImpl_AttributeFileType() +:SALOMEDSImpl_GenericAttribute("AttributeFileType") +{ +} + +//======================================================================= +//function : SetValue +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeFileType::SetValue (const TCollection_ExtendedString& S) +{ + CheckLocked(); + + if(myString == S) return; + + Backup(); + + myString = S; +} + +//======================================================================= +//function : ID +//purpose : +//======================================================================= + +const Standard_GUID& SALOMEDSImpl_AttributeFileType::ID () const { return GetID(); } + + +//======================================================================= +//function : NewEmpty +//purpose : +//======================================================================= + +Handle(TDF_Attribute) SALOMEDSImpl_AttributeFileType::NewEmpty () const +{ + return new SALOMEDSImpl_AttributeFileType(); +} + +//======================================================================= +//function : Restore +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributeFileType::Restore(const Handle(TDF_Attribute)& with) +{ + myString = Handle(SALOMEDSImpl_AttributeFileType)::DownCast (with)->Value (); +} + +//======================================================================= +//function : Paste +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributeFileType::Paste (const Handle(TDF_Attribute)& into, + const Handle(TDF_RelocationTable)& RT) const +{ + Handle(SALOMEDSImpl_AttributeFileType)::DownCast (into)->SetValue (myString); +} + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeFileType.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeFileType.hxx new file mode 100644 index 000000000..3e643b19a --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeFileType.hxx @@ -0,0 +1,45 @@ + +#ifndef _SALOMEDSImpl_AttributeFileType_HeaderFile +#define _SALOMEDSImpl_AttributeFileType_HeaderFile + +#include +#include +#include +#include +#include +#include "SALOMEDSImpl_GenericAttribute.hxx" + +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_AttributeFileType, SALOMEDSImpl_GenericAttribute ) + +class SALOMEDSImpl_AttributeFileType : public SALOMEDSImpl_GenericAttribute +{ +private: + + TCollection_ExtendedString myString; + +public: +Standard_EXPORT static const Standard_GUID& GetID() ; +Standard_EXPORT static Handle_SALOMEDSImpl_AttributeFileType Set(const TDF_Label& label, + const TCollection_ExtendedString& Name) ; +Standard_EXPORT SALOMEDSImpl_AttributeFileType(); +Standard_EXPORT void SetValue(const TCollection_ExtendedString& value); +Standard_EXPORT TCollection_ExtendedString Value() const { return myString; } +Standard_EXPORT const Standard_GUID& ID() const; +Standard_EXPORT void Restore(const Handle(TDF_Attribute)& with) ; +Standard_EXPORT Handle_TDF_Attribute NewEmpty() const; +Standard_EXPORT void Paste(const Handle(TDF_Attribute)& into,const Handle(TDF_RelocationTable)& RT) const; +Standard_EXPORT ~SALOMEDSImpl_AttributeFileType() {} + +Standard_EXPORT virtual TCollection_AsciiString Save() { return myString; } +Standard_EXPORT virtual void Load(const TCollection_AsciiString& theValue) { myString = theValue; } + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_AttributeFileType ) +}; + + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeFlags.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeFlags.cxx new file mode 100644 index 000000000..0406fef31 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeFlags.cxx @@ -0,0 +1,138 @@ +// File : SALOMEDSImpl_AttributeFlags.cxx +// Author : Sergey LITONIN +// Module : SALOME + +#include "SALOMEDSImpl_AttributeFlags.hxx" +#include + +using namespace std; + + +/* + Class : SALOMEDSImpl_AttributeFlags + Description : This class is intended for storing different object attributes that + have only two states (0 and 1). +*/ + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeFlags, SALOMEDSImpl_GenericAttribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeFlags, SALOMEDSImpl_GenericAttribute ) + +//======================================================================= +//function : SALOMEDSImpl_AttributeFlags::GetID +//purpose : Get GUID of this attribute +//======================================================================= +const Standard_GUID& SALOMEDSImpl_AttributeFlags::GetID () +{ + static Standard_GUID SALOMEDSImpl_AttributeFlagsID( "866EEC9F-A517-4cb4-88E6-E208DB8FC96F" ); + return SALOMEDSImpl_AttributeFlagsID; +} + +//======================================================================= +//function : SALOMEDSImpl_AttributeFlags::Set +//purpose : Set value of the attribute +//======================================================================= +Handle(SALOMEDSImpl_AttributeFlags) SALOMEDSImpl_AttributeFlags::Set(const TDF_Label& L, + const Standard_Integer value ) +{ + Handle(SALOMEDSImpl_AttributeFlags) A; + if ( !L.FindAttribute(SALOMEDSImpl_AttributeFlags::GetID(),A ) ) + { + A = new SALOMEDSImpl_AttributeFlags(); + L.AddAttribute( A ); + } + + A->Set( value ); + return A; +} + +//======================================================================= +//function : SALOMEDSImpl_AttributeFlags::SALOMEDSImpl_AttributeFlags +//purpose : Constructor +//======================================================================= +SALOMEDSImpl_AttributeFlags::SALOMEDSImpl_AttributeFlags() +:SALOMEDSImpl_GenericAttribute("AttributeFlags") +{ + myValue = 0; +} + +SALOMEDSImpl_AttributeFlags::~SALOMEDSImpl_AttributeFlags() +{ +} + +//======================================================================= +//function : SALOMEDSImpl_AttributeFlags::ID +//purpose : Get GUID of this attribute +//======================================================================= +const Standard_GUID& SALOMEDSImpl_AttributeFlags::ID () const +{ + return GetID(); +} + +//======================================================================= +//function : SALOMEDSImpl_AttributeFlags::NewEmpty +//purpose : Create new empty attribute +//======================================================================= + +Handle(TDF_Attribute) SALOMEDSImpl_AttributeFlags::NewEmpty () const +{ + return new SALOMEDSImpl_AttributeFlags(); +} + +//======================================================================= +//function : SALOMEDSImpl_AttributeFlags::Restore +//purpose : Assign given value to the attribute +//======================================================================= +void SALOMEDSImpl_AttributeFlags::Restore( const Handle(TDF_Attribute)& with ) +{ + myValue = Handle(SALOMEDSImpl_AttributeFlags)::DownCast( with )->Get(); + return; +} + +//======================================================================= +//function : SALOMEDSImpl_AttributeFlags::Paste +//purpose : Assign internal value to the given attribute +//======================================================================= +void SALOMEDSImpl_AttributeFlags::Paste(const Handle(TDF_Attribute)& into, + const Handle(TDF_RelocationTable)& RT ) const +{ + Handle(SALOMEDSImpl_AttributeFlags)::DownCast( into )->Set( myValue ); +} + +//======================================================================= +//function : SALOMEDSImpl_AttributeFlags::Set +//purpose : Set value +//======================================================================= +void SALOMEDSImpl_AttributeFlags::Set( const Standard_Integer v ) +{ + Backup(); + myValue=v; +} + +//======================================================================= +//function : SALOMEDSImpl_AttributeFlags::Get +//purpose : GetValue +//======================================================================= +Standard_Integer SALOMEDSImpl_AttributeFlags::Get() const +{ + return myValue; +} + + + + + + + + + + + + + + + + + + + + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeFlags.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeFlags.hxx new file mode 100644 index 000000000..a142b6be4 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeFlags.hxx @@ -0,0 +1,50 @@ +// File : SALOMEDSImpl_AttributeFlags.hxx +// Author : Sergey LITONIN +// Module : SALOME + +#ifndef SALOMEDSImpl_AttributeFlags_HeaderFile +#define SALOMEDSImpl_AttributeFlags_HeaderFile + +#include +#include +#include +#include "SALOMEDSImpl_GenericAttribute.hxx" + +class Standard_GUID; +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + + +/* + Class : SALOMEDSImpl_AttributeFlags + Description : This class is intended for storing different object attributes that + have only two states (0 and 1). +*/ + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_AttributeFlags, SALOMEDSImpl_GenericAttribute ) + +class Standard_EXPORT SALOMEDSImpl_AttributeFlags : public SALOMEDSImpl_GenericAttribute +{ +private: +Standard_Integer myValue; + +public: +Standard_EXPORT static const Standard_GUID& GetID() ; +Standard_EXPORT static Handle(SALOMEDSImpl_AttributeFlags) Set(const TDF_Label&, const Standard_Integer ); + + SALOMEDSImpl_AttributeFlags(); +Standard_EXPORT virtual ~SALOMEDSImpl_AttributeFlags(); + +Standard_EXPORT const Standard_GUID& ID() const; +Standard_EXPORT void Restore( const Handle(TDF_Attribute)& with ); +Standard_EXPORT Handle_TDF_Attribute NewEmpty() const; +Standard_EXPORT void Paste( const Handle(TDF_Attribute)& into, + const Handle(TDF_RelocationTable)& RT ) const; +Standard_EXPORT void Set( const Standard_Integer ); +Standard_EXPORT Standard_Integer Get() const; + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_AttributeFlags ) +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeGraphic.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeGraphic.cxx new file mode 100644 index 000000000..062a6c75b --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeGraphic.cxx @@ -0,0 +1,161 @@ +// File : SALOMEDSImpl_AttributeGraphic.cxx +// Author : Sergey LITONIN +// Module : SALOME + +#include "SALOMEDSImpl_AttributeGraphic.hxx" +#include +#include +#include + +/* + Class : SALOMEDSImpl_AttributeGraphic + Description : This class is intended for storing information about + graphic representation of objects in dirrent views +*/ + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeGraphic, SALOMEDSImpl_GenericAttribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeGraphic, SALOMEDSImpl_GenericAttribute ) + +//======================================================================= +//function : GetID +//purpose : Get GUID of this attribute +//======================================================================= +const Standard_GUID& SALOMEDSImpl_AttributeGraphic::GetID() +{ + static Standard_GUID SALOMEDSImpl_AttributeGraphicID( "F17AE8F0-E354-4d6f-8E42-38385C36E67E" ); + return SALOMEDSImpl_AttributeGraphicID; +} + +//======================================================================= +//function : SALOMEDSImpl_AttributeGraphic +//purpose : Empty Constructor +//======================================================================= +SALOMEDSImpl_AttributeGraphic::SALOMEDSImpl_AttributeGraphic() +:SALOMEDSImpl_GenericAttribute("AttributeGraphic") +{ +} + +//======================================================================= +//function : ~SALOMEDSImpl_AttributeGraphic +//purpose : Destructor +//======================================================================= +SALOMEDSImpl_AttributeGraphic::~SALOMEDSImpl_AttributeGraphic() +{ +} + +//======================================================================= +//function : SetVisibility +//purpose : Set visibility of object in given view +//======================================================================= +void SALOMEDSImpl_AttributeGraphic::SetVisibility(const Standard_Integer theViewId, + const Standard_Boolean theValue ) +{ + if ( myVisibility.IsBound( theViewId ) && myVisibility( theViewId ) == theValue ) + return; + + Backup(); + if ( myVisibility.IsBound( theViewId ) ) + myVisibility.ChangeFind( theViewId ) = theValue ? 1 : 0; + else + myVisibility.Bind( theViewId, theValue ? 1 : 0 ); +} + + +//======================================================================= +//function : Get +//purpose : Get visibility of object in given view +//======================================================================= +Standard_Boolean SALOMEDSImpl_AttributeGraphic::GetVisibility(const Standard_Integer theViewId ) const +{ + return myVisibility.IsBound( theViewId ) ? myVisibility( theViewId ) : false; +} + + +//======================================================================= +//function : ID +//purpose : Get GUID of this attribute +//======================================================================= +const Standard_GUID& SALOMEDSImpl_AttributeGraphic::ID () const +{ + return GetID(); +} + + +//======================================================================= +//function : NewEmpty +//purpose : Create new empty attribute +//======================================================================= +Handle(TDF_Attribute) SALOMEDSImpl_AttributeGraphic::NewEmpty () const +{ + return new SALOMEDSImpl_AttributeGraphic (); +} + +//======================================================================= +//function : SetVisibility +//purpose : Set visibility of object in all views +//======================================================================= +void SALOMEDSImpl_AttributeGraphic::SetVisibility( const TColStd_DataMapOfIntegerInteger& theMap ) +{ + myVisibility = theMap; +} + +//======================================================================= +//function : SetVisibility +//purpose : Get visibility of object in all views +//======================================================================= +const TColStd_DataMapOfIntegerInteger& SALOMEDSImpl_AttributeGraphic::GetVisibility() +{ + return myVisibility; +} + +//======================================================================= +//function : Restore +//purpose : Restore value of attribute with value of theWith one +//======================================================================= +void SALOMEDSImpl_AttributeGraphic::Restore( const Handle(TDF_Attribute)& theWith ) +{ + Handle(SALOMEDSImpl_AttributeGraphic) anAttr = + Handle(SALOMEDSImpl_AttributeGraphic)::DownCast( theWith ); + + if ( !anAttr.IsNull() ) + SetVisibility( anAttr->GetVisibility() ); +} + +//======================================================================= +//function : Paste +//purpose : Paste value of current attribute to the value of entry one +//======================================================================= +void SALOMEDSImpl_AttributeGraphic::Paste( const Handle(TDF_Attribute)& theInto, + const Handle(TDF_RelocationTable)& ) const +{ + Handle(SALOMEDSImpl_AttributeGraphic) anAttr = + Handle(SALOMEDSImpl_AttributeGraphic)::DownCast( theInto ); + + if ( !anAttr.IsNull() ) + anAttr->SetVisibility( myVisibility ); +} + +//======================================================================= +//function : Dump +//purpose : Dump +//======================================================================= +Standard_OStream& SALOMEDSImpl_AttributeGraphic::Dump( Standard_OStream& anOS ) const +{ + anOS << "Visibility of object:" << endl; + TColStd_DataMapIteratorOfDataMapOfIntegerInteger anIter( myVisibility ); + for ( ; anIter.More(); anIter.Next() ) + { + char str[ 100 ]; + + if ( GetVisibility( anIter.Key() ) ) + sprintf( str, "Viewer ID = 0x%X State = VISIBLE\n", anIter.Key() ); + else + sprintf( str, "Viewer ID = 0x%X State = INVISIBLE\n", anIter.Key() ); + + anOS << str; + } + + anOS << "Integer"; + return anOS; +} + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeGraphic.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeGraphic.hxx new file mode 100644 index 000000000..4e958a9ab --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeGraphic.hxx @@ -0,0 +1,58 @@ +// File : SALOMEDSImpl_AttributeGraphic.hxx +// Author : Sergey LITONIN +// Module : SALOME + +#ifndef SALOMEDSImpl_AttributeGraphic_HeaderFile +#define SALOMEDSImpl_AttributeGraphic_HeaderFile + +#include +#include +#include +#include +#include "SALOMEDSImpl_GenericAttribute.hxx" + +class Standard_GUID; +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + +/* + Class : SALOMEDSImpl_AttributeGraphic + Description : This class is intended for storing information about + graphic representation of objects in dirrent views +*/ + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_AttributeGraphic, SALOMEDSImpl_GenericAttribute) + + + +class Standard_EXPORT SALOMEDSImpl_AttributeGraphic : public SALOMEDSImpl_GenericAttribute +{ + +public: +Standard_EXPORT SALOMEDSImpl_AttributeGraphic(); +Standard_EXPORT ~SALOMEDSImpl_AttributeGraphic(); + +Standard_EXPORT static const Standard_GUID& GetID() ; + +Standard_EXPORT void SetVisibility( const Standard_Integer, + const Standard_Boolean ); +Standard_EXPORT Standard_Boolean GetVisibility( const Standard_Integer ) const; +Standard_EXPORT const Standard_GUID& ID() const; +Standard_EXPORT void Restore( const Handle(TDF_Attribute)& theWith ); +Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const; +Standard_EXPORT void Paste( const Handle(TDF_Attribute)& theInto, + const Handle(TDF_RelocationTable)& ) const; +Standard_EXPORT virtual Standard_OStream& Dump( Standard_OStream& anOS ) const; + +Standard_EXPORT void SetVisibility( const TColStd_DataMapOfIntegerInteger& ); + +Standard_EXPORT const TColStd_DataMapOfIntegerInteger& GetVisibility(); + +private: + TColStd_DataMapOfIntegerInteger myVisibility; + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_AttributeGraphic ) +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx new file mode 100644 index 000000000..0ee05dc2b --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx @@ -0,0 +1,122 @@ +// File : SALOMEDSImpl_AttributeIOR.cxx +// Author : Sergey RUIN +// Module : SALOME + +using namespace std; +#include "SALOMEDSImpl_AttributeIOR.hxx" +#include +#include "SALOMEDSImpl_Study.hxx" +#include + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeIOR, SALOMEDSImpl_GenericAttribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeIOR, SALOMEDSImpl_GenericAttribute ) + + +//======================================================================= +//function : GetID +//purpose : +//======================================================================= + +const Standard_GUID& SALOMEDSImpl_AttributeIOR::GetID () +{ + static Standard_GUID SALOMEDSImpl_AttributeIORID ("92888E01-7074-11d5-A690-0800369C8A03"); + return SALOMEDSImpl_AttributeIORID; +} + + + +//======================================================================= +//function : Set +//purpose : +//======================================================================= + +Handle(SALOMEDSImpl_AttributeIOR) SALOMEDSImpl_AttributeIOR::Set (const TDF_Label& L, + const TCollection_ExtendedString& S) +{ + Handle(SALOMEDSImpl_AttributeIOR) A; + if (!L.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID(),A)) { + A = new SALOMEDSImpl_AttributeIOR(); + L.AddAttribute(A); + } + + A->SetValue(S); + SALOMEDSImpl_Study::IORUpdated(A); + return A; +} + +//======================================================================= +//function : SetValue +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeIOR::SetValue(const TCollection_ExtendedString& theValue) +{ + CheckLocked(); + + Handle(SALOMEDSImpl_Study) aStudy = SALOMEDSImpl_Study::GetStudy(Label()); + aStudy->AddCreatedPostponed(theValue); + aStudy->AddPostponed(theValue); + + Backup(); + myString = theValue; + + SALOMEDSImpl_Study::IORUpdated(this); +} + +//======================================================================= +//function : Value +//purpose : +//======================================================================= +TCollection_ExtendedString SALOMEDSImpl_AttributeIOR::Value() const +{ + return myString; +} + +//======================================================================= +//function : constructor +//purpose : +//======================================================================= +SALOMEDSImpl_AttributeIOR::SALOMEDSImpl_AttributeIOR() +:SALOMEDSImpl_GenericAttribute("AttributeIOR") +{ +} + +//======================================================================= +//function : ID +//purpose : +//======================================================================= + +const Standard_GUID& SALOMEDSImpl_AttributeIOR::ID () const { return GetID(); } + + +//======================================================================= +//function : NewEmpty +//purpose : +//======================================================================= + +Handle(TDF_Attribute) SALOMEDSImpl_AttributeIOR::NewEmpty () const +{ + return new SALOMEDSImpl_AttributeIOR(); +} + +//======================================================================= +//function : Restore +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributeIOR::Restore(const Handle(TDF_Attribute)& with) +{ + myString = Handle(SALOMEDSImpl_AttributeIOR)::DownCast (with)->Value(); + return; +} + +//======================================================================= +//function : Paste +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributeIOR::Paste (const Handle(TDF_Attribute)& into, + const Handle(TDF_RelocationTable)& RT) const +{ + Handle(SALOMEDSImpl_AttributeIOR)::DownCast (into)->SetValue(myString); +} + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.hxx new file mode 100644 index 000000000..692701f9a --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.hxx @@ -0,0 +1,45 @@ +// File : SALOMEDSImpl_AttributeIOR.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef _SALOMEDSImpl_AttributeIOR_HeaderFile +#define _SALOMEDSImpl_AttributeIOR_HeaderFile + +#include +#include +#include +#include +#include "SALOMEDSImpl_GenericAttribute.hxx" + +class Standard_GUID; +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_AttributeIOR, SALOMEDSImpl_GenericAttribute ) + +class SALOMEDSImpl_AttributeIOR : public SALOMEDSImpl_GenericAttribute +{ +private: + + TCollection_ExtendedString myString; + +public: + +Standard_EXPORT static const Standard_GUID& GetID() ; +Standard_EXPORT static Handle_SALOMEDSImpl_AttributeIOR Set(const TDF_Label& label, + const TCollection_ExtendedString& string); +Standard_EXPORT SALOMEDSImpl_AttributeIOR(); +Standard_EXPORT const Standard_GUID& ID() const; +Standard_EXPORT void SetValue(const TCollection_ExtendedString& theValue); +Standard_EXPORT TCollection_ExtendedString Value() const ; +Standard_EXPORT void Restore(const Handle(TDF_Attribute)& with) ; +Standard_EXPORT Handle_TDF_Attribute NewEmpty() const; +Standard_EXPORT void Paste(const Handle(TDF_Attribute)& into,const Handle(TDF_RelocationTable)& RT) const; +Standard_EXPORT ~SALOMEDSImpl_AttributeIOR() {} + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_AttributeIOR ) +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeInteger.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeInteger.cxx new file mode 100644 index 000000000..78988c0b8 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeInteger.cxx @@ -0,0 +1,79 @@ +// File : SALOMEDSImpl_AttributeInteger.cxx +// Author : Sergey RUIN +// Module : SALOME + +using namespace std; +#include "SALOMEDSImpl_AttributeInteger.hxx" + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeInteger, SALOMEDSImpl_GenericAttribute) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeInteger, SALOMEDSImpl_GenericAttribute ) + + +//======================================================================= +//function : GetID +//purpose : +//======================================================================= +const Standard_GUID& SALOMEDSImpl_AttributeInteger::GetID () +{ + static Standard_GUID IntegerID ("8CC3E213-C9B4-47e4-8496-DD5E62E22018"); + return IntegerID; +} + +Handle(SALOMEDSImpl_AttributeInteger) SALOMEDSImpl_AttributeInteger::Set (const TDF_Label& L, Standard_Integer Val) +{ + Handle(SALOMEDSImpl_AttributeInteger) A; + if (!L.FindAttribute(SALOMEDSImpl_AttributeInteger::GetID(), A)) { + A = new SALOMEDSImpl_AttributeInteger(); + L.AddAttribute(A); + } + + A->SetValue(Val); + return A; +} + +//======================================================================= +//function : SetValue +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeInteger::SetValue(const Standard_Integer v) +{ + if(myValue == v) return; + + Backup(); + myValue = v; +} + +//======================================================================= +//function : ID +//purpose : +//======================================================================= +const Standard_GUID& SALOMEDSImpl_AttributeInteger::ID () const { return GetID(); } + + +//======================================================================= +//function : NewEmpty +//purpose : +//======================================================================= +Handle(TDF_Attribute) SALOMEDSImpl_AttributeInteger::NewEmpty () const +{ + return new SALOMEDSImpl_AttributeInteger(); +} + +//======================================================================= +//function : Restore +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeInteger::Restore(const Handle(TDF_Attribute)& With) +{ + myValue = Handle(SALOMEDSImpl_AttributeInteger)::DownCast (With)->Value(); +} + +//======================================================================= +//function : Paste +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeInteger::Paste (const Handle(TDF_Attribute)& Into, + const Handle(TDF_RelocationTable)& RT) const +{ + Handle(SALOMEDSImpl_AttributeInteger)::DownCast(Into)->SetValue(myValue); +} diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeInteger.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeInteger.hxx new file mode 100644 index 000000000..c9113ba2f --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeInteger.hxx @@ -0,0 +1,48 @@ +// File : SALOMEDSImpl_AttributeInteger.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef _SALOMEDSImpl_AttributeInteger_HeaderFile +#define _SALOMEDSImpl_AttributeInteger_HeaderFile + +#include +#include +#include +#include +#include "SALOMEDSImpl_GenericAttribute.hxx" + +class Standard_GUID; +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_AttributeInteger, SALOMEDSImpl_GenericAttribute ) + + +class SALOMEDSImpl_AttributeInteger : public SALOMEDSImpl_GenericAttribute +{ +private: +Standard_Integer myValue; + +public: +Standard_EXPORT static const Standard_GUID& GetID() ; + +Standard_EXPORT SALOMEDSImpl_AttributeInteger():SALOMEDSImpl_GenericAttribute("AttributeInteger") {} +Standard_EXPORT static Handle(SALOMEDSImpl_AttributeInteger) Set (const TDF_Label& L, Standard_Integer Val); +Standard_EXPORT void SetValue(const Standard_Integer theVal); +Standard_EXPORT Standard_Integer Value() const { return myValue; } +Standard_EXPORT virtual TCollection_AsciiString Save() { return TCollection_AsciiString(myValue); } +Standard_EXPORT virtual void Load(const TCollection_AsciiString& theValue) { myValue = theValue.IntegerValue(); } + +Standard_EXPORT const Standard_GUID& ID() const; +Standard_EXPORT void Restore(const Handle(TDF_Attribute)& with) ; +Standard_EXPORT Handle_TDF_Attribute NewEmpty() const; +Standard_EXPORT void Paste(const Handle(TDF_Attribute)& into,const Handle(TDF_RelocationTable)& RT) const; +Standard_EXPORT ~SALOMEDSImpl_AttributeInteger() {} + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_AttributeInteger ) + +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeLocalID.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeLocalID.cxx new file mode 100644 index 000000000..59489e809 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeLocalID.cxx @@ -0,0 +1,106 @@ +// File : SALOMEDSImpl_AttributeLocalID.cxx +// Author : Sergey RUIN +// Module : SALOME + +using namespace std; +#include "SALOMEDSImpl_AttributeLocalID.hxx" +#include + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeLocalID, SALOMEDSImpl_GenericAttribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeLocalID, SALOMEDSImpl_GenericAttribute ) + +//======================================================================= +//function : GetID +//purpose : +//======================================================================= + +const Standard_GUID& SALOMEDSImpl_AttributeLocalID::GetID () +{ + static Standard_GUID SALOMEDSImpl_AttributeLocalID ("12837196-8F52-11d6-A8A3-0001021E8C7F"); + return SALOMEDSImpl_AttributeLocalID; +} + + + +//======================================================================= +//function : Set +//purpose : +//======================================================================= + +Handle(SALOMEDSImpl_AttributeLocalID) SALOMEDSImpl_AttributeLocalID::Set (const TDF_Label& L, + const Standard_Integer value) +{ + Handle(SALOMEDSImpl_AttributeLocalID) A; + if (!L.FindAttribute(SALOMEDSImpl_AttributeLocalID::GetID(),A)) { + A = new SALOMEDSImpl_AttributeLocalID(); + L.AddAttribute(A); + } + + A->SetValue(value); + return A; +} + + +//======================================================================= +//function : constructor +//purpose : +//======================================================================= +SALOMEDSImpl_AttributeLocalID::SALOMEDSImpl_AttributeLocalID() +:SALOMEDSImpl_GenericAttribute("AttributeLocalID") +{ + myValue = 0; +} + +//======================================================================= +//function : Set +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeLocalID::SetValue(const Standard_Integer theValue) +{ + CheckLocked(); + + Backup(); + + myValue = theValue; +} + + +//======================================================================= +//function : ID +//purpose : +//======================================================================= + +const Standard_GUID& SALOMEDSImpl_AttributeLocalID::ID () const { return GetID(); } + + +//======================================================================= +//function : NewEmpty +//purpose : +//======================================================================= + +Handle(TDF_Attribute) SALOMEDSImpl_AttributeLocalID::NewEmpty () const +{ + return new SALOMEDSImpl_AttributeLocalID(); +} + +//======================================================================= +//function : Restore +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributeLocalID::Restore(const Handle(TDF_Attribute)& with) +{ + myValue = Handle(SALOMEDSImpl_AttributeLocalID)::DownCast (with)->Value(); +} + +//======================================================================= +//function : Paste +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributeLocalID::Paste (const Handle(TDF_Attribute)& into, + const Handle(TDF_RelocationTable)& RT) const +{ + Handle(SALOMEDSImpl_AttributeLocalID)::DownCast (into)->SetValue(myValue); +} + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeLocalID.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeLocalID.hxx new file mode 100644 index 000000000..78dadd861 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeLocalID.hxx @@ -0,0 +1,48 @@ +// File : SALOMEDSImpl_AttributeLocalID.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef _SALOMEDSImpl_AttributeLocalID_HeaderFile +#define _SALOMEDSImpl_AttributeLocalID_HeaderFile + +#include +#include +#include +#include +#include "SALOMEDSImpl_GenericAttribute.hxx" + +class Standard_GUID; +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_AttributeLocalID, SALOMEDSImpl_GenericAttribute ) + + + +class SALOMEDSImpl_AttributeLocalID : public SALOMEDSImpl_GenericAttribute +{ +private: +Standard_Integer myValue; + +public: + +Standard_EXPORT virtual TCollection_AsciiString Save() { return TCollection_AsciiString(myValue); } +Standard_EXPORT virtual void Load(const TCollection_AsciiString& theValue) { myValue = theValue.IntegerValue(); } + +Standard_EXPORT static const Standard_GUID& GetID() ; +Standard_EXPORT static Handle_SALOMEDSImpl_AttributeLocalID Set(const TDF_Label& label,const Standard_Integer value) ; +Standard_EXPORT void SetValue(const Standard_Integer value); +Standard_EXPORT Standard_Integer Value() const { return myValue; } +Standard_EXPORT SALOMEDSImpl_AttributeLocalID(); +Standard_EXPORT const Standard_GUID& ID() const; +Standard_EXPORT void Restore(const Handle(TDF_Attribute)& with) ; +Standard_EXPORT Handle_TDF_Attribute NewEmpty() const; +Standard_EXPORT void Paste(const Handle(TDF_Attribute)& into,const Handle(TDF_RelocationTable)& RT) const; +Standard_EXPORT ~SALOMEDSImpl_AttributeLocalID() {} + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_AttributeLocalID ) +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeName.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeName.cxx new file mode 100644 index 000000000..1aa7c3717 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeName.cxx @@ -0,0 +1,83 @@ +// File : SALOMEDSImpl_AttributeName.cxx +// Author : Sergey RUIN +// Module : SALOME + +using namespace std; +#include "SALOMEDSImpl_AttributeName.hxx" + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeName, SALOMEDSImpl_GenericAttribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeName, SALOMEDSImpl_GenericAttribute ) + +//======================================================================= +//function : GetID +//purpose : +//======================================================================= +const Standard_GUID& SALOMEDSImpl_AttributeName::GetID () +{ + static Standard_GUID NameID ("8650000D-63A0-4651-B621-CC95C9308598"); + return NameID; +} + +Handle(SALOMEDSImpl_AttributeName) SALOMEDSImpl_AttributeName::Set (const TDF_Label& L, + const TCollection_ExtendedString& Val) +{ + Handle(SALOMEDSImpl_AttributeName) A; + if (!L.FindAttribute(SALOMEDSImpl_AttributeName::GetID(), A)) { + A = new SALOMEDSImpl_AttributeName(); + L.AddAttribute(A); + } + + A->SetValue(Val); + return A; +} + +//======================================================================= +//function : SetValue +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeName::SetValue (const TCollection_ExtendedString& S) +{ + CheckLocked(); + + if(myString == S) return; + + Backup(); + + myString = S; +} + + +//======================================================================= +//function : ID +//purpose : +//======================================================================= +const Standard_GUID& SALOMEDSImpl_AttributeName::ID () const { return GetID(); } + +//======================================================================= +//function : NewEmpty +//purpose : +//======================================================================= +Handle(TDF_Attribute) SALOMEDSImpl_AttributeName::NewEmpty () const +{ + return new SALOMEDSImpl_AttributeName(); +} + +//======================================================================= +//function : Restore +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeName::Restore(const Handle(TDF_Attribute)& with) +{ + myString = Handle(SALOMEDSImpl_AttributeName)::DownCast (with)->Value (); +} + +//======================================================================= +//function : Paste +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributeName::Paste (const Handle(TDF_Attribute)& into, + const Handle(TDF_RelocationTable)& RT) const +{ + Handle(SALOMEDSImpl_AttributeName)::DownCast (into)->SetValue(myString); +} diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeName.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeName.hxx new file mode 100644 index 000000000..299db5f92 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeName.hxx @@ -0,0 +1,52 @@ +// File : SALOMEDSImpl_AttributeIOR.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef _SALOMEDSImpl_AttributeName_HeaderFile +#define _SALOMEDSImpl_AttributeName_HeaderFile + +#include +#include +#include +#include +#include +#include "SALOMEDSImpl_GenericAttribute.hxx" + +class Standard_GUID; +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_AttributeName, SALOMEDSImpl_GenericAttribute ) + + +class SALOMEDSImpl_AttributeName : public SALOMEDSImpl_GenericAttribute +{ + +private: + + TCollection_ExtendedString myString; + +public: +Standard_EXPORT static const Standard_GUID& GetID() ; + +Standard_EXPORT SALOMEDSImpl_AttributeName():SALOMEDSImpl_GenericAttribute("AttributeName") {} +Standard_EXPORT static Handle(SALOMEDSImpl_AttributeName) Set (const TDF_Label& L, const TCollection_ExtendedString& Val); +Standard_EXPORT void SetValue(const TCollection_ExtendedString& theVal); +Standard_EXPORT TCollection_ExtendedString Value() const { return myString; } + +Standard_EXPORT virtual TCollection_AsciiString Save() { return myString; } +Standard_EXPORT virtual void Load(const TCollection_AsciiString& theValue) { myString = theValue; } + +Standard_EXPORT const Standard_GUID& ID() const; +Standard_EXPORT void Restore(const Handle(TDF_Attribute)& with) ; +Standard_EXPORT Handle_TDF_Attribute NewEmpty() const; +Standard_EXPORT void Paste(const Handle(TDF_Attribute)& into,const Handle(TDF_RelocationTable)& RT) const; + +Standard_EXPORT ~SALOMEDSImpl_AttributeName() {} + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_AttributeName ) +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeOpened.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeOpened.cxx new file mode 100644 index 000000000..a91afbbe2 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeOpened.cxx @@ -0,0 +1,103 @@ +// File : SALOMEDSImpl_AttributeOpened.cxx +// Author : Sergey RUIN +// Module : SALOME + +using namespace std; +#include "SALOMEDSImpl_AttributeOpened.hxx" +#include + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeOpened, SALOMEDSImpl_GenericAttribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeOpened, SALOMEDSImpl_GenericAttribute ) + +//======================================================================= +//function : GetID +//purpose : +//======================================================================= + +const Standard_GUID& SALOMEDSImpl_AttributeOpened::GetID () +{ + static Standard_GUID SALOMEDSImpl_AttributeOpenedID ("12837186-8F52-11d6-A8A3-0001021E8C7F"); + return SALOMEDSImpl_AttributeOpenedID; +} + + + +//======================================================================= +//function : Set +//purpose : +//======================================================================= + +Handle(SALOMEDSImpl_AttributeOpened) SALOMEDSImpl_AttributeOpened::Set (const TDF_Label& L, + const Standard_Integer value) +{ + Handle(SALOMEDSImpl_AttributeOpened) A; + if (!L.FindAttribute(SALOMEDSImpl_AttributeOpened::GetID(),A)) { + A = new SALOMEDSImpl_AttributeOpened(); + L.AddAttribute(A); + } + + A->SetOpened (value); + return A; +} + + +//======================================================================= +//function : constructor +//purpose : +//======================================================================= +SALOMEDSImpl_AttributeOpened::SALOMEDSImpl_AttributeOpened() +:SALOMEDSImpl_GenericAttribute("AttributeOpened") +{ + myValue = 0; +} + +//======================================================================= +//function : SetOpened +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeOpened::SetOpened(const Standard_Integer theValue) +{ + Backup(); + + (theValue!=0)?myValue=1:myValue=0; +} + +//======================================================================= +//function : ID +//purpose : +//======================================================================= + +const Standard_GUID& SALOMEDSImpl_AttributeOpened::ID () const { return GetID(); } + + +//======================================================================= +//function : NewEmpty +//purpose : +//======================================================================= + +Handle(TDF_Attribute) SALOMEDSImpl_AttributeOpened::NewEmpty () const +{ + return new SALOMEDSImpl_AttributeOpened(); +} + +//======================================================================= +//function : Restore +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributeOpened::Restore(const Handle(TDF_Attribute)& with) +{ + myValue = Handle(SALOMEDSImpl_AttributeOpened)::DownCast (with)->IsOpened (); +} + +//======================================================================= +//function : Paste +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributeOpened::Paste (const Handle(TDF_Attribute)& into, + const Handle(TDF_RelocationTable)& RT) const +{ + Handle(SALOMEDSImpl_AttributeOpened)::DownCast (into)->SetOpened (myValue); +} + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeOpened.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeOpened.hxx new file mode 100644 index 000000000..e72918267 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeOpened.hxx @@ -0,0 +1,46 @@ +// File : SALOMEDSImpl_AttributeOpened.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef _SALOMEDSImpl_AttributeOpened_HeaderFile +#define _SALOMEDSImpl_AttributeOpened_HeaderFile + +#include +#include +#include +#include +#include "SALOMEDSImpl_GenericAttribute.hxx" + +class Standard_GUID; +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_AttributeOpened, SALOMEDSImpl_GenericAttribute ) + +class SALOMEDSImpl_AttributeOpened : public SALOMEDSImpl_GenericAttribute +{ +private: +Standard_Integer myValue; + +public: + +Standard_EXPORT virtual TCollection_AsciiString Save() { return (myValue == 0)?(char*)"0":(char*)"1"; } +Standard_EXPORT virtual void Load(const TCollection_AsciiString& theValue) { (theValue == "0")?myValue=0:myValue=1; } + +Standard_EXPORT static const Standard_GUID& GetID() ; +Standard_EXPORT static Handle_SALOMEDSImpl_AttributeOpened Set(const TDF_Label& label,const Standard_Integer value) ; +Standard_EXPORT SALOMEDSImpl_AttributeOpened(); +Standard_EXPORT void SetOpened(const Standard_Integer value); +Standard_EXPORT int IsOpened() const { return myValue; } +Standard_EXPORT const Standard_GUID& ID() const; +Standard_EXPORT void Restore(const Handle(TDF_Attribute)& with) ; +Standard_EXPORT Handle_TDF_Attribute NewEmpty() const; +Standard_EXPORT void Paste(const Handle(TDF_Attribute)& into,const Handle(TDF_RelocationTable)& RT) const; +Standard_EXPORT ~SALOMEDSImpl_AttributeOpened() {} + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_AttributeOpened ) +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributePersistentRef.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributePersistentRef.cxx new file mode 100644 index 000000000..5b49e9876 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributePersistentRef.cxx @@ -0,0 +1,106 @@ +// File : SALOMEDSImpl_AttributePersistentRef.cxx +// Author : Sergey RUIN +// Module : SALOME + +using namespace std; +#include "SALOMEDSImpl_AttributePersistentRef.hxx" +#include + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributePersistentRef, SALOMEDSImpl_GenericAttribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributePersistentRef, SALOMEDSImpl_GenericAttribute ) + +//======================================================================= +//function : GetID +//purpose : +//======================================================================= + +const Standard_GUID& SALOMEDSImpl_AttributePersistentRef::GetID () +{ + static Standard_GUID SALOMEDSImpl_AttributePersistentRefID ("92888E06-7074-11d5-A690-0800369C8A03"); + return SALOMEDSImpl_AttributePersistentRefID; +} + + + +//======================================================================= +//function : Set +//purpose : +//======================================================================= + +Handle(SALOMEDSImpl_AttributePersistentRef) SALOMEDSImpl_AttributePersistentRef::Set (const TDF_Label& L, + const TCollection_ExtendedString& S) +{ + Handle(SALOMEDSImpl_AttributePersistentRef) A; + if (!L.FindAttribute(SALOMEDSImpl_AttributePersistentRef::GetID(),A)) { + A = new SALOMEDSImpl_AttributePersistentRef(); + L.AddAttribute(A); + } + + A->SetValue (S); + return A; +} + + +//======================================================================= +//function : constructor +//purpose : +//======================================================================= +SALOMEDSImpl_AttributePersistentRef::SALOMEDSImpl_AttributePersistentRef() +:SALOMEDSImpl_GenericAttribute("AttributePersistentRef") +{ +} + +//======================================================================= +//function : ID +//purpose : +//======================================================================= + +const Standard_GUID& SALOMEDSImpl_AttributePersistentRef::ID () const { return GetID(); } + + +//======================================================================= +//function : SetValue +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributePersistentRef::SetValue (const TCollection_ExtendedString& S) +{ + CheckLocked(); + + if(myString == S) return; + + Backup(); + + myString = S; +} + +//======================================================================= +//function : NewEmpty +//purpose : +//======================================================================= + +Handle(TDF_Attribute) SALOMEDSImpl_AttributePersistentRef::NewEmpty () const +{ + return new SALOMEDSImpl_AttributePersistentRef(); +} + +//======================================================================= +//function : Restore +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributePersistentRef::Restore(const Handle(TDF_Attribute)& with) +{ + myString = Handle(SALOMEDSImpl_AttributePersistentRef)::DownCast (with)->Value (); +} + +//======================================================================= +//function : Paste +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributePersistentRef::Paste (const Handle(TDF_Attribute)& into, + const Handle(TDF_RelocationTable)& RT) const +{ + Handle(SALOMEDSImpl_AttributePersistentRef)::DownCast (into)->SetValue(myString); +} + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributePersistentRef.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributePersistentRef.hxx new file mode 100644 index 000000000..f660a28fd --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributePersistentRef.hxx @@ -0,0 +1,48 @@ +// File : SALOMEDSImpl_AttributePersistentRef.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef _SALOMEDSImpl_AttributePersistentRef_HeaderFile +#define _SALOMEDSImpl_AttributePersistentRef_HeaderFile + +#include +#include +#include +#include +#include +#include "SALOMEDSImpl_GenericAttribute.hxx" + +class Standard_GUID; +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_AttributePersistentRef, SALOMEDSImpl_GenericAttribute ) + +class SALOMEDSImpl_AttributePersistentRef : public SALOMEDSImpl_GenericAttribute +{ +private: + TCollection_ExtendedString myString; + +public: + +Standard_EXPORT virtual TCollection_AsciiString Save() { return myString; } +Standard_EXPORT virtual void Load(const TCollection_AsciiString& theValue) { myString = theValue; } + +Standard_EXPORT static const Standard_GUID& GetID() ; +Standard_EXPORT static Handle_SALOMEDSImpl_AttributePersistentRef Set(const TDF_Label& label, + const TCollection_ExtendedString& string) ; +Standard_EXPORT SALOMEDSImpl_AttributePersistentRef(); +Standard_EXPORT const Standard_GUID& ID() const; +Standard_EXPORT void SetValue(const TCollection_ExtendedString& value); +Standard_EXPORT TCollection_ExtendedString Value() const { return myString; } +Standard_EXPORT void Restore(const Handle(TDF_Attribute)& with) ; +Standard_EXPORT Handle_TDF_Attribute NewEmpty() const; +Standard_EXPORT void Paste(const Handle(TDF_Attribute)& into,const Handle(TDF_RelocationTable)& RT) const; +Standard_EXPORT ~SALOMEDSImpl_AttributePersistentRef() {} + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_AttributePersistentRef ) +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributePixMap.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributePixMap.cxx new file mode 100644 index 000000000..072341ba2 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributePixMap.cxx @@ -0,0 +1,108 @@ +// File : SALOMEDSImpl_AttributePixMap.cxx +// Author : Sergey RUIN +// Module : SALOME + +using namespace std; +#include "SALOMEDSImpl_AttributePixMap.hxx" +#include +#include + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributePixMap, SALOMEDSImpl_GenericAttribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributePixMap, SALOMEDSImpl_GenericAttribute ) + +//======================================================================= +//function : GetID +//purpose : +//======================================================================= + +const Standard_GUID& SALOMEDSImpl_AttributePixMap::GetID () +{ + static Standard_GUID SALOMEDSImpl_AttributePixMapID ("12837187-8F52-11d6-A8A3-0001021E8C7F"); + return SALOMEDSImpl_AttributePixMapID; +} + + + +//======================================================================= +//function : Set +//purpose : +//======================================================================= + +Handle(SALOMEDSImpl_AttributePixMap) SALOMEDSImpl_AttributePixMap::Set (const TDF_Label& L, + const TCollection_ExtendedString& S) +{ + Handle(SALOMEDSImpl_AttributePixMap) A; + if (!L.FindAttribute(SALOMEDSImpl_AttributePixMap::GetID(),A)) { + A = new SALOMEDSImpl_AttributePixMap(); + L.AddAttribute(A); + } + + A->SetPixMap (S); + return A; +} + + +//======================================================================= +//function : constructor +//purpose : +//======================================================================= +SALOMEDSImpl_AttributePixMap::SALOMEDSImpl_AttributePixMap() +:SALOMEDSImpl_GenericAttribute("AttributePixMap") +{ + myString = "None"; +} + +//======================================================================= +//function : SetPixMap +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributePixMap::SetPixMap (const TCollection_ExtendedString& S) +{ + CheckLocked(); + + if(myString == S) return; + + Backup(); + + myString = S; +} + +//======================================================================= +//function : ID +//purpose : +//======================================================================= + +const Standard_GUID& SALOMEDSImpl_AttributePixMap::ID () const { return GetID(); } + + +//======================================================================= +//function : NewEmpty +//purpose : +//======================================================================= + +Handle(TDF_Attribute) SALOMEDSImpl_AttributePixMap::NewEmpty () const +{ + return new SALOMEDSImpl_AttributePixMap(); +} + +//======================================================================= +//function : Restore +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributePixMap::Restore(const Handle(TDF_Attribute)& with) +{ + myString = Handle(SALOMEDSImpl_AttributePixMap)::DownCast (with)->GetPixMap (); +} + +//======================================================================= +//function : Paste +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributePixMap::Paste (const Handle(TDF_Attribute)& into, + const Handle(TDF_RelocationTable)& RT) const +{ + Handle(SALOMEDSImpl_AttributePixMap)::DownCast (into)->SetPixMap (myString); +} + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributePixMap.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributePixMap.hxx new file mode 100644 index 000000000..521c79f45 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributePixMap.hxx @@ -0,0 +1,51 @@ +// File : SALOMEDSImpl_AttributePixMap.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef _SALOMEDSImpl_AttributePixMap_HeaderFile +#define _SALOMEDSImpl_AttributePixMap_HeaderFile + +#include +#include +#include +#include +#include +#include "SALOMEDSImpl_GenericAttribute.hxx" + +class Standard_GUID; +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_AttributePixMap, SALOMEDSImpl_GenericAttribute ) + + + +class SALOMEDSImpl_AttributePixMap : public SALOMEDSImpl_GenericAttribute +{ +private: + + TCollection_ExtendedString myString; +public: + +Standard_EXPORT virtual TCollection_AsciiString Save() { return myString; } +Standard_EXPORT virtual void Load(const TCollection_AsciiString& theValue) { myString = theValue; } + +Standard_EXPORT static const Standard_GUID& GetID() ; +Standard_EXPORT static Handle_SALOMEDSImpl_AttributePixMap Set(const TDF_Label& label, + const TCollection_ExtendedString& string) ; +Standard_EXPORT SALOMEDSImpl_AttributePixMap(); +Standard_EXPORT const Standard_GUID& ID() const; +Standard_EXPORT void SetPixMap(const TCollection_ExtendedString& value); +Standard_EXPORT TCollection_ExtendedString GetPixMap() const { return myString; } +Standard_EXPORT Standard_Boolean HasPixMap() const { return (myString != "None"); } +Standard_EXPORT void Restore(const Handle(TDF_Attribute)& with) ; +Standard_EXPORT Handle_TDF_Attribute NewEmpty() const; +Standard_EXPORT void Paste(const Handle(TDF_Attribute)& into,const Handle(TDF_RelocationTable)& RT) const; +Standard_EXPORT ~SALOMEDSImpl_AttributePixMap() {} + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_AttributePixMap ) +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributePythonObject.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributePythonObject.cxx new file mode 100644 index 000000000..71b12bf0f --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributePythonObject.cxx @@ -0,0 +1,98 @@ +// File : SALOMEDSImpl_AttributePythonObject.cxx +// Author : Michael Ponikarov +// Module : SALOME + +using namespace std; +#include "SALOMEDSImpl_AttributePythonObject.hxx" +#include +#include + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributePythonObject, SALOMEDSImpl_GenericAttribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributePythonObject, SALOMEDSImpl_GenericAttribute ) + +const Standard_GUID& SALOMEDSImpl_AttributePythonObject::GetID() +{ + static Standard_GUID SALOMEDSImpl_AttributePythonObjectID ("128371A3-8F52-11d6-A8A3-0001021E8C7F"); + return SALOMEDSImpl_AttributePythonObjectID; +} + +Handle(SALOMEDSImpl_AttributePythonObject) SALOMEDSImpl_AttributePythonObject::Set(const TDF_Label& label) +{ + Handle(SALOMEDSImpl_AttributePythonObject) anAttr; + if (!label.FindAttribute(SALOMEDSImpl_AttributePythonObject::GetID(),anAttr)) { + anAttr = new SALOMEDSImpl_AttributePythonObject(); + label.AddAttribute(anAttr); + } + return anAttr; +} + +SALOMEDSImpl_AttributePythonObject::SALOMEDSImpl_AttributePythonObject() +:SALOMEDSImpl_GenericAttribute("AttributePythonObject") +{ +} + +void SALOMEDSImpl_AttributePythonObject::SetObject(const TCollection_AsciiString& theSequence, + const bool theScript) +{ + CheckLocked(); + Backup(); + mySequence = theSequence; + myIsScript = theScript; +} + +TCollection_AsciiString SALOMEDSImpl_AttributePythonObject::GetObject() const +{ + return mySequence; +} + +bool SALOMEDSImpl_AttributePythonObject::IsScript() const +{ + return myIsScript; +} + +int SALOMEDSImpl_AttributePythonObject::GetLength() const +{ + return mySequence.Length(); +} + +const Standard_GUID& SALOMEDSImpl_AttributePythonObject::ID() const +{ + return GetID(); +} + +void SALOMEDSImpl_AttributePythonObject::Restore(const Handle(TDF_Attribute)& with) +{ + Handle(SALOMEDSImpl_AttributePythonObject) anObj = Handle(SALOMEDSImpl_AttributePythonObject)::DownCast(with); + SetObject(anObj->GetObject(),anObj->IsScript()); +} + +Handle(TDF_Attribute) SALOMEDSImpl_AttributePythonObject::NewEmpty() const +{ + return new SALOMEDSImpl_AttributePythonObject(); +} + +void SALOMEDSImpl_AttributePythonObject::Paste(const Handle(TDF_Attribute)& into, + const Handle(TDF_RelocationTable)&) const +{ + Handle(SALOMEDSImpl_AttributePythonObject) anObj = Handle(SALOMEDSImpl_AttributePythonObject)::DownCast(into); + anObj->SetObject(GetObject(),IsScript()); +} + + +TCollection_AsciiString SALOMEDSImpl_AttributePythonObject::Save() +{ + char* aString = (char*)GetObject().ToCString(); + char* aResult = new char[strlen(aString) + 2]; + aResult[0] = IsScript()?'s':'n'; + strcpy(aResult+1, aString); + TCollection_AsciiString ret(aResult); + + delete aResult; + return ret; +} + +void SALOMEDSImpl_AttributePythonObject::Load(const TCollection_AsciiString& value) +{ + char* aString = value.ToCString(); + SetObject(aString + 1, aString[0]=='s'); +} diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributePythonObject.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributePythonObject.hxx new file mode 100644 index 000000000..460e3023e --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributePythonObject.hxx @@ -0,0 +1,54 @@ +// File : SALOMEDSImpl_AttributePythonObject.hxx +// Author : Michael Ponikarov +// Module : SALOME + +#ifndef _SALOMEDSImpl_AttributePythonObject_HeaderFile +#define _SALOMEDSImpl_AttributePythonObject_HeaderFile + +#include +#include +#include +#include +#include +#include "SALOMEDSImpl_GenericAttribute.hxx" + +class Standard_GUID; +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_AttributePythonObject, SALOMEDSImpl_GenericAttribute ) + + + +class SALOMEDSImpl_AttributePythonObject : public SALOMEDSImpl_GenericAttribute +{ + +public: +Standard_EXPORT virtual TCollection_AsciiString Save(); +Standard_EXPORT virtual void Load(const TCollection_AsciiString&); + +Standard_EXPORT static const Standard_GUID& GetID() ; +Standard_EXPORT static Handle_SALOMEDSImpl_AttributePythonObject Set(const TDF_Label& label) ; +Standard_EXPORT SALOMEDSImpl_AttributePythonObject(); +Standard_EXPORT void SetObject(const TCollection_AsciiString& theSequence, const bool theScript) ; +Standard_EXPORT TCollection_AsciiString GetObject() const; +Standard_EXPORT bool IsScript() const; +Standard_EXPORT int GetLength() const; +Standard_EXPORT const Standard_GUID& ID() const; +Standard_EXPORT void Restore(const Handle(TDF_Attribute)& with) ; +Standard_EXPORT Handle_TDF_Attribute NewEmpty() const; +Standard_EXPORT void Paste(const Handle(TDF_Attribute)& into,const Handle(TDF_RelocationTable)& RT) const; +Standard_EXPORT ~SALOMEDSImpl_AttributePythonObject() {} + +private: + +TCollection_AsciiString mySequence; +bool myIsScript; + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_AttributePythonObject ) + +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeReal.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeReal.cxx new file mode 100644 index 000000000..2d1e16f27 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeReal.cxx @@ -0,0 +1,82 @@ +// File : SALOMEDSImpl_AttributeReal.cxx +// Author : Sergey RUIN +// Module : SALOME + +using namespace std; +#include "SALOMEDSImpl_AttributeReal.hxx" + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeReal, SALOMEDSImpl_GenericAttribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeReal, SALOMEDSImpl_GenericAttribute ) + +//======================================================================= +//function : GetID +//purpose : +//======================================================================= +const Standard_GUID& SALOMEDSImpl_AttributeReal::GetID () +{ + static Standard_GUID realID ("1D1992F0-56F4-46b4-8065-CDEA68061CAB"); + return realID; +} + +Handle(SALOMEDSImpl_AttributeReal) SALOMEDSImpl_AttributeReal::Set (const TDF_Label& L, const Standard_Real Val) +{ + Handle(SALOMEDSImpl_AttributeReal) A; + if (!L.FindAttribute(SALOMEDSImpl_AttributeReal::GetID(), A)) { + A = new SALOMEDSImpl_AttributeReal(); + L.AddAttribute(A); + } + + A->SetValue(Val); + return A; +} + +//======================================================================= +//function : SetValue +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeReal::SetValue(const Standard_Real v) +{ + CheckLocked(); + + if( myValue == v) return; + + Backup(); + myValue = v; +} + +//======================================================================= +//function : ID +//purpose : +//======================================================================= +const Standard_GUID& SALOMEDSImpl_AttributeReal::ID () const +{ + return GetID(); +} + +//======================================================================= +//function : NewEmpty +//purpose : +//======================================================================= +Handle(TDF_Attribute) SALOMEDSImpl_AttributeReal::NewEmpty () const +{ + return new SALOMEDSImpl_AttributeReal(); +} + +//======================================================================= +//function : Restore +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeReal::Restore(const Handle(TDF_Attribute)& with) +{ + myValue = Handle(SALOMEDSImpl_AttributeReal)::DownCast (with)->Value (); +} + +//======================================================================= +//function : Paste +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeReal::Paste (const Handle(TDF_Attribute)& into, + const Handle(TDF_RelocationTable)& RT) const +{ + Handle(SALOMEDSImpl_AttributeReal)::DownCast (into)->SetValue(myValue); +} diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeReal.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeReal.hxx new file mode 100644 index 000000000..de47ad445 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeReal.hxx @@ -0,0 +1,48 @@ +// File : SALOMEDSImpl_AttributeReal.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef _SALOMEDSImpl_AttributeReal_HeaderFile +#define _SALOMEDSImpl_AttributeReal_HeaderFile + +#include +#include +#include +#include +#include "SALOMEDSImpl_GenericAttribute.hxx" + +class Standard_GUID; +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_AttributeReal, SALOMEDSImpl_GenericAttribute ) + + +class SALOMEDSImpl_AttributeReal : public SALOMEDSImpl_GenericAttribute +{ +private: + Standard_Real myValue; +public: + +Standard_EXPORT Standard_EXPORT static const Standard_GUID& GetID() ; + +Standard_EXPORT SALOMEDSImpl_AttributeReal():SALOMEDSImpl_GenericAttribute("AttributeReal") {} +Standard_EXPORT static Handle(SALOMEDSImpl_AttributeReal) Set (const TDF_Label& L, const Standard_Real Val); +Standard_EXPORT void SetValue(const Standard_Real theVal); +Standard_EXPORT Standard_Real Value() const { return myValue; } +Standard_EXPORT virtual TCollection_AsciiString Save() { return TCollection_AsciiString(myValue); } +Standard_EXPORT virtual void Load(const TCollection_AsciiString& theValue) { myValue = theValue.RealValue(); } + +Standard_EXPORT const Standard_GUID& ID() const; +Standard_EXPORT void Restore(const Handle(TDF_Attribute)& with) ; +Standard_EXPORT Handle_TDF_Attribute NewEmpty() const; +Standard_EXPORT void Paste(const Handle(TDF_Attribute)& into,const Handle(TDF_RelocationTable)& RT) const; +Standard_EXPORT ~SALOMEDSImpl_AttributeReal() {} + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_AttributeReal ) + +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeReference.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeReference.cxx new file mode 100644 index 000000000..6677fddb5 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeReference.cxx @@ -0,0 +1,105 @@ +// File : SALOMEDSImpl_AttributeReference.cxx +// Author : Sergey RUIN +// Module : SALOME + +using namespace std; +#include "SALOMEDSImpl_AttributeReference.hxx" +#include +#include +#include + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeReference, SALOMEDSImpl_GenericAttribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeReference, SALOMEDSImpl_GenericAttribute ) + + +//======================================================================= +//function : GetID +//purpose : +//======================================================================= +const Standard_GUID& SALOMEDSImpl_AttributeReference::GetID () +{ + static Standard_GUID refID ("D913E0B3-0A9F-4ea6-9480-18A9B72D9D86"); + return refID; +} + +Handle(SALOMEDSImpl_AttributeReference) SALOMEDSImpl_AttributeReference::Set(const TDF_Label& theLabel, + const TDF_Label& theRefLabel) +{ + Handle(SALOMEDSImpl_AttributeReference) A; + if (!theLabel.FindAttribute(SALOMEDSImpl_AttributeReference::GetID(), A)) { + A = new SALOMEDSImpl_AttributeReference(); + theLabel.AddAttribute(A); + } + + A->Set(theRefLabel); + return A; +} + +//======================================================================= +//function : Set +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeReference::Set(const TDF_Label& Origin) +{ + CheckLocked(); + + if(myLabel == Origin) return; + + Backup(); + myLabel = Origin; +} + +//======================================================================= +//function : ID +//purpose : +//======================================================================= +const Standard_GUID& SALOMEDSImpl_AttributeReference::ID () const { return GetID(); } + + +TCollection_AsciiString SALOMEDSImpl_AttributeReference::Save() +{ + TCollection_AsciiString anEntry; + TDF_Tool::Entry(myLabel, anEntry); + return anEntry; +} + +void SALOMEDSImpl_AttributeReference::Load(const TCollection_AsciiString& value) +{ + TDF_Label aLabel; + TDF_Tool::Label(Label().Data(), value, aLabel); + myLabel = aLabel; +} + +//======================================================================= +//function : NewEmpty +//purpose : +//======================================================================= +Handle(TDF_Attribute) SALOMEDSImpl_AttributeReference::NewEmpty () const +{ + return new SALOMEDSImpl_AttributeReference(); +} + +//======================================================================= +//function : Restore +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributeReference::Restore(const Handle(TDF_Attribute)& With) +{ + myLabel = Handle(SALOMEDSImpl_AttributeReference)::DownCast (With)->Get (); +} + +//======================================================================= +//function : Paste +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributeReference::Paste (const Handle(TDF_Attribute)& Into, + const Handle(TDF_RelocationTable)& RT) const +{ + TDF_Label tLab; + if (!myLabel.IsNull()) { + if (!RT->HasRelocation(myLabel,tLab)) tLab = myLabel; + } + Handle(SALOMEDSImpl_AttributeReference)::DownCast(Into)->Set(tLab); +} diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeReference.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeReference.hxx new file mode 100644 index 000000000..6468c71d9 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeReference.hxx @@ -0,0 +1,50 @@ +// File : SALOMEDSImpl_AttributeIOR.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef _SALOMEDSImpl_AttributeReference_HeaderFile +#define _SALOMEDSImpl_AttributeReference_HeaderFile + +#include +#include +#include +#include +#include "SALOMEDSImpl_GenericAttribute.hxx" + +class Standard_GUID; +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_AttributeReference, SALOMEDSImpl_GenericAttribute ) + + + +class SALOMEDSImpl_AttributeReference : public SALOMEDSImpl_GenericAttribute +{ +private: + TDF_Label myLabel; + +public: + +Standard_EXPORT static const Standard_GUID& GetID() ; + +Standard_EXPORT SALOMEDSImpl_AttributeReference():SALOMEDSImpl_GenericAttribute("AttributeReference") {} +Standard_EXPORT static Handle(SALOMEDSImpl_AttributeReference) Set(const TDF_Label& theLabel, const TDF_Label& theRefLabel); +Standard_EXPORT void Set(const TDF_Label& theLabel); +Standard_EXPORT TDF_Label Get() const { return myLabel; } +Standard_EXPORT virtual TCollection_AsciiString Save(); +Standard_EXPORT virtual void Load(const TCollection_AsciiString& theValue); + +Standard_EXPORT const Standard_GUID& ID() const; +Standard_EXPORT void Restore(const Handle(TDF_Attribute)& with) ; +Standard_EXPORT Handle_TDF_Attribute NewEmpty() const; +Standard_EXPORT void Paste(const Handle(TDF_Attribute)& into,const Handle(TDF_RelocationTable)& RT) const; + +Standard_EXPORT ~SALOMEDSImpl_AttributeReference() {} + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_AttributeReference ) +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeSelectable.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeSelectable.cxx new file mode 100644 index 000000000..9fc8088cf --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeSelectable.cxx @@ -0,0 +1,103 @@ +// File : SALOMEDSImpl_AttributeSelectable.cxx +// Author : Sergey RUIN +// Module : SALOME + +using namespace std; +#include "SALOMEDSImpl_AttributeSelectable.hxx" +#include + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeSelectable, SALOMEDSImpl_GenericAttribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeSelectable, SALOMEDSImpl_GenericAttribute ) + +//======================================================================= +//function : GetID +//purpose : +//======================================================================= + +const Standard_GUID& SALOMEDSImpl_AttributeSelectable::GetID () +{ + static Standard_GUID SALOMEDSImpl_AttributeSelectableID ("12837188-8F52-11d6-A8A3-0001021E8C7F"); + return SALOMEDSImpl_AttributeSelectableID; +} + + + +//======================================================================= +//function : Set +//purpose : +//======================================================================= + +Handle(SALOMEDSImpl_AttributeSelectable) SALOMEDSImpl_AttributeSelectable::Set (const TDF_Label& L, + const Standard_Integer value) +{ + Handle(SALOMEDSImpl_AttributeSelectable) A; + if (!L.FindAttribute(SALOMEDSImpl_AttributeSelectable::GetID(),A)) { + A = new SALOMEDSImpl_AttributeSelectable(); + L.AddAttribute(A); + } + + A->SetSelectable (value); + return A; +} + + +//======================================================================= +//function : constructor +//purpose : +//======================================================================= +SALOMEDSImpl_AttributeSelectable::SALOMEDSImpl_AttributeSelectable() +:SALOMEDSImpl_GenericAttribute("AttributeSelectable") +{ + myValue = 0; +} + +//======================================================================= +//function : SetSelectable +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeSelectable::SetSelectable(const Standard_Integer theValue) +{ + Backup(); + + (theValue!=0)?myValue=1:myValue=0; +} + +//======================================================================= +//function : ID +//purpose : +//======================================================================= + +const Standard_GUID& SALOMEDSImpl_AttributeSelectable::ID () const { return GetID(); } + + +//======================================================================= +//function : NewEmpty +//purpose : +//======================================================================= + +Handle(TDF_Attribute) SALOMEDSImpl_AttributeSelectable::NewEmpty () const +{ + return new SALOMEDSImpl_AttributeSelectable(); +} + +//======================================================================= +//function : Restore +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributeSelectable::Restore(const Handle(TDF_Attribute)& with) +{ + myValue = Handle(SALOMEDSImpl_AttributeSelectable)::DownCast (with)->IsSelectable (); +} + +//======================================================================= +//function : Paste +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributeSelectable::Paste (const Handle(TDF_Attribute)& into, + const Handle(TDF_RelocationTable)& RT) const +{ + Handle(SALOMEDSImpl_AttributeSelectable)::DownCast (into)->SetSelectable (myValue); +} + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeSelectable.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeSelectable.hxx new file mode 100644 index 000000000..5f6ee4fb2 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeSelectable.hxx @@ -0,0 +1,49 @@ +// File : SALOMEDSImpl_AttributeSelectable.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef _SALOMEDSImpl_AttributeSelectable_HeaderFile +#define _SALOMEDSImpl_AttributeSelectable_HeaderFile + +#include +#include +#include +#include +#include "SALOMEDSImpl_GenericAttribute.hxx" + +class Standard_GUID; +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_AttributeSelectable, SALOMEDSImpl_GenericAttribute ) + + + +class SALOMEDSImpl_AttributeSelectable : public SALOMEDSImpl_GenericAttribute +{ +private: +Standard_Integer myValue; + +public: + +Standard_EXPORT virtual TCollection_AsciiString Save() { return (myValue == 0)?(char*)"0":(char*)"1"; } +Standard_EXPORT virtual void Load(const TCollection_AsciiString& theValue) { (theValue == "0")?myValue=0:myValue=1; } + +Standard_EXPORT static const Standard_GUID& GetID() ; +Standard_EXPORT static Handle_SALOMEDSImpl_AttributeSelectable Set(const TDF_Label& label,const Standard_Integer value) ; +Standard_EXPORT SALOMEDSImpl_AttributeSelectable(); +Standard_EXPORT void SetSelectable(const Standard_Integer value); +Standard_EXPORT Standard_Integer IsSelectable() const { return myValue; } +Standard_EXPORT const Standard_GUID& ID() const; +Standard_EXPORT void Restore(const Handle(TDF_Attribute)& with) ; +Standard_EXPORT Handle_TDF_Attribute NewEmpty() const; +Standard_EXPORT void Paste(const Handle(TDF_Attribute)& into,const Handle(TDF_RelocationTable)& RT) const; +Standard_EXPORT ~SALOMEDSImpl_AttributeSelectable() {} + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_AttributeDrawable ) + +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeSequenceOfInteger.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeSequenceOfInteger.cxx new file mode 100644 index 000000000..47b8ca653 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeSequenceOfInteger.cxx @@ -0,0 +1,170 @@ +// File : SALOMEDSImpl_AttributeSequenceOfInteger.cxx +// Author : Sergey RUIN +// Module : SALOME + +using namespace std; +#include "SALOMEDSImpl_AttributeSequenceOfInteger.hxx" +#include + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeSequenceOfInteger, SALOMEDSImpl_GenericAttribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeSequenceOfInteger, SALOMEDSImpl_GenericAttribute ) + + +//======================================================================= +//function : GetID +//purpose : +//======================================================================= + +const Standard_GUID& SALOMEDSImpl_AttributeSequenceOfInteger::GetID () +{ + static Standard_GUID SALOMEDSImpl_AttributeSequenceOfIntegerID ("12837182-8F52-11d6-A8A3-0001021E8C7F"); + return SALOMEDSImpl_AttributeSequenceOfIntegerID; +} + + + +//======================================================================= +//function : Set +//purpose : +//======================================================================= + +Handle(SALOMEDSImpl_AttributeSequenceOfInteger) SALOMEDSImpl_AttributeSequenceOfInteger::Set (const TDF_Label& L) +{ + Handle(SALOMEDSImpl_AttributeSequenceOfInteger) A; + if (!L.FindAttribute(SALOMEDSImpl_AttributeSequenceOfInteger::GetID(),A)) { + A = new SALOMEDSImpl_AttributeSequenceOfInteger(); + L.AddAttribute(A); + } + return A; +} + + +//======================================================================= +//function : constructor +//purpose : +//======================================================================= +SALOMEDSImpl_AttributeSequenceOfInteger::SALOMEDSImpl_AttributeSequenceOfInteger() +:SALOMEDSImpl_GenericAttribute("AttributeSequenceOfInteger") +{ + myValue = new TColStd_HSequenceOfInteger(); +} + +//======================================================================= +//function : ID +//purpose : +//======================================================================= + +const Standard_GUID& SALOMEDSImpl_AttributeSequenceOfInteger::ID () const { return GetID(); } + + +//======================================================================= +//function : NewEmpty +//purpose : +//======================================================================= + +Handle(TDF_Attribute) SALOMEDSImpl_AttributeSequenceOfInteger::NewEmpty () const +{ + return new SALOMEDSImpl_AttributeSequenceOfInteger(); +} + +//======================================================================= +//function : Restore +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributeSequenceOfInteger::Restore(const Handle(TDF_Attribute)& with) +{ + Standard_Integer i; + Handle(SALOMEDSImpl_AttributeSequenceOfInteger) anSeq = Handle(SALOMEDSImpl_AttributeSequenceOfInteger)::DownCast(with); + if(!anSeq->myValue.IsNull()) { + myValue = new TColStd_HSequenceOfInteger(); + Standard_Integer Len = anSeq->Length(); + for(i = 1; i<=Len; i++) Add(anSeq->Value(i)); + } + else + myValue.Nullify(); + return; +} + +//======================================================================= +//function : Paste +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributeSequenceOfInteger::Paste (const Handle(TDF_Attribute)& into, + const Handle(TDF_RelocationTable)& ) const +{ + if(!myValue.IsNull()) { + Handle(SALOMEDSImpl_AttributeSequenceOfInteger)::DownCast (into)->Assign(myValue); + } +} + +void SALOMEDSImpl_AttributeSequenceOfInteger::Assign(const Handle(TColStd_HSequenceOfInteger)& other) +{ + CheckLocked(); + Backup(); + if (myValue.IsNull()) myValue = new TColStd_HSequenceOfInteger; + myValue->ChangeSequence() = other->Sequence(); +} + +void SALOMEDSImpl_AttributeSequenceOfInteger::ChangeValue(const Standard_Integer Index,const Standard_Integer Value) +{ + CheckLocked(); + Backup(); + myValue->SetValue(Index, Value); +} + +void SALOMEDSImpl_AttributeSequenceOfInteger::Add(const Standard_Integer Value) +{ + CheckLocked(); + Backup(); + myValue->Append(Value); +} + +void SALOMEDSImpl_AttributeSequenceOfInteger::Remove(const Standard_Integer Index) +{ + CheckLocked(); + Backup(); + myValue->Remove(Index); +} + +Standard_Integer SALOMEDSImpl_AttributeSequenceOfInteger::Length() +{ + return myValue->Length(); +} +Standard_Integer SALOMEDSImpl_AttributeSequenceOfInteger::Value(const Standard_Integer Index) +{ + return myValue->Value(Index); +} + + + +TCollection_AsciiString SALOMEDSImpl_AttributeSequenceOfInteger::Save() +{ + Standard_Integer aLength = Length(); + char* aResult = new char[aLength * 25]; + aResult[0] = 0; + Standard_Integer aPosition = 0; + for (int i = 1; i <= aLength; i++) { + sprintf(aResult + aPosition , "%d ", Value(i)); + aPosition += strlen(aResult + aPosition); + } + TCollection_AsciiString ret(aResult); + delete aResult; + + return ret; +} + +void SALOMEDSImpl_AttributeSequenceOfInteger::Load(const TCollection_AsciiString& value) +{ + Handle(TColStd_HSequenceOfInteger) CasCadeSeq = new TColStd_HSequenceOfInteger; + + char* aCopy = value.ToCString(); + char* adr = strtok(aCopy, " "); + while (adr) { + int l = atol(adr); + CasCadeSeq->Append(l); + adr = strtok(NULL, " "); + } + Assign(CasCadeSeq); +} diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeSequenceOfInteger.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeSequenceOfInteger.hxx new file mode 100644 index 000000000..a24aa5646 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeSequenceOfInteger.hxx @@ -0,0 +1,54 @@ +// File : SALOMEDSImpl_AttributeSequenceOfInteger.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef _SALOMEDSImpl_AttributeSequenceOfInteger_HeaderFile +#define _SALOMEDSImpl_AttributeSequenceOfInteger_HeaderFile + +#include +#include +#include +#include +#include +#include "SALOMEDSImpl_GenericAttribute.hxx" + +class Standard_GUID; +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_AttributeSequenceOfInteger, SALOMEDSImpl_GenericAttribute ) + +class SALOMEDSImpl_AttributeSequenceOfInteger : public SALOMEDSImpl_GenericAttribute +{ + +public: + +Standard_EXPORT virtual TCollection_AsciiString Save(); +Standard_EXPORT virtual void Load(const TCollection_AsciiString&); + +Standard_EXPORT static const Standard_GUID& GetID() ; +Standard_EXPORT static Handle_SALOMEDSImpl_AttributeSequenceOfInteger Set(const TDF_Label& label) ; +Standard_EXPORT SALOMEDSImpl_AttributeSequenceOfInteger(); +Standard_EXPORT void Assign(const Handle(TColStd_HSequenceOfInteger)& other) ; +Standard_EXPORT void ChangeValue(const Standard_Integer Index,const Standard_Integer Value) ; +Standard_EXPORT void Add(const Standard_Integer value) ; +Standard_EXPORT Standard_Integer Value(const Standard_Integer Index) ; +Standard_EXPORT void Remove(const Standard_Integer Index) ; +Standard_EXPORT Standard_Integer Length() ; +Standard_EXPORT const Standard_GUID& ID() const; +Standard_EXPORT void Restore(const Handle(TDF_Attribute)& with) ; +Standard_EXPORT Handle_TDF_Attribute NewEmpty() const; +Standard_EXPORT void Paste(const Handle(TDF_Attribute)& into,const Handle(TDF_RelocationTable)& RT) const; +Standard_EXPORT ~SALOMEDSImpl_AttributeSequenceOfInteger() {} + +private: + +Handle_TColStd_HSequenceOfInteger myValue; + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_AttributeSequenceOfInteger ) + +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeSequenceOfReal.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeSequenceOfReal.cxx new file mode 100644 index 000000000..5b038b61a --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeSequenceOfReal.cxx @@ -0,0 +1,170 @@ +// File : SALOMEDSImpl_AttributeSequenceOfReal.cxx +// Author : Sergey RUIN +// Module : SALOME + +using namespace std; +#include "SALOMEDSImpl_AttributeSequenceOfReal.hxx" +#include + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeSequenceOfReal, SALOMEDSImpl_GenericAttribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeSequenceOfReal, SALOMEDSImpl_GenericAttribute ) + +//======================================================================= +//function : GetID +//purpose : +//======================================================================= + +const Standard_GUID& SALOMEDSImpl_AttributeSequenceOfReal::GetID () +{ + static Standard_GUID SALOMEDSImpl_AttributeSequenceOfRealID ("12837183-8F52-11d6-A8A3-0001021E8C7F"); + return SALOMEDSImpl_AttributeSequenceOfRealID; +} + + + +//======================================================================= +//function : Set +//purpose : +//======================================================================= + +Handle(SALOMEDSImpl_AttributeSequenceOfReal) SALOMEDSImpl_AttributeSequenceOfReal::Set (const TDF_Label& L) +{ + Handle(SALOMEDSImpl_AttributeSequenceOfReal) A; + if (!L.FindAttribute(SALOMEDSImpl_AttributeSequenceOfReal::GetID(),A)) { + A = new SALOMEDSImpl_AttributeSequenceOfReal(); + L.AddAttribute(A); + } + return A; +} + + +//======================================================================= +//function : constructor +//purpose : +//======================================================================= +SALOMEDSImpl_AttributeSequenceOfReal::SALOMEDSImpl_AttributeSequenceOfReal() +:SALOMEDSImpl_GenericAttribute("AttributeSequenceOfReal") +{ + myValue = new TColStd_HSequenceOfReal(); +} + +//======================================================================= +//function : ID +//purpose : +//======================================================================= + +const Standard_GUID& SALOMEDSImpl_AttributeSequenceOfReal::ID () const { return GetID(); } + + +//======================================================================= +//function : NewEmpty +//purpose : +//======================================================================= + +Handle(TDF_Attribute) SALOMEDSImpl_AttributeSequenceOfReal::NewEmpty () const +{ + return new SALOMEDSImpl_AttributeSequenceOfReal(); +} + +//======================================================================= +//function : Restore +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributeSequenceOfReal::Restore(const Handle(TDF_Attribute)& with) +{ + Standard_Integer i; + Handle(SALOMEDSImpl_AttributeSequenceOfReal) anSeq = Handle(SALOMEDSImpl_AttributeSequenceOfReal)::DownCast(with); + if(!anSeq->myValue.IsNull()) { + myValue = new TColStd_HSequenceOfReal(); + Standard_Integer Len = anSeq->Length(); + for(i = 1; i<=Len; i++) Add(anSeq->Value(i)); + } + else + myValue.Nullify(); + return; +} + +//======================================================================= +//function : Paste +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributeSequenceOfReal::Paste (const Handle(TDF_Attribute)& into, + const Handle(TDF_RelocationTable)& ) const +{ + if(!myValue.IsNull()) { + Handle(SALOMEDSImpl_AttributeSequenceOfReal)::DownCast (into)->Assign(myValue); + } +} + +void SALOMEDSImpl_AttributeSequenceOfReal::Assign(const Handle(TColStd_HSequenceOfReal)& other) +{ + CheckLocked(); + Backup(); + if (myValue.IsNull()) myValue = new TColStd_HSequenceOfReal; + myValue->ChangeSequence() = other->Sequence(); +} + +void SALOMEDSImpl_AttributeSequenceOfReal::ChangeValue(const Standard_Integer Index,const Standard_Real Value) +{ + CheckLocked(); + Backup(); + myValue->SetValue(Index, Value); +} + +void SALOMEDSImpl_AttributeSequenceOfReal::Add(const Standard_Real Value) +{ + CheckLocked(); + Backup(); + myValue->Append(Value); +} + +void SALOMEDSImpl_AttributeSequenceOfReal::Remove(const Standard_Integer Index) +{ + CheckLocked(); + Backup(); + myValue->Remove(Index); +} + +Standard_Integer SALOMEDSImpl_AttributeSequenceOfReal::Length() +{ + return myValue->Length(); +} + +Standard_Real SALOMEDSImpl_AttributeSequenceOfReal::Value(const Standard_Integer Index) +{ + return myValue->Value(Index); +} + + +TCollection_AsciiString SALOMEDSImpl_AttributeSequenceOfReal::Save() +{ + Standard_Integer aLength = Length(); + char* aResult = new char[aLength * 25]; + aResult[0] = 0; + Standard_Integer aPosition = 0; + for (int i = 1; i <= aLength; i++) { + sprintf(aResult + aPosition , "%f ", Value(i)); + aPosition += strlen(aResult + aPosition); + } + TCollection_AsciiString ret(aResult); + delete aResult; + + return ret; +} + +void SALOMEDSImpl_AttributeSequenceOfReal::Load(const TCollection_AsciiString& value) +{ + Handle(TColStd_HSequenceOfReal) CasCadeSeq = new TColStd_HSequenceOfReal; + + char* aCopy = value.ToCString(); + char* adr = strtok(aCopy, " "); + char *err = NULL; + while (adr) { + Standard_Real r = strtod(adr, &err); + CasCadeSeq->Append(r); + adr = strtok(NULL, " "); + } + Assign(CasCadeSeq); +} diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeSequenceOfReal.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeSequenceOfReal.hxx new file mode 100644 index 000000000..a7c93716f --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeSequenceOfReal.hxx @@ -0,0 +1,53 @@ +// File : SALOMEDSImpl_AttributeSequenceOfReal.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef _SALOMEDSImpl_AttributeSequenceOfReal_HeaderFile +#define _SALOMEDSImpl_AttributeSequenceOfReal_HeaderFile + +#include +#include +#include +#include +#include +#include "SALOMEDSImpl_GenericAttribute.hxx" + +class Standard_GUID; +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_AttributeSequenceOfReal, SALOMEDSImpl_GenericAttribute ) + +class SALOMEDSImpl_AttributeSequenceOfReal : public SALOMEDSImpl_GenericAttribute +{ + +public: + +Standard_EXPORT virtual TCollection_AsciiString Save(); +Standard_EXPORT virtual void Load(const TCollection_AsciiString&); + +Standard_EXPORT static const Standard_GUID& GetID() ; +Standard_EXPORT static Handle_SALOMEDSImpl_AttributeSequenceOfReal Set(const TDF_Label& label) ; +Standard_EXPORT SALOMEDSImpl_AttributeSequenceOfReal(); +Standard_EXPORT void Assign(const Handle(TColStd_HSequenceOfReal)& other) ; +Standard_EXPORT void ChangeValue(const Standard_Integer Index,const Standard_Real Value) ; +Standard_EXPORT void Add(const Standard_Real Value) ; +Standard_EXPORT Standard_Real Value(const Standard_Integer Index) ; +Standard_EXPORT void Remove(const Standard_Integer Index) ; +Standard_EXPORT Standard_Integer Length() ; +Standard_EXPORT const Standard_GUID& ID() const; +Standard_EXPORT void Restore(const Handle(TDF_Attribute)& with) ; +Standard_EXPORT Handle_TDF_Attribute NewEmpty() const; +Standard_EXPORT void Paste(const Handle(TDF_Attribute)& into,const Handle(TDF_RelocationTable)& RT) const; +Standard_EXPORT ~SALOMEDSImpl_AttributeSequenceOfReal() {} + +private: +Handle_TColStd_HSequenceOfReal myValue; + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_AttributeSequenceOfReal ) + +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeStudyProperties.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeStudyProperties.cxx new file mode 100644 index 000000000..b22df3386 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeStudyProperties.cxx @@ -0,0 +1,304 @@ +// File : SALOMEDSImpl_AttributeStudyProperties.cxx +// Author : Sergey RUIN +// Module : SALOME + +using namespace std; +#include +#include +#include + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeStudyProperties, SALOMEDSImpl_GenericAttribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeStudyProperties, SALOMEDSImpl_GenericAttribute ) + +const Standard_GUID& SALOMEDSImpl_AttributeStudyProperties::GetID() +{ + static Standard_GUID SALOMEDSImpl_AttributeStudyPropertiesID ("128371A2-8F52-11d6-A8A3-0001021E8C7F"); + return SALOMEDSImpl_AttributeStudyPropertiesID; +} + +Handle(SALOMEDSImpl_AttributeStudyProperties) SALOMEDSImpl_AttributeStudyProperties::Set(const TDF_Label& label) +{ + Handle(SALOMEDSImpl_AttributeStudyProperties) anAttr; + if (!label.FindAttribute(SALOMEDSImpl_AttributeStudyProperties::GetID(),anAttr)) { + anAttr = new SALOMEDSImpl_AttributeStudyProperties(); + label.AddAttribute(anAttr); + } + return anAttr; +} + +SALOMEDSImpl_AttributeStudyProperties::SALOMEDSImpl_AttributeStudyProperties() +:SALOMEDSImpl_GenericAttribute("AttributeStudyProperties") +{ + myLocked = Standard_False; + myLockChanged = Standard_False; + Init(); +} + +void SALOMEDSImpl_AttributeStudyProperties::Init() +{ + myUserName = new TColStd_HSequenceOfExtendedString(); + myMinute = new TColStd_HSequenceOfInteger(); + myHour = new TColStd_HSequenceOfInteger(); + myDay = new TColStd_HSequenceOfInteger(); + myMonth = new TColStd_HSequenceOfInteger(); + myYear = new TColStd_HSequenceOfInteger(); +// myModified = 0; + myMode = 0; // none +} + +void SALOMEDSImpl_AttributeStudyProperties::SetUserName(const TCollection_ExtendedString& theName) +{ + CheckLocked(); + Backup(); + myUserName->Append(theName); +} + +void SALOMEDSImpl_AttributeStudyProperties::SetFirstName(const TCollection_ExtendedString& theName) +{ + CheckLocked(); + Backup(); + if (myUserName->Length() == 0) myUserName->Append(theName); + else myUserName->SetValue(1, theName); +} + +TCollection_ExtendedString SALOMEDSImpl_AttributeStudyProperties::GetCreatorName() const +{ + if (myUserName->Length() == 0) return TCollection_ExtendedString(""); + return myUserName->Value(1); +} + +Handle(TColStd_HSequenceOfExtendedString) SALOMEDSImpl_AttributeStudyProperties::GetUserNames() const +{ + return myUserName; +} + +void SALOMEDSImpl_AttributeStudyProperties::SetModificationDate(const Standard_Integer theMinute, + const Standard_Integer theHour, + const Standard_Integer theDay, + const Standard_Integer theMonth, + const Standard_Integer theYear) +{ + CheckLocked(); + Backup(); + if (theMinute<0 || theMinute>60 || theHour<0 || theHour>24 || theDay<0 || theDay>31 || theMonth<0 || theMonth>12) + return; + myMinute->Append(theMinute); + myHour->Append(theHour); + myDay->Append(theDay); + myMonth->Append(theMonth); + myYear->Append(theYear); +} + +Standard_Boolean SALOMEDSImpl_AttributeStudyProperties::GetCreationDate(Standard_Integer& theMinute, + Standard_Integer& theHour, + Standard_Integer& theDay, + Standard_Integer& theMonth, + Standard_Integer& theYear) const +{ + if (myMinute->Length() != 0) { + theMinute = myMinute->Value(1); + theHour = myHour->Value(1); + theDay = myDay->Value(1); + theMonth = myMonth->Value(1); + theYear = myYear->Value(1); + return Standard_True; + } + return Standard_False; +} + +void SALOMEDSImpl_AttributeStudyProperties::GetModificationDates(Handle(TColStd_HSequenceOfInteger)& theMinutes, + Handle(TColStd_HSequenceOfInteger)& theHours, + Handle(TColStd_HSequenceOfInteger)& theDays, + Handle(TColStd_HSequenceOfInteger)& theMonths, + Handle(TColStd_HSequenceOfInteger)& theYears) const +{ + theMinutes = myMinute; + theHours = myHour; + theDays = myDay; + theMonths = myMonth; + theYears = myYear; +} + +void SALOMEDSImpl_AttributeStudyProperties::SetCreationMode(const Standard_Integer theMode) +{ + CheckLocked(); + Backup(); + myMode = theMode; +} + +Standard_Integer SALOMEDSImpl_AttributeStudyProperties::GetCreationMode() const +{ + return myMode; +} + +void SALOMEDSImpl_AttributeStudyProperties::SetModified(const Standard_Integer theModified) +{ + myModified = theModified; +} + +Standard_Boolean SALOMEDSImpl_AttributeStudyProperties::IsModified() const +{ + return (myModified != 0); +} + +Standard_Integer SALOMEDSImpl_AttributeStudyProperties::GetModified() const +{ + return myModified; +} + +void SALOMEDSImpl_AttributeStudyProperties::SetLocked(const Standard_Boolean theLocked) +{ +// Backup(); + if (myLocked != theLocked) { + myLockChanged = Standard_True; + myLocked = theLocked; + } +} + +Standard_Boolean SALOMEDSImpl_AttributeStudyProperties::IsLocked() const +{ + return myLocked; +} + +Standard_Boolean SALOMEDSImpl_AttributeStudyProperties::IsLockChanged(const Standard_Boolean theErase) { + if (!myLockChanged) return Standard_False; + if (theErase) myLockChanged = Standard_False; + return Standard_True; +} + +const Standard_GUID& SALOMEDSImpl_AttributeStudyProperties::ID() const +{ + return GetID(); +} + +void SALOMEDSImpl_AttributeStudyProperties::Restore(const Handle(TDF_Attribute)& with) +{ + Handle(SALOMEDSImpl_AttributeStudyProperties) aProp = Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(with); + Init(); + Standard_Integer i; + Handle(TColStd_HSequenceOfExtendedString) aNames = aProp->GetUserNames(); + for(i = aNames->Length(); i > 0; i--) { + myUserName->Prepend(aNames->Value(i)); + } + Handle(TColStd_HSequenceOfInteger) aMinutes, aHours, aDays, aMonths, aYears; + aProp->GetModificationDates(aMinutes, aHours, aDays, aMonths, aYears); + for(i = aMinutes->Length(); i > 0; i--) { + myMinute->Prepend(aMinutes->Value(i)); + myHour->Prepend(aHours->Value(i)); + myDay->Prepend(aDays->Value(i)); + myMonth->Prepend(aMonths->Value(i)); + myYear->Prepend(aYears->Value(i)); + } + myMode = aProp->GetCreationMode(); +// myModified = aProp->GetModified(); +// myLocked = aProp->IsLocked(); +} + +Handle(TDF_Attribute) SALOMEDSImpl_AttributeStudyProperties::NewEmpty() const +{ + return new SALOMEDSImpl_AttributeStudyProperties(); +} + +void SALOMEDSImpl_AttributeStudyProperties::Paste(const Handle(TDF_Attribute)& into, + const Handle(TDF_RelocationTable)&) const +{ + Handle(SALOMEDSImpl_AttributeStudyProperties) aProp = Handle(SALOMEDSImpl_AttributeStudyProperties)::DownCast(into); + aProp->Init(); + + Standard_Integer i; + for(i = 1; i <= myUserName->Length(); i++) { + aProp->SetUserName(myUserName->Value(i)); + } + for(i = 1; i <= myMinute->Length(); i++) { + aProp->SetModificationDate(myMinute->Value(i), myHour->Value(i), myDay->Value(i), myMonth->Value(i), myYear->Value(i)); + } + + aProp->SetCreationMode(myMode); +// aProp->SetModified(myModified); +// aProp->SetLocked(myLocked); +} + + +TCollection_AsciiString SALOMEDSImpl_AttributeStudyProperties::Save() +{ + Handle(TColStd_HSequenceOfExtendedString) aNames; + Handle(TColStd_HSequenceOfInteger) aMinutes, aHours, aDays, aMonths, aYears; + aNames = GetUserNames(); + GetModificationDates(aMinutes, aHours, aDays, aMonths, aYears); + + int aLength, anIndex; + for(aLength = 0, anIndex = aNames->Length(); anIndex > 0; anIndex--) aLength += aNames->Value(anIndex).Length() + 1; + + char* aProperty = new char[3 + aLength + 12 * aNames->Length()]; + + char crMode = (char)GetCreationMode(); + + sprintf(aProperty,"%c%c", crMode, IsLocked()?'l':'u'); + + aLength = aNames->Length(); + int a = 2; + for(anIndex = 1; anIndex <= aLength; anIndex++) { + sprintf(&(aProperty[a]),"%2d%2d%2d%2d%4d%s", + (int)(aMinutes->Value(anIndex)), + (int)(aHours->Value(anIndex)), + (int)(aDays->Value(anIndex)), + (int)(aMonths->Value(anIndex)), + (int)(aYears->Value(anIndex)), + (char*)(TCollection_AsciiString(aNames->Value(anIndex)).ToCString())); + a = strlen(aProperty); + aProperty[a++] = 1; + } + aProperty[a] = 0; + TCollection_AsciiString prop(aProperty); + delete aProperty; + + return prop; +} + +void SALOMEDSImpl_AttributeStudyProperties::Load(const TCollection_AsciiString& value) +{ + char* aCopy = value.ToCString(); + + int crMode = (int)aCopy[0]; + SetCreationMode(crMode); + + int anIndex; + for(anIndex = 2; anIndex + 2 < value.Length() ;) { + char str[10]; + Standard_Integer aMinute, aHour, aDay, aMonth, aYear; + str[0] = aCopy[anIndex++]; + str[1] = aCopy[anIndex++]; + str[2] = 0; + aMinute = atoi(str); + str[0] = aCopy[anIndex++]; + str[1] = aCopy[anIndex++]; + aHour = atoi(str); + str[0] = aCopy[anIndex++]; + str[1] = aCopy[anIndex++]; + aDay = atoi(str); + str[0] = aCopy[anIndex++]; + str[1] = aCopy[anIndex++]; + aMonth = atoi(str); + str[0] = aCopy[anIndex++]; + str[1] = aCopy[anIndex++]; + str[2] = aCopy[anIndex++]; + str[3] = aCopy[anIndex++]; + str[4] = 0; + aYear = atoi(str); + + int aNameSize; + for(aNameSize = 0; aCopy[anIndex+aNameSize]!=1; aNameSize++); + char *aName = new char[aNameSize+1]; + strncpy(aName, &(aCopy[anIndex]), aNameSize); + aName[aNameSize] = 0; + SetUserName(aName); + SetModificationDate(aMinute,aHour,aDay,aMonth,aYear); + delete(aName); + anIndex += aNameSize + 1; + } + if (aCopy[1] == 'l') { + SetLocked(Standard_True); + } + SetModified(0); +} + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeStudyProperties.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeStudyProperties.hxx new file mode 100644 index 000000000..f9d3c1a16 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeStudyProperties.hxx @@ -0,0 +1,86 @@ +// File : SALOMEDSImpl_AttributeStudyProperties.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef _SALOMEDSImpl_AttributeStudyProperties_HeaderFile +#define _SALOMEDSImpl_AttributeStudyProperties_HeaderFile + +#include +#include +#include +#include +#include +#include "SALOMEDSImpl_GenericAttribute.hxx" + +class Standard_GUID; +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_AttributeStudyProperties, SALOMEDSImpl_GenericAttribute ) + +#include +#include + +class SALOMEDSImpl_AttributeStudyProperties : public SALOMEDSImpl_GenericAttribute +{ + +public: +Standard_EXPORT virtual TCollection_AsciiString Save(); +Standard_EXPORT virtual void Load(const TCollection_AsciiString&); +Standard_EXPORT static const Standard_GUID& GetID() ; +Standard_EXPORT static Handle_SALOMEDSImpl_AttributeStudyProperties Set(const TDF_Label& label) ; +Standard_EXPORT SALOMEDSImpl_AttributeStudyProperties(); +Standard_EXPORT void Init() ; +Standard_EXPORT void SetUserName(const TCollection_ExtendedString& theName) ; +Standard_EXPORT void SetFirstName(const TCollection_ExtendedString& theName) ; +Standard_EXPORT TCollection_ExtendedString GetCreatorName() const; +Standard_EXPORT Handle_TColStd_HSequenceOfExtendedString GetUserNames() const; +Standard_EXPORT void SetModificationDate(const Standard_Integer theMinute, + const Standard_Integer theHour, + const Standard_Integer theDay, + const Standard_Integer theMonth, + const Standard_Integer theYear) ; +Standard_EXPORT Standard_Boolean GetCreationDate(Standard_Integer& theMinute, + Standard_Integer& theHour, + Standard_Integer& theDay, + Standard_Integer& theMonth, + Standard_Integer& theYear) const; +Standard_EXPORT void GetModificationDates(Handle(TColStd_HSequenceOfInteger)& theMinutes, + Handle(TColStd_HSequenceOfInteger)& theHours, + Handle(TColStd_HSequenceOfInteger)& theDays, + Handle(TColStd_HSequenceOfInteger)& theMonths, + Handle(TColStd_HSequenceOfInteger)& theYears) const; +Standard_EXPORT void SetCreationMode(const Standard_Integer theMode) ; +Standard_EXPORT Standard_Integer GetCreationMode() const; +Standard_EXPORT void SetModified(const Standard_Integer theModified) ; +Standard_EXPORT Standard_Boolean IsModified() const; +Standard_EXPORT Standard_Integer GetModified() const; +Standard_EXPORT void SetLocked(const Standard_Boolean theLocked) ; +Standard_EXPORT Standard_Boolean IsLocked() const; +Standard_EXPORT Standard_Boolean IsLockChanged(const Standard_Boolean theErase) ; +Standard_EXPORT const Standard_GUID& ID() const; +Standard_EXPORT void Restore(const Handle(TDF_Attribute)& with) ; +Standard_EXPORT Handle_TDF_Attribute NewEmpty() const; +Standard_EXPORT void Paste(const Handle(TDF_Attribute)& into,const Handle(TDF_RelocationTable)& RT) const; +Standard_EXPORT ~SALOMEDSImpl_AttributeStudyProperties() {} + +private: + +Handle_TColStd_HSequenceOfExtendedString myUserName; +Handle_TColStd_HSequenceOfInteger myMinute; +Handle_TColStd_HSequenceOfInteger myHour; +Handle_TColStd_HSequenceOfInteger myDay; +Handle_TColStd_HSequenceOfInteger myMonth; +Handle_TColStd_HSequenceOfInteger myYear; +Standard_Integer myMode; +Standard_Integer myModified; +Standard_Boolean myLocked; +Standard_Boolean myLockChanged; + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_AttributeStudyProperties ) + +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfInteger.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfInteger.cxx new file mode 100644 index 000000000..6723c2100 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfInteger.cxx @@ -0,0 +1,519 @@ +// File : SALOMEDSImpl_AttributeTableOfInteger.cxx +// Author : Michael Ponikarov +// Module : SALOME + +using namespace std; +#include +#include +#include +#include +#include + + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeTableOfInteger, SALOMEDSImpl_GenericAttribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeTableOfInteger, SALOMEDSImpl_GenericAttribute ) + +#define SEPARATOR '\1' + +static TCollection_ExtendedString getUnit(TCollection_ExtendedString theString) +{ + TCollection_ExtendedString aString(theString); + int aPos = aString.Search(SEPARATOR); + if(aPos <= 0 || aPos == aString.Length() ) return TCollection_ExtendedString(); + return aString.Split(aPos); +} + +static TCollection_ExtendedString getTitle(TCollection_ExtendedString theString) +{ + TCollection_ExtendedString aString(theString); + int aPos = aString.Search(SEPARATOR); + if(aPos < 1) return aString; + if(aPos == 1) return TCollection_ExtendedString(); + aString.Split(aPos-1); + return aString; +} + +const Standard_GUID& SALOMEDSImpl_AttributeTableOfInteger::GetID() +{ + static Standard_GUID SALOMEDSImpl_AttributeTableOfIntegerID ("128371A0-8F52-11d6-A8A3-0001021E8C7F"); + return SALOMEDSImpl_AttributeTableOfIntegerID; +} + +Handle(SALOMEDSImpl_AttributeTableOfInteger) SALOMEDSImpl_AttributeTableOfInteger::Set(const TDF_Label& label) +{ + Handle(SALOMEDSImpl_AttributeTableOfInteger) anAttr; + if (!label.FindAttribute(SALOMEDSImpl_AttributeTableOfInteger::GetID(),anAttr)) { + anAttr = new SALOMEDSImpl_AttributeTableOfInteger(); + label.AddAttribute(anAttr); + } + return anAttr; +} + +SALOMEDSImpl_AttributeTableOfInteger::SALOMEDSImpl_AttributeTableOfInteger() +:SALOMEDSImpl_GenericAttribute("AttributeTableOfInteger") +{ + myRows = new TColStd_HSequenceOfExtendedString(); + myCols = new TColStd_HSequenceOfExtendedString(); + myNbRows = 0; + myNbColumns = 0; +} + +void SALOMEDSImpl_AttributeTableOfInteger::SetNbColumns(const Standard_Integer theNbColumns) +{ + CheckLocked(); + Backup(); + + TColStd_DataMapOfIntegerInteger aMap; + aMap = myTable; + myTable.Clear(); + + TColStd_DataMapIteratorOfDataMapOfIntegerInteger anIterator(aMap); + for(; anIterator.More(); anIterator.Next()) { + int aRow = (int)(anIterator.Key()/myNbColumns) + 1; + int aCol = (int)(anIterator.Key() - myNbColumns*(aRow-1)); + if(aCol == 0) { aCol = myNbColumns; aRow--; } + if(aCol > theNbColumns) continue; + int aKey = (aRow-1)*theNbColumns+aCol; + myTable.Bind(aKey, anIterator.Value()); + } + + myNbColumns = theNbColumns; + + while (myCols->Length() < myNbColumns) { // append empty columns titles + myCols->Append(TCollection_ExtendedString("")); + } +} + +void SALOMEDSImpl_AttributeTableOfInteger::SetTitle(const TCollection_ExtendedString& theTitle) +{ + CheckLocked(); + Backup(); + myTitle = theTitle; +} + +TCollection_ExtendedString SALOMEDSImpl_AttributeTableOfInteger::GetTitle() const +{ + return myTitle; +} + +void SALOMEDSImpl_AttributeTableOfInteger::SetRowData(const Standard_Integer theRow, + const Handle(TColStd_HSequenceOfInteger)& theData) +{ + CheckLocked(); + if(theData->Length() > myNbColumns) SetNbColumns(theData->Length()); + + Backup(); + + while (myRows->Length() < theRow) { // append new row titles + myRows->Append(TCollection_ExtendedString("")); + } + + Standard_Integer i, aShift = (theRow-1)*myNbColumns, aLength = theData->Length(); + for(i = 1; i <= aLength; i++) { + myTable.Bind(aShift + i, theData->Value(i)); + } + + if(theRow > myNbRows) myNbRows = theRow; +} + +Handle(TColStd_HSequenceOfInteger) SALOMEDSImpl_AttributeTableOfInteger::GetRowData(const Standard_Integer theRow) +{ + Handle(TColStd_HSequenceOfInteger) aSeq = new TColStd_HSequenceOfInteger(); + Standard_Integer i, aShift = (theRow-1)*myNbColumns; + for(i = 1; i <= myNbColumns; i++) { + if(myTable.IsBound(aShift+i)) + aSeq->Append(myTable.Find(aShift+i)); + else + aSeq->Append(0); + } + + return aSeq; +} + +void SALOMEDSImpl_AttributeTableOfInteger::SetRowTitle(const Standard_Integer theRow, + const TCollection_ExtendedString& theTitle) +{ + CheckLocked(); + Backup(); + TCollection_ExtendedString aTitle(theTitle), aUnit = GetRowUnit(theRow); + if(aUnit.Length()>0) { + aTitle += SEPARATOR; + aTitle += aUnit; + } + myRows->SetValue(theRow, aTitle); +} + +void SALOMEDSImpl_AttributeTableOfInteger::SetRowUnit(const Standard_Integer theRow, + const TCollection_ExtendedString& theUnit) +{ + CheckLocked(); + Backup(); + TCollection_ExtendedString aTitle = GetRowTitle(theRow); + aTitle += SEPARATOR; + aTitle += theUnit; + + myRows->SetValue(theRow, aTitle); +} + +void SALOMEDSImpl_AttributeTableOfInteger::SetRowUnits(const Handle(TColStd_HSequenceOfExtendedString)& theUnits) +{ + if (theUnits->Length() != GetNbRows()) Standard_Failure::Raise("Invalid number of rows"); + int aLength = theUnits->Length(), i; + for(i = 1; i <= aLength; i++) SetRowUnit(i, theUnits->Value(i)); +} + +Handle(TColStd_HSequenceOfExtendedString) SALOMEDSImpl_AttributeTableOfInteger::GetRowUnits() +{ + Handle(TColStd_HSequenceOfExtendedString) aSeq = new TColStd_HSequenceOfExtendedString; + int aLength = myRows->Length(), i; + for(i=1; i<=aLength; i++) aSeq->Append(getUnit(myRows->Value(i))); + return aSeq; +} + +void SALOMEDSImpl_AttributeTableOfInteger::SetRowTitles(const Handle(TColStd_HSequenceOfExtendedString)& theTitles) +{ + if (theTitles->Length() != GetNbRows()) Standard_Failure::Raise("Invalid number of rows"); + int aLength = theTitles->Length(), i; + for(i = 1; i <= aLength; i++) SetRowTitle(i, theTitles->Value(i)); +} + +Handle(TColStd_HSequenceOfExtendedString) SALOMEDSImpl_AttributeTableOfInteger::GetRowTitles() +{ + Handle(TColStd_HSequenceOfExtendedString) aSeq = new TColStd_HSequenceOfExtendedString; + int aLength = myRows->Length(), i; + for(i=1; i<=aLength; i++) aSeq->Append(getTitle(myRows->Value(i))); + return aSeq; +} + + +TCollection_ExtendedString SALOMEDSImpl_AttributeTableOfInteger::GetRowTitle(const Standard_Integer theRow) const +{ + return getTitle(myRows->Value(theRow)); +} + + +TCollection_ExtendedString SALOMEDSImpl_AttributeTableOfInteger::GetRowUnit(const Standard_Integer theRow) const +{ + return getUnit(myRows->Value(theRow)); +} + + +void SALOMEDSImpl_AttributeTableOfInteger::SetColumnData(const Standard_Integer theColumn, + const Handle(TColStd_HSequenceOfInteger)& theData) +{ + CheckLocked(); + if(theColumn > myNbColumns) SetNbColumns(theColumn); + + Backup(); + + Standard_Integer i, aLength = theData->Length(); + for(i = 1; i <= aLength; i++) { + myTable.Bind(myNbColumns*(i-1)+theColumn, theData->Value(i)); + } + + if(aLength > myNbRows) { + myNbRows = aLength; + while (myRows->Length() < myNbRows) { // append empty row titles + myRows->Append(TCollection_ExtendedString("")); + } + } +} + + +Handle(TColStd_HSequenceOfInteger) SALOMEDSImpl_AttributeTableOfInteger::GetColumnData(const Standard_Integer theColumn) +{ + Handle(TColStd_HSequenceOfInteger) aSeq = new TColStd_HSequenceOfInteger; + + Standard_Integer i, anIndex; + for(i = 1; i <= myNbRows; i++) { + anIndex = myNbColumns*(i-1) + theColumn; + if(myTable.IsBound(anIndex)) + aSeq->Append(myTable.Find(anIndex)); + else + aSeq->Append(0); + } + + return aSeq; +} + +void SALOMEDSImpl_AttributeTableOfInteger::SetColumnTitle(const Standard_Integer theColumn, + const TCollection_ExtendedString& theTitle) +{ + CheckLocked(); + Backup(); + while(myCols->Length() < theColumn) myCols->Append(TCollection_ExtendedString("")); + myCols->SetValue(theColumn,theTitle); +} + +TCollection_ExtendedString SALOMEDSImpl_AttributeTableOfInteger::GetColumnTitle(const Standard_Integer theColumn) const +{ + if(myCols.IsNull()) return ""; + if(myCols->Length() < theColumn) return ""; + return myCols->Value(theColumn); +} + +void SALOMEDSImpl_AttributeTableOfInteger::SetColumnTitles(const Handle(TColStd_HSequenceOfExtendedString)& theTitles) +{ + if (theTitles->Length() != myNbColumns) Standard_Failure::Raise("Invalid number of columns"); + int aLength = theTitles->Length(), i; + for(i = 1; i <= aLength; i++) myCols->SetValue(i, theTitles->Value(i)); +} + +Handle(TColStd_HSequenceOfExtendedString) SALOMEDSImpl_AttributeTableOfInteger::GetColumnTitles() +{ + Handle(TColStd_HSequenceOfExtendedString) aSeq = new TColStd_HSequenceOfExtendedString; + int aLength = myCols->Length(), i; + for(i=1; i<=aLength; i++) aSeq->Append(myCols->Value(i)); + return aSeq; +} + +Standard_Integer SALOMEDSImpl_AttributeTableOfInteger::GetNbRows() const +{ + return myNbRows; +} + +Standard_Integer SALOMEDSImpl_AttributeTableOfInteger::GetNbColumns() const +{ + return myNbColumns; +} + +void SALOMEDSImpl_AttributeTableOfInteger::PutValue(const Standard_Integer theValue, + const Standard_Integer theRow, + const Standard_Integer theColumn) +{ + CheckLocked(); + if(theColumn > myNbColumns) SetNbColumns(theColumn); + + Standard_Integer anIndex = (theRow-1)*myNbColumns + theColumn; + myTable.Bind(anIndex, theValue); + + if(theRow > myNbRows) { + while (myRows->Length() < theRow) { // append empty row titles + myRows->Append(TCollection_ExtendedString("")); + } + myNbRows = theRow; + } +} + +Standard_Boolean SALOMEDSImpl_AttributeTableOfInteger::HasValue(const Standard_Integer theRow, + const Standard_Integer theColumn) +{ + if(theRow > myNbRows || theRow < 1) return Standard_False; + if(theColumn > myNbColumns || theColumn < 1) return Standard_False; + Standard_Integer anIndex = (theRow-1)*myNbColumns + theColumn; + return myTable.IsBound(anIndex); +} + +Standard_Integer SALOMEDSImpl_AttributeTableOfInteger::GetValue(const Standard_Integer theRow, + const Standard_Integer theColumn) +{ + if(theRow > myNbRows || theRow < 1) Standard_Failure::Raise("Invalid cell index"); + if(theColumn > myNbColumns || theColumn < 1) Standard_Failure::Raise("Invalid cell index"); + + Standard_Integer anIndex = (theRow-1)*myNbColumns + theColumn; + if(myTable.IsBound(anIndex)) return myTable.Find(anIndex); + + Standard_Failure::Raise("Invalid cell index"); + return 0; +} + +const Standard_GUID& SALOMEDSImpl_AttributeTableOfInteger::ID() const +{ + return GetID(); +} + +void SALOMEDSImpl_AttributeTableOfInteger::Restore(const Handle(TDF_Attribute)& with) +{ + Standard_Integer anIndex; + Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(with); + + myTable.Clear(); + myCols->Clear(); + myRows->Clear(); + + myTable = aTable->myTable; + myNbRows = aTable->myNbRows; + myNbColumns = aTable->myNbColumns; + myTitle = aTable->myTitle; + + for(anIndex = 1; anIndex <= aTable->GetNbRows();anIndex++) + myRows->Append(aTable->GetRowTitle(anIndex)); + + for(anIndex = 1; anIndex <= aTable->GetNbColumns(); anIndex++) + myCols->Append(aTable->GetColumnTitle(anIndex)); +} + +Handle(TDF_Attribute) SALOMEDSImpl_AttributeTableOfInteger::NewEmpty() const +{ + return new SALOMEDSImpl_AttributeTableOfInteger(); +} + +void SALOMEDSImpl_AttributeTableOfInteger::Paste(const Handle(TDF_Attribute)& into, + const Handle(TDF_RelocationTable)&) const +{ + Standard_Integer anIndex; + Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(into); + + aTable->myTable.Clear(); + aTable->myCols->Clear(); + aTable->myRows->Clear(); + + aTable->myTable = myTable; + aTable->myTitle = myTitle; + aTable->myNbRows = myNbRows; + aTable->myNbColumns = myNbColumns; + + for(anIndex = 1; anIndex <= GetNbRows();anIndex++) + aTable->myRows->Append(GetRowTitle(anIndex)); + for(anIndex = 1; anIndex <= GetNbColumns(); anIndex++) + aTable->myCols->Append(GetColumnTitle(anIndex)); +} + + +Handle_TColStd_HSequenceOfInteger SALOMEDSImpl_AttributeTableOfInteger::GetSetRowIndices(const Standard_Integer theRow) +{ + Handle(TColStd_HSequenceOfInteger) aSeq = new TColStd_HSequenceOfInteger; + + Standard_Integer i, aShift = myNbColumns*(theRow-1); + for(i = 1; i <= myNbColumns; i++) { + if(myTable.IsBound(aShift + i)) aSeq->Append(i); + } + + return aSeq; +} + +Handle_TColStd_HSequenceOfInteger SALOMEDSImpl_AttributeTableOfInteger::GetSetColumnIndices(const Standard_Integer theColumn) +{ + Handle(TColStd_HSequenceOfInteger) aSeq = new TColStd_HSequenceOfInteger; + + Standard_Integer i, anIndex; + for(i = 1; i <= myNbRows; i++) { + anIndex = myNbColumns*(i-1)+theColumn; + if(myTable.IsBound(anIndex)) aSeq->Append(i); + } + + return aSeq; +} + + +void SALOMEDSImpl_AttributeTableOfInteger::ConvertToString(ostrstream& theStream) +{ + int i, j, l; + + theStream.precision(64); + + //Title + l = myTitle.Length(); + theStream << l << "\n"; + for(i=1; i<=l; i++) + theStream << myTitle.Value(i) << "\n"; + + //Nb rows + theStream << myNbRows << "\n"; + + //Rows titles + for(i=1; i<=myNbRows; i++) { + l = myRows->Value(i).Length(); + theStream << l << "\n"; + for(j=1; j<=l; j++) + theStream << myRows->Value(i).Value(j) << "\n"; + } + + //Nb columns + theStream << myNbColumns << "\n"; + + //Columns titles + for(i=1; i<=myNbColumns; i++) { + l = myCols->Value(i).Length(); + theStream << l << "\n"; + for(j=1; j<=l; j++) + theStream << myCols->Value(i).Value(j) << "\n"; + } + + //Store the table values + l = myTable.Extent(); + theStream << l << "\n"; + TColStd_DataMapIteratorOfDataMapOfIntegerInteger anIterator(myTable); + for(; anIterator.More(); anIterator.Next()) { + theStream << anIterator.Key() << "\n"; + theStream << anIterator.Value() << "\n"; + } + + return; +} + +bool SALOMEDSImpl_AttributeTableOfInteger::RestoreFromString(istrstream& theStream) +{ + Backup(); + + int i, j, l; + + Standard_ExtCharacter anExtChar; + TCollection_ExtendedString aStr; + + //Title + theStream >> l; + + myTitle = TCollection_ExtendedString(l, 0); + for(i=1; i<=l; i++) { + theStream >> anExtChar; + myTitle.SetValue(i, anExtChar); + } + + //Nb rows + theStream >> myNbRows; + + //Rows titles + myRows->Clear(); + for(i=1; i<=myNbRows; i++) { + theStream >> l; + aStr = TCollection_ExtendedString(l,0); + for(j=1; j<=l; j++) { + theStream >> anExtChar; + aStr.SetValue(j, anExtChar); + } + myRows->Append(aStr); + } + + //Nb columns + theStream >> myNbColumns; + + //Columns titles + myCols->Clear(); + for(i=1; i<=myNbColumns; i++) { + theStream >> l; + aStr = TCollection_ExtendedString(l,0); + for(j=1; j<=l; j++) { + theStream >> anExtChar; + aStr.SetValue(j, anExtChar); + } + myCols->Append(aStr); + } + + //Restore the table values + theStream >> l; + myTable.Clear(); + for(i=1; i<=l; i++) { + int aKey, aValue; + theStream >> aKey; + theStream >> aValue; + myTable.Bind(aKey, aValue); + } + + return true; +} + + +TCollection_AsciiString SALOMEDSImpl_AttributeTableOfInteger::Save() +{ + ostrstream ostr; + ConvertToString(ostr); + TCollection_AsciiString aString((char*)ostr.rdbuf()->str()); + return aString; +} + +void SALOMEDSImpl_AttributeTableOfInteger::Load(const TCollection_AsciiString& value) +{ + istrstream aStream(value.ToCString(), strlen(value.ToCString())); + RestoreFromString(aStream); +} diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfInteger.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfInteger.hxx new file mode 100644 index 000000000..d1c1d402f --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfInteger.hxx @@ -0,0 +1,94 @@ +// SALOME SALOMEDSImpl : data structure of SALOME and sources of Salome data server +// +// Copyright (C) 2003 CEA/DEN, EDF R&D +// +// +// +// File : SALOMEDSImpl_AttributeTableOfInteger.hxx +// Author : Michael Ponikarov +// Module : SALOME + +#ifndef _SALOMEDSImpl_AttributeTableOfInteger_HeaderFile +#define _SALOMEDSImpl_AttributeTableOfInteger_HeaderFile + +#include +#include +#include +#include +#include "SALOMEDSImpl_GenericAttribute.hxx" + +class Standard_GUID; +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + +#include +#include +#include +#include +#include +#include +#include + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_AttributeTableOfInteger, SALOMEDSImpl_GenericAttribute ) + +class SALOMEDSImpl_AttributeTableOfInteger : public SALOMEDSImpl_GenericAttribute +{ + +public: +Standard_EXPORT virtual TCollection_AsciiString Save(); +Standard_EXPORT virtual void Load(const TCollection_AsciiString&); +Standard_EXPORT static const Standard_GUID& GetID() ; +Standard_EXPORT static Handle_SALOMEDSImpl_AttributeTableOfInteger Set(const TDF_Label& label) ; +Standard_EXPORT SALOMEDSImpl_AttributeTableOfInteger(); +Standard_EXPORT void SetNbColumns(const Standard_Integer theNbColumns); +Standard_EXPORT void SetTitle(const TCollection_ExtendedString& theTitle) ; +Standard_EXPORT TCollection_ExtendedString GetTitle() const; +Standard_EXPORT void SetRowData(const Standard_Integer theRow,const Handle(TColStd_HSequenceOfInteger)& theData) ; +Standard_EXPORT Handle_TColStd_HSequenceOfInteger GetRowData(const Standard_Integer theRow) ; +Standard_EXPORT void SetRowTitle(const Standard_Integer theRow,const TCollection_ExtendedString& theTitle) ; +Standard_EXPORT void SetRowUnit(const Standard_Integer theRow,const TCollection_ExtendedString& theUnit) ; +Standard_EXPORT TCollection_ExtendedString GetRowUnit(const Standard_Integer theRow) const; +Standard_EXPORT void SetRowUnits(const Handle(TColStd_HSequenceOfExtendedString)& theUnits) ; +Standard_EXPORT Handle(TColStd_HSequenceOfExtendedString) GetRowUnits(); +Standard_EXPORT void SetRowTitles(const Handle(TColStd_HSequenceOfExtendedString)& theTitles) ; +Standard_EXPORT Handle(TColStd_HSequenceOfExtendedString) GetRowTitles(); +Standard_EXPORT TCollection_ExtendedString GetRowTitle(const Standard_Integer theRow) const; +Standard_EXPORT void SetColumnData(const Standard_Integer theColumn,const Handle(TColStd_HSequenceOfInteger)& theData) ; +Standard_EXPORT Handle_TColStd_HSequenceOfInteger GetColumnData(const Standard_Integer theColumn) ; +Standard_EXPORT void SetColumnTitle(const Standard_Integer theColumn,const TCollection_ExtendedString& theTitle) ; +Standard_EXPORT TCollection_ExtendedString GetColumnTitle(const Standard_Integer theColumn) const; +Standard_EXPORT void SetColumnTitles(const Handle(TColStd_HSequenceOfExtendedString)& theTitles); +Standard_EXPORT Handle(TColStd_HSequenceOfExtendedString) GetColumnTitles(); +Standard_EXPORT Standard_Integer GetNbRows() const; +Standard_EXPORT Standard_Integer GetNbColumns() const; + +Standard_EXPORT void PutValue(const Standard_Integer theValue,const Standard_Integer theRow,const Standard_Integer theColumn) ; +Standard_EXPORT Standard_Boolean HasValue(const Standard_Integer theRow,const Standard_Integer theColumn) ; +Standard_EXPORT Standard_Integer GetValue(const Standard_Integer theRow,const Standard_Integer theColumn) ; +Standard_EXPORT const Standard_GUID& ID() const; +Standard_EXPORT void Restore(const Handle(TDF_Attribute)& with) ; +Standard_EXPORT Handle_TDF_Attribute NewEmpty() const; +Standard_EXPORT void Paste(const Handle(TDF_Attribute)& into,const Handle(TDF_RelocationTable)& RT) const; + +Standard_EXPORT Handle_TColStd_HSequenceOfInteger GetSetRowIndices(const Standard_Integer theRow); +Standard_EXPORT Handle_TColStd_HSequenceOfInteger GetSetColumnIndices(const Standard_Integer theColumn); + +Standard_EXPORT void ConvertToString(ostrstream& theStream); +Standard_EXPORT bool RestoreFromString(istrstream& theStream); + +Standard_EXPORT ~SALOMEDSImpl_AttributeTableOfInteger() {} + +private: + +TColStd_DataMapOfIntegerInteger myTable; +TCollection_ExtendedString myTitle; +Handle_TColStd_HSequenceOfExtendedString myRows; +Handle_TColStd_HSequenceOfExtendedString myCols; +Standard_Integer myNbRows; +Standard_Integer myNbColumns; + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_AttributeTableOfInteger ) +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfReal.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfReal.cxx new file mode 100644 index 000000000..eb35801ec --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfReal.cxx @@ -0,0 +1,523 @@ +// File : SALOMEDSImpl_AttributeTableOfReal.cxx +// Author : Michael Ponikarov +// Module : SALOME + +using namespace std; +#include +#include +#include +#include +#include +#include + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeTableOfReal, SALOMEDSImpl_GenericAttribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeTableOfReal, SALOMEDSImpl_GenericAttribute ) + +#define SEPARATOR '\1' + +static TCollection_ExtendedString getUnit(TCollection_ExtendedString theString) +{ + TCollection_ExtendedString aString(theString); + int aPos = aString.Search(SEPARATOR); + if(aPos <= 0 || aPos == aString.Length() ) return TCollection_ExtendedString(); + return aString.Split(aPos); +} + +static TCollection_ExtendedString getTitle(TCollection_ExtendedString theString) +{ + TCollection_ExtendedString aString(theString); + int aPos = aString.Search(SEPARATOR); + if(aPos < 1) return aString; + if(aPos == 1) return TCollection_ExtendedString(); + aString.Split(aPos-1); + return aString; +} + +const Standard_GUID& SALOMEDSImpl_AttributeTableOfReal::GetID() +{ + static Standard_GUID SALOMEDSImpl_AttributeTableOfRealID ("128371A1-8F52-11d6-A8A3-0001021E8C7F"); + return SALOMEDSImpl_AttributeTableOfRealID; +} + +Handle(SALOMEDSImpl_AttributeTableOfReal) SALOMEDSImpl_AttributeTableOfReal::Set(const TDF_Label& label) +{ + Handle(SALOMEDSImpl_AttributeTableOfReal) anAttr; + if (!label.FindAttribute(SALOMEDSImpl_AttributeTableOfReal::GetID(),anAttr)) { + anAttr = new SALOMEDSImpl_AttributeTableOfReal(); + label.AddAttribute(anAttr); + } + return anAttr; +} + +SALOMEDSImpl_AttributeTableOfReal::SALOMEDSImpl_AttributeTableOfReal() +:SALOMEDSImpl_GenericAttribute("AttributeTableOfReal") +{ + myRows = new TColStd_HSequenceOfExtendedString(); + myCols = new TColStd_HSequenceOfExtendedString(); + myNbRows = 0; + myNbColumns = 0; +} + +void SALOMEDSImpl_AttributeTableOfReal::SetNbColumns(const Standard_Integer theNbColumns) +{ + CheckLocked(); + Backup(); + + TColStd_DataMapOfIntegerReal aMap; + aMap = myTable; + myTable.Clear(); + + TColStd_DataMapIteratorOfDataMapOfIntegerReal anIterator(aMap); + for(; anIterator.More(); anIterator.Next()) { + int aRow = (int)(anIterator.Key()/myNbColumns) + 1; + int aCol = (int)(anIterator.Key() - myNbColumns*(aRow-1)); + if(aCol == 0) { aCol = myNbColumns; aRow--; } + if(aCol > theNbColumns) continue; + int aKey = (aRow-1)*theNbColumns+aCol; + myTable.Bind(aKey, anIterator.Value()); + } + + myNbColumns = theNbColumns; + + while (myCols->Length() < myNbColumns) { // append empty columns titles + myCols->Append(TCollection_ExtendedString("")); + } +} + +void SALOMEDSImpl_AttributeTableOfReal::SetTitle(const TCollection_ExtendedString& theTitle) +{ + CheckLocked(); + Backup(); + myTitle = theTitle; +} + +TCollection_ExtendedString SALOMEDSImpl_AttributeTableOfReal::GetTitle() const +{ + return myTitle; +} + +void SALOMEDSImpl_AttributeTableOfReal::SetRowData(const Standard_Integer theRow, + const Handle(TColStd_HSequenceOfReal)& theData) +{ + CheckLocked(); + if(theData->Length() > myNbColumns) SetNbColumns(theData->Length()); + + Backup(); + + while (myRows->Length() < theRow) { // append new row titles + myRows->Append(TCollection_ExtendedString("")); + } + + Standard_Integer i, aShift = (theRow-1)*myNbColumns, aLength = theData->Length(); + for(i = 1; i <= aLength; i++) { + myTable.Bind(aShift + i, theData->Value(i)); + } + + if(theRow > myNbRows) myNbRows = theRow; +} + +Handle(TColStd_HSequenceOfReal) SALOMEDSImpl_AttributeTableOfReal::GetRowData(const Standard_Integer theRow) +{ + Handle(TColStd_HSequenceOfReal) aSeq = new TColStd_HSequenceOfReal(); + Standard_Integer i, aShift = (theRow-1)*myNbColumns; + for(i = 1; i <= myNbColumns; i++) { + if(myTable.IsBound(aShift+i)) + aSeq->Append(myTable.Find(aShift+i)); + else + aSeq->Append(0.); + } + + return aSeq; +} + + +void SALOMEDSImpl_AttributeTableOfReal::SetRowTitle(const Standard_Integer theRow, + const TCollection_ExtendedString& theTitle) +{ + CheckLocked(); + Backup(); + TCollection_ExtendedString aTitle(theTitle), aUnit = GetRowUnit(theRow); + if(aUnit.Length()>0) { + aTitle += SEPARATOR; + aTitle += aUnit; + } + myRows->SetValue(theRow, aTitle); +} + +void SALOMEDSImpl_AttributeTableOfReal::SetRowUnit(const Standard_Integer theRow, + const TCollection_ExtendedString& theUnit) +{ + CheckLocked(); + Backup(); + TCollection_ExtendedString aTitle = GetRowTitle(theRow); + aTitle += SEPARATOR; + aTitle += theUnit; + + myRows->SetValue(theRow, aTitle); +} + +void SALOMEDSImpl_AttributeTableOfReal::SetRowUnits(const Handle(TColStd_HSequenceOfExtendedString)& theUnits) +{ + if (theUnits->Length() != GetNbRows()) Standard_Failure::Raise("Invalid number of rows"); + int aLength = theUnits->Length(), i; + for(i = 1; i <= aLength; i++) SetRowUnit(i, theUnits->Value(i)); +} + +Handle(TColStd_HSequenceOfExtendedString) SALOMEDSImpl_AttributeTableOfReal::GetRowUnits() +{ + Handle(TColStd_HSequenceOfExtendedString) aSeq = new TColStd_HSequenceOfExtendedString; + int aLength = myRows->Length(), i; + for(i=1; i<=aLength; i++) aSeq->Append(getUnit(myRows->Value(i))); + return aSeq; +} + +void SALOMEDSImpl_AttributeTableOfReal::SetRowTitles(const Handle(TColStd_HSequenceOfExtendedString)& theTitles) +{ + if (theTitles->Length() != GetNbRows()) Standard_Failure::Raise("Invalid number of rows"); + int aLength = theTitles->Length(), i; + for(i = 1; i <= aLength; i++) SetRowTitle(i, theTitles->Value(i)); +} + +Handle(TColStd_HSequenceOfExtendedString) SALOMEDSImpl_AttributeTableOfReal::GetRowTitles() +{ + Handle(TColStd_HSequenceOfExtendedString) aSeq = new TColStd_HSequenceOfExtendedString; + int aLength = myRows->Length(), i; + for(i=1; i<=aLength; i++) aSeq->Append(getTitle(myRows->Value(i))); + return aSeq; +} + + +TCollection_ExtendedString SALOMEDSImpl_AttributeTableOfReal::GetRowTitle(const Standard_Integer theRow) const +{ + return getTitle(myRows->Value(theRow)); +} + + +TCollection_ExtendedString SALOMEDSImpl_AttributeTableOfReal::GetRowUnit(const Standard_Integer theRow) const +{ + return getUnit(myRows->Value(theRow)); +} + +void SALOMEDSImpl_AttributeTableOfReal::SetColumnData(const Standard_Integer theColumn, + const Handle(TColStd_HSequenceOfReal)& theData) +{ + CheckLocked(); + if(theColumn > myNbColumns) SetNbColumns(theColumn); + + Backup(); + + Standard_Integer i, aLength = theData->Length(); + for(i = 1; i <= aLength; i++) { + myTable.Bind(myNbColumns*(i-1)+theColumn, theData->Value(i)); + } + + if(aLength > myNbRows) { + myNbRows = aLength; + while (myRows->Length() < myNbRows) { // append empty row titles + myRows->Append(TCollection_ExtendedString("")); + } + } +} + + +Handle(TColStd_HSequenceOfReal) SALOMEDSImpl_AttributeTableOfReal::GetColumnData(const Standard_Integer theColumn) +{ + Handle(TColStd_HSequenceOfReal) aSeq = new TColStd_HSequenceOfReal; + + Standard_Integer i, anIndex; + for(i = 1; i <= myNbRows; i++) { + anIndex = myNbColumns*(i-1) + theColumn; + if(myTable.IsBound(anIndex)) + aSeq->Append(myTable.Find(anIndex)); + else + aSeq->Append(0.); + } + + return aSeq; +} + +void SALOMEDSImpl_AttributeTableOfReal::SetColumnTitle(const Standard_Integer theColumn, + const TCollection_ExtendedString& theTitle) +{ + CheckLocked(); + Backup(); + while(myCols->Length() < theColumn) myCols->Append(TCollection_ExtendedString("")); + myCols->SetValue(theColumn,theTitle); +} + +TCollection_ExtendedString SALOMEDSImpl_AttributeTableOfReal::GetColumnTitle(const Standard_Integer theColumn) const +{ + if(myCols.IsNull()) return ""; + if(myCols->Length() < theColumn) return ""; + return myCols->Value(theColumn); +} + +void SALOMEDSImpl_AttributeTableOfReal::SetColumnTitles(const Handle(TColStd_HSequenceOfExtendedString)& theTitles) +{ + if (theTitles->Length() != myNbColumns) Standard_Failure::Raise("Invalid number of columns"); + int aLength = theTitles->Length(), i; + for(i = 1; i <= aLength; i++) myCols->SetValue(i, theTitles->Value(i)); +} + +Handle(TColStd_HSequenceOfExtendedString) SALOMEDSImpl_AttributeTableOfReal::GetColumnTitles() +{ + Handle(TColStd_HSequenceOfExtendedString) aSeq = new TColStd_HSequenceOfExtendedString; + int aLength = myCols->Length(), i; + for(i=1; i<=aLength; i++) aSeq->Append(myCols->Value(i)); + return aSeq; +} + +Standard_Integer SALOMEDSImpl_AttributeTableOfReal::GetNbRows() const +{ + return myNbRows; +} + +Standard_Integer SALOMEDSImpl_AttributeTableOfReal::GetNbColumns() const +{ + return myNbColumns; +} + +void SALOMEDSImpl_AttributeTableOfReal::PutValue(const Standard_Real theValue, + const Standard_Integer theRow, + const Standard_Integer theColumn) +{ + CheckLocked(); + if(theColumn > myNbColumns) SetNbColumns(theColumn); + + Standard_Integer anIndex = (theRow-1)*myNbColumns + theColumn; + myTable.Bind(anIndex, theValue); + + if(theRow > myNbRows) { + while (myRows->Length() < theRow) { // append empty row titles + myRows->Append(TCollection_ExtendedString("")); + } + myNbRows = theRow; + } +} + +Standard_Boolean SALOMEDSImpl_AttributeTableOfReal::HasValue(const Standard_Integer theRow, + const Standard_Integer theColumn) +{ + if(theRow > myNbRows || theRow < 1) return Standard_False; + if(theColumn > myNbColumns || theColumn < 1) return Standard_False; + Standard_Integer anIndex = (theRow-1)*myNbColumns + theColumn; + return myTable.IsBound(anIndex); +} + +Standard_Real SALOMEDSImpl_AttributeTableOfReal::GetValue(const Standard_Integer theRow, + const Standard_Integer theColumn) +{ + if(theRow > myNbRows || theRow < 1) Standard_Failure::Raise("Invalid cell index"); + if(theColumn > myNbColumns || theColumn < 1) Standard_Failure::Raise("Invalid cell index"); + + Standard_Integer anIndex = (theRow-1)*myNbColumns + theColumn; + if(myTable.IsBound(anIndex)) return myTable.Find(anIndex); + + Standard_Failure::Raise("Invalid cell index"); + return 0.; +} + +const Standard_GUID& SALOMEDSImpl_AttributeTableOfReal::ID() const +{ + return GetID(); +} + +void SALOMEDSImpl_AttributeTableOfReal::Restore(const Handle(TDF_Attribute)& with) +{ + Standard_Integer anIndex; + Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(with); + + myTable.Clear(); + myCols->Clear(); + myRows->Clear(); + + myTable = aTable->myTable; + myNbRows = aTable->myNbRows; + myNbColumns = aTable->myNbColumns; + myTitle = aTable->myTitle; + + for(anIndex = 1; anIndex <= aTable->GetNbRows();anIndex++) + myRows->Append(aTable->GetRowTitle(anIndex)); + + for(anIndex = 1; anIndex <= aTable->GetNbColumns(); anIndex++) + myCols->Append(aTable->GetColumnTitle(anIndex)); +} + +Handle(TDF_Attribute) SALOMEDSImpl_AttributeTableOfReal::NewEmpty() const +{ + return new SALOMEDSImpl_AttributeTableOfReal(); +} + +void SALOMEDSImpl_AttributeTableOfReal::Paste(const Handle(TDF_Attribute)& into, + const Handle(TDF_RelocationTable)&) const +{ + Standard_Integer anIndex; + Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(into); + + aTable->myTable.Clear(); + aTable->myCols->Clear(); + aTable->myRows->Clear(); + + aTable->myTable = myTable; + aTable->myTitle = myTitle; + aTable->myNbRows = myNbRows; + aTable->myNbColumns = myNbColumns; + + for(anIndex = 1; anIndex <= GetNbRows();anIndex++) + aTable->myRows->Append(GetRowTitle(anIndex)); + for(anIndex = 1; anIndex <= GetNbColumns(); anIndex++) + aTable->myCols->Append(GetColumnTitle(anIndex)); +} + + +Handle_TColStd_HSequenceOfInteger SALOMEDSImpl_AttributeTableOfReal::GetSetRowIndices(const Standard_Integer theRow) +{ + Handle(TColStd_HSequenceOfInteger) aSeq = new TColStd_HSequenceOfInteger; + + Standard_Integer i, aShift = myNbColumns*(theRow-1); + for(i = 1; i <= myNbColumns; i++) { + if(myTable.IsBound(aShift + i)) aSeq->Append(i); + } + + return aSeq; +} + +Handle_TColStd_HSequenceOfInteger SALOMEDSImpl_AttributeTableOfReal::GetSetColumnIndices(const Standard_Integer theColumn) +{ + Handle(TColStd_HSequenceOfInteger) aSeq = new TColStd_HSequenceOfInteger; + + Standard_Integer i, anIndex; + for(i = 1; i <= myNbRows; i++) { + anIndex = myNbColumns*(i-1)+theColumn; + if(myTable.IsBound(anIndex)) aSeq->Append(i); + } + + return aSeq; +} + + + +void SALOMEDSImpl_AttributeTableOfReal::ConvertToString(ostrstream& theStream) +{ + int i, j, l; + + + //Title + l = myTitle.Length(); + theStream << l << "\n"; + for(i=1; i<=l; i++) + theStream << myTitle.Value(i) << "\n"; + + //Nb rows + theStream << myNbRows << "\n"; + + //Rows titles + for(i=1; i<=myNbRows; i++) { + l = myRows->Value(i).Length(); + theStream << l << "\n"; + for(j=1; j<=l; j++) + theStream << myRows->Value(i).Value(j) << "\n"; + } + + //Nb columns + theStream << myNbColumns << "\n"; + + //Columns titles + for(i=1; i<=myNbColumns; i++) { + l = myCols->Value(i).Length(); + theStream << l << "\n"; + for(j=1; j<=l; j++) + theStream << myCols->Value(i).Value(j) << "\n"; + } + + //Store the table values + l = myTable.Extent(); + theStream << l << "\n"; + char *aBuffer = new char[128]; + TColStd_DataMapIteratorOfDataMapOfIntegerReal anIterator(myTable); + for(; anIterator.More(); anIterator.Next()) { + theStream << anIterator.Key() << "\n"; + sprintf(aBuffer, "%.64e", anIterator.Value()); + theStream << aBuffer << "\n"; + } + + delete []aBuffer; + + return; +} + +bool SALOMEDSImpl_AttributeTableOfReal::RestoreFromString(istrstream& theStream) +{ + Backup(); + + int i, j, l; + + Standard_ExtCharacter anExtChar; + TCollection_ExtendedString aStr; + + //Title + theStream >> l; + + myTitle = TCollection_ExtendedString(l, 0); + for(i=1; i<=l; i++) { + theStream >> anExtChar; + myTitle.SetValue(i, anExtChar); + } + + //Nb rows + theStream >> myNbRows; + + //Rows titles + myRows->Clear(); + for(i=1; i<=myNbRows; i++) { + theStream >> l; + aStr = TCollection_ExtendedString(l,0); + for(j=1; j<=l; j++) { + theStream >> anExtChar; + aStr.SetValue(j, anExtChar); + } + myRows->Append(aStr); + } + + //Nb columns + theStream >> myNbColumns; + + //Columns titles + myCols->Clear(); + for(i=1; i<=myNbColumns; i++) { + theStream >> l; + aStr = TCollection_ExtendedString(l,0); + for(j=1; j<=l; j++) { + theStream >> anExtChar; + aStr.SetValue(j, anExtChar); + } + myCols->Append(aStr); + } + + //Restore the table values + theStream >> l; + myTable.Clear(); + for(i=1; i<=l; i++) { + Standard_Integer aKey; + Standard_Real aValue; + theStream >> aKey; + theStream >> aValue; + myTable.Bind(aKey, aValue); + } + + return true; +} + +TCollection_AsciiString SALOMEDSImpl_AttributeTableOfReal::Save() +{ + ostrstream ostr; + ConvertToString(ostr); + TCollection_AsciiString aString((char*)ostr.rdbuf()->str()); + return aString; +} + +void SALOMEDSImpl_AttributeTableOfReal::Load(const TCollection_AsciiString& value) +{ + istrstream aStream(value.ToCString(), strlen(value.ToCString())); + RestoreFromString(aStream); +} diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfReal.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfReal.hxx new file mode 100644 index 000000000..221309287 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfReal.hxx @@ -0,0 +1,97 @@ +// SALOME SALOMEDSImpl : data structure of SALOME and sources of Salome data server +// +// Copyright (C) 2003 CEA/DEN, EDF R&D +// +// +// +// File : SALOMEDSImpl_AttributeTableOfReal.hxx +// Author : Michael Ponikarov +// Module : SALOME + +#ifndef _SALOMEDSImpl_AttributeTableOfReal_HeaderFile +#define _SALOMEDSImpl_AttributeTableOfReal_HeaderFile + +#include +#include +#include +#include +#include "SALOMEDSImpl_GenericAttribute.hxx" + +class Standard_GUID; +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_AttributeTableOfReal, SALOMEDSImpl_GenericAttribute ) + +#include +#include +#include +#include +#include +#include + +#include +#include + +class SALOMEDSImpl_AttributeTableOfReal : public SALOMEDSImpl_GenericAttribute +{ + +public: +Standard_EXPORT virtual TCollection_AsciiString Save(); +Standard_EXPORT virtual void Load(const TCollection_AsciiString&); +Standard_EXPORT static const Standard_GUID& GetID() ; +Standard_EXPORT static Handle_SALOMEDSImpl_AttributeTableOfReal Set(const TDF_Label& label) ; +Standard_EXPORT SALOMEDSImpl_AttributeTableOfReal(); +Standard_EXPORT void SetNbColumns(const Standard_Integer theNbColumns); +Standard_EXPORT void SetTitle(const TCollection_ExtendedString& theTitle) ; +Standard_EXPORT TCollection_ExtendedString GetTitle() const; +Standard_EXPORT void SetRowData(const Standard_Integer theRow,const Handle(TColStd_HSequenceOfReal)& theData) ; +Standard_EXPORT Handle_TColStd_HSequenceOfReal GetRowData(const Standard_Integer theRow) ; +Standard_EXPORT void SetRowTitle(const Standard_Integer theRow,const TCollection_ExtendedString& theTitle) ; +Standard_EXPORT void SetRowUnit(const Standard_Integer theRow,const TCollection_ExtendedString& theUnit) ; +Standard_EXPORT TCollection_ExtendedString GetRowUnit(const Standard_Integer theRow) const; +Standard_EXPORT void SetRowUnits(const Handle(TColStd_HSequenceOfExtendedString)& theUnits) ; +Standard_EXPORT Handle(TColStd_HSequenceOfExtendedString) GetRowUnits(); +Standard_EXPORT void SetRowTitles(const Handle(TColStd_HSequenceOfExtendedString)& theTitles) ; +Standard_EXPORT Handle(TColStd_HSequenceOfExtendedString) GetRowTitles(); +Standard_EXPORT TCollection_ExtendedString GetRowTitle(const Standard_Integer theRow) const; +Standard_EXPORT void SetColumnData(const Standard_Integer theColumn,const Handle(TColStd_HSequenceOfReal)& theData) ; +Standard_EXPORT Handle_TColStd_HSequenceOfReal GetColumnData(const Standard_Integer theColumn) ; +Standard_EXPORT void SetColumnTitle(const Standard_Integer theColumn,const TCollection_ExtendedString& theTitle) ; +Standard_EXPORT void SetColumnTitles(const Handle(TColStd_HSequenceOfExtendedString)& theTitles); +Standard_EXPORT Handle(TColStd_HSequenceOfExtendedString) GetColumnTitles(); +Standard_EXPORT TCollection_ExtendedString GetColumnTitle(const Standard_Integer theColumn) const; +Standard_EXPORT Standard_Integer GetNbRows() const; +Standard_EXPORT Standard_Integer GetNbColumns() const; + +Standard_EXPORT void PutValue(const Standard_Real theValue,const Standard_Integer theRow,const Standard_Integer theColumn) ; +Standard_EXPORT Standard_Boolean HasValue(const Standard_Integer theRow,const Standard_Integer theColumn) ; +Standard_EXPORT Standard_Real GetValue(const Standard_Integer theRow,const Standard_Integer theColumn) ; +Standard_EXPORT const Standard_GUID& ID() const; +Standard_EXPORT void Restore(const Handle(TDF_Attribute)& with) ; +Standard_EXPORT Handle_TDF_Attribute NewEmpty() const; +Standard_EXPORT void Paste(const Handle(TDF_Attribute)& into,const Handle(TDF_RelocationTable)& RT) const; + +Standard_EXPORT Handle_TColStd_HSequenceOfInteger GetSetRowIndices(const Standard_Integer theRow); +Standard_EXPORT Handle_TColStd_HSequenceOfInteger GetSetColumnIndices(const Standard_Integer theColumn); + +Standard_EXPORT void ConvertToString(ostrstream& theStream); +Standard_EXPORT bool RestoreFromString(istrstream& theStream); + +Standard_EXPORT ~SALOMEDSImpl_AttributeTableOfReal() {} + +private: +TColStd_DataMapOfIntegerReal myTable; +TCollection_ExtendedString myTitle; +Handle_TColStd_HSequenceOfExtendedString myRows; +Handle_TColStd_HSequenceOfExtendedString myCols; +Standard_Integer myNbRows; +Standard_Integer myNbColumns; + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_AttributeTableOfReal ) + +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfString.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfString.cxx new file mode 100644 index 000000000..64e49ce02 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfString.cxx @@ -0,0 +1,545 @@ +// File : SALOMEDSImpl_AttributeTableOfString.cxx +// Author : Sergey Ruin +// Module : SALOME + +using namespace std; +#include +#include +#include +#include +#include + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeTableOfString, SALOMEDSImpl_GenericAttribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeTableOfString, SALOMEDSImpl_GenericAttribute ) + +typedef NCollection_DataMap::Iterator DataMapIterator; + +#define SEPARATOR '\1' + +static TCollection_ExtendedString getUnit(TCollection_ExtendedString theString) +{ + TCollection_ExtendedString aString(theString); + int aPos = aString.Search(SEPARATOR); + if(aPos <= 0 || aPos == aString.Length() ) return TCollection_ExtendedString(); + return aString.Split(aPos); +} + +static TCollection_ExtendedString getTitle(TCollection_ExtendedString theString) +{ + TCollection_ExtendedString aString(theString); + int aPos = aString.Search(SEPARATOR); + if(aPos < 1) return aString; + if(aPos == 1) return TCollection_ExtendedString(); + aString.Split(aPos-1); + return aString; +} + +const Standard_GUID& SALOMEDSImpl_AttributeTableOfString::GetID() +{ + static Standard_GUID SALOMEDSImpl_AttributeTableOfStringID ("128371A4-8F52-11d6-A8A3-0001021E8C7F"); + return SALOMEDSImpl_AttributeTableOfStringID; +} + +Handle(SALOMEDSImpl_AttributeTableOfString) SALOMEDSImpl_AttributeTableOfString::Set(const TDF_Label& label) +{ + Handle(SALOMEDSImpl_AttributeTableOfString) anAttr; + if (!label.FindAttribute(SALOMEDSImpl_AttributeTableOfString::GetID(),anAttr)) { + anAttr = new SALOMEDSImpl_AttributeTableOfString(); + label.AddAttribute(anAttr); + } + return anAttr; +} + +SALOMEDSImpl_AttributeTableOfString::SALOMEDSImpl_AttributeTableOfString() +:SALOMEDSImpl_GenericAttribute("AttributeTableOfString") +{ + myRows = new TColStd_HSequenceOfExtendedString(); + myCols = new TColStd_HSequenceOfExtendedString(); + myNbRows = 0; + myNbColumns = 0; +} + +void SALOMEDSImpl_AttributeTableOfString::SetNbColumns(const Standard_Integer theNbColumns) +{ + CheckLocked(); + Backup(); + + DataMapOfIntegerString aMap; + aMap = myTable; + myTable.Clear(); + + DataMapIterator anIterator(aMap); + for(; anIterator.More(); anIterator.Next()) { + int aRow = (int)(anIterator.Key()/myNbColumns) + 1; + int aCol = (int)(anIterator.Key() - myNbColumns*(aRow-1)); + if(aCol == 0) { aCol = myNbColumns; aRow--; } + if(aCol > theNbColumns) continue; + int aKey = (aRow-1)*theNbColumns+aCol; + myTable.Bind(aKey, anIterator.Value()); + } + + myNbColumns = theNbColumns; + + while (myCols->Length() < myNbColumns) { // append empty columns titles + myCols->Append(TCollection_ExtendedString("")); + } +} + +void SALOMEDSImpl_AttributeTableOfString::SetRowTitle(const Standard_Integer theRow, + const TCollection_ExtendedString& theTitle) +{ + CheckLocked(); + Backup(); + TCollection_ExtendedString aTitle(theTitle), aUnit = GetRowUnit(theRow); + if(aUnit.Length()>0) { + aTitle += SEPARATOR; + aTitle += aUnit; + } + myRows->SetValue(theRow, aTitle); +} + +void SALOMEDSImpl_AttributeTableOfString::SetRowUnit(const Standard_Integer theRow, + const TCollection_ExtendedString& theUnit) +{ + CheckLocked(); + Backup(); + TCollection_ExtendedString aTitle = GetRowTitle(theRow); + aTitle += SEPARATOR; + aTitle += theUnit; + + myRows->SetValue(theRow, aTitle); +} + +void SALOMEDSImpl_AttributeTableOfString::SetRowUnits(const Handle(TColStd_HSequenceOfExtendedString)& theUnits) +{ + if (theUnits->Length() != GetNbRows()) Standard_Failure::Raise("Invalid number of rows"); + int aLength = theUnits->Length(), i; + for(i = 1; i <= aLength; i++) SetRowUnit(i, theUnits->Value(i)); +} + +Handle(TColStd_HSequenceOfExtendedString) SALOMEDSImpl_AttributeTableOfString::GetRowUnits() +{ + Handle(TColStd_HSequenceOfExtendedString) aSeq = new TColStd_HSequenceOfExtendedString; + int aLength = myRows->Length(), i; + for(i=1; i<=aLength; i++) aSeq->Append(getUnit(myRows->Value(i))); + return aSeq; +} + +void SALOMEDSImpl_AttributeTableOfString::SetRowTitles(const Handle(TColStd_HSequenceOfExtendedString)& theTitles) +{ + if (theTitles->Length() != GetNbRows()) Standard_Failure::Raise("Invalid number of rows"); + int aLength = theTitles->Length(), i; + for(i = 1; i <= aLength; i++) SetRowTitle(i, theTitles->Value(i)); +} + +Handle(TColStd_HSequenceOfExtendedString) SALOMEDSImpl_AttributeTableOfString::GetRowTitles() +{ + Handle(TColStd_HSequenceOfExtendedString) aSeq = new TColStd_HSequenceOfExtendedString; + int aLength = myRows->Length(), i; + for(i=1; i<=aLength; i++) aSeq->Append(getTitle(myRows->Value(i))); + return aSeq; +} + + +TCollection_ExtendedString SALOMEDSImpl_AttributeTableOfString::GetRowTitle(const Standard_Integer theRow) const +{ + return getTitle(myRows->Value(theRow)); +} + + +TCollection_ExtendedString SALOMEDSImpl_AttributeTableOfString::GetRowUnit(const Standard_Integer theRow) const +{ + return getUnit(myRows->Value(theRow)); +} + +void SALOMEDSImpl_AttributeTableOfString::SetRowData(const Standard_Integer theRow, + const Handle(TColStd_HSequenceOfExtendedString)& theData) +{ + CheckLocked(); + if(theData->Length() > myNbColumns) SetNbColumns(theData->Length()); + + Backup(); + + while (myRows->Length() < theRow) { // append new row titles + myRows->Append(TCollection_ExtendedString("")); + } + + Standard_Integer i, aShift = (theRow-1)*myNbColumns, aLength = theData->Length(); + for(i = 1; i <= aLength; i++) { + myTable.Bind(aShift + i, theData->Value(i)); + } + + if(theRow > myNbRows) myNbRows = theRow; +} + +void SALOMEDSImpl_AttributeTableOfString::SetTitle(const TCollection_ExtendedString& theTitle) +{ + CheckLocked(); + Backup(); + myTitle = theTitle; +} + +TCollection_ExtendedString SALOMEDSImpl_AttributeTableOfString::GetTitle() const +{ + return myTitle; +} + +Handle(TColStd_HSequenceOfExtendedString) SALOMEDSImpl_AttributeTableOfString::GetRowData(const Standard_Integer theRow) +{ + Handle(TColStd_HSequenceOfExtendedString) aSeq = new TColStd_HSequenceOfExtendedString(); + Standard_Integer i, aShift = (theRow-1)*myNbColumns; + for(i = 1; i <= myNbColumns; i++) { + if(myTable.IsBound(aShift+i)) + aSeq->Append(myTable.Find(aShift+i)); + else + aSeq->Append(0.); + } + + return aSeq; +} + +void SALOMEDSImpl_AttributeTableOfString::SetColumnData(const Standard_Integer theColumn, + const Handle(TColStd_HSequenceOfExtendedString)& theData) +{ + CheckLocked(); + if(theColumn > myNbColumns) SetNbColumns(theColumn); + + Backup(); + + Standard_Integer i, aLength = theData->Length(); + for(i = 1; i <= aLength; i++) { + myTable.Bind(myNbColumns*(i-1)+theColumn, theData->Value(i)); + } + + if(aLength > myNbRows) { + myNbRows = aLength; + while (myRows->Length() < myNbRows) { // append empty row titles + myRows->Append(TCollection_ExtendedString("")); + } + } +} + + +Handle(TColStd_HSequenceOfExtendedString) SALOMEDSImpl_AttributeTableOfString::GetColumnData(const Standard_Integer theColumn) +{ + Handle(TColStd_HSequenceOfExtendedString) aSeq = new TColStd_HSequenceOfExtendedString; + + Standard_Integer i, anIndex; + for(i = 1; i <= myNbRows; i++) { + anIndex = myNbColumns*(i-1) + theColumn; + if(myTable.IsBound(anIndex)) + aSeq->Append(myTable.Find(anIndex)); + else + aSeq->Append(0.); + } + + return aSeq; +} + +void SALOMEDSImpl_AttributeTableOfString::SetColumnTitle(const Standard_Integer theColumn, + const TCollection_ExtendedString& theTitle) +{ + CheckLocked(); + Backup(); + while(myCols->Length() < theColumn) myCols->Append(TCollection_ExtendedString("")); + myCols->SetValue(theColumn,theTitle); +} + +TCollection_ExtendedString SALOMEDSImpl_AttributeTableOfString::GetColumnTitle(const Standard_Integer theColumn) const +{ + if(myCols.IsNull()) return ""; + if(myCols->Length() < theColumn) return ""; + return myCols->Value(theColumn); +} + + +void SALOMEDSImpl_AttributeTableOfString::SetColumnTitles(const Handle(TColStd_HSequenceOfExtendedString)& theTitles) +{ + if (theTitles->Length() != myNbColumns) Standard_Failure::Raise("Invalid number of columns"); + int aLength = theTitles->Length(), i; + for(i = 1; i <= aLength; i++) myCols->SetValue(i, theTitles->Value(i)); +} + +Handle(TColStd_HSequenceOfExtendedString) SALOMEDSImpl_AttributeTableOfString::GetColumnTitles() +{ + Handle(TColStd_HSequenceOfExtendedString) aSeq = new TColStd_HSequenceOfExtendedString; + int aLength = myCols->Length(), i; + for(i=1; i<=aLength; i++) aSeq->Append(myCols->Value(i)); + return aSeq; +} + + +Standard_Integer SALOMEDSImpl_AttributeTableOfString::GetNbRows() const +{ + return myNbRows; +} + +Standard_Integer SALOMEDSImpl_AttributeTableOfString::GetNbColumns() const +{ + return myNbColumns; +} + +void SALOMEDSImpl_AttributeTableOfString::PutValue(const TCollection_ExtendedString& theValue, + const Standard_Integer theRow, + const Standard_Integer theColumn) +{ + CheckLocked(); + if(theColumn > myNbColumns) SetNbColumns(theColumn); + + Standard_Integer anIndex = (theRow-1)*myNbColumns + theColumn; + myTable.Bind(anIndex, theValue); + + if(theRow > myNbRows) { + while (myRows->Length() < theRow) { // append empty row titles + myRows->Append(TCollection_ExtendedString("")); + } + myNbRows = theRow; + } +} + +Standard_Boolean SALOMEDSImpl_AttributeTableOfString::HasValue(const Standard_Integer theRow, + const Standard_Integer theColumn) +{ + if(theRow > myNbRows || theRow < 1) return Standard_False; + if(theColumn > myNbColumns || theColumn < 1) return Standard_False; + + Standard_Integer anIndex = (theRow-1)*myNbColumns + theColumn; + return myTable.IsBound(anIndex); +} + +TCollection_ExtendedString SALOMEDSImpl_AttributeTableOfString::GetValue(const Standard_Integer theRow, + const Standard_Integer theColumn) +{ + if(theRow > myNbRows || theRow < 1) Standard_Failure::Raise("Invalid cell index"); + if(theColumn > myNbColumns || theColumn < 1) Standard_Failure::Raise("Invalid cell index"); + + Standard_Integer anIndex = (theRow-1)*myNbColumns + theColumn; + if(myTable.IsBound(anIndex)) return myTable.Find(anIndex); + + Standard_Failure::Raise("Invalid cell index"); + return 0.; +} + +const Standard_GUID& SALOMEDSImpl_AttributeTableOfString::ID() const +{ + return GetID(); +} + +void SALOMEDSImpl_AttributeTableOfString::Restore(const Handle(TDF_Attribute)& with) +{ + Standard_Integer anIndex; + Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(with); + + myTable.Clear(); + myCols->Clear(); + myRows->Clear(); + + myTable = aTable->myTable; + myNbRows = aTable->myNbRows; + myNbColumns = aTable->myNbColumns; + myTitle = aTable->myTitle; + + for(anIndex = 1; anIndex <= aTable->GetNbRows();anIndex++) + myRows->Append(aTable->GetRowTitle(anIndex)); + + for(anIndex = 1; anIndex <= aTable->GetNbColumns(); anIndex++) + myCols->Append(aTable->GetColumnTitle(anIndex)); +} + +Handle(TDF_Attribute) SALOMEDSImpl_AttributeTableOfString::NewEmpty() const +{ + return new SALOMEDSImpl_AttributeTableOfString(); +} + +void SALOMEDSImpl_AttributeTableOfString::Paste(const Handle(TDF_Attribute)& into, + const Handle(TDF_RelocationTable)&) const +{ + Standard_Integer anIndex; + Handle(SALOMEDSImpl_AttributeTableOfString) aTable = Handle(SALOMEDSImpl_AttributeTableOfString)::DownCast(into); + + aTable->myTable.Clear(); + aTable->myCols->Clear(); + aTable->myRows->Clear(); + + aTable->myTable = myTable; + aTable->myTitle = myTitle; + aTable->myNbRows = myNbRows; + aTable->myNbColumns = myNbColumns; + + for(anIndex = 1; anIndex <= GetNbRows();anIndex++) + aTable->myRows->Append(GetRowTitle(anIndex)); + for(anIndex = 1; anIndex <= GetNbColumns(); anIndex++) + aTable->myCols->Append(GetColumnTitle(anIndex)); +} + + +Handle_TColStd_HSequenceOfInteger SALOMEDSImpl_AttributeTableOfString::GetSetRowIndices(const Standard_Integer theRow) +{ + Handle(TColStd_HSequenceOfInteger) aSeq = new TColStd_HSequenceOfInteger; + + Standard_Integer i, aShift = myNbColumns*(theRow-1); + for(i = 1; i <= myNbColumns; i++) { + if(myTable.IsBound(aShift + i)) aSeq->Append(i); + } + + return aSeq; +} + +Handle_TColStd_HSequenceOfInteger SALOMEDSImpl_AttributeTableOfString::GetSetColumnIndices(const Standard_Integer theColumn) +{ + Handle(TColStd_HSequenceOfInteger) aSeq = new TColStd_HSequenceOfInteger; + + Standard_Integer i, anIndex; + for(i = 1; i <= myNbRows; i++) { + anIndex = myNbColumns*(i-1)+theColumn; + if(myTable.IsBound(anIndex)) aSeq->Append(i); + } + + return aSeq; +} + + + +void SALOMEDSImpl_AttributeTableOfString::ConvertToString(ostrstream& theStream) +{ + int i, j, l; + + //Title + l = myTitle.Length(); + theStream << l << "\n"; + for(i=1; i<=l; i++) + theStream << myTitle.Value(i) << "\n"; + + //Nb rows + theStream << myNbRows << "\n"; + + //Rows titles + for(i=1; i<=myNbRows; i++) { + l = myRows->Value(i).Length(); + theStream << l << "\n"; + for(j=1; j<=l; j++) + theStream << myRows->Value(i).Value(j) << "\n"; + } + + //Nb columns + theStream << myNbColumns << "\n"; + + //Columns titles + for(i=1; i<=myNbColumns; i++) { + l = myCols->Value(i).Length(); + theStream << l << "\n"; + for(j=1; j<=l; j++) + theStream << myCols->Value(i).Value(j) << "\n"; + } + + //Store the table values + l = myTable.Extent(); + theStream << l << "\n"; + DataMapIterator anIterator(myTable); + for(; anIterator.More(); anIterator.Next()) { + if (anIterator.Value().Length()) { // check empty string in the value table + theStream << anIterator.Key() << "\n"; + unsigned long aValueSize = anIterator.Value().Length(); + theStream<> l; + + myTitle = TCollection_ExtendedString(l, 0); + for(i=1; i<=l; i++) { + theStream >> anExtChar; + myTitle.SetValue(i, anExtChar); + } + + //Nb rows + theStream >> myNbRows; + + //Rows titles + myRows->Clear(); + for(i=1; i<=myNbRows; i++) { + theStream >> l; + aStr = TCollection_ExtendedString(l,0); + for(j=1; j<=l; j++) { + theStream >> anExtChar; + aStr.SetValue(j, anExtChar); + } + myRows->Append(aStr); + } + + //Nb columns + theStream >> myNbColumns; + + //Columns titles + myCols->Clear(); + for(i=1; i<=myNbColumns; i++) { + theStream >> l; + aStr = TCollection_ExtendedString(l,0); + for(j=1; j<=l; j++) { + theStream >> anExtChar; + aStr.SetValue(j, anExtChar); + } + myCols->Append(aStr); + } + + //Restore the table values + TCollection_AsciiString aValue; + theStream >> l; + myTable.Clear(); + theStream.getline(aValueString,aSize,'\n'); + for(i=1; i<=l; i++) { + Standard_Integer aKey; + + theStream.getline(aValueString,aSize,'\n'); + aValue = aValueString; + aKey = aValue.IntegerValue(); + if (aValue.Value(1) == '0') + aValue = ""; + else { + unsigned long aValueSize; + theStream >> aValueSize; + theStream.read(aValueString, 1); // an '\n' omitting + theStream.read(aValueString, aValueSize); + theStream.read(aValueString, 1); // an '\n' omitting + aValue = aValueString; + } + myTable.Bind(aKey, aValue); + } + delete(aValueString); + return true; +} + +TCollection_AsciiString SALOMEDSImpl_AttributeTableOfString::Save() +{ + ostrstream ostr; + ConvertToString(ostr); + TCollection_AsciiString aString((char*)ostr.rdbuf()->str()); + return aString; +} + +void SALOMEDSImpl_AttributeTableOfString::Load(const TCollection_AsciiString& value) +{ + istrstream aStream(value.ToCString(), strlen(value.ToCString())); + RestoreFromString(aStream); +} diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfString.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfString.hxx new file mode 100644 index 000000000..3c73a89c0 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfString.hxx @@ -0,0 +1,98 @@ +// SALOME SALOMEDSImpl : data structure of SALOME and sources of Salome data server +// +// Copyright (C) 2003 CEA/DEN, EDF R&D +// +// +// +// File : SALOMEDSImpl_AttributeTableOfString.hxx +// Author : Sergey Ruin +// Module : SALOME + +#ifndef _SALOMEDSImpl_AttributeTableOfString_HeaderFile +#define _SALOMEDSImpl_AttributeTableOfString_HeaderFile + +#include +#include +#include +#include +#include "SALOMEDSImpl_GenericAttribute.hxx" + +class Standard_GUID; +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_AttributeTableOfString, SALOMEDSImpl_GenericAttribute ) + +#include +#include +#include +#include +#include +#include +#include + +typedef NCollection_DataMap DataMapOfIntegerString; + +class SALOMEDSImpl_AttributeTableOfString : public SALOMEDSImpl_GenericAttribute +{ + +public: +Standard_EXPORT virtual TCollection_AsciiString Save(); +Standard_EXPORT virtual void Load(const TCollection_AsciiString&); +Standard_EXPORT static const Standard_GUID& GetID() ; +Standard_EXPORT static Handle_SALOMEDSImpl_AttributeTableOfString Set(const TDF_Label& label) ; +Standard_EXPORT SALOMEDSImpl_AttributeTableOfString(); +Standard_EXPORT void SetNbColumns(const Standard_Integer theNbColumns); +Standard_EXPORT void SetTitle(const TCollection_ExtendedString& theTitle) ; +Standard_EXPORT TCollection_ExtendedString GetTitle() const; +Standard_EXPORT void SetRowData(const Standard_Integer theRow,const Handle(TColStd_HSequenceOfExtendedString)& theData) ; +Standard_EXPORT Handle_TColStd_HSequenceOfExtendedString GetRowData(const Standard_Integer theRow) ; +Standard_EXPORT void SetRowTitle(const Standard_Integer theRow,const TCollection_ExtendedString& theTitle) ; +Standard_EXPORT void SetRowUnit(const Standard_Integer theRow,const TCollection_ExtendedString& theUnit) ; +Standard_EXPORT TCollection_ExtendedString GetRowUnit(const Standard_Integer theRow) const; +Standard_EXPORT void SetRowUnits(const Handle(TColStd_HSequenceOfExtendedString)& theUnits) ; +Standard_EXPORT Handle(TColStd_HSequenceOfExtendedString) GetRowUnits(); +Standard_EXPORT void SetRowTitles(const Handle(TColStd_HSequenceOfExtendedString)& theTitles) ; +Standard_EXPORT Handle(TColStd_HSequenceOfExtendedString) GetRowTitles(); +Standard_EXPORT TCollection_ExtendedString GetRowTitle(const Standard_Integer theRow) const; +Standard_EXPORT void SetColumnData(const Standard_Integer theColumn,const Handle(TColStd_HSequenceOfExtendedString)& theData) ; +Standard_EXPORT Handle_TColStd_HSequenceOfExtendedString GetColumnData(const Standard_Integer theColumn) ; +Standard_EXPORT void SetColumnTitle(const Standard_Integer theColumn,const TCollection_ExtendedString& theTitle) ; +Standard_EXPORT TCollection_ExtendedString GetColumnTitle(const Standard_Integer theColumn) const; +Standard_EXPORT void SetColumnTitles(const Handle(TColStd_HSequenceOfExtendedString)& theTitles); +Standard_EXPORT Handle(TColStd_HSequenceOfExtendedString) GetColumnTitles(); +Standard_EXPORT Standard_Integer GetNbRows() const; +Standard_EXPORT Standard_Integer GetNbColumns() const; + +Standard_EXPORT void PutValue(const TCollection_ExtendedString& theValue,const Standard_Integer theRow,const Standard_Integer theColumn) ; +Standard_EXPORT Standard_Boolean HasValue(const Standard_Integer theRow,const Standard_Integer theColumn) ; +Standard_EXPORT TCollection_ExtendedString GetValue(const Standard_Integer theRow,const Standard_Integer theColumn) ; +Standard_EXPORT const Standard_GUID& ID() const; +Standard_EXPORT void Restore(const Handle(TDF_Attribute)& with) ; +Standard_EXPORT Handle_TDF_Attribute NewEmpty() const; +Standard_EXPORT void Paste(const Handle(TDF_Attribute)& into,const Handle(TDF_RelocationTable)& RT) const; + +Standard_EXPORT Handle_TColStd_HSequenceOfInteger GetSetRowIndices(const Standard_Integer theRow); +Standard_EXPORT Handle_TColStd_HSequenceOfInteger GetSetColumnIndices(const Standard_Integer theColumn); + +Standard_EXPORT void ConvertToString(ostrstream& theStream); +Standard_EXPORT bool RestoreFromString(istrstream& theStream); + +Standard_EXPORT ~SALOMEDSImpl_AttributeTableOfString() {} + +private: + +DataMapOfIntegerString myTable; +TCollection_ExtendedString myTitle; +Handle_TColStd_HSequenceOfExtendedString myRows; +Handle_TColStd_HSequenceOfExtendedString myCols; +Standard_Integer myNbRows; +Standard_Integer myNbColumns; + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_AttributeTableOfString ) + +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTarget.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTarget.cxx new file mode 100644 index 000000000..4c341b533 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTarget.cxx @@ -0,0 +1,158 @@ +// File : SALOMEDSImpl_AttributeTarget.cxx +// Author : Sergey RUIN +// Module : SALOME + +using namespace std; +#include "SALOMEDSImpl_AttributeTarget.hxx" +#include "SALOMEDSImpl_AttributeReference.hxx" +#include "SALOMEDSImpl_Study.hxx" +#include +#include +#include + + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeTarget, SALOMEDSImpl_GenericAttribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeTarget, SALOMEDSImpl_GenericAttribute ) + +//======================================================================= +//function : GetID +//purpose : +//======================================================================= + +const Standard_GUID& SALOMEDSImpl_AttributeTarget::GetID () +{ + static Standard_GUID SALOMEDSImpl_AttributeTargetID ("12837197-8F52-11d6-A8A3-0001021E8C7F"); + return SALOMEDSImpl_AttributeTargetID; +} + + +//======================================================================= +//function : Set +//purpose : +//======================================================================= + +Handle(SALOMEDSImpl_AttributeTarget) SALOMEDSImpl_AttributeTarget::Set (const TDF_Label& L) +{ + Handle(SALOMEDSImpl_AttributeTarget) A; + if (!L.FindAttribute(SALOMEDSImpl_AttributeTarget::GetID(),A)) { + A = new SALOMEDSImpl_AttributeTarget(); + L.AddAttribute(A); + } + return A; +} + + +//======================================================================= +//function : constructor +//purpose : +//======================================================================= +SALOMEDSImpl_AttributeTarget::SALOMEDSImpl_AttributeTarget() +:SALOMEDSImpl_GenericAttribute("AttributeTarget") +{ +} + +void SALOMEDSImpl_AttributeTarget::SetRelation(const TCollection_ExtendedString& theRelation) +{ + CheckLocked(); + if(myRelation == theRelation) return; + + Backup(); + myRelation = theRelation; +} + +//======================================================================= +//function : Add +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeTarget::Add(const Handle(SALOMEDSImpl_SObject)& theSO) +{ + Backup(); + TDF_Label aRefLabel = theSO->GetLabel(); + Handle(SALOMEDSImpl_AttributeReference) aReference; + if (aRefLabel.FindAttribute(SALOMEDSImpl_AttributeReference::GetID(),aReference)) { + TDF_ListIteratorOfAttributeList anIter(GetVariables()); + for(;anIter.More();anIter.Next()) if(anIter.Value()->Label() == aRefLabel) return; //BugID: PAL6192 + GetVariables().Append(aReference); + } +} + +//======================================================================= +//function : Get +//purpose : +//======================================================================= +Handle(TColStd_HSequenceOfTransient) SALOMEDSImpl_AttributeTarget::Get() +{ + Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient; + + TDF_ListIteratorOfAttributeList anIter(GetVariables()); + for(;anIter.More();anIter.Next()) { + const TDF_Label& aLabel = anIter.Value()->Label(); + aSeq->Append( SALOMEDSImpl_Study::SObject(aLabel)); + } + return aSeq; +} + +//======================================================================= +//function : Remove +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeTarget::Remove(const Handle(SALOMEDSImpl_SObject)& theSO) +{ + Backup(); + TDF_Label aRefLabel = theSO->GetLabel(); + TDF_ListIteratorOfAttributeList anIter(GetVariables()); + for(;anIter.More();anIter.Next()) { + if (anIter.Value()->Label() == aRefLabel) { + GetVariables().Remove(anIter); + return; + } + } +} + +//======================================================================= +//function : ID +//purpose : +//======================================================================= +const Standard_GUID& SALOMEDSImpl_AttributeTarget::ID () const { return GetID(); } + +//======================================================================= +//function : Restore +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeTarget::Restore(const Handle(TDF_Attribute)& With) +{ + Handle(SALOMEDSImpl_AttributeTarget) REL = Handle(SALOMEDSImpl_AttributeTarget)::DownCast (With); + myRelation = REL->GetRelation(); + Handle(SALOMEDSImpl_AttributeReference) V; + myVariables.Clear(); + for (TDF_ListIteratorOfAttributeList it (REL->GetVariables()); it.More(); it.Next()) { + V = Handle(SALOMEDSImpl_AttributeReference)::DownCast(it.Value()); + myVariables.Append(V); + } +} + +//======================================================================= +//function : NewEmpty +//purpose : +//======================================================================= +Handle(TDF_Attribute) SALOMEDSImpl_AttributeTarget::NewEmpty() const +{ + return new SALOMEDSImpl_AttributeTarget(); +} + +//======================================================================= +//function : Paste +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeTarget::Paste(const Handle(TDF_Attribute)& Into, + const Handle(TDF_RelocationTable)& RT) const +{ + Handle(SALOMEDSImpl_AttributeTarget) REL = Handle(SALOMEDSImpl_AttributeTarget)::DownCast (Into); + REL->SetRelation(myRelation); + Handle(SALOMEDSImpl_AttributeReference) V1,V2; + for (TDF_ListIteratorOfAttributeList it (myVariables); it.More(); it.Next()) { + V1 = Handle(SALOMEDSImpl_AttributeReference)::DownCast(it.Value()); + RT->HasRelocation (V1,V2); + REL->GetVariables().Append(V2); + } +} diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTarget.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTarget.hxx new file mode 100644 index 000000000..0eb78bb0d --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTarget.hxx @@ -0,0 +1,53 @@ +// File : SALOMEDSImpl_AttributeTarget.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef _SALOMEDSImpl_AttributeTarget_HeaderFile +#define _SALOMEDSImpl_AttributeTarget_HeaderFile + +#include +#include +#include +#include +#include +#include +#include +#include "SALOMEDSImpl_GenericAttribute.hxx" +#include "SALOMEDSImpl_SObject.hxx" + +class Standard_GUID; +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_AttributeTarget, SALOMEDSImpl_GenericAttribute ) + + +class SALOMEDSImpl_AttributeTarget : public SALOMEDSImpl_GenericAttribute +{ +private: +TCollection_ExtendedString myRelation; +TDF_AttributeList myVariables; + +public: +Standard_EXPORT static const Standard_GUID& GetID() ; +Standard_EXPORT static Handle_SALOMEDSImpl_AttributeTarget Set(const TDF_Label& label) ; +Standard_EXPORT SALOMEDSImpl_AttributeTarget(); +Standard_EXPORT void SALOMEDSImpl_AttributeTarget::Add(const Handle(SALOMEDSImpl_SObject)& theSO); +Standard_EXPORT Handle(TColStd_HSequenceOfTransient) SALOMEDSImpl_AttributeTarget::Get(); +Standard_EXPORT void SALOMEDSImpl_AttributeTarget::Remove(const Handle(SALOMEDSImpl_SObject)& theSO); +Standard_EXPORT TCollection_ExtendedString GetRelation() { return myRelation; } +Standard_EXPORT void SetRelation(const TCollection_ExtendedString& theRelation); +Standard_EXPORT TDF_AttributeList& GetVariables() { return myVariables; } +Standard_EXPORT const Standard_GUID& ID() const; +Standard_EXPORT void Restore(const Handle(TDF_Attribute)& with) ; +Standard_EXPORT Handle_TDF_Attribute NewEmpty() const; +Standard_EXPORT void Paste(const Handle(TDF_Attribute)& into,const Handle(TDF_RelocationTable)& RT) const; +Standard_EXPORT ~SALOMEDSImpl_AttributeTarget() {} + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_AttributeTarget ) + +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTextColor.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTextColor.cxx new file mode 100644 index 000000000..3ce415307 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTextColor.cxx @@ -0,0 +1,131 @@ +// File : SALOMEDSImpl_AttributeTextColor.cxx +// Author : Sergey RUIN +// Module : SALOME + +using namespace std; +#include "SALOMEDSImpl_AttributeTextColor.hxx" +#include + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeTextColor, SALOMEDSImpl_GenericAttribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeTextColor, SALOMEDSImpl_GenericAttribute ) + +//======================================================================= +//function : GetID +//purpose : +//======================================================================= + +const Standard_GUID& SALOMEDSImpl_AttributeTextColor::GetID () +{ + static Standard_GUID SALOMEDSImpl_AttributeTextColorID ("12837189-8F52-11d6-A8A3-0001021E8C7F"); + return SALOMEDSImpl_AttributeTextColorID; +} + + +//======================================================================= +//function : constructor +//purpose : +//======================================================================= +SALOMEDSImpl_AttributeTextColor::SALOMEDSImpl_AttributeTextColor() +:SALOMEDSImpl_GenericAttribute("AttributeTextColor") +{ + myValue = new TColStd_HArray1OfReal(1, 3, RealFirst()); +} + +//======================================================================= +//function : SetTextColor +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeTextColor::SetTextColor(const Standard_Real R, const Standard_Real G, const Standard_Real B) +{ + CheckLocked(); + if(myValue.IsNull()) return; + Backup(); + + myValue->SetValue(1, R); + myValue->SetValue(2, G); + myValue->SetValue(3, B); +} + +//======================================================================= +//function : TextColor +//purpose : +//======================================================================= +Handle(TColStd_HArray1OfReal) SALOMEDSImpl_AttributeTextColor::TextColor() +{ + return myValue; +} + +//======================================================================= +//function : ChangeArray +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeTextColor::ChangeArray(const Handle(TColStd_HArray1OfReal)& newArray) +{ + Backup(); + + for(int i = 1; i <= 3; i++) + myValue->SetValue(i, newArray->Value(i)); +} + +//======================================================================= +//function : ID +//purpose : +//======================================================================= + +const Standard_GUID& SALOMEDSImpl_AttributeTextColor::ID () const { return GetID(); } + + +//======================================================================= +//function : NewEmpty +//purpose : +//======================================================================= + +Handle(TDF_Attribute) SALOMEDSImpl_AttributeTextColor::NewEmpty () const +{ + return new SALOMEDSImpl_AttributeTextColor(); +} + +//======================================================================= +//function : Restore +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributeTextColor::Restore(const Handle(TDF_Attribute)& with) +{ + Handle(TColStd_HArray1OfReal) s = Handle(SALOMEDSImpl_AttributeTextColor)::DownCast (with)->TextColor (); + ChangeArray(s); + return; +} + +//======================================================================= +//function : Paste +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributeTextColor::Paste (const Handle(TDF_Attribute)& into, + const Handle(TDF_RelocationTable)& RT) const +{ + Handle(SALOMEDSImpl_AttributeTextColor)::DownCast (into)->ChangeArray (myValue); +} + + + +TCollection_AsciiString SALOMEDSImpl_AttributeTextColor::Save() +{ + char *Val = new char[75]; + sprintf(Val, "%f %f %f", (float)myValue->Value(1), + (float)myValue->Value(2), + (float)myValue->Value(3)); + TCollection_AsciiString ret(Val); + delete Val; + return ret; +} + +void SALOMEDSImpl_AttributeTextColor::Load(const TCollection_AsciiString& value) +{ + float r, g, b; + sscanf(value.ToCString(), "%f %f %f", &r, &g, &b); + myValue->SetValue(1, r); + myValue->SetValue(2, g); + myValue->SetValue(3, b); +} diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTextColor.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTextColor.hxx new file mode 100644 index 000000000..1601eb0a5 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTextColor.hxx @@ -0,0 +1,45 @@ +// File : SALOMEDSImpl_AttributeTextColor.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef _SALOMEDSImpl_AttributeTextColor_HeaderFile +#define _SALOMEDSImpl_AttributeTextColor_HeaderFile + +#include +#include +#include +#include +#include +#include "SALOMEDSImpl_GenericAttribute.hxx" + +class Standard_GUID; +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_AttributeTextColor, SALOMEDSImpl_GenericAttribute ) + +class SALOMEDSImpl_AttributeTextColor : public SALOMEDSImpl_GenericAttribute +{ +private: + Handle(TColStd_HArray1OfReal) myValue; + +public: +Standard_EXPORT virtual TCollection_AsciiString Save(); +Standard_EXPORT virtual void Load(const TCollection_AsciiString&); +Standard_EXPORT static const Standard_GUID& GetID() ; +Standard_EXPORT SALOMEDSImpl_AttributeTextColor(); +Standard_EXPORT const Standard_GUID& ID() const; +Standard_EXPORT void SetTextColor(const Standard_Real R, const Standard_Real G, const Standard_Real B); +Standard_EXPORT Handle(TColStd_HArray1OfReal) TextColor(); +Standard_EXPORT void ChangeArray(const Handle(TColStd_HArray1OfReal)& newArray); +Standard_EXPORT void Restore(const Handle(TDF_Attribute)& with) ; +Standard_EXPORT Handle_TDF_Attribute NewEmpty() const; +Standard_EXPORT void Paste(const Handle(TDF_Attribute)& into,const Handle(TDF_RelocationTable)& RT) const; +Standard_EXPORT ~SALOMEDSImpl_AttributeTextColor() {} + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_AttributeTextColor ) +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTextHighlightColor.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTextHighlightColor.cxx new file mode 100644 index 000000000..96fdefb62 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTextHighlightColor.cxx @@ -0,0 +1,133 @@ +// File : SALOMEDSImpl_AttributeTextHighlightColor.cxx +// Author : Sergey RUIN +// Module : SALOME + +using namespace std; +#include "SALOMEDSImpl_AttributeTextHighlightColor.hxx" +#include + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeTextHighlightColor, SALOMEDSImpl_GenericAttribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeTextHighlightColor, SALOMEDSImpl_GenericAttribute ) + +//======================================================================= +//function : GetID +//purpose : +//======================================================================= + +const Standard_GUID& SALOMEDSImpl_AttributeTextHighlightColor::GetID () +{ + static Standard_GUID SALOMEDSImpl_AttributeTextHighlightColorID ("12837190-8F52-11d6-A8A3-0001021E8C7F"); + return SALOMEDSImpl_AttributeTextHighlightColorID; +} + + + +//======================================================================= +//function : constructor +//purpose : +//======================================================================= +SALOMEDSImpl_AttributeTextHighlightColor::SALOMEDSImpl_AttributeTextHighlightColor() +:SALOMEDSImpl_GenericAttribute("AttributeTextHighlightColor") +{ + myValue = new TColStd_HArray1OfReal(1, 3, RealFirst()); +} + +//======================================================================= +//function : ID +//purpose : +//======================================================================= + +const Standard_GUID& SALOMEDSImpl_AttributeTextHighlightColor::ID () const { return GetID(); } + + +//======================================================================= +//function : SetTextHighlightColor +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeTextHighlightColor::SetTextHighlightColor(const Standard_Real R, + const Standard_Real G, + const Standard_Real B) +{ + CheckLocked(); + if(myValue.IsNull()) return; + Backup(); + + myValue->SetValue(1, R); + myValue->SetValue(2, G); + myValue->SetValue(3, B); +} + +//======================================================================= +//function : TextHighlightColor +//purpose : +//======================================================================= +Handle(TColStd_HArray1OfReal) SALOMEDSImpl_AttributeTextHighlightColor::TextHighlightColor() +{ + return myValue; +} + +//======================================================================= +//function : ChangeArray +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeTextHighlightColor::ChangeArray(const Handle(TColStd_HArray1OfReal)& newArray) +{ + Backup(); + + for(int i = 1; i <= 3; i++) + myValue->SetValue(i, newArray->Value(i)); +} + +//======================================================================= +//function : NewEmpty +//purpose : +//======================================================================= + +Handle(TDF_Attribute) SALOMEDSImpl_AttributeTextHighlightColor::NewEmpty () const +{ + return new SALOMEDSImpl_AttributeTextHighlightColor(); +} + +//======================================================================= +//function : Restore +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributeTextHighlightColor::Restore(const Handle(TDF_Attribute)& with) +{ + Handle(TColStd_HArray1OfReal) s = Handle(SALOMEDSImpl_AttributeTextHighlightColor)::DownCast (with)->TextHighlightColor (); + ChangeArray(s); + return; +} + +//======================================================================= +//function : Paste +//purpose : +//======================================================================= + +void SALOMEDSImpl_AttributeTextHighlightColor::Paste (const Handle(TDF_Attribute)& into, + const Handle(TDF_RelocationTable)& ) const +{ + Handle(SALOMEDSImpl_AttributeTextHighlightColor)::DownCast (into)->ChangeArray (myValue); +} + +TCollection_AsciiString SALOMEDSImpl_AttributeTextHighlightColor::Save() +{ + char *Val = new char[75]; + sprintf(Val, "%f %f %f", (float)myValue->Value(1), + (float)myValue->Value(2), + (float)myValue->Value(3)); + TCollection_AsciiString ret(Val); + delete Val; + return ret; +} + +void SALOMEDSImpl_AttributeTextHighlightColor::Load(const TCollection_AsciiString& value) +{ + float r, g, b; + sscanf(value.ToCString(), "%f %f %f", &r, &g, &b); + myValue->SetValue(1, r); + myValue->SetValue(2, g); + myValue->SetValue(3, b); +} + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTextHighlightColor.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTextHighlightColor.hxx new file mode 100644 index 000000000..4322c19f7 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTextHighlightColor.hxx @@ -0,0 +1,45 @@ +// File : SALOMEDSImpl_AttributeTextHighlightColor.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef _SALOMEDSImpl_AttributeTextHighlightColor_HeaderFile +#define _SALOMEDSImpl_AttributeTextHighlightColor_HeaderFile + +#include +#include +#include +#include +#include +#include "SALOMEDSImpl_GenericAttribute.hxx" + +class Standard_GUID; +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_AttributeTextHighlightColor, SALOMEDSImpl_GenericAttribute ) + +class SALOMEDSImpl_AttributeTextHighlightColor : public SALOMEDSImpl_GenericAttribute +{ +private: + Handle(TColStd_HArray1OfReal) myValue; + +public: +Standard_EXPORT virtual TCollection_AsciiString Save(); +Standard_EXPORT virtual void Load(const TCollection_AsciiString&); +Standard_EXPORT static const Standard_GUID& GetID() ; +Standard_EXPORT SALOMEDSImpl_AttributeTextHighlightColor(); +Standard_EXPORT void SetTextHighlightColor(const Standard_Real R, const Standard_Real G, const Standard_Real B); +Standard_EXPORT Handle(TColStd_HArray1OfReal) TextHighlightColor(); +Standard_EXPORT void ChangeArray(const Handle(TColStd_HArray1OfReal)& newArray); +Standard_EXPORT const Standard_GUID& ID() const; +Standard_EXPORT void Restore(const Handle(TDF_Attribute)& with) ; +Standard_EXPORT Handle_TDF_Attribute NewEmpty() const; +Standard_EXPORT void Paste(const Handle(TDF_Attribute)& into,const Handle(TDF_RelocationTable)& RT) const; +Standard_EXPORT ~SALOMEDSImpl_AttributeTextHighlightColor() {} + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_AttributeTextHighlightColor ) +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTreeNode.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTreeNode.cxx new file mode 100644 index 000000000..299619443 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTreeNode.cxx @@ -0,0 +1,548 @@ +// File : SALOMEDSImpl_AttributeTreeNode.cxx +// Author : Sergey RUIN +// Module : SALOME + +using namespace std; +#include "SALOMEDSImpl_AttributeTreeNode.hxx" +#include +#include +#include +#include +#include +#include + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeTreeNode, SALOMEDSImpl_GenericAttribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeTreeNode, SALOMEDSImpl_GenericAttribute ) + +static char* Entry(const TDF_Label& theLabel) +{ + TCollection_AsciiString anEntry; + TDF_Tool::Entry(theLabel, anEntry); + return anEntry.ToCString(); +} + +const Standard_GUID& SALOMEDSImpl_AttributeTreeNode::GetDefaultTreeID() +{ + static Standard_GUID TreeNodeID ("0E1C36E6-379B-4d90-AC37-17A14310E648"); + return TreeNodeID; +} + + +SALOMEDSImpl_AttributeTreeNode::SALOMEDSImpl_AttributeTreeNode() +:SALOMEDSImpl_GenericAttribute("AttributeTreeNode"), myFather(NULL), myPrevious(NULL), myNext(NULL), myFirst(NULL) +{} + + +Handle(SALOMEDSImpl_AttributeTreeNode) SALOMEDSImpl_AttributeTreeNode::Set (const TDF_Label& L, const Standard_GUID& ID) +{ + Handle(SALOMEDSImpl_AttributeTreeNode) TN; + + if (!L.FindAttribute(ID,TN)) { + TN = new SALOMEDSImpl_AttributeTreeNode (); + TN->SetTreeID(ID); + L.AddAttribute(TN); + } + + return TN; +} + +//======================================================================= +//TreeNode : ID +//purpose : Returns GUID of the TreeNode +//======================================================================= +const Standard_GUID& SALOMEDSImpl_AttributeTreeNode::ID() const +{ + return myTreeID; +} + +//======================================================================= +//function : Append +//purpose : Add as last child of me +//======================================================================= +Standard_Boolean SALOMEDSImpl_AttributeTreeNode::Append (const Handle(SALOMEDSImpl_AttributeTreeNode)& TN) +{ + CheckLocked(); + + if (!(TN->ID() == myTreeID) ) + Standard_DomainError::Raise("SALOMEDSImpl_AttributeTreeNode::Append : uncompatible GUID"); + + Handle(SALOMEDSImpl_AttributeTreeNode) bid; + TN->SetNext(bid); // Deconnects from next. + + // Find the last + if (!HasFirst()) { + SetFirst(TN); + TN->SetPrevious(bid); // Deconnects from previous. + } + else { + Handle(SALOMEDSImpl_AttributeTreeNode) Last = GetFirst(); + while (Last->HasNext()) { + Last = Last->GetNext(); + } + Last->SetNext(TN); + TN->SetPrevious(Last); + } + // Set Father + TN->SetFather(this); + return !TN.IsNull(); +} + +//======================================================================= +//function : Prepend +//purpose : Add as first child of me +//======================================================================= +Standard_Boolean SALOMEDSImpl_AttributeTreeNode::Prepend (const Handle(SALOMEDSImpl_AttributeTreeNode)& TN) +{ + CheckLocked(); + + if (!(TN->ID() == myTreeID) ) + Standard_DomainError::Raise("SALOMEDSImpl_AttributeTreeNode::Prepend : uncompatible GUID"); + + Handle(SALOMEDSImpl_AttributeTreeNode) bid; + TN->SetPrevious(bid); + if (HasFirst()) { + TN->SetNext(GetFirst()); + GetFirst()->SetPrevious(TN); + } + else { + TN->SetNext(bid); + } + TN->SetFather(this); + SetFirst(TN); + return !TN.IsNull(); +} + + +//======================================================================= +//function : InsertBefore +//purpose : Inserts the TreeNode before me +//======================================================================= +Standard_Boolean SALOMEDSImpl_AttributeTreeNode::InsertBefore (const Handle(SALOMEDSImpl_AttributeTreeNode)& TN) +{ + CheckLocked(); + + if (!(TN->ID() == myTreeID) ) + Standard_DomainError::Raise("SALOMEDSImpl_AttributeTreeNode::InsertBefore : uncompatible GUID"); + + TN->SetFather(GetFather()); + TN->SetPrevious(GetPrevious()); + TN->SetNext(this); + + if (!HasPrevious()) + GetFather()->SetFirst(TN); + else + GetPrevious()->SetNext(TN); + + SetPrevious(TN); + return !TN.IsNull(); +} + +//======================================================================= +//function : InsertAfter +//purpose : Inserts the TreeNode after me +//======================================================================= +Standard_Boolean SALOMEDSImpl_AttributeTreeNode::InsertAfter (const Handle(SALOMEDSImpl_AttributeTreeNode)& TN) +{ + CheckLocked(); + + if (!(TN->ID() == myTreeID) ) + Standard_DomainError::Raise("SALOMEDSImpl_AttributeTreeNode::InsertAfter : uncompatible GUID"); + + TN->SetFather(GetFather()); + TN->SetPrevious(this); + TN->SetNext(GetNext()); + + if (HasNext()) GetNext()->SetPrevious(TN); + + SetNext(TN); + return !TN.IsNull(); +} + +//======================================================================= +//function : Remove +//purpose : Removees the function from the function tree +//======================================================================= +Standard_Boolean SALOMEDSImpl_AttributeTreeNode::Remove () +{ + CheckLocked(); + + if (IsRoot()) return Standard_True; + + Handle(SALOMEDSImpl_AttributeTreeNode) bid; + if (!HasPrevious()) + GetFather()->SetFirst(GetNext()); + else + GetPrevious()->SetNext(GetNext()); + + if (HasNext()) { + if (HasPrevious()) GetNext()->SetPrevious(GetPrevious()); + else GetNext()->SetPrevious(bid); + } + else { + if (HasPrevious()) GetPrevious()->SetNext(bid); + } + + if (GetFather()->HasFirst()) { + if (Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(this) == GetFather()->GetFirst()) { + if (HasNext()) { + GetFather()->SetFirst(GetNext()); + } + else GetFather()->SetFirst(bid); + } + } + + SetFather(bid); + SetNext(bid); + SetPrevious(bid); + + return Standard_True; +} + +//======================================================================= +//function : Depth +//purpose : +//======================================================================= +Standard_Integer SALOMEDSImpl_AttributeTreeNode::Depth () const +{ + Standard_Integer depth = 0; + Handle(SALOMEDSImpl_AttributeTreeNode) current = this; + while (current->HasFather()) { + depth++; + current = current->GetFather(); + } + return depth; +} + +//======================================================================= +//function : SetTreeID +//purpose : Finds or creates a TreeNode attribute with explicit ID +// : a driver for it +//======================================================================= +void SALOMEDSImpl_AttributeTreeNode::SetTreeID (const Standard_GUID& explicitID) +{ + myTreeID = explicitID; +} + + +//======================================================================= +//function : IsAscendant +//purpose : +//======================================================================= +Standard_Boolean SALOMEDSImpl_AttributeTreeNode::IsAscendant (const Handle(SALOMEDSImpl_AttributeTreeNode)& ofTN) const +{ + return ofTN->IsDescendant(this); +} + +//======================================================================= +//function : IsDescendant +//purpose : +//======================================================================= + +Standard_Boolean SALOMEDSImpl_AttributeTreeNode::IsDescendant (const Handle(SALOMEDSImpl_AttributeTreeNode)& ofTN) const +{ + Handle(SALOMEDSImpl_AttributeTreeNode) current = this; + while (current->HasFather()) { + if (current->GetFather() == ofTN) return Standard_True; + current = current->GetFather(); + } + return Standard_False; +} + +//======================================================================= +//function : IsFather +//purpose : +//======================================================================= + +Standard_Boolean SALOMEDSImpl_AttributeTreeNode::IsFather (const Handle(SALOMEDSImpl_AttributeTreeNode)& ofTN) const +{ + return (ofTN->GetFather() == this); +} + + +//======================================================================= +//function : IsChild +//purpose : +//======================================================================= + +Standard_Boolean SALOMEDSImpl_AttributeTreeNode::IsChild (const Handle(SALOMEDSImpl_AttributeTreeNode)& ofTN) const +{ + return (myFather == ofTN); +} + +//======================================================================= +//TreeNode : IsRoot +//purpose : Returns Standard_True if the TreeNode is not attached to a +// TreeNode tree or hasn't an Father. +//======================================================================= +Standard_Boolean SALOMEDSImpl_AttributeTreeNode::IsRoot() const +{ + if (myFather.IsNull() && + myPrevious.IsNull() && + myNext.IsNull()) + return Standard_True; + return Standard_False; +} + +//======================================================================= +//TreeNode : Root +//purpose : Returns the TreeNode which has no Father +//======================================================================= +Handle(SALOMEDSImpl_AttributeTreeNode) SALOMEDSImpl_AttributeTreeNode::Root() const +{ + Handle(SALOMEDSImpl_AttributeTreeNode) O = this; + while (O->HasFather()) + O = O->GetFather(); + return O; +} + +//======================================================================= +//TreeNode : SetFather +//purpose : Sets the TreeNode F as Father of me +//======================================================================= +void SALOMEDSImpl_AttributeTreeNode::SetFather(const Handle(SALOMEDSImpl_AttributeTreeNode)& F) +{ + CheckLocked(); + Backup(); + myFather = F; +} + +//======================================================================= +//TreeNode : SetNext +//purpose : Sets the TreeNode F next to me +//======================================================================= +void SALOMEDSImpl_AttributeTreeNode::SetNext(const Handle(SALOMEDSImpl_AttributeTreeNode)& F) +{ + CheckLocked(); + Backup(); + myNext = F; +} + + +//======================================================================= +//TreeNode : SetPrevious +//purpose : Sets the TreeNode F previous to me +//======================================================================= +void SALOMEDSImpl_AttributeTreeNode::SetPrevious(const Handle(SALOMEDSImpl_AttributeTreeNode)& F) +{ + CheckLocked(); + Backup(); + myPrevious = F; +} + +//======================================================================= +//TreeNode : SetFirst +//purpose : Sets the TreeNode F as first in the TreeNode tree +//======================================================================= +void SALOMEDSImpl_AttributeTreeNode::SetFirst(const Handle(SALOMEDSImpl_AttributeTreeNode)& F) +{ + CheckLocked(); + Backup(); + myFirst = F; +} + +//======================================================================= +//TreeNode : AfterAddition +//purpose : Connects the TreeNode to the tree. +// Backuped attribute must stay disconnected +//======================================================================= +void SALOMEDSImpl_AttributeTreeNode::AfterAddition() +{ + if (!IsBackuped()) { + if (!myPrevious.IsNull()) { + myPrevious->SetNext(this); + } + else if (!myFather.IsNull()) { + myFather->SetFirst(this); + } + if (!myNext.IsNull()) + myNext->SetPrevious(this); + } +} + +//======================================================================= +//TreeNode : BeforeForget +//purpose : Disconnect the TreeNode from the tree. +// Backuped attribute is normaly not concerned by such an operation +//======================================================================= +void SALOMEDSImpl_AttributeTreeNode::BeforeForget() +{ + if (!IsBackuped()) { + Remove(); + while (HasFirst()) GetFirst()->Remove(); + } +} + +//======================================================================= +//TreeNode : AfterResume +//purpose : Connects the TreeNode to the tree +//======================================================================= +void SALOMEDSImpl_AttributeTreeNode::AfterResume() +{ + AfterAddition(); +} + +//======================================================================= +//TreeNode : BeforeUndo +//purpose : Disconnect the TreeNode from the tree. +//======================================================================= +Standard_Boolean SALOMEDSImpl_AttributeTreeNode::BeforeUndo(const Handle(TDF_AttributeDelta)& anAttDelta, + const Standard_Boolean forceIt) +{ + if (anAttDelta->IsKind(STANDARD_TYPE(TDF_DeltaOnAddition))) BeforeForget(); // Disconnect. + return Standard_True; +} + +//======================================================================= +//TreeNode : AfterUndo +//purpose : Connect the TreeNode from the tree. +//======================================================================= +Standard_Boolean SALOMEDSImpl_AttributeTreeNode::AfterUndo(const Handle(TDF_AttributeDelta)& anAttDelta, + const Standard_Boolean forceIt) +{ + if (anAttDelta->IsKind(STANDARD_TYPE(TDF_DeltaOnRemoval))) AfterAddition(); // Reconnect. + return Standard_True; +} + +//======================================================================= +//TreeNode : Restore +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeTreeNode::Restore(const Handle(TDF_Attribute)& other) +{ + Handle(SALOMEDSImpl_AttributeTreeNode) F = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(other); + myFather = F->myFather; + myPrevious = F->myPrevious; + myNext = F->myNext; + myFirst = F->myFirst; + myTreeID = F->myTreeID; +} + +//======================================================================= +//TreeNode : Paste +//purpose : Method for Copy mechanism +//======================================================================= + +void SALOMEDSImpl_AttributeTreeNode::Paste(const Handle(TDF_Attribute)& into, + const Handle(TDF_RelocationTable)& RT) const +{ + Handle(SALOMEDSImpl_AttributeTreeNode) intof = Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(into); + Handle(SALOMEDSImpl_AttributeTreeNode) func; + if (!RT->HasRelocation(myFather, func) && RT->AfterRelocate()) { + func.Nullify(); + } + intof->SetFather(func); + if (!RT->HasRelocation(myNext, func) && RT->AfterRelocate()) { + func.Nullify(); + } + intof->SetNext(func); + if (!RT->HasRelocation(myPrevious, func) && RT->AfterRelocate()) { + func.Nullify(); + } + intof->SetPrevious(func); + if (!RT->HasRelocation(myFirst, func) && RT->AfterRelocate()) { + func.Nullify(); + } + + intof->SetFirst(func); + intof->SetTreeID(myTreeID); +} + +//======================================================================= +//TreeNode : NewEmpty +//purpose : Returns new empty TreeNode attribute +//======================================================================= + +Handle(TDF_Attribute) SALOMEDSImpl_AttributeTreeNode::NewEmpty() const +{ + Handle(SALOMEDSImpl_AttributeTreeNode) T = new SALOMEDSImpl_AttributeTreeNode(); + T->SetTreeID(myTreeID); + return T; +} + +//======================================================================= +//TreeNode : References +//purpose : Collects the references +//======================================================================= +void SALOMEDSImpl_AttributeTreeNode::References(const Handle(TDF_DataSet)& aDataSet) const +{ + Handle(SALOMEDSImpl_AttributeTreeNode) fct = myFirst; + while (!fct.IsNull()) { + aDataSet->AddAttribute(fct); + fct = fct->myNext; + } +} + +TCollection_AsciiString SALOMEDSImpl_AttributeTreeNode::Type() +{ + char* aNodeName = new char[60]; + char aGUID[40]; + ID().ToCString(aGUID); + sprintf(aNodeName, "AttributeTreeNodeGUID%s",aGUID); + TCollection_AsciiString ret(aNodeName); + delete aNodeName; + + return ret; +} + +TCollection_AsciiString SALOMEDSImpl_AttributeTreeNode::Save() +{ + TCollection_AsciiString aFather, aPrevious, aNext, aFirst; + + if (HasFather()) aFather = Entry(GetFather()->Label()); else aFather = "!"; + if (HasPrevious()) aPrevious = Entry(GetPrevious()->Label()); else aPrevious = "!"; + if (HasNext()) aNext = Entry(GetNext()->Label()); else aNext = "!"; + if (HasFirst()) aFirst = Entry(GetFirst()->Label()); else aFirst = "!"; + + int aLength = 4; + aLength += aFather.Length() + aPrevious.Length() + aNext.Length() + aFirst.Length(); + char* aResult = new char[aLength]; + sprintf(aResult, "%s %s %s %s", aFather.ToCString(), aPrevious.ToCString(), aNext.ToCString(), aFirst.ToCString()); + TCollection_AsciiString ret(aResult); + delete aResult; + return ret; +} + +void SALOMEDSImpl_AttributeTreeNode::Load(const TCollection_AsciiString& value) +{ + Handle(TDF_Data) DF = Label().Data(); + + char* aCopy = (char*)value.ToCString(); + char* adr = strtok(aCopy, " "); + + TDF_Label aLabel; + Handle(SALOMEDSImpl_AttributeTreeNode) aDepNode; + + if (adr && adr[0] != '!') { + TDF_Tool::Label(DF, adr, aLabel, 1); + if (!aLabel.FindAttribute(ID(), aDepNode)) + aDepNode = SALOMEDSImpl_AttributeTreeNode::Set(aLabel, ID()); + + SetFather(aDepNode); + } + + adr = strtok(NULL, " "); + if (adr && adr[0] != '!') { + TDF_Tool::Label(DF, adr, aLabel, 1); + if (!aLabel.FindAttribute(ID(), aDepNode)) + aDepNode = SALOMEDSImpl_AttributeTreeNode::Set(aLabel, ID()); + SetPrevious(aDepNode); + } + + adr = strtok(NULL, " "); + if (adr && adr[0] != '!') { + TDF_Tool::Label(DF, adr, aLabel, 1); + if (!aLabel.FindAttribute(ID(), aDepNode)) + aDepNode = SALOMEDSImpl_AttributeTreeNode::Set(aLabel, ID()); + SetNext(aDepNode); + } + + adr = strtok(NULL, " "); + if (adr && adr[0] != '!') { + TDF_Tool::Label(DF, adr, aLabel, 1); + if (!aLabel.FindAttribute(ID(), aDepNode)) + aDepNode = SALOMEDSImpl_AttributeTreeNode::Set(aLabel, ID()); + SetFirst(aDepNode); + } +} + + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTreeNode.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTreeNode.hxx new file mode 100644 index 000000000..c61715f51 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTreeNode.hxx @@ -0,0 +1,94 @@ +// File : SALOMEDSImpl_AttributeTreeNode.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef _SALOMEDSImpl_AttributeTreeNode_HeaderFile +#define _SALOMEDSImpl_AttributeTreeNode_HeaderFile + +#include +#include +#include +#include +#include +#include +#include "SALOMEDSImpl_GenericAttribute.hxx" + +class Handle_TDF_DataSet; +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); +class SALOMEDSImpl_ChildNodeIterator; + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_AttributeTreeNode, SALOMEDSImpl_GenericAttribute ) + +class SALOMEDSImpl_AttributeTreeNode : public SALOMEDSImpl_GenericAttribute +{ +public: + +Standard_EXPORT const static Standard_GUID& GetDefaultTreeID(); +Standard_EXPORT static Handle_SALOMEDSImpl_AttributeTreeNode Set(const TDF_Label& L, const Standard_GUID& ID); + +Standard_EXPORT SALOMEDSImpl_AttributeTreeNode(); +Standard_EXPORT void SetFather(const Handle(SALOMEDSImpl_AttributeTreeNode)& value); +Standard_EXPORT void SetPrevious(const Handle(SALOMEDSImpl_AttributeTreeNode)& value); +Standard_EXPORT void SetNext(const Handle(SALOMEDSImpl_AttributeTreeNode)& value); +Standard_EXPORT void SetFirst(const Handle(SALOMEDSImpl_AttributeTreeNode)& value); +Standard_EXPORT void SetTreeID(const Standard_GUID& value); + +Standard_EXPORT Standard_Boolean Append(const Handle(SALOMEDSImpl_AttributeTreeNode)& value); +Standard_EXPORT Standard_Boolean Prepend(const Handle(SALOMEDSImpl_AttributeTreeNode)& value); +Standard_EXPORT Standard_Boolean Remove(); +Standard_EXPORT Standard_Boolean InsertBefore(const Handle(SALOMEDSImpl_AttributeTreeNode)& value); +Standard_EXPORT Standard_Boolean InsertAfter(const Handle(SALOMEDSImpl_AttributeTreeNode)& value); + +Standard_EXPORT Handle(SALOMEDSImpl_AttributeTreeNode) GetFather() { return myFather; } +Standard_EXPORT Handle(SALOMEDSImpl_AttributeTreeNode) GetPrevious() { return myPrevious; } +Standard_EXPORT Handle(SALOMEDSImpl_AttributeTreeNode) GetNext() { return myNext; } +Standard_EXPORT Handle(SALOMEDSImpl_AttributeTreeNode) GetFirst() { return myFirst; } + +Standard_EXPORT Standard_Boolean HasFather() { return (!myFather.IsNull()); } +Standard_EXPORT Standard_Boolean HasPrevious() { return (!myPrevious.IsNull()); } +Standard_EXPORT Standard_Boolean HasNext() {return (!myNext.IsNull()); } +Standard_EXPORT Standard_Boolean HasFirst() { return (!myFirst.IsNull()); } +Standard_EXPORT const Standard_GUID& GetTreeID() { return ID(); } +Standard_EXPORT Standard_Integer Depth() const; +Standard_EXPORT Standard_Boolean IsRoot() const ; +Standard_EXPORT Handle(SALOMEDSImpl_AttributeTreeNode) Root() const; +Standard_EXPORT Standard_Boolean IsAscendant (const Handle(SALOMEDSImpl_AttributeTreeNode)& ofTN) const; +Standard_EXPORT Standard_Boolean IsDescendant(const Handle(SALOMEDSImpl_AttributeTreeNode)& value) const; +Standard_EXPORT Standard_Boolean IsFather(const Handle(SALOMEDSImpl_AttributeTreeNode)& value) const; +Standard_EXPORT Standard_Boolean IsChild(const Handle(SALOMEDSImpl_AttributeTreeNode)& value) const; + +Standard_EXPORT virtual TCollection_AsciiString Save(); +Standard_EXPORT virtual void Load(const TCollection_AsciiString&); +Standard_EXPORT virtual TCollection_AsciiString Type(); + +Standard_EXPORT virtual void AfterAddition() ; +Standard_EXPORT virtual void BeforeForget() ; +Standard_EXPORT virtual void AfterResume() ; +Standard_EXPORT virtual Standard_Boolean BeforeUndo(const Handle(TDF_AttributeDelta)& anAttDelta, + const Standard_Boolean forceIt = Standard_False) ; +Standard_EXPORT virtual Standard_Boolean AfterUndo(const Handle(TDF_AttributeDelta)& anAttDelta, + const Standard_Boolean forceIt = Standard_False) ; +Standard_EXPORT const Standard_GUID& ID() const; +Standard_EXPORT void Restore(const Handle(TDF_Attribute)& with) ; +Standard_EXPORT void Paste(const Handle(TDF_Attribute)& into,const Handle(TDF_RelocationTable)& RT) const; +Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const; +Standard_EXPORT void References(const Handle(TDF_DataSet)& aDataSet) const; +Standard_EXPORT ~SALOMEDSImpl_AttributeTreeNode() {} + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_AttributeTreeNode ) + +private: + +Standard_GUID myTreeID; +Handle(SALOMEDSImpl_AttributeTreeNode) myFather; +Handle(SALOMEDSImpl_AttributeTreeNode) myPrevious; +Handle(SALOMEDSImpl_AttributeTreeNode) myNext; +Handle(SALOMEDSImpl_AttributeTreeNode) myFirst; + +friend class SALOMEDSImpl_ChildNodeIterator; + +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeUserID.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeUserID.cxx new file mode 100644 index 000000000..8eebc2b41 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeUserID.cxx @@ -0,0 +1,87 @@ +// File : SALOMEDSImpl_AttributeUAttribute.cxx +// Author : Sergey RUIN +// Module : SALOME + +using namespace std; +#include "SALOMEDSImpl_AttributeUserID.hxx" + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeUserID, SALOMEDSImpl_GenericAttribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeUserID, SALOMEDSImpl_GenericAttribute ) + +Handle(SALOMEDSImpl_AttributeUserID) SALOMEDSImpl_AttributeUserID::Set (const TDF_Label& L, const Standard_GUID& ID) +{ + Handle(SALOMEDSImpl_AttributeUserID) A; + if (!L.FindAttribute(ID, A)) { + A = new SALOMEDSImpl_AttributeUserID(); + A->SetValue(ID); + L.AddAttribute(A); + } + return A; +} + +//======================================================================= +//function : ID +//purpose : +//======================================================================= +const Standard_GUID& SALOMEDSImpl_AttributeUserID::ID() const +{ return myID; } + + +//======================================================================= +//function : SetValue +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeUserID::SetValue( const Standard_GUID& guid) +{ + CheckLocked(); + if(myID == guid) return; + + Backup(); + myID = guid; +} + +//======================================================================= +//function : NewEmpty +//purpose : +//======================================================================= +Handle(TDF_Attribute) SALOMEDSImpl_AttributeUserID::NewEmpty () const +{ + Handle(SALOMEDSImpl_AttributeUserID) A = new SALOMEDSImpl_AttributeUserID(); + A->SetValue(myID); + return A; +} + +//======================================================================= +//function : Restore +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeUserID::Restore(const Handle(TDF_Attribute)& with) +{ + Handle(SALOMEDSImpl_AttributeUserID) A = Handle(SALOMEDSImpl_AttributeUserID)::DownCast(with); + SetValue( A->ID() ); +} + +//======================================================================= +//function : Paste +//purpose : +//======================================================================= +void SALOMEDSImpl_AttributeUserID::Paste (const Handle(TDF_Attribute)& into, + const Handle(TDF_RelocationTable)& RT) const +{ + Handle(SALOMEDSImpl_AttributeUserID) A = Handle(SALOMEDSImpl_AttributeUserID)::DownCast(into); + A->SetValue( myID ); +} + +TCollection_AsciiString SALOMEDSImpl_AttributeUserID::Type() +{ + + char* aUAttrName = new char[60]; + char aGUID[40]; + ID().ToCString(aGUID); + sprintf(aUAttrName, "AttributeUserID_%s",aGUID); + + TCollection_AsciiString ret(aUAttrName); + delete aUAttrName; + + return ret; +} diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeUserID.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeUserID.hxx new file mode 100644 index 000000000..106c973ab --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeUserID.hxx @@ -0,0 +1,51 @@ +// File : SALOMEDSImpl_AttributeUAttribute.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef _SALOMEDSImpl_AttributeUserID_HeaderFile +#define _SALOMEDSImpl_AttributeUserID_HeaderFile + +#include +#include +#include +#include +#include +#include "SALOMEDSImpl_GenericAttribute.hxx" + +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_AttributeUserID, SALOMEDSImpl_GenericAttribute ) + +class SALOMEDSImpl_AttributeUserID : public SALOMEDSImpl_GenericAttribute +{ +private: +Standard_GUID myID; + +public: +SALOMEDSImpl_AttributeUserID():SALOMEDSImpl_GenericAttribute("AttributeUserID") {} +static Handle(SALOMEDSImpl_AttributeUserID) Set (const TDF_Label& L, const Standard_GUID& ID); +static const Standard_GUID& DefaultID() +{ + static Standard_GUID SALOMEDSImpl_DefaultUserAttributeID ("FFFFFFFF-D9CD-11d6-945D-1050DA506788"); + return SALOMEDSImpl_DefaultUserAttributeID; +} + +Standard_EXPORT const Standard_GUID& Value() const { return ID(); } +Standard_EXPORT void SetValue(const Standard_GUID& value); + +Standard_EXPORT virtual TCollection_AsciiString Type(); + +Standard_EXPORT const Standard_GUID& ID() const; +Standard_EXPORT void Restore(const Handle(TDF_Attribute)& with) ; +Standard_EXPORT Handle_TDF_Attribute NewEmpty() const; +Standard_EXPORT void Paste(const Handle(TDF_Attribute)& into,const Handle(TDF_RelocationTable)& RT) const; +Standard_EXPORT ~SALOMEDSImpl_AttributeUserID() {} + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_AttributeUserID ) + +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Attributes.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_Attributes.hxx new file mode 100644 index 000000000..c37e2a14e --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Attributes.hxx @@ -0,0 +1,128 @@ +// File : SALOMEDSImpl_Attributes.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef __SALOMEDSIMPL_ATTRIBUTES__H__ +#define __SALOMEDSIMPL_ATTRIBUTES__H__ + +#include +class LockProtection +{ +public : + LockProtection(const char *message) { + std::cerr << message << std::endl; + } +}; + +#include "SALOMEDSImpl_GenericAttribute.hxx" +#include "SALOMEDSImpl_AttributeName.hxx" +#include "SALOMEDSImpl_AttributeComment.hxx" +#include "SALOMEDSImpl_AttributeInteger.hxx" +#include "SALOMEDSImpl_AttributeReal.hxx" +#include "SALOMEDSImpl_AttributeTreeNode.hxx" +#include "SALOMEDSImpl_AttributeUserID.hxx" +#include "SALOMEDSImpl_AttributeReference.hxx" +#include "SALOMEDSImpl_AttributeSequenceOfReal.hxx" +#include "SALOMEDSImpl_AttributeSequenceOfInteger.hxx" +#include "SALOMEDSImpl_AttributeIOR.hxx" +#include "SALOMEDSImpl_AttributePersistentRef.hxx" +#include "SALOMEDSImpl_AttributeDrawable.hxx" +#include "SALOMEDSImpl_AttributeSelectable.hxx" +#include "SALOMEDSImpl_AttributeExpandable.hxx" +#include "SALOMEDSImpl_AttributeOpened.hxx" +#include "SALOMEDSImpl_AttributeTextColor.hxx" +#include "SALOMEDSImpl_AttributeTextHighlightColor.hxx" +#include "SALOMEDSImpl_AttributePixMap.hxx" +#include "SALOMEDSImpl_AttributeLocalID.hxx" +#include "SALOMEDSImpl_AttributeTarget.hxx" +#include "SALOMEDSImpl_AttributeTableOfInteger.hxx" +#include "SALOMEDSImpl_AttributeTableOfReal.hxx" +#include "SALOMEDSImpl_AttributeTableOfString.hxx" +#include "SALOMEDSImpl_AttributeStudyProperties.hxx" +#include "SALOMEDSImpl_AttributePythonObject.hxx" +#include "SALOMEDSImpl_AttributeExternalFileDef.hxx" +#include "SALOMEDSImpl_AttributeFileType.hxx" +#include "SALOMEDSImpl_AttributeFlags.hxx" +#include "SALOMEDSImpl_AttributeGraphic.hxx" + + +#define __AttributeTypeToGUIDForSObject \ + if(theType == "AttributeReal") return SALOMEDSImpl_AttributeReal::GetID(); \ + if(theType == "AttributeInteger") return SALOMEDSImpl_AttributeInteger::GetID(); \ + if(theType == "AttributeSequenceOfReal") return SALOMEDSImpl_AttributeSequenceOfReal::GetID(); \ + if(theType == "AttributeSequenceOfInteger") return SALOMEDSImpl_AttributeSequenceOfInteger::GetID(); \ + if(theType == "AttributeName") return SALOMEDSImpl_AttributeName::GetID(); \ + if(theType == "AttributeComment") return SALOMEDSImpl_AttributeComment::GetID(); \ + if(theType == "AttributeIOR") return SALOMEDSImpl_AttributeIOR::GetID(); \ + if(theType == "AttributePersistentRef") return SALOMEDSImpl_AttributePersistentRef::GetID(); \ + if(theType == "AttributeDrawable") return SALOMEDSImpl_AttributeDrawable::GetID(); \ + if(theType == "AttributeSelectable") return SALOMEDSImpl_AttributeSelectable::GetID(); \ + if(theType == "AttributeExpandable") return SALOMEDSImpl_AttributeExpandable::GetID(); \ + if(theType == "AttributeOpened") return SALOMEDSImpl_AttributeOpened::GetID(); \ + if(theType == "AttributeTextColor") return SALOMEDSImpl_AttributeTextColor::GetID(); \ + if(theType == "AttributeTextHighlightColor") return SALOMEDSImpl_AttributeTextHighlightColor::GetID(); \ + if(theType == "AttributePixMap") return SALOMEDSImpl_AttributePixMap::GetID(); \ + if(theType == "AttributeLocalID") return SALOMEDSImpl_AttributeLocalID::GetID(); \ + if(theType == "AttributeTarget") return SALOMEDSImpl_AttributeTarget::GetID(); \ + if(theType == "AttributeTableOfInteger") return SALOMEDSImpl_AttributeTableOfInteger::GetID(); \ + if(theType == "AttributeTableOfReal") return SALOMEDSImpl_AttributeTableOfReal::GetID(); \ + if(theType == "AttributeTableOfString") return SALOMEDSImpl_AttributeTableOfString::GetID(); \ + if(theType == "AttributeStudyProperties") return SALOMEDSImpl_AttributeStudyProperties::GetID(); \ + if(theType == "AttributePythonObject") return SALOMEDSImpl_AttributePythonObject::GetID(); \ + if(theType == "AttributeUserID") return Standard_GUID("FFFFFFFF-D9CD-11d6-945D-1050DA506788"); \ + if(theType == "AttributeExternalFileDef") return SALOMEDSImpl_AttributeExternalFileDef::GetID(); \ + if(theType == "AttributeFileType") return SALOMEDSImpl_AttributeFileType::GetID(); \ + if(theType == "AttributeFlags") return SALOMEDSImpl_AttributeFlags::GetID(); \ + if(theType == "AttributeGraphic") return SALOMEDSImpl_AttributeGraphic::GetID(); \ + if(theType == "AttributeReference") return SALOMEDSImpl_AttributeReference::GetID(); + + +#define __FindOrCreateAttributeLocked(ClassName) if (strcmp(aTypeOfAttribute.ToCString(), #ClassName) == 0) { \ + Handle(SALOMEDSImpl_##ClassName) anAttr; \ + if (!Lab.FindAttribute(SALOMEDSImpl_##ClassName::GetID(), anAttr)) { \ + CheckLocked(); \ + anAttr = new SALOMEDSImpl_##ClassName; \ + Lab.AddAttribute(anAttr); \ + } \ + return anAttr; \ + } + +#define __FindOrCreateAttribute(ClassName) if (strcmp(aTypeOfAttribute.ToCString(), #ClassName) == 0) { \ + Handle(SALOMEDSImpl_##ClassName) anAttr; \ + if (!Lab.FindAttribute(SALOMEDSImpl_##ClassName::GetID(), anAttr)) { \ + anAttr = new SALOMEDSImpl_##ClassName; \ + Lab.AddAttribute(anAttr); \ + } \ + return anAttr; \ + } + +#define __FindOrCreateAttributeForBuilder \ +__FindOrCreateAttributeLocked(AttributeReal) \ +__FindOrCreateAttributeLocked(AttributeInteger) \ +__FindOrCreateAttributeLocked(AttributeSequenceOfReal) \ +__FindOrCreateAttributeLocked(AttributeSequenceOfInteger) \ +__FindOrCreateAttributeLocked(AttributeName) \ +__FindOrCreateAttributeLocked(AttributeComment) \ +__FindOrCreateAttributeLocked(AttributeIOR) \ +__FindOrCreateAttributeLocked(AttributePixMap) \ +__FindOrCreateAttributeLocked(AttributeLocalID) \ +__FindOrCreateAttributeLocked(AttributeTableOfInteger) \ +__FindOrCreateAttributeLocked(AttributeTableOfReal) \ +__FindOrCreateAttributeLocked(AttributeTableOfString) \ +__FindOrCreateAttributeLocked(AttributePythonObject) \ +__FindOrCreateAttribute(AttributePersistentRef) \ +__FindOrCreateAttribute(AttributeDrawable) \ +__FindOrCreateAttribute(AttributeSelectable) \ +__FindOrCreateAttribute(AttributeExpandable) \ +__FindOrCreateAttribute(AttributeOpened) \ +__FindOrCreateAttribute(AttributeTextColor) \ +__FindOrCreateAttribute(AttributeTextHighlightColor) \ +__FindOrCreateAttribute(AttributeTarget) \ +__FindOrCreateAttribute(AttributeStudyProperties) \ +__FindOrCreateAttribute(AttributeExternalFileDef) \ +__FindOrCreateAttribute(AttributeFileType) \ +__FindOrCreateAttribute(AttributeFlags) \ +__FindOrCreateAttribute(AttributeGraphic) + + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Callback.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_Callback.cxx new file mode 100644 index 000000000..8b5563993 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Callback.cxx @@ -0,0 +1,9 @@ +// File : SALOMEDSImpl_Callback.cxx +// Author : Sergey RUIN +// Module : SALOME + +#include "SALOMEDSImpl_Callback.hxx" + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_Callback, MMgt_TShared ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_Callback, MMgt_TShared ) + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Callback.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_Callback.hxx new file mode 100644 index 000000000..c78054bd7 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Callback.hxx @@ -0,0 +1,42 @@ +// File : SALOMEDSImpl_Callback.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef __SALOMEDSIMPL_CALLBACK_H__ +#define __SALOMEDSIMPL_CALLBACK_H__ + +//Handle definition +#include +#include +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_Callback, MMgt_TShared ) + +#include "SALOMEDSImpl_UseCaseBuilder.hxx" + +class SALOMEDSImpl_Callback : public MMgt_TShared +{ +private: + Handle(SALOMEDSImpl_UseCaseBuilder) _builder; + +public: + + SALOMEDSImpl_Callback(const Handle(SALOMEDSImpl_UseCaseBuilder)& builder) + { + _builder = builder; + } + + virtual void OnAddSObject(Handle(SALOMEDSImpl_SObject) theObject) + { + if(_builder != NULL && theObject != NULL) _builder->Append(theObject); + } + + virtual void OnRemoveSObject(Handle(SALOMEDSImpl_SObject) theObject) + { + if(_builder != NULL && theObject != NULL) _builder->Remove(theObject); + } + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_Callback ) + +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_ChildIterator.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_ChildIterator.cxx new file mode 100644 index 000000000..053346ccd --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_ChildIterator.cxx @@ -0,0 +1,62 @@ +// File : SALOMEDSImpl_ChildIterator.cxx +// Author : Sergey RUIN +// Module : SALOME + + +#include "SALOMEDSImpl_ChildIterator.hxx" +#include "SALOMEDSImpl_Study.hxx" + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_ChildIterator, MMgt_TShared ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_ChildIterator, MMgt_TShared ) + +SALOMEDSImpl_ChildIterator::SALOMEDSImpl_ChildIterator(const Handle(SALOMEDSImpl_SObject)& theSO) +{ + _so = theSO; + _it = TDF_ChildIterator(_so->GetLabel()); +} + +SALOMEDSImpl_ChildIterator::SALOMEDSImpl_ChildIterator(const TDF_Label& theLabel) +{ + _so = SALOMEDSImpl_Study::SObject(theLabel); + _it = TDF_ChildIterator(theLabel); +} + +void SALOMEDSImpl_ChildIterator::Init() +{ + _it.Initialize(_so->GetLabel(), Standard_False); +} + +void SALOMEDSImpl_ChildIterator::Init(const TDF_Label& theLabel) +{ + _it.Initialize(theLabel, Standard_False); +} + +void SALOMEDSImpl_ChildIterator::InitEx(bool theAllLevels) +{ + _it.Initialize(_so->GetLabel(), theAllLevels); +} + +void SALOMEDSImpl_ChildIterator::InitEx(const TDF_Label& theLabel, bool theAllLevels) +{ + _it.Initialize(theLabel, theAllLevels); +} + +bool SALOMEDSImpl_ChildIterator::More() +{ + return _it.More(); +} + +void SALOMEDSImpl_ChildIterator::Next() +{ + return _it.Next(); +} + +Handle(SALOMEDSImpl_SObject) SALOMEDSImpl_ChildIterator::Value() +{ + return SALOMEDSImpl_Study::SObject(_it.Value()); +} + +TDF_Label SALOMEDSImpl_ChildIterator::Label() +{ + return _it.Value(); +} diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_ChildIterator.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_ChildIterator.hxx new file mode 100644 index 000000000..7ee1d8974 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_ChildIterator.hxx @@ -0,0 +1,41 @@ +// File : SALOMEDSImpl_ChildIterator.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef __SALOMEDSImpl_CHILDITERATOR_H__ +#define __SALOMEDSImpl_CHILDITERATOR_H__ + +//Handle definition +#include +#include +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_ChildIterator, MMgt_TShared ) + +#include "SALOMEDSImpl_SObject.hxx" +#include "TDF_ChildIterator.hxx" +#include "TDF_Label.hxx" + +class SALOMEDSImpl_ChildIterator: public MMgt_TShared +{ +private: + TDF_ChildIterator _it; + Handle(SALOMEDSImpl_SObject) _so; + +public: + + SALOMEDSImpl_ChildIterator(const Handle(SALOMEDSImpl_SObject)& theSO); + SALOMEDSImpl_ChildIterator(const TDF_Label& theLabel); + ~SALOMEDSImpl_ChildIterator() {}; + + virtual void Init(); + virtual void Init(const TDF_Label& theLabel); + virtual void InitEx(bool theAllLevels); + virtual void InitEx(const TDF_Label& theLabel, bool theAllLevels); + virtual bool More(); + virtual void Next(); + virtual Handle(SALOMEDSImpl_SObject) Value(); + virtual TDF_Label Label(); + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_SObject ) +}; +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_ChildNodeIterator.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_ChildNodeIterator.cxx new file mode 100644 index 000000000..11ce37bd5 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_ChildNodeIterator.cxx @@ -0,0 +1,75 @@ +// File: SALOMEDSImpl_ChildNodeIterator.cxx +// Created: Wed Jan 26 16:43:08 2000 +// Author: Denis PASCAL +// + + +#include + +#define ChildNodeIterator_UpToBrother \ +{ \ + while (!myNode.IsNull() && (myNode->Depth() > myFirstLevel) && myNode->myNext == NULL) \ + myNode = myNode->myFather; \ + if (!myNode.IsNull() && (myNode->Depth() > myFirstLevel) && myNode->myFather != NULL) \ + myNode = myNode->myNext; \ + else \ + myNode = NULL; \ +} + +//======================================================================= +//function : SALOMEDSImpl_ChildNodeIterator +//purpose : +//======================================================================= +SALOMEDSImpl_ChildNodeIterator::SALOMEDSImpl_ChildNodeIterator() + : myFirstLevel(0) +{} + +//======================================================================= +//function : SALOMEDSImpl_ChildNodeIterator +//purpose : +//======================================================================= + +SALOMEDSImpl_ChildNodeIterator::SALOMEDSImpl_ChildNodeIterator (const Handle(SALOMEDSImpl_AttributeTreeNode)& aNode, + const Standard_Boolean allLevels) +: myNode(aNode->myFirst), + myFirstLevel(allLevels ? aNode->Depth() : -1) +{} + +//======================================================================= +//function : Initialize +//purpose : +//======================================================================= + +void SALOMEDSImpl_ChildNodeIterator::Initialize(const Handle(SALOMEDSImpl_AttributeTreeNode)& aNode, + const Standard_Boolean allLevels) +{ + myNode = aNode->myFirst; + myFirstLevel = allLevels ? aNode->Depth() : -1; +} + +//======================================================================= +//function : Next +//purpose : +//======================================================================= + +void SALOMEDSImpl_ChildNodeIterator::Next() +{ + if (myFirstLevel == -1) { + myNode = myNode->myNext; + } + else { + if (myNode->myFirst != NULL) myNode = myNode->myFirst; + else ChildNodeIterator_UpToBrother; + } +} + +//======================================================================= +//function : NextBrother +//purpose : +//======================================================================= + +void SALOMEDSImpl_ChildNodeIterator::NextBrother() +{ + if (myNode->myNext != NULL) myNode = myNode->myNext; + else ChildNodeIterator_UpToBrother; +} diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_ChildNodeIterator.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_ChildNodeIterator.hxx new file mode 100644 index 000000000..5b7b5924a --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_ChildNodeIterator.hxx @@ -0,0 +1,45 @@ + +#ifndef _SALOMEDSImpl_ChildNodeIterator_HeaderFile +#define _SALOMEDSImpl_ChildNodeIterator_HeaderFile + +#ifndef _Standard_Integer_HeaderFile +#include +#endif +#ifndef _Standard_Boolean_HeaderFile +#include +#endif + +#include "SALOMEDSImpl_AttributeTreeNode.hxx" + + +#ifndef _Standard_HeaderFile +#include +#endif +#ifndef _Standard_Macro_HeaderFile +#include +#endif + +class SALOMEDSImpl_ChildNodeIterator +{ + +public: + +Standard_EXPORT SALOMEDSImpl_ChildNodeIterator(); +Standard_EXPORT SALOMEDSImpl_ChildNodeIterator(const Handle(SALOMEDSImpl_AttributeTreeNode)& aTreeNode, + const Standard_Boolean allLevels = Standard_False); +Standard_EXPORT void Initialize(const Handle(SALOMEDSImpl_AttributeTreeNode)& aTreeNode, + const Standard_Boolean allLevels = Standard_False) ; +Standard_EXPORT Standard_Boolean More() const { return !myNode.IsNull(); } +Standard_EXPORT void Next() ; +Standard_EXPORT void NextBrother() ; +Standard_EXPORT Handle_SALOMEDSImpl_AttributeTreeNode Value() const { return myNode; } + +private: + +Handle_SALOMEDSImpl_AttributeTreeNode myNode; +Standard_Integer myFirstLevel; + +}; + + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Driver.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_Driver.hxx new file mode 100644 index 000000000..000b0acf5 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Driver.hxx @@ -0,0 +1,80 @@ +#ifndef __SALOMEDSIMPL_DRIVER_H__ +#define __SALOMEDSIMPL_DRIVER_H__ + +#include +#include +#include + + +class SALOMEDSImpl_Driver +{ +public: + + virtual TCollection_AsciiString GetIOR() = 0; + + virtual unsigned char* Save(const Handle(SALOMEDSImpl_SComponent)& theComponent, + const TCollection_AsciiString& theURL, + long& theStreamLength, + bool isMultiFile) = 0; + + virtual unsigned char* SaveASCII(const Handle(SALOMEDSImpl_SComponent)& theComponent, + const TCollection_AsciiString& theURL, + long& theStreamLength, + bool isMultiFile) = 0; + + virtual bool Load(const Handle(SALOMEDSImpl_SComponent)& theComponent, + const unsigned char* theStream, + const long theStreamLength, + const TCollection_AsciiString& theURL, + bool isMultiFile) = 0; + + virtual bool LoadASCII(const Handle(SALOMEDSImpl_SComponent)& theComponent, + const unsigned char* theStream, + const long theStreamLength, + const TCollection_AsciiString& theURL, + bool isMultiFile) = 0; + + virtual void Close(const Handle(SALOMEDSImpl_SComponent)& theComponent) = 0; + + virtual TCollection_AsciiString ComponentDataType() = 0; + + + virtual TCollection_AsciiString IORToLocalPersistentID(const Handle(SALOMEDSImpl_SObject)& theSObject, + const TCollection_AsciiString& IORString, + bool isMultiFile, + bool isASCII) = 0; + + virtual TCollection_AsciiString LocalPersistentIDToIOR(const Handle(SALOMEDSImpl_SObject)& theSObject, + const TCollection_AsciiString& aLocalPersistentID, + bool isMultiFile, + bool isASCII) = 0; + + virtual bool CanCopy(const Handle(SALOMEDSImpl_SObject)& theObject) = 0; + + virtual unsigned char* CopyFrom(const Handle(SALOMEDSImpl_SObject)& theObject, + int& theObjectID, + long& theStreamLength) = 0; + + virtual bool CanPaste(const TCollection_AsciiString& theComponentName, int theObjectID) = 0; + + virtual TCollection_AsciiString PasteInto(const unsigned char* theStream, + const long theStreamLength, + int theObjectID, + const Handle(SALOMEDSImpl_SObject)& theObject) = 0; + + virtual unsigned char* DumpPython(const Handle(SALOMEDSImpl_Study)& theStudy, + bool isPublished, + bool& isValidScript, + long& theStreamLength) = 0; +}; + +class SALOMEDSImpl_DriverFactory +{ +public: + + virtual SALOMEDSImpl_Driver* GetDriverByType(const TCollection_AsciiString& theComponentType) = 0; + + virtual SALOMEDSImpl_Driver* GetDriverByIOR(const TCollection_AsciiString& theIOR) = 0; +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_GenericAttribute.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_GenericAttribute.cxx new file mode 100644 index 000000000..5d8648e91 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_GenericAttribute.cxx @@ -0,0 +1,56 @@ +// File : SALOMEDSImpl_GenericAttribute.hxx +// Author : SERGEY_RUIN +// Module : SALOME + +using namespace std; + +#include "SALOMEDSImpl_Attributes.hxx" +#include "SALOMEDSImpl_Study.hxx" +#include "SALOMEDSImpl_StudyBuilder.hxx" + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_GenericAttribute, TDF_Attribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_GenericAttribute, TDF_Attribute ) + +char* SALOMEDSImpl_GenericAttribute::Impl_GetType(const Handle(TDF_Attribute)& theAttr) +{ + Handle(SALOMEDSImpl_GenericAttribute) ga = Handle(SALOMEDSImpl_GenericAttribute)::DownCast(theAttr); + return ga->Type().ToCString(); +} + +char* SALOMEDSImpl_GenericAttribute::Impl_GetClassType(const Handle(TDF_Attribute)& theAttr) +{ + Handle(SALOMEDSImpl_GenericAttribute) ga = Handle(SALOMEDSImpl_GenericAttribute)::DownCast(theAttr); + return ga->GetClassType().ToCString(); +} + +void SALOMEDSImpl_GenericAttribute::Impl_CheckLocked(const Handle(TDF_Attribute)& theAttr) +{ + Handle(SALOMEDSImpl_GenericAttribute) ga = Handle(SALOMEDSImpl_GenericAttribute)::DownCast(theAttr); + ga->CheckLocked(); +} + +TCollection_AsciiString SALOMEDSImpl_GenericAttribute::Type() +{ + return _type; +} + + +void SALOMEDSImpl_GenericAttribute::CheckLocked() +{ + TDF_Label aLabel = Label(); + if(aLabel.IsNull()) return; + + Handle(SALOMEDSImpl_Study) aStudy = SALOMEDSImpl_Study::GetStudy(aLabel); + if(aStudy.IsNull() || aStudy->NewBuilder()->HasOpenCommand()) return; + if(aStudy->IsLocked()) { + aStudy->_errorCode = "LockProtection"; + throw LockProtection("LockProtection"); + } +} + +Handle(SALOMEDSImpl_SObject) SALOMEDSImpl_GenericAttribute::GetSObject() +{ + TDF_Label aLabel = Label(); + if(aLabel.IsNull()) return NULL; + return SALOMEDSImpl_Study::SObject(aLabel); +} diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_GenericAttribute.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_GenericAttribute.hxx new file mode 100644 index 000000000..9ed1f341f --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_GenericAttribute.hxx @@ -0,0 +1,51 @@ +// File : SALOMEDSImpl_GenericAttribute.hxx +// Author : SERGEY_RUIN +// Module : SALOME + +#ifndef _GENERICIMPL_ATTRIBUTE_HXX_ +#define _GENERICIMPL_ATTRIBUTE_HXX_ + +#include +#include +#include +#include +#include + +#include "SALOMEDSImpl_SObject.hxx" + +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_GenericAttribute, TDF_Attribute ) + +class SALOMEDSImpl_GenericAttribute: public TDF_Attribute +{ +protected: + + TCollection_AsciiString _type; //This field must be filled in each attribute that inherits from this class. + +public: + +Standard_EXPORT SALOMEDSImpl_GenericAttribute(const TCollection_AsciiString& theType) +:_type(theType) +{} + +Standard_EXPORT virtual TCollection_AsciiString Save() { return ""; } +Standard_EXPORT virtual void Load(const TCollection_AsciiString&) {} +Standard_EXPORT virtual TCollection_AsciiString Type(); +Standard_EXPORT virtual void CheckLocked(); +Standard_EXPORT TCollection_AsciiString GetClassType() { return _type; } +Standard_EXPORT Handle(SALOMEDSImpl_SObject) GetSObject(); + +Standard_EXPORT static char* Impl_GetType(const Handle(TDF_Attribute)& theAttr); +Standard_EXPORT static char* Impl_GetClassType(const Handle(TDF_Attribute)& theAttr); +Standard_EXPORT static void Impl_CheckLocked(const Handle(TDF_Attribute)& theAttr); + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_GenericAttribute ) + +}; + + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_OCAFApplication.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_OCAFApplication.cxx new file mode 100644 index 000000000..9d5addbf7 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_OCAFApplication.cxx @@ -0,0 +1,45 @@ +// File : SALOMEDSImpl_OCAFApplication.cxx +// Author : Sergey RUIN +// Module : SALOME + +using namespace std; +#include "SALOMEDSImpl_OCAFApplication.hxx" + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_OCAFApplication, TDocStd_Application ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_OCAFApplication, TDocStd_Application ) + +//======================================================================= +//function : SALOMEDSImpl_OCAFApplication +//purpose : +//======================================================================= + +SALOMEDSImpl_OCAFApplication::SALOMEDSImpl_OCAFApplication() +{ +} + + +//======================================================================= +//function : Formats +//purpose : +//======================================================================= + +void SALOMEDSImpl_OCAFApplication::Formats(TColStd_SequenceOfExtendedString& Formats) +{ + Formats.Append(TCollection_ExtendedString ("SALOME_STUDY")); +} + + +//======================================================================= +//function : ResourcesName +//purpose : +//======================================================================= + +Standard_CString SALOMEDSImpl_OCAFApplication::ResourcesName() +{ + return Standard_CString ("SALOMEDSImpl_Resources"); +} + + + + + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_OCAFApplication.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_OCAFApplication.hxx new file mode 100644 index 000000000..e34a1fa09 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_OCAFApplication.hxx @@ -0,0 +1,32 @@ +// File : SALOMEDSImpl_OCAFApplication.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef _SALOMEDSImpl_OCAFApplication_HeaderFile +#define _SALOMEDSImpl_OCAFApplication_HeaderFile + + +//Handle definition +#include +#include +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_OCAFApplication, TDocStd_Application) + +#include +#include + + +class SALOMEDSImpl_OCAFApplication : public TDocStd_Application { + +public: + +Standard_EXPORT SALOMEDSImpl_OCAFApplication(); +Standard_EXPORT virtual void Formats(TColStd_SequenceOfExtendedString& Formats) ; +Standard_EXPORT Standard_CString ResourcesName() ; +Standard_EXPORT ~SALOMEDSImpl_OCAFApplication() {} + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_OCAFApplication ) + +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_SComponent.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_SComponent.cxx new file mode 100644 index 000000000..4e542e1de --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_SComponent.cxx @@ -0,0 +1,76 @@ +// File : SALOMEDSImpl_SComponent.cxx +// Author : Sergey RUIN +// Module : SALOME + +using namespace std; +#include "SALOMEDSImpl_SComponent.hxx" +#include "SALOMEDSImpl_AttributeComment.hxx" +#include "SALOMEDSImpl_AttributeIOR.hxx" + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_SComponent, SALOMEDSImpl_SObject ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_SComponent, SALOMEDSImpl_SObject ) + +//============================================================================ +/*! Function : constructor + * Purpose : + */ +//============================================================================ +SALOMEDSImpl_SComponent::SALOMEDSImpl_SComponent(const TDF_Label& theLabel) + :SALOMEDSImpl_SObject(theLabel) +{ +} + +//============================================================================ +/*! Function : destructor + * Purpose : + */ +//============================================================================ +SALOMEDSImpl_SComponent::~SALOMEDSImpl_SComponent() +{} + + +//============================================================================ +/*! Function : ComponentDataType + * Purpose : + */ +//============================================================================ +TCollection_AsciiString SALOMEDSImpl_SComponent::ComponentDataType() +{ + TCollection_AsciiString res = ""; + Handle(SALOMEDSImpl_AttributeComment) type; + if ( _lab.FindAttribute(SALOMEDSImpl_AttributeComment::GetID(),type) ) { + res = type->Value(); + } + + return res; +} + + +//============================================================================ +/*! Function : ComponentIOR + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_SComponent::ComponentIOR(TCollection_AsciiString& IOR) +{ + Handle(SALOMEDSImpl_AttributeIOR) ior; + if (!_lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID(),ior) ) + return false; + IOR = ior->Value(); + return true; +} + + +//============================================================================ +/*! Function : IsA + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_SComponent::IsA(const TDF_Label& theLabel) +{ + // scomponent must contain comment and belong to the 2th depth label + if ( theLabel.IsAttribute(SALOMEDSImpl_AttributeComment::GetID()) && theLabel.Depth() == 2) { + return true; + } + return false; +} diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_SComponent.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_SComponent.hxx new file mode 100644 index 000000000..bc3c32923 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_SComponent.hxx @@ -0,0 +1,41 @@ +// File : SALOMEDSImpl_SComponent.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef __SALOMEDSIMPL_SCOMPONENT_H__ +#define __SALOMEDSIMPL_SCOMPONENT_H__ + +//SALOMEDSImpl headers +#include "SALOMEDSImpl_SObject.hxx" + +//Handle definition +#include +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_SComponent, SALOMEDSImpl_SObject ) + +// std C++ headers +#include + +// Cascade headers +#include +#include +#include +#include +#include + +class SALOMEDSImpl_SComponent : public SALOMEDSImpl_SObject +{ +public: + + SALOMEDSImpl_SComponent(const TDF_Label& lab); + + ~SALOMEDSImpl_SComponent(); + + virtual TCollection_AsciiString ComponentDataType(); + virtual bool ComponentIOR(TCollection_AsciiString& theID); + static bool IsA(const TDF_Label& theLabel); + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_SComponent ) + +}; +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_SComponentIterator.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_SComponentIterator.cxx new file mode 100644 index 000000000..ff3eaec0d --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_SComponentIterator.cxx @@ -0,0 +1,66 @@ +// File : SALOMEDSImpl_SComponentIterator.cxx +// Author : Sergey RUIN +// Module : SALOME + +using namespace std; +#include "SALOMEDSImpl_SComponentIterator.hxx" +#include "SALOMEDSImpl_Study.hxx" + +//============================================================================ +/*! Function : constructor + * + */ +//============================================================================ + +SALOMEDSImpl_SComponentIterator::SALOMEDSImpl_SComponentIterator(const Handle(TDocStd_Document)& theDocument) +{ + _lab = theDocument->Main(); + _it.Initialize (_lab); +} + +//============================================================================ +/*! Function : Init + * + */ +//============================================================================ +void SALOMEDSImpl_SComponentIterator::Init() +{ + _it.Initialize (_lab); +} + +//============================================================================ +/*! Function : More + * + */ +//============================================================================ +bool SALOMEDSImpl_SComponentIterator::More() +{ + if (!_it.More()) + return false; + TDF_Label L = _it.Value(); + if (SALOMEDSImpl_SComponent::IsA(L)) + return true; + + return _it.More(); +} + + //============================================================================ +/*! Function : Next + */ +//============================================================================ +void SALOMEDSImpl_SComponentIterator::Next() +{ + _it.Next(); +} + + +//============================================================================ +/*! Function : Value + * + */ +//============================================================================ +Handle(SALOMEDSImpl_SComponent) SALOMEDSImpl_SComponentIterator::Value() +{ + return SALOMEDSImpl_Study::SComponent(_it.Value()); +} + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_SComponentIterator.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_SComponentIterator.hxx new file mode 100644 index 000000000..42ca6ffe8 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_SComponentIterator.hxx @@ -0,0 +1,44 @@ +// File : SALOMEDSImpl_SComponentIterator_i.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef __SALOMEDSIMPL_SCOMPONENTITERATOR_H__ +#define __SALOMEDSIMPL_SCOMPONENTITERATOR_H__ + + +//SALOMEDSImpl headers +#include "SALOMEDSImpl_SComponent.hxx" + +// Cascade headers +#include +#include +#include +#include + +class SALOMEDSImpl_SComponentIterator +{ +private: + + TDF_ChildIterator _it; + TDF_Label _lab; + +public: + + SALOMEDSImpl_SComponentIterator(const SALOMEDSImpl_SComponentIterator& theIterator) + { + _it = theIterator._it; + _lab = theIterator._lab; + } + + SALOMEDSImpl_SComponentIterator() {}; + + SALOMEDSImpl_SComponentIterator(const Handle(TDocStd_Document)& theDocument); + + ~SALOMEDSImpl_SComponentIterator() {}; + + virtual void Init(); + virtual bool More(); + virtual void Next(); + virtual Handle(SALOMEDSImpl_SComponent) Value(); +}; +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_SObject.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_SObject.cxx new file mode 100644 index 000000000..9ca0d5d58 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_SObject.cxx @@ -0,0 +1,219 @@ +// SALOME SALOMEDS : data structure of SALOME and sources of Salome data server +// File : SALOMEDSImpl_SObject.cxx +// Author : Sergey RUIN +// Module : SALOME + +using namespace std; + +#include "SALOMEDSImpl_SObject.hxx" +#include "SALOMEDSImpl_Attributes.hxx" +#include "SALOMEDSImpl_SComponent.hxx" +#include "SALOMEDSImpl_Study.hxx" + +#include +#include + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_SObject, MMgt_TShared ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_SObject, MMgt_TShared ) + +//============================================================================ +/*! Function : constructor + * Purpose : + */ +//============================================================================ +SALOMEDSImpl_SObject::SALOMEDSImpl_SObject(const TDF_Label& theLabel) + :_lab(theLabel) +{ + _value = ""; + _type = ""; + _name = ""; +} + +//============================================================================ +/*! Function : Desctructor + * Purpose : + */ +//============================================================================ +SALOMEDSImpl_SObject::~SALOMEDSImpl_SObject() +{} + +//============================================================================ +/*! Function : GetID + * Purpose : + */ +//============================================================================ +TCollection_AsciiString SALOMEDSImpl_SObject::GetID() +{ + TCollection_AsciiString anEntry; + TDF_Tool::Entry (_lab,anEntry); + return anEntry; +} + +//============================================================================ +/*! Function : GetFatherComponent + * Purpose : + */ +//============================================================================ +Handle(SALOMEDSImpl_SComponent) SALOMEDSImpl_SObject::GetFatherComponent() +{ + TDF_Label LF = _lab; + while (!SALOMEDSImpl_SComponent::IsA(LF) && !LF.IsRoot()) { + LF = LF.Father(); + } + + if(LF.IsRoot()) return NULL; + + return GetStudy()->GetSComponent(LF); +} + +//============================================================================ +/*! Function : GetFather + * Purpose : + */ +//============================================================================ +Handle(SALOMEDSImpl_SObject) SALOMEDSImpl_SObject::GetFather() +{ + return GetStudy()->GetSObject(_lab.Father()); +} + + +//============================================================================ +/*! Function : GetStudy + * Purpose : + */ +//============================================================================ +Handle(SALOMEDSImpl_Study) SALOMEDSImpl_SObject::GetStudy() +{ + return SALOMEDSImpl_Study::GetStudy(_lab); +} + +//============================================================================ +/*! Function : FindAttribute + * Purpose : Find attribute of given type on this SObject + */ +//============================================================================ +bool SALOMEDSImpl_SObject::FindAttribute(Handle(TDF_Attribute)& theAttribute, + const TCollection_AsciiString& theTypeOfAttribute) +{ + if(_lab.IsNull()) return Standard_False; + Standard_GUID aGUID = GetGUID(theTypeOfAttribute); + if (_lab.FindAttribute(aGUID, theAttribute)) return Standard_True; + return Standard_False; +} + + + +//============================================================================ +/*! Function : GetAllAttributes + * Purpose : Returns list of all attributes for this sobject + */ +//============================================================================ +Handle(TColStd_HSequenceOfTransient) SALOMEDSImpl_SObject::GetAllAttributes() +{ + Standard_Integer NumAttr = _lab.NbAttributes(); + Handle(TColStd_HSequenceOfTransient) SeqOfAttr = new TColStd_HSequenceOfTransient(); + Handle(SALOMEDSImpl_GenericAttribute) anAttr; + if (NumAttr != 0) { + for(TDF_AttributeIterator iter(_lab);iter.More();iter.Next()) { + anAttr = Handle(SALOMEDSImpl_GenericAttribute)::DownCast(iter.Value()); + if(!anAttr.IsNull() && anAttr->Type() != "AttributeReference") + SeqOfAttr->Append(anAttr); + } + } + return SeqOfAttr; +} + + +//============================================================================ +/*! Function : ReferencedObject + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_SObject::ReferencedObject(Handle(SALOMEDSImpl_SObject)& theObject) +{ + Handle(SALOMEDSImpl_AttributeReference) Ref; + if (!_lab.FindAttribute(SALOMEDSImpl_AttributeReference::GetID(),Ref)) + return false; + + theObject = GetStudy()->GetSObject(Ref->Get()); + return true; +} + +//============================================================================ +/*! Function : FindSubObject + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_SObject::FindSubObject(int theTag, Handle(SALOMEDSImpl_SObject)& theObject) +{ + TDF_Label L = _lab.FindChild(theTag, false); + if (L.IsNull()) return false; + + theObject = GetStudy()->GetSObject(L); + return true; + +} + + +//============================================================================ +/*! Function : GetName + * Purpose : + */ +//============================================================================ +TCollection_AsciiString SALOMEDSImpl_SObject::GetName() +{ + TCollection_AsciiString aStr = ""; + Handle(SALOMEDSImpl_AttributeName) aName; + if (_lab.FindAttribute(SALOMEDSImpl_AttributeName::GetID(), aName)) { + aStr = aName->Value(); + } + return aStr; +} + +//============================================================================ +/*! Function : GetComment + * Purpose : + */ +//============================================================================ +TCollection_AsciiString SALOMEDSImpl_SObject::GetComment() +{ + TCollection_AsciiString aStr = ""; + Handle(SALOMEDSImpl_AttributeComment) aComment; + if (_lab.FindAttribute(SALOMEDSImpl_AttributeComment::GetID(), aComment)) { + aStr = aComment->Value(); + } + return aStr; +} + +//============================================================================ +/*! Function : GetIOR + * Purpose : + */ +//============================================================================ +TCollection_AsciiString SALOMEDSImpl_SObject::GetIOR() +{ + TCollection_AsciiString aStr = ""; + Handle(SALOMEDSImpl_AttributeIOR) anIOR; + if (_lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID(), anIOR)) { + aStr = anIOR->Value(); + } + return aStr; +} + + +Standard_GUID SALOMEDSImpl_SObject::GetGUID(const TCollection_AsciiString& theType) +{ + __AttributeTypeToGUIDForSObject + + if (strncmp(theType.ToCString(), "AttributeTreeNodeGUID",21) == 0) { + const char* aCType = theType.ToCString(); + char* aGUIDString = new char[40]; + sprintf(aGUIDString, &(aCType[21])); + Standard_GUID aGUID = Standard_GUID(aGUIDString); // create tree node GUID by name + delete(aGUIDString); + return aGUID; + } + return Standard_GUID(); +} + + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_SObject.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_SObject.hxx new file mode 100644 index 000000000..a69e6191f --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_SObject.hxx @@ -0,0 +1,66 @@ +// File : SALOMEDSImpl_SObject.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef __SALOMEDSIMPL_SOBJECT_H__ +#define __SALOMEDSIMPL_SOBJECT_H__ + +//Handle definition +#include +#include +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_SObject, MMgt_TShared ) + +class SALOMEDSImpl_SComponent; +class Handle_SALOMEDSImpl_SComponent; +class SALOMEDSImpl_Study; +class Handle_SALOMEDSImpl_Study; + +// Cascade headers +#include +#include +#include +#include +#include +#include +#include + +class SALOMEDSImpl_SObject : public MMgt_TShared +{ +protected: + TDF_Label _lab; + TCollection_AsciiString _name; + TCollection_AsciiString _value; + TCollection_AsciiString _type; + +public: + + SALOMEDSImpl_SObject(const TDF_Label& theLabel); + ~SALOMEDSImpl_SObject(); + + virtual TCollection_AsciiString GetID(); + virtual Handle(SALOMEDSImpl_SComponent) GetFatherComponent(); + virtual Handle(SALOMEDSImpl_SObject) GetFather() ; + virtual bool FindAttribute(Handle(TDF_Attribute)& theAttribute, const TCollection_AsciiString& theTypeOfAttribute); + virtual bool ReferencedObject(Handle(SALOMEDSImpl_SObject)& theObject) ; + virtual bool FindSubObject(int theTag, Handle(SALOMEDSImpl_SObject)& theObject); + + virtual Handle(SALOMEDSImpl_Study) GetStudy() ; + virtual TCollection_AsciiString Name() { return _name; } + virtual void Name(const TCollection_AsciiString& theName) { _name = theName; } + virtual Handle(TColStd_HSequenceOfTransient) GetAllAttributes(); + + virtual TCollection_AsciiString GetName(); + virtual TCollection_AsciiString GetComment(); + virtual TCollection_AsciiString GetIOR(); + + virtual int Tag() { return _lab.Tag(); } + virtual int Depth() { return _lab.Depth(); } + + virtual TDF_Label GetLabel() { return _lab; } + + static Standard_GUID GetGUID(const TCollection_AsciiString& theTypeOfAttribute); + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_SObject ) +}; +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx new file mode 100644 index 000000000..6e0899ff8 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx @@ -0,0 +1,1463 @@ +// File : SALOMEDSImpl_Study.cxx +// Author : Sergey RUIN +// Module : SALOME + +using namespace std; +#include "SALOMEDSImpl_Study.hxx" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "SALOMEDSImpl_ChildNodeIterator.hxx" +#include "SALOMEDSImpl_Attributes.hxx" +#include "SALOMEDSImpl_UseCaseIterator.hxx" +#include "SALOMEDSImpl_AttributeReference.hxx" +#include "SALOMEDSImpl_StudyHandle.hxx" +#include "SALOMEDSImpl_Tool.hxx" + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_Study, MMgt_TShared ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_Study, MMgt_TShared ) + +#define DIRECTORYID 16661 +#define FILELOCALID 26662 +#define FILEID "FILE: " + +//============================================================================ +/*! Function : SALOMEDSImpl_Study + * Purpose : SALOMEDSImpl_Study constructor + */ +//============================================================================ +SALOMEDSImpl_Study::SALOMEDSImpl_Study(const Handle(TDocStd_Document)& doc, + const TCollection_AsciiString& study_name) +{ + _name = study_name; + _doc = doc; + _Saved = false ; + _URL = ""; + _StudyId = -1; + _autoFill = true; + myNbPostponed.Append(0); + myNbUndos = 0; + _errorCode = ""; + _useCaseBuilder = new SALOMEDSImpl_UseCaseBuilder(_doc); + _builder = new SALOMEDSImpl_StudyBuilder(this); + _cb = new SALOMEDSImpl_Callback(_useCaseBuilder); + //Put on the root label a StudyHandle attribute to store the address of this object + //It will be used to retrieve the study object by TDF_Label that belongs to the study + SALOMEDSImpl_StudyHandle::Set(_doc->Main().Root(), this); +} + + +//============================================================================ +/*! Function : ~SALOMEDSImpl_Study + * Purpose : SALOMEDSImpl_Study destructor + */ +//============================================================================ +SALOMEDSImpl_Study::~SALOMEDSImpl_Study() +{} + +//============================================================================ +/*! Function : GetPersistentReference + * Purpose : Get persistent reference of study (idem URL()) + */ +//============================================================================ +TCollection_AsciiString SALOMEDSImpl_Study::GetPersistentReference() +{ + _errorCode = ""; + return URL(); +} +//============================================================================ +/*! Function : GetTransientReference + * Purpose : Get IOR of the Study (registred in OCAF document in doc->Root) + */ +//============================================================================ +TCollection_AsciiString SALOMEDSImpl_Study::GetTransientReference() +{ + _errorCode = ""; + TCollection_AsciiString IOR = ""; + + Handle(SALOMEDSImpl_AttributeIOR) Att; + TDF_Label _lab = _doc->GetData()->Root(); + if (_lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID(),Att)) { + IOR = Att->Value(); + } + else { + _errorCode = "IOR is empty"; + } + + return IOR; +} + +void SALOMEDSImpl_Study::SetTransientReference(const TCollection_AsciiString& theIOR) +{ + _errorCode = ""; + + Handle(SALOMEDSImpl_AttributeStudyProperties) aProp = GetProperties(); + int aLocked = aProp->IsLocked(); + if (aLocked) aProp->SetLocked(Standard_False); + + // Assign the value of the IOR in the study->root + SALOMEDSImpl_AttributeIOR::Set(_doc->Main().Root(), theIOR); + + if (aLocked) aProp->SetLocked(Standard_True); +} + +//============================================================================ +/*! Function : IsEmpty + * Purpose : Detect if study is empty + */ +//============================================================================ +bool SALOMEDSImpl_Study::IsEmpty() +{ + _errorCode = ""; + if (_doc.IsNull()) return true; + return _doc->IsEmpty(); +} + +//============================================================================ +/*! Function : FindComponent + * Purpose : Find a Component with ComponentDataType = aComponentName + */ +//============================================================================ +Handle(SALOMEDSImpl_SComponent) SALOMEDSImpl_Study::FindComponent (const TCollection_AsciiString& aComponentName) +{ + _errorCode = ""; + bool _find = false; + TCollection_AsciiString name; + SALOMEDSImpl_SComponentIterator itcomp = NewComponentIterator(); + Handle(SALOMEDSImpl_SComponent) compo; + + for (; itcomp.More(); itcomp.Next()) { + Handle(SALOMEDSImpl_SComponent) SC = itcomp.Value(); + name = SC->ComponentDataType(); + if(aComponentName == name) { + _find = true; + return SC; + } + } + + if(!_find) + { + _errorCode = "No component was found"; + return NULL; + } + return compo; +} + +//============================================================================ +/*! Function : FindComponentID + * Purpose : Find a Component from it's ID + */ +//============================================================================ +Handle(SALOMEDSImpl_SComponent) SALOMEDSImpl_Study::FindComponentID(const TCollection_AsciiString& aComponentID) +{ + _errorCode = ""; + + // Iterate on each components defined in the study + // Get the component ID and compare with aComponentID + bool _find = false; + TCollection_AsciiString ID; + Handle(SALOMEDSImpl_SComponent) compo; + + SALOMEDSImpl_SComponentIterator itcomp = NewComponentIterator(); + for (; itcomp.More(); itcomp.Next()) { + Handle(SALOMEDSImpl_SComponent) SC = itcomp.Value(); + ID = SC->GetID(); + if(aComponentID == ID) + { + // ComponentID found + _find = true; + compo = SC; + } + } + if(!_find) + { + _errorCode = "No component was found"; + compo = NULL; + } + + return compo; +} + +//============================================================================ +/*! Function : FindObject + * Purpose : Find an Object with SALOMEDSImpl_Name = anObjectName + */ +//============================================================================ +Handle(SALOMEDSImpl_SObject) SALOMEDSImpl_Study::FindObject(const TCollection_AsciiString& anObjectName) +{ + _errorCode = ""; + + // Iterate to all components defined in the study + // After testing the component name, iterate in all objects defined under + // components (function _FindObject) + bool _find = false; + Handle(SALOMEDSImpl_SObject) RefSO = NULL; + + SALOMEDSImpl_SComponentIterator it = NewComponentIterator(); + for (; it.More();it.Next()){ + if(!_find) + { + Handle(SALOMEDSImpl_SComponent) SC = it.Value(); + if (SC->GetName() == anObjectName) + { + _find = true; + RefSO = SC; + + } + if (!_find) RefSO = _FindObject(SC, anObjectName, _find); + } + } + if(RefSO.IsNull()) _errorCode = "No object was found"; + return RefSO; +} + +//============================================================================ +/*! Function : FindObjectID + * Purpose : Find an Object with ID = anObjectID + */ +//============================================================================ +Handle(SALOMEDSImpl_SObject) SALOMEDSImpl_Study::FindObjectID(const TCollection_AsciiString& anObjectID) +{ + _errorCode = ""; + + // Convert aSO->GetID in TDF_Label. + TDF_Label Lab; + TDF_Tool::Label(_doc->Main().Data(), anObjectID, Lab); + + if (Lab.IsNull()) { + _errorCode = "No label was found by ID"; + return NULL; + } + return GetSObject(Lab); + +} + +//============================================================================ +/*! Function : CreateObjectID + * Purpose : Creates an Object with ID = anObjectID + */ +//============================================================================ +Handle(SALOMEDSImpl_SObject) SALOMEDSImpl_Study::CreateObjectID(const TCollection_AsciiString& anObjectID) +{ + _errorCode = ""; + + // Convert aSO->GetID in TDF_Label. + TDF_Label Lab; + TDF_Tool::Label(_doc->Main().Data(), anObjectID, Lab, Standard_True); + + if (Lab.IsNull()) { + _errorCode = "Can not create a label"; + return NULL; + } + return GetSObject(Lab); + +} + +//============================================================================ +/*! Function : FindObjectByName + * Purpose : Find Objects with SALOMEDSImpl_Name = anObjectName in a Component + * : with ComponentDataType = aComponentName + */ +//============================================================================ +Handle(TColStd_HSequenceOfTransient) SALOMEDSImpl_Study::FindObjectByName(const TCollection_AsciiString& anObjectName, + const TCollection_AsciiString& aComponentName) +{ + _errorCode = ""; + + Handle(TColStd_HSequenceOfTransient) listSO = new TColStd_HSequenceOfTransient(); + + Handle(SALOMEDSImpl_SComponent) compo = FindComponent(aComponentName) ; + if ( compo.IsNull() ) { + _errorCode = "Can not find the component"; + return listSO; + } + + // Iterate on each object and subobject of the component + // If objectName is found add it to the list of SObjects + TCollection_AsciiString childName ; + + TCollection_AsciiString compoId = compo->GetID(); + Handle(SALOMEDSImpl_ChildIterator) it = NewChildIterator(compo); + for ( ; it->More(); it->Next() ) { + + Handle(SALOMEDSImpl_SObject) CSO = it->Value(); + if ( CSO->GetName() == anObjectName ) { + /* add to list */ + listSO->Append(CSO) ; + } + + /* looks also for eventual children */ + bool found = false ; + CSO = _FindObject( CSO, anObjectName, found ) ; + if( found) { + listSO->Append(CSO) ; + } + } + + return listSO; +} + + + +//============================================================================ +/*! Function : FindObjectIOR + * Purpose : Find an Object with IOR = anObjectIOR + */ +//============================================================================ +Handle(SALOMEDSImpl_SObject) SALOMEDSImpl_Study::FindObjectIOR(const TCollection_AsciiString& anObjectIOR) +{ + _errorCode = ""; + + // firstly searching in the datamap for optimization + if (myIORLabels.IsBound(anObjectIOR)) { + Handle(SALOMEDSImpl_SObject) aResult = GetSObject(myIORLabels.Find(anObjectIOR)); + // 11 oct 2002: forbidden attributes must be checked here + if (!aResult->GetLabel().IsAttribute(SALOMEDSImpl_AttributeIOR::GetID())) { + myIORLabels.UnBind(anObjectIOR); + } else + return aResult; + } + // Iterate to all components defined in the study + // After testing the component name, iterate in all objects defined under + // components (function _FindObject) + bool _find = false; + Handle(SALOMEDSImpl_SObject) RefSO = NULL; + + SALOMEDSImpl_SComponentIterator it = NewComponentIterator(); + Handle(SALOMEDSImpl_SComponent) SC; + for (; it.More();it.Next()){ + if(!_find) + { + SC = it.Value(); + TCollection_AsciiString ior = SC->GetIOR(); + if (ior != "") + { + if (ior == anObjectIOR) + { + _find = true; + RefSO = SC; + } + } + if (!_find) + RefSO = _FindObjectIOR(SC, anObjectIOR, _find); + } + } + + if(RefSO.IsNull()) _errorCode = "No object was found"; + return RefSO; +} + +//============================================================================ +/*! Function : FindObjectByPath + * Purpose : Find an Object by its path = thePath + */ +//============================================================================ +Handle(SALOMEDSImpl_SObject) SALOMEDSImpl_Study::FindObjectByPath(const TCollection_AsciiString& thePath) +{ + _errorCode = ""; + + TCollection_AsciiString aPath(thePath), aToken; + Handle(SALOMEDSImpl_SObject) aSO = NULL; + int i = 1, aLength = aPath.Length(); + bool isRelative = false; + + if(aLength == 0) { //Empty path - return the current context + return GetSObject(_current); + } + + if(aPath.Value(1) != '/') //Relative path + isRelative = true; + + TDF_ChildIterator anIterator; + TDF_Label aLabel; + Handle(SALOMEDSImpl_AttributeName) anAttr; + + if(isRelative) { + if(_current.IsNull()) return NULL; + anIterator.Initialize(_current, Standard_False); + } + else { + if(aPath.Length() == 1 && aPath.Value(1) == '/') { //Root + return GetSObject(_doc->Main()); + } + anIterator.Initialize(_doc->Main(), Standard_False); + } + + while(i <= aLength) { + + aToken = aPath.Token("/", i); + if(aToken.Length() == 0) break; + + for ( ; anIterator.More(); anIterator.Next() ) { + aLabel = anIterator.Value(); + if(aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID(), anAttr)) { + if(anAttr->Value() == aToken) { + aToken = aPath.Token("/", i+1); //Check if it was the last part of the path + if(aToken.Length() == 0) { //The searched label is found (no part of the path is left) + return GetSObject(aLabel); + } + + anIterator.Initialize(aLabel, Standard_False); + break; + } + } + } + + i++; + } + + if(aSO.IsNull()) _errorCode = "No object was found"; + return aSO; +} + +//============================================================================ +/*! Function : GetObjectPath + * Purpose : + */ +//============================================================================ +TCollection_AsciiString SALOMEDSImpl_Study::GetObjectPath(const Handle(SALOMEDSImpl_SObject)& theObject) +{ + _errorCode = ""; + + TCollection_AsciiString aPath(""); + if(theObject.IsNull()) { + _errorCode = "Null object"; + return aPath.ToCString(); + } + + TCollection_AsciiString aName = theObject->GetName(); + if(!aName.IsEmpty() && aName != "" ) { + TCollection_AsciiString aValue((char*)aName.ToCString()); + aValue.Prepend("/"); + aValue += aPath; + aPath = aValue; + Handle(SALOMEDSImpl_SObject) aFather = theObject->GetFather(); + if(!aFather.IsNull()) { + aName = aFather->GetName(); + if(!aName.IsEmpty() && aName != "") { + aValue = (char*)GetObjectPath(aFather).ToCString(); + aPath = aValue + aPath; + } + } + } + + return aPath; +} + + +//============================================================================ +/*! Function : GetObjectPathByIOR + * Purpose : + */ +//============================================================================ +TCollection_AsciiString SALOMEDSImpl_Study::GetObjectPathByIOR(const TCollection_AsciiString& theIOR) +{ + _errorCode = ""; + + TCollection_AsciiString aPath; + Handle(SALOMEDSImpl_SObject) so = FindObjectIOR(theIOR); + if(so.IsNull()) { + _errorCode = "No SObject was found by IOR"; + return aPath; + } + + return GetObjectPath(so); +} + + +//============================================================================ +/*! Function : SetContext + * Purpose : Sets the current context + */ +//============================================================================ +bool SALOMEDSImpl_Study::SetContext(const TCollection_AsciiString& thePath) +{ + _errorCode = ""; + if(thePath.IsEmpty()) { + _errorCode = "InvalidPath"; + return false; + } + + TCollection_AsciiString aPath(thePath), aContext(""); + bool isInvalid = false; + Handle(SALOMEDSImpl_SObject) aSO; + + if(aPath.Value(1) != '/') { //Relative path + aContext = GetContext(); + aContext += '/'; + aContext += aPath; + } + else + aContext = aPath; + + try { + aSO = FindObjectByPath(aContext.ToCString()); + } + catch( ... ) { + isInvalid = true; + } + + if(isInvalid || aSO.IsNull()) { + _errorCode = "InvalidContext"; + return false; + } + + TDF_Label aLabel = aSO->GetLabel(); + if(aLabel.IsNull()) { + _errorCode = "InvalidContext"; + return false; + } + else + _current = aLabel; //Set the current context + + return true; +} + +//============================================================================ +/*! Function : GetContext + * Purpose : Gets the current context + */ +//============================================================================ +TCollection_AsciiString SALOMEDSImpl_Study::GetContext() +{ + _errorCode = ""; + + if(_current.IsNull()) { + _errorCode = "InvaidContext"; + return ""; + } + Handle(SALOMEDSImpl_SObject) so = GetSObject(_current); + return GetObjectPath(so); +} + +//============================================================================ +/*! Function : GetObjectNames + * Purpose : method to get all object names in the given context (or in the current context, if 'theContext' is empty) + */ +//============================================================================ +Handle(TColStd_HSequenceOfAsciiString) SALOMEDSImpl_Study::GetObjectNames(const TCollection_AsciiString& theContext) +{ + _errorCode = ""; + + Handle(TColStd_HSequenceOfAsciiString) aResultSeq = new TColStd_HSequenceOfAsciiString; + TDF_Label aLabel; + if (theContext.IsEmpty()) { + if(_current.IsNull()) { + _errorCode = "InvalidContext"; + return aResultSeq; + } + aLabel = _current; + } else { + TDF_Label aTmp = _current; + SetContext(theContext); + aLabel = _current; + _current = aTmp; + } + TDF_ChildIterator anIter(aLabel, Standard_False); // iterate all subchildren at all sublevels + for(; anIter.More(); anIter.Next()) { + TDF_Label aLabel = anIter.Value(); + Handle(SALOMEDSImpl_AttributeName) aName; + if (aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID(), aName)) aResultSeq->Append(aName->Value()); + } + + return aResultSeq; +} + +//============================================================================ +/*! Function : GetDirectoryNames + * Purpose : method to get all directory names in the given context (or in the current context, if 'theContext' is empty) + */ +//============================================================================ +Handle(TColStd_HSequenceOfAsciiString) SALOMEDSImpl_Study::GetDirectoryNames(const TCollection_AsciiString& theContext) +{ + _errorCode = ""; + + Handle(TColStd_HSequenceOfAsciiString) aResultSeq = new TColStd_HSequenceOfAsciiString; + TDF_Label aLabel; + if (theContext.IsEmpty()) { + if(_current.IsNull()) { + _errorCode = "InvalidContext"; + return aResultSeq; + } + aLabel = _current; + } else { + TDF_Label aTmp = _current; + SetContext(theContext); + aLabel = _current; + _current = aTmp; + } + TDF_ChildIterator anIter(aLabel, Standard_False); // iterate first-level children at all sublevels + for(; anIter.More(); anIter.Next()) { + TDF_Label aLabel = anIter.Value(); + Handle(SALOMEDSImpl_AttributeLocalID) anID; + if (aLabel.FindAttribute(SALOMEDSImpl_AttributeLocalID::GetID(), anID)) { + if (anID->Value() == DIRECTORYID) { + Handle(SALOMEDSImpl_AttributeName) aName; + if (aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID(), aName)) { + aResultSeq->Append(aName->Value()); + } + } + } + } + + return aResultSeq; +} + +//============================================================================ +/*! Function : GetFileNames + * Purpose : method to get all file names in the given context (or in the current context, if 'theContext' is empty) + */ +//============================================================================ +Handle(TColStd_HSequenceOfAsciiString) SALOMEDSImpl_Study::GetFileNames(const TCollection_AsciiString& theContext) +{ + _errorCode = ""; + + Handle(TColStd_HSequenceOfAsciiString) aResultSeq = new TColStd_HSequenceOfAsciiString; + TDF_Label aLabel; + if (theContext.IsEmpty()) { + if(_current.IsNull()) { + _errorCode = "InvalidContext"; + return aResultSeq; + } + aLabel = _current; + } else { + TDF_Label aTmp = _current; + SetContext(theContext); + aLabel = _current; + _current = aTmp; + } + TDF_ChildIterator anIter(aLabel, Standard_False); // iterate all subchildren at all sublevels + for(; anIter.More(); anIter.Next()) { + TDF_Label aLabel = anIter.Value(); + Handle(SALOMEDSImpl_AttributeLocalID) anID; + if (aLabel.FindAttribute(SALOMEDSImpl_AttributeLocalID::GetID(), anID)) { + if (anID->Value() == FILELOCALID) { + Handle(SALOMEDSImpl_AttributePersistentRef) aName; + if(aLabel.FindAttribute(SALOMEDSImpl_AttributePersistentRef::GetID(), aName)) { + TCollection_ExtendedString aFileName = aName->Value(); + if(aFileName.Length() > 0) + aResultSeq->Append(aFileName.Split(strlen(FILEID))); + } + } + } + } + + return aResultSeq; +} + +//============================================================================ +/*! Function : GetComponentNames + * Purpose : method to get all components names + */ +//============================================================================ +Handle(TColStd_HSequenceOfAsciiString) SALOMEDSImpl_Study::GetComponentNames(const TCollection_AsciiString& theContext) +{ + _errorCode = ""; + + Handle(TColStd_HSequenceOfAsciiString) aResultSeq = new TColStd_HSequenceOfAsciiString; + TDF_ChildIterator anIter(_doc->Main(), Standard_False); // iterate all subchildren at first level + for(; anIter.More(); anIter.Next()) { + TDF_Label aLabel = anIter.Value(); + Handle(SALOMEDSImpl_AttributeName) aName; + if (aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID(), aName)) aResultSeq->Append(aName->Value()); + } + + return aResultSeq; +} + +//============================================================================ +/*! Function : NewChildIterator + * Purpose : Create a ChildIterator from an SObject + */ +//============================================================================ +Handle(SALOMEDSImpl_ChildIterator) SALOMEDSImpl_Study::NewChildIterator(const Handle(SALOMEDSImpl_SObject)& aSO) +{ + _errorCode = ""; + return new SALOMEDSImpl_ChildIterator(aSO); +} + + +//============================================================================ +/*! Function : NewComponentIterator + * Purpose : Create a SComponentIterator + */ +//============================================================================ +SALOMEDSImpl_SComponentIterator SALOMEDSImpl_Study::NewComponentIterator() +{ + _errorCode = ""; + return SALOMEDSImpl_SComponentIterator(_doc); +} + + +//============================================================================ +/*! Function : NewBuilder + * Purpose : Create a StudyBuilder + */ +//============================================================================ +Handle(SALOMEDSImpl_StudyBuilder) SALOMEDSImpl_Study::NewBuilder() +{ + _errorCode = ""; + if(_autoFill) { + _builder->SetOnAddSObject(_cb); + _builder->SetOnRemoveSObject(_cb); + } + return _builder; + +} + +//============================================================================ +/*! Function : Name + * Purpose : get study name + */ +//============================================================================ +TCollection_AsciiString SALOMEDSImpl_Study::Name() +{ + _errorCode = ""; + return _name; +} + +//============================================================================ +/*! Function : Name + * Purpose : set study name + */ +//============================================================================ +void SALOMEDSImpl_Study::Name(const TCollection_AsciiString& name) +{ + _errorCode = ""; + _name = name; +} + +//============================================================================ +/*! Function : IsSaved + * Purpose : get if study has been saved + */ +//============================================================================ +bool SALOMEDSImpl_Study::IsSaved() +{ + _errorCode = ""; + return _Saved; +} + +//============================================================================ +/*! Function : IsSaved + * Purpose : set if study has been saved + */ +//============================================================================ +void SALOMEDSImpl_Study::IsSaved(bool save) +{ + _errorCode = ""; + _Saved = save; +} + +//============================================================================ +/*! Function : IsModified + * Purpose : Detect if a Study has been modified since it has been saved + */ +//============================================================================ +bool SALOMEDSImpl_Study::IsModified() +{ + _errorCode = ""; + + // True if is modified and not saved + if (_doc->IsModified()) + if (!_Saved) return true; + else return false; + else return false; +} + +//============================================================================ +/*! Function : URL + * Purpose : get URL of the study (persistent reference of the study) + */ +//============================================================================ +TCollection_AsciiString SALOMEDSImpl_Study::URL() +{ + _errorCode = ""; + return _URL; +} + +//============================================================================ +/*! Function : URL + * Purpose : set URL of the study (persistent reference of the study) + */ +//============================================================================ +void SALOMEDSImpl_Study::URL(const TCollection_AsciiString& url) +{ + _errorCode = ""; + _URL = url; + + TCollection_AsciiString tmp(_URL); + + char *aName = (char*)tmp.ToCString(); + char *adr = strtok(aName, "/"); + while (adr) + { + aName = adr; + adr = strtok(NULL, "/"); + } + Name(aName); +} + + +//============================================================================ +/*! Function : _FindObject + * Purpose : Find an Object with SALOMEDSImpl_Name = anObjectName + */ +//============================================================================ +Handle(SALOMEDSImpl_SObject) SALOMEDSImpl_Study::_FindObject(const Handle(SALOMEDSImpl_SObject)& SO, + const TCollection_AsciiString& theObjectName, + bool& _find) +{ + if(SO.IsNull()) return NULL; + + // Iterate on each objects and subobjects of the component + // If objectName find, stop the loop and get the object reference + Handle(SALOMEDSImpl_SObject) RefSO; + Handle(SALOMEDSImpl_AttributeName) anAttr; + + TCollection_AsciiString soid = SO->GetID(); + TDF_ChildIterator it(SO->GetLabel()); + for (; it.More(); it.Next()){ + if(!_find) + { + if (it.Value().FindAttribute(SALOMEDSImpl_AttributeName::GetID(), anAttr)) + { + TCollection_AsciiString Val(anAttr->Value()); + if (Val == theObjectName) + { + RefSO = GetSObject(it.Value()); + _find = true; + } + } + if (!_find) RefSO = _FindObject(GetSObject(it.Value()), theObjectName, _find); + } + } + return RefSO; +} + +//============================================================================ +/*! Function : _FindObjectIOR + * Purpose : Find an Object with SALOMEDSImpl_IOR = anObjectIOR + */ +//============================================================================ +Handle(SALOMEDSImpl_SObject) +SALOMEDSImpl_Study::_FindObjectIOR(const Handle(SALOMEDSImpl_SObject)& SO, + const TCollection_AsciiString& theObjectIOR, + bool& _find) +{ + if(SO.IsNull()) return NULL; + + // Iterate on each objects and subobjects of the component + // If objectName find, stop the loop and get the object reference + Handle(SALOMEDSImpl_SObject) RefSO, aSO; + Handle(SALOMEDSImpl_AttributeIOR) anAttr; + + TDF_ChildIterator it(SO->GetLabel()); + for (; it.More();it.Next()){ + if(!_find) + { + if (it.Value().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID(), anAttr)) + { + TCollection_AsciiString Val(anAttr->Value()); + if (Val == theObjectIOR) + { + RefSO = GetSObject(it.Value()); + _find = true; + } + } + aSO = GetSObject(it.Value()); + if (!_find) RefSO = _FindObjectIOR(aSO, theObjectIOR, _find); + } + } + return RefSO; +} + +bool SALOMEDSImpl_Study::IsLocked() +{ + _errorCode = ""; + return GetProperties()->IsLocked(); +} + +int SALOMEDSImpl_Study::StudyId() +{ + _errorCode = ""; + return _StudyId; +} + +void SALOMEDSImpl_Study::StudyId(int id) +{ + _errorCode = ""; + _StudyId = id; +} + +void SALOMEDSImpl_Study::UpdateIORLabelMap(const TCollection_AsciiString& anIOR,const TCollection_AsciiString& anEntry) +{ + _errorCode = ""; + TDF_Label aLabel; + char* anEn = (char*)anEntry.ToCString(); + char* IOR = (char*)anIOR.ToCString(); + TDF_Tool::Label(_doc->GetData(),anEn, aLabel, Standard_True); + if (myIORLabels.IsBound(TCollection_ExtendedString(IOR))) myIORLabels.UnBind(TCollection_ExtendedString(IOR)); + myIORLabels.Bind(TCollection_ExtendedString(IOR), aLabel); +} + +Handle(SALOMEDSImpl_Study) SALOMEDSImpl_Study::GetStudy(const TDF_Label& theLabel) +{ + Handle(SALOMEDSImpl_StudyHandle) Att; + if (theLabel.Root().FindAttribute(SALOMEDSImpl_StudyHandle::GetID(),Att)) { + return Att->GetHandle(); + } + return NULL; +} + +Handle(SALOMEDSImpl_SObject) SALOMEDSImpl_Study::SObject(const TDF_Label& theLabel) +{ + return GetStudy(theLabel)->GetSObject(theLabel); +} + +Handle(SALOMEDSImpl_SComponent) SALOMEDSImpl_Study::SComponent(const TDF_Label& theLabel) +{ + return GetStudy(theLabel)->GetSComponent(theLabel); +} + + +void SALOMEDSImpl_Study::IORUpdated(const Handle(SALOMEDSImpl_AttributeIOR)& theAttribute) +{ + TCollection_AsciiString aString; + TDF_Tool::Entry(theAttribute->Label(), aString); + GetStudy(theAttribute->Label())->UpdateIORLabelMap(theAttribute->Value(), aString); +} + +Handle(TColStd_HSequenceOfTransient) SALOMEDSImpl_Study::FindDependances(const Handle(SALOMEDSImpl_SObject)& anObject) +{ + _errorCode = ""; + Handle(TColStd_HSequenceOfTransient) aSeq; + + Handle(SALOMEDSImpl_AttributeTarget) aTarget; + if (anObject->GetLabel().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID(), aTarget)) { + return aTarget->Get(); + } + + return aSeq; +} + + +Handle(SALOMEDSImpl_AttributeStudyProperties) SALOMEDSImpl_Study::GetProperties() +{ + _errorCode = ""; + return SALOMEDSImpl_AttributeStudyProperties::Set(_doc->Main()); +} + +TCollection_AsciiString SALOMEDSImpl_Study::GetLastModificationDate() +{ + _errorCode = ""; + Handle(SALOMEDSImpl_AttributeStudyProperties) aProp = GetProperties(); + + Handle(TColStd_HSequenceOfExtendedString) aNames; + Handle(TColStd_HSequenceOfInteger) aMinutes, aHours, aDays, aMonths, aYears; + aNames = aProp->GetUserNames(); + aProp->GetModificationDates(aMinutes, aHours, aDays, aMonths, aYears); + + int aLastIndex = aNames->Length(); + char aResult[20]; + sprintf(aResult, "%2.2d/%2.2d/%4.4d %2.2d:%2.2d", (int)(aDays->Value(aLastIndex)),(int)(aMonths->Value(aLastIndex)), + (int)(aYears->Value(aLastIndex)), (int)(aHours->Value(aLastIndex)), (int)(aMinutes->Value(aLastIndex))); + TCollection_AsciiString aResStr(aResult); + return aResStr; +} + +Handle(TColStd_HSequenceOfAsciiString) SALOMEDSImpl_Study::GetModificationsDate() +{ + _errorCode = ""; + Handle(SALOMEDSImpl_AttributeStudyProperties) aProp = GetProperties(); + + Handle(TColStd_HSequenceOfExtendedString) aNames; + Handle(TColStd_HSequenceOfInteger) aMinutes, aHours, aDays, aMonths, aYears; + aNames = aProp->GetUserNames(); + aProp->GetModificationDates(aMinutes, aHours, aDays, aMonths, aYears); + + int anIndex, aLength = aNames->Length(); + Handle(TColStd_HSequenceOfAsciiString) aDates = new TColStd_HSequenceOfAsciiString; + + for(anIndex = 2; anIndex <= aLength; anIndex++) { + char aDate[20]; + sprintf(aDate, "%2.2d/%2.2d/%4.4d %2.2d:%2.2d", (int)(aDays->Value(anIndex)), (int)(aMonths->Value(anIndex)), + (int)(aYears->Value(anIndex)), (int)(aHours->Value(anIndex)), (int)(aMinutes->Value(anIndex))); + aDates->Append(aDate); + } + return aDates; +} + + + +//============================================================================ +/*! Function : GetUseCaseBuilder + * Purpose : Returns a UseCase builder + */ +//============================================================================ +Handle(SALOMEDSImpl_UseCaseBuilder) SALOMEDSImpl_Study::GetUseCaseBuilder() +{ + _errorCode = ""; + return _useCaseBuilder; +} + + +//============================================================================ +/*! Function : Close + * Purpose : + */ +//============================================================================ +void SALOMEDSImpl_Study::Close() +{ + _errorCode = ""; + Handle(TDocStd_Application) anApp = Handle(TDocStd_Application)::DownCast(_doc->Application()); + if(!anApp.IsNull()) anApp->Close(_doc); + _doc.Nullify(); + _mapOfSO.Clear(); + _mapOfSCO.Clear(); +} + +//============================================================================ +/*! Function : AddPostponed + * Purpose : + */ + //============================================================================ +void SALOMEDSImpl_Study::AddPostponed(const TCollection_AsciiString& theIOR) +{ + _errorCode = ""; + if (!NewBuilder()->HasOpenCommand()) return; + TCollection_AsciiString anIOR(theIOR); + anIOR.Prepend("d"); + myPostponedIORs.Append(anIOR); // add prefix: deleted + myNbPostponed.SetValue(myNbPostponed.Length(), myNbPostponed.Last() + 1); +} + +//============================================================================ +/*! Function : AddCreatedPostponed + * Purpose : + */ + //============================================================================ +void SALOMEDSImpl_Study::AddCreatedPostponed(const TCollection_AsciiString& theIOR) +{ + _errorCode = ""; + if (!NewBuilder()->HasOpenCommand()) return; + TCollection_AsciiString anIOR(theIOR); + anIOR.Prepend("c"); + myPostponedIORs.Append(anIOR); // add prefix: created + myNbPostponed.SetValue(myNbPostponed.Length(), myNbPostponed.Last() + 1); +} + +//============================================================================ +/*! Function : RemovePostponed + * Purpose : + */ +//============================================================================ +Handle(TColStd_HSequenceOfAsciiString) SALOMEDSImpl_Study::RemovePostponed(const int theUndoLimit) +{ + _errorCode = ""; + + int anIndex; + int anOld; + + int aUndoLimit = theUndoLimit; + if (theUndoLimit < 0) aUndoLimit = 0; + + Handle(TColStd_HSequenceOfAsciiString) aSeq = new TColStd_HSequenceOfAsciiString; + + if (myNbUndos > 0) { // remove undone + anOld = 0; + for(anIndex = 1; anIndex < myNbPostponed.Length() - myNbUndos; anIndex++) + anOld += myNbPostponed(anIndex); + int aNew = myPostponedIORs.Length() - myNbPostponed.Last(); + + for(anIndex = anOld + 1; anIndex <= aNew; anIndex++) { + TCollection_AsciiString anIOR = myPostponedIORs(anIndex); + if (anIOR.Value(1) == 'c') { + aSeq->Append(anIOR.Split(1).ToCString()); + } + } + if (anOld < aNew) myPostponedIORs.Remove(anOld + 1, aNew); + if (myNbPostponed.Length() > 0) myNbPostponed.Remove(myNbPostponed.Length() - myNbUndos, myNbPostponed.Length() - 1); + + myNbUndos = 0; + } + + if (myNbPostponed.Length() > aUndoLimit) { // remove objects, that can not be undone + anOld = 0; + for(anIndex = myNbPostponed.Length() - aUndoLimit; anIndex >= 1; anIndex--) + anOld += myNbPostponed(anIndex); + for(anIndex = 1; anIndex <= anOld; anIndex++) { + TCollection_AsciiString anIOR = myPostponedIORs(anIndex); + if (anIOR.Value(1) == 'd') { + aSeq->Append(anIOR.Split(1).ToCString()); + } + } + if (anOld > 0) myPostponedIORs.Remove(1, anOld); + myNbPostponed.Remove(1, myNbPostponed.Length() - aUndoLimit); + } + + if (theUndoLimit == -1) { // remove all IORs from the study on the study close + TDF_ChildIDIterator anIter(_doc->GetData()->Root(), SALOMEDSImpl_AttributeIOR::GetID(), Standard_True); + for(; anIter.More(); anIter.Next()) { + Handle(SALOMEDSImpl_AttributeIOR) anAttr = Handle(SALOMEDSImpl_AttributeIOR)::DownCast(anIter.Value()); + aSeq->Append(anAttr->Value()); + } + } else myNbPostponed.Append(0); + + return aSeq; +} + +//============================================================================ +/*! Function : UndoPostponed + * Purpose : + */ +//============================================================================ +void SALOMEDSImpl_Study::UndoPostponed(const int theWay) +{ + _errorCode = ""; + + myNbUndos += theWay; + // remove current postponed + if (myNbPostponed.Last() > 0) + myPostponedIORs.Remove(myPostponedIORs.Length() - myNbPostponed.Last() + 1, myPostponedIORs.Length()); + myNbPostponed(myNbPostponed.Length()) = 0; +} + + +//============================================================================ +/*! Function : GetSComponent + * Purpose : + */ +//============================================================================ +Handle(SALOMEDSImpl_SComponent) SALOMEDSImpl_Study::GetSComponent(const TCollection_AsciiString& theEntry) +{ + Handle(SALOMEDSImpl_SComponent) aSCO; + if(_mapOfSCO.IsBound(theEntry)) + aSCO = Handle(SALOMEDSImpl_SComponent)::DownCast(_mapOfSCO.Find(theEntry)); + else { + TDF_Label aLabel; + TDF_Tool::Label(_doc->GetData(), theEntry, aLabel); + aSCO = new SALOMEDSImpl_SComponent(aLabel); + _mapOfSCO.Bind(theEntry, aSCO); + } + + return aSCO; +} + +//============================================================================ +/*! Function : GetSComponent + * Purpose : + */ +//============================================================================ +Handle(SALOMEDSImpl_SComponent) SALOMEDSImpl_Study::GetSComponent(const TDF_Label& theLabel) +{ + TCollection_AsciiString anEntry; + TDF_Tool::Entry(theLabel, anEntry); + return GetSComponent(anEntry); +} + +//============================================================================ +/*! Function : GetSObject + * Purpose : + */ +//============================================================================ +Handle(SALOMEDSImpl_SObject) SALOMEDSImpl_Study::GetSObject(const TCollection_AsciiString& theEntry) +{ + Handle(SALOMEDSImpl_SObject) aSO; + if(_mapOfSO.IsBound(theEntry)) + aSO = Handle(SALOMEDSImpl_SObject)::DownCast(_mapOfSO.Find(theEntry)); + else { + TDF_Label aLabel; + TDF_Tool::Label(_doc->GetData(), theEntry, aLabel); + aSO = new SALOMEDSImpl_SObject(aLabel); + _mapOfSO.Bind(theEntry, aSO); + } + + return aSO; +} + +//============================================================================ +/*! Function : GetSObject + * Purpose : + */ +//============================================================================ +Handle(SALOMEDSImpl_SObject) SALOMEDSImpl_Study::GetSObject(const TDF_Label& theLabel) +{ + TCollection_AsciiString anEntry; + TDF_Tool::Entry(theLabel, anEntry); + return GetSObject(anEntry); +} + +//============================================================================ +/*! Function : GetAttribute + * Purpose : + */ +//============================================================================ +Handle(TDF_Attribute) SALOMEDSImpl_Study::GetAttribute(const TCollection_AsciiString& theEntry, + const TCollection_AsciiString& theType) +{ + Handle(SALOMEDSImpl_SObject) aSO = GetSObject(theEntry); + Handle(TDF_Attribute) anAttr; + aSO->FindAttribute(anAttr, theType); + return anAttr; +} + +//============================================================================ +/*! Function : DumpStudy + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_Study::DumpStudy(const TCollection_AsciiString& thePath, + const TCollection_AsciiString& theBaseName, + bool isPublished, + SALOMEDSImpl_DriverFactory* theFactory) +{ + _errorCode = ""; + + if(theFactory == NULL) { + _errorCode = "Null factory for creation of Engines"; + return false; + } + + TColStd_SequenceOfExtendedString aSeq; + TCollection_AsciiString aCompType, aFactoryType; + + //Build a list of all components in the Study + SALOMEDSImpl_SComponentIterator itcomponent = NewComponentIterator(); + + for (; itcomponent.More(); itcomponent.Next()) { + Handle(SALOMEDSImpl_SComponent) sco = itcomponent.Value(); + aCompType = sco->ComponentDataType(); + //GEOM and MED are independent components + if(aCompType == "GEOM" || aCompType == "MED") aSeq.Prepend(TCollection_ExtendedString(aCompType)); + else aSeq.Append(TCollection_ExtendedString(aCompType)); + } + +#ifdef WIN32 + TCollection_AsciiString aFileName=thePath+TCollection_AsciiString("\\")+theBaseName+TCollection_AsciiString(".py"); +#else + TCollection_AsciiString aFileName=thePath+TCollection_AsciiString("/")+theBaseName+TCollection_AsciiString(".py"); +#endif + + //Create a file that will contain a main Study script + fstream fp; + fp.open(aFileName.ToCString(), ios::out); + +#ifdef WIN32 + bool isOpened = fp.is_open(); +#else + bool isOpened = fp.rdbuf()->is_open(); +#endif + + if(!isOpened) { + _errorCode = TCollection_AsciiString("Can't create a file ")+aFileName; + return false; + } + + TCollection_AsciiString aBatchModeScript = "salome"; + + //Output to the main Study script required Python modules import, set sys.path and add a creation of the study. + fp << GetDumpStudyComment().ToCString() << endl << endl; + fp << "import sys" << endl; + fp << "import " << aBatchModeScript << "\n" << endl; + fp << "sys.path.insert( 0, \'" << thePath << "\')\n" << endl; + + Handle(TColStd_HSequenceOfAsciiString) aSeqOfFileNames = new TColStd_HSequenceOfAsciiString; + + //Iterate all components and create the componponents specific scripts. + bool isOk = true; + int aLength = aSeq.Length(); + for(int i = 1; i <= aLength; i++) { + + aCompType = aSeq.Value(i); + Handle(SALOMEDSImpl_SComponent) sco = FindComponent(aCompType); + SALOMEDSImpl_Driver* aDriver = NULL; + // if there is an associated Engine call its method for saving + TCollection_AsciiString IOREngine; + try { + if (!sco->ComponentIOR(IOREngine)) { + if (!aCompType.IsEmpty()) { + + aDriver = theFactory->GetDriverByType(aCompType); + + if (aDriver != NULL) { + Handle(SALOMEDSImpl_StudyBuilder) SB = NewBuilder(); + cout << "Before SB" << endl; + if(!SB->LoadWith(sco, aDriver)) { + _errorCode = SB->GetErrorCode(); + return false; + } + cout << "After SB" << endl; + } + else continue; + } + } + else { + aDriver = theFactory->GetDriverByIOR(IOREngine); + } + } catch(...) { + _errorCode = "Can not restore information to dump it"; + return false; + } + + if(aDriver == NULL) continue; + + bool isValidScript; + long aStreamLength = 0; + unsigned char* aStream = aDriver->DumpPython(this, isPublished, isValidScript, aStreamLength); + if ( !isValidScript ) + isOk = false; + + //Create a file that will contain the component specific script + fstream fp2; +#ifdef WIN32 + aFileName=thePath+TCollection_AsciiString("\\"); +#else + aFileName=thePath+TCollection_AsciiString("/"); +#endif + TCollection_AsciiString aScriptName; + aScriptName += theBaseName; + aScriptName += "_"; + aScriptName += aCompType; + + aFileName += aScriptName+ TCollection_AsciiString(".py"); + aSeqOfFileNames->Append(aFileName); + + fp2.open(aFileName.ToCString(), ios::out); + +#ifdef WIN32 + isOpened = fp.is_open(); +#else + isOpened = fp.rdbuf()->is_open(); +#endif + + if(!isOpened) { + _errorCode = TCollection_AsciiString("Can't create a file ")+aFileName; + SALOMEDSImpl_Tool::RemoveTemporaryFiles(thePath, aSeqOfFileNames, false); + return false; + } + + //Output the Python script generated by the component in the newly created file. + fp2 << aStream; + fp2.close(); + + //Add to the main script a call to RebuildData of the generated by the component the Python script + fp << "import " << aScriptName << endl; + fp << aScriptName << ".RebuildData(" << aBatchModeScript << ".myStudy)" << endl; + } + + fp.close(); + return isOk; +} + +//======================================================================= +//function : GetDumpStudyComment +//purpose : return a header comment for a DumpStudy script +//======================================================================= + +TCollection_AsciiString SALOMEDSImpl_Study::GetDumpStudyComment(const char* theComponentName) +{ + TCollection_AsciiString txt + ("### This file is generated by SALOME automatically by dump python funcitonality"); + if ( theComponentName ) + txt += TCollection_AsciiString(" of ") + (char*) theComponentName + " component"; + return txt; +} + +void dumpSO(const Handle(SALOMEDSImpl_SObject)& theSO, + fstream& fp, + const TCollection_AsciiString& Tab, + const Handle(SALOMEDSImpl_Study) theStudy); +//============================================================================ +/*! Function : dump + * Purpose : + */ +//============================================================================ +void SALOMEDSImpl_Study::dump(const TCollection_AsciiString& theFileName) +{ + //Create a file that will contain a main Study script + fstream fp; + fp.open(theFileName.ToCString(), ios::out); + +#ifdef WIN32 + bool isOpened = fp.is_open(); +#else + bool isOpened = fp.rdbuf()->is_open(); +#endif + + if(!isOpened) { + _errorCode = TCollection_AsciiString("Can't create a file ")+theFileName; + cout << "### SALOMEDSImpl_Study::dump Error: " << _errorCode << endl; + return; + } + + Handle(SALOMEDSImpl_SObject) aSO = FindObjectID("0:1"); + fp << "0:1" << endl; + Handle(SALOMEDSImpl_ChildIterator) Itr = NewChildIterator(aSO); + TCollection_AsciiString aTab(" "); + for(; Itr->More(); Itr->Next()) { + dumpSO(Itr->Value(), fp, aTab, this); + } + + fp.close(); +} + + +void dumpSO(const Handle(SALOMEDSImpl_SObject)& theSO, + fstream& fp, + const TCollection_AsciiString& Tab, + const Handle(SALOMEDSImpl_Study) theStudy) +{ + TCollection_AsciiString aTab(Tab), anID(theSO->GetID()); + fp << aTab << anID << endl; + TDF_AttributeIterator anItr(theSO->GetLabel()); + for(; anItr.More(); anItr.Next()) { + Handle(SALOMEDSImpl_GenericAttribute) anAttr = Handle(SALOMEDSImpl_GenericAttribute)::DownCast(anItr.Value()); + + if(anAttr.IsNull()) { + fp << Tab << " -- " << anItr.Value()->DynamicType(); + continue; + } + + TCollection_AsciiString aType = anAttr->GetClassType(); + fp << Tab << " -- " << aType; + + if(aType == "AttributeReal") { + fp << " : " << Handle(SALOMEDSImpl_AttributeReal)::DownCast(anAttr)->Value(); + } + else if(aType == "AttributeInteger") { + fp << " : " << Handle(SALOMEDSImpl_AttributeInteger)::DownCast(anAttr)->Value(); + } + else if(aType == "AttributeName") { + fp << " : " << Handle(SALOMEDSImpl_AttributeName)::DownCast(anAttr)->Value(); + } + else if(aType == "AttributeComment") { + fp << " : " << Handle(SALOMEDSImpl_AttributeComment)::DownCast(anAttr)->Value(); + } + else if(aType == "AttributeReference") { + fp << " : " << Handle(SALOMEDSImpl_AttributeReference)::DownCast(anAttr)->Save(); + } + fp << endl; + } + + Handle(SALOMEDSImpl_ChildIterator) Itr = theStudy->NewChildIterator(theSO); + TCollection_AsciiString aNewTab(" "); + aNewTab+=aTab; + for(; Itr->More(); Itr->Next()) { + dumpSO(Itr->Value(), fp, aNewTab, theStudy); + } + + return; +} diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx new file mode 100644 index 000000000..c4b0b2cf5 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx @@ -0,0 +1,246 @@ +// File : SALOMEDSImpl_Study.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef __SALOMEDSIMPL_STUDY_I_H__ +#define __SALOMEDSIMPL_STUDY_I_H__ + +//Handle definition +#include +#include +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_Study, MMgt_TShared ) + +// std C++ headers +#include + +// Cascade headers +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//SALOMEDSImpl headers +#include "SALOMEDSImpl_SComponentIterator.hxx" +#include "SALOMEDSImpl_SObject.hxx" +#include "SALOMEDSImpl_StudyBuilder.hxx" +#include "SALOMEDSImpl_UseCaseBuilder.hxx" +#include "SALOMEDSImpl_AttributeStudyProperties.hxx" +#include "SALOMEDSImpl_AttributeIOR.hxx" +#include "SALOMEDSImpl_Callback.hxx" +#include "SALOMEDSImpl_Driver.hxx" +#include "SALOMEDSImpl_ChildIterator.hxx" + +class SALOMEDSImpl_StudyManager; +class SALOMEDSImpl_GenericAttribute; + +typedef NCollection_DataMap DataMapOfAsciiStringTransient; +typedef NCollection_DataMap DataMapAsciiStringLabel; + +class SALOMEDSImpl_Study : public MMgt_TShared +{ +private: + TCollection_AsciiString _name; + Handle(TDocStd_Document) _doc; // OCAF Document + bool _Saved; // True if the Study is saved + TCollection_AsciiString _URL; //URL of the persistent reference of the study + int _StudyId; + TDF_Label _current; + bool _autoFill; + TCollection_AsciiString _errorCode; + Handle(SALOMEDSImpl_Callback) _cb; + Handle(SALOMEDSImpl_StudyBuilder) _builder; + Handle(SALOMEDSImpl_UseCaseBuilder) _useCaseBuilder; + + DataMapOfAsciiStringTransient _mapOfSO; + DataMapOfAsciiStringTransient _mapOfSCO; + + // data structures for postponed destroying of object functionality + TColStd_SequenceOfAsciiString myPostponedIORs; // ordered set of IORs + TColStd_SequenceOfInteger myNbPostponed; // number of IOR in the each transaction + int myNbUndos; // number of current Undos, made by user + DataMapAsciiStringLabel myIORLabels; + + + Handle(SALOMEDSImpl_SObject) _FindObject(const Handle(SALOMEDSImpl_SObject)& SO, + const TCollection_AsciiString& anObjectName, + bool& _find); + + Handle(SALOMEDSImpl_SObject) _FindObjectIOR(const Handle(SALOMEDSImpl_SObject)& SO, + const TCollection_AsciiString& anObjectIOR, + bool& _find); + +public: + + static Handle(SALOMEDSImpl_Study) GetStudy(const TDF_Label& theLabel); + static Handle(SALOMEDSImpl_SObject) SObject(const TDF_Label& theLabel); + static Handle(SALOMEDSImpl_SComponent) SComponent(const TDF_Label& theLabel); + static void IORUpdated(const Handle(SALOMEDSImpl_AttributeIOR)& theAttribute); + + //! standard constructor + SALOMEDSImpl_Study(const Handle(TDocStd_Document)&, const TCollection_AsciiString& study_name); + + //! standard destructor + virtual ~SALOMEDSImpl_Study(); + + //! method to Get persistent reference of study (idem URL()) + virtual TCollection_AsciiString GetPersistentReference(); + + //! method to Get transient reference of study + virtual TCollection_AsciiString GetTransientReference(); + + virtual void SetTransientReference(const TCollection_AsciiString& theIOR); + + //! method to detect if a study is empty + virtual bool IsEmpty(); + + //! method to Find a Component with ComponentDataType = aComponentName + virtual Handle(SALOMEDSImpl_SComponent) FindComponent (const TCollection_AsciiString& aComponentName); + + //! method to Find a Component Find a Component from it's ID + virtual Handle(SALOMEDSImpl_SComponent) FindComponentID(const TCollection_AsciiString& aComponentID); + + //! method to Find an Object with SALOMEDSImpl::Name = anObjectName + virtual Handle(SALOMEDSImpl_SObject) FindObject(const TCollection_AsciiString& anObjectName); + + + //! method to Find Object(s) with SALOMEDSImpl::Name=anObjectName in a component with ComponentDataType = aComponentName + virtual Handle(TColStd_HSequenceOfTransient) FindObjectByName( const TCollection_AsciiString& anObjectName, + const TCollection_AsciiString& aComponentName ) ; + + //! method to Find an Object with ID = anObjectID + virtual Handle(SALOMEDSImpl_SObject) FindObjectID(const TCollection_AsciiString& anObjectID); + + //! method to Create an Object with ID = anObjectID + virtual Handle(SALOMEDSImpl_SObject) CreateObjectID(const TCollection_AsciiString& anObjectID); + + //! method to Find an Object with ID = anObjectIOR + virtual Handle(SALOMEDSImpl_SObject) FindObjectIOR(const TCollection_AsciiString& anObjectIOR); + + //! method to Find an Object by its path + virtual Handle(SALOMEDSImpl_SObject) FindObjectByPath(const TCollection_AsciiString& thePath); + + //! method to get a path of SObject + virtual TCollection_AsciiString GetObjectPath(const Handle(SALOMEDSImpl_SObject)& theObject); + + TCollection_AsciiString GetObjectPathByIOR(const TCollection_AsciiString& theIOR); + + //! method to set a context: root ('/') is UserData component + virtual bool SetContext(const TCollection_AsciiString& thePath); + + //! method to get a context + virtual TCollection_AsciiString GetContext(); + + //! method to get all object names in the given context (or in the current context, if 'theContext' is empty) + virtual Handle(TColStd_HSequenceOfAsciiString) GetObjectNames(const TCollection_AsciiString& theContext); + + //! method to get all directory names in the given context (or in the current context, if 'theContext' is empty) + virtual Handle(TColStd_HSequenceOfAsciiString) GetDirectoryNames(const TCollection_AsciiString& theContext); + + //! method to get all file names in the given context (or in the current context, if 'theContext' is empty) + virtual Handle(TColStd_HSequenceOfAsciiString) GetFileNames(const TCollection_AsciiString& theContext); + + //! method to get all components names + virtual Handle(TColStd_HSequenceOfAsciiString) GetComponentNames(const TCollection_AsciiString& theContext); + + //! method to Create a ChildIterator from an SObject + virtual Handle(SALOMEDSImpl_ChildIterator) NewChildIterator(const Handle(SALOMEDSImpl_SObject)& aSO); + + //! method to Create a SComponentIterator + virtual SALOMEDSImpl_SComponentIterator NewComponentIterator(); + + //! method to Create a StudyBuilder + virtual Handle(SALOMEDSImpl_StudyBuilder) NewBuilder(); + + //! method to get study name + virtual TCollection_AsciiString Name(); + + //! method to set study name + virtual void Name(const TCollection_AsciiString& name); + + //! method to get if study has been saved + virtual bool IsSaved(); + + //! method to set if study has been saved + virtual void IsSaved(bool save); + + //! method to Detect if a Study has been modified since it has been saved + virtual bool IsModified(); + + //! method to get URL of the study (idem GetPersistentReference) + virtual TCollection_AsciiString URL(); + + //! method to set URL of the study + virtual void URL(const TCollection_AsciiString& url); + + virtual bool IsLocked(); + + virtual int StudyId(); + + virtual void StudyId(int id); + + virtual void UpdateIORLabelMap(const TCollection_AsciiString& anIOR, const TCollection_AsciiString& aLabel); + + virtual Handle(TColStd_HSequenceOfTransient) FindDependances(const Handle(SALOMEDSImpl_SObject)& anObject); + + virtual Handle(SALOMEDSImpl_AttributeStudyProperties) SALOMEDSImpl_Study::GetProperties(); + + virtual TCollection_AsciiString GetLastModificationDate(); + + virtual Handle(TColStd_HSequenceOfAsciiString) GetModificationsDate(); + + virtual Handle(SALOMEDSImpl_UseCaseBuilder) GetUseCaseBuilder(); + + virtual void Close(); + + void EnableUseCaseAutoFilling(bool isEnabled) { _errorCode = ""; _autoFill = isEnabled; } + + // postponed destroying of object functionality + virtual void AddPostponed(const TCollection_AsciiString& theIOR); + + virtual void AddCreatedPostponed(const TCollection_AsciiString& theIOR); + + virtual Handle(TColStd_HSequenceOfAsciiString) RemovePostponed(const int theUndoLimit); + // removes postponed IORs of old transaction + // if theUndoLimit==0, removes all + virtual void UndoPostponed(const int theWay); // theWay = 1: resurrect objects, + // theWay = -1: get back to the list of postponed + + + virtual TCollection_AsciiString GetErrorCode() { return _errorCode; } + virtual bool IsError() { return _errorCode != ""; } + + virtual Handle(SALOMEDSImpl_SComponent) GetSComponent(const TCollection_AsciiString& theEntry); + virtual Handle(SALOMEDSImpl_SComponent) GetSComponent(const TDF_Label& theLabel); + virtual Handle(SALOMEDSImpl_SObject) GetSObject(const TCollection_AsciiString& theEntry); + virtual Handle(SALOMEDSImpl_SObject) GetSObject(const TDF_Label& theEntryLabel); + virtual Handle(TDF_Attribute) GetAttribute(const TCollection_AsciiString& theEntry, + const TCollection_AsciiString& theType); + + virtual bool HasCurrentContext() { return !_current.IsNull(); } + + virtual bool DumpStudy(const TCollection_AsciiString& thePath, + const TCollection_AsciiString& theBaseName, + bool isPublished, + SALOMEDSImpl_DriverFactory* theFactory); + + static TCollection_AsciiString GetDumpStudyComment(const char* theComponentName = 0); + + virtual Handle(TDocStd_Document) GetDocument() { return _doc; } + + //The method dump creates a txt file that contain a dump of the study, for debug use + void dump(const TCollection_AsciiString& theFileName); + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_Study ) + +friend class SALOMEDSImpl_StudyManager; +friend class SALOMEDSImpl_GenericAttribute; +}; +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.cxx new file mode 100644 index 000000000..72334106b --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.cxx @@ -0,0 +1,982 @@ +// File : SALOMEDSImpl_StudyBuilder.cxx +// Author : Sergey RUIN +// Module : SALOME + +using namespace std; + +#include "SALOMEDSImpl_Attributes.hxx" + +#include "SALOMEDSImpl_Study.hxx" +#include "SALOMEDSImpl_StudyBuilder.hxx" +#include "SALOMEDSImpl_SObject.hxx" +#include "SALOMEDSImpl_SComponent.hxx" +#include "SALOMEDSImpl_Tool.hxx" + +#include +#include +#include +#include +#include +#include + +#include +#include + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_StudyBuilder, MMgt_TShared ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_StudyBuilder, MMgt_TShared ) + +#define USE_CASE_LABEL_TAG 2 +#define DIRECTORYID 16661 +#define FILELOCALID 26662 + +static void Translate_persistentID_to_IOR(TDF_Label& Lab, SALOMEDSImpl_Driver* driver, bool isMultiFile, bool isASCII); + +//============================================================================ +/*! Function : constructor + * Purpose : + */ +//============================================================================ +SALOMEDSImpl_StudyBuilder::SALOMEDSImpl_StudyBuilder(const Handle(Standard_Transient)& theOwner) +{ + _errorCode = ""; + _study = theOwner; + _doc = Handle(SALOMEDSImpl_Study)::DownCast(theOwner)->GetDocument(); +} + +//============================================================================ +/*! Function : destructor + * Purpose : + */ +//============================================================================ +SALOMEDSImpl_StudyBuilder::~SALOMEDSImpl_StudyBuilder() +{} + +//============================================================================ +/*! Function : NewComponent + * Purpose : Create a new component (Scomponent) + */ +//============================================================================ +Handle(SALOMEDSImpl_SComponent) SALOMEDSImpl_StudyBuilder::NewComponent(const TCollection_AsciiString& DataType) +{ + _errorCode = ""; + CheckLocked(); + //Always create component under main label. + TDF_Label L = _doc->Main(); + + int imax = 0; + for (TDF_ChildIterator it(L); it.More(); it.Next()) { + if (it.Value().Tag() > imax) + imax = it.Value().Tag(); + } + imax++; + TDF_Label NL = L.FindChild(imax); + + SALOMEDSImpl_AttributeComment::Set(NL, DataType); + + Handle(SALOMEDSImpl_SComponent) so = Handle(SALOMEDSImpl_Study)::DownCast(_study)->GetSComponent (NL); + + if(!_callbackOnAdd.IsNull()) _callbackOnAdd->OnAddSObject(so); + + return so; +} + +//============================================================================ +/*! Function : DefineComponentInstance + * Purpose : Add IOR attribute of a Scomponent + */ +//============================================================================ +bool SALOMEDSImpl_StudyBuilder::DefineComponentInstance(const Handle(SALOMEDSImpl_SComponent)& aComponent, + const TCollection_AsciiString& IOR) +{ + _errorCode = ""; + + CheckLocked(); + if(aComponent.IsNull() || IOR.IsEmpty()) { + _errorCode = "Invalid arguments"; + return false; + } + //add IOR definition + SALOMEDSImpl_AttributeIOR::Set(aComponent->GetLabel(), IOR); + return true; +} + +//============================================================================ +/*! Function : RemoveComponent + * Purpose : Delete a Scomponent + */ +//============================================================================ +bool SALOMEDSImpl_StudyBuilder::RemoveComponent(const Handle(SALOMEDSImpl_SComponent)& aComponent) +{ + _errorCode = ""; + CheckLocked(); + return RemoveObject(aComponent); +} + +//============================================================================ +/*! Function : NewObject + * Purpose : Create a new SObject + */ +//============================================================================ +Handle(SALOMEDSImpl_SObject) SALOMEDSImpl_StudyBuilder::NewObject(const Handle(SALOMEDSImpl_SObject)& theFatherObject) +{ + _errorCode = ""; + CheckLocked(); + + //Find label of father + TDF_Label Lab = theFatherObject->GetLabel(); + + //Create a new label + int imax = 0; + for (TDF_ChildIterator it(Lab); it.More(); it.Next()) { + if (it.Value().Tag() > imax) + imax = it.Value().Tag(); + } + imax++; + TDF_Label NewLab = Lab.FindChild(imax); + + Handle(SALOMEDSImpl_SObject) so = Handle(SALOMEDSImpl_Study)::DownCast(_study)->GetSObject(NewLab); + if(!_callbackOnAdd.IsNull()) _callbackOnAdd->OnAddSObject(so); + + return so; +} + +//============================================================================ +/*! Function : NewObjectToTag + * Purpose : + */ +//============================================================================ +Handle(SALOMEDSImpl_SObject) SALOMEDSImpl_StudyBuilder::NewObjectToTag(const Handle(SALOMEDSImpl_SObject)& theFatherObject, + const int theTag) +{ + _errorCode = ""; + CheckLocked(); + //Find label of father + TDF_Label Lab = theFatherObject->GetLabel(); + + //Create or find label + TDF_Label NewLab = Lab.FindChild(theTag, 1); + + Handle(SALOMEDSImpl_SObject) so = Handle(SALOMEDSImpl_Study)::DownCast(_study)->GetSObject(NewLab); + + if(!_callbackOnAdd.IsNull()) _callbackOnAdd->OnAddSObject(so); + + return so; +} + +//============================================================================ +/*! Function : RemoveObject + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_StudyBuilder::RemoveObject(const Handle(SALOMEDSImpl_SObject)& anObject) +{ + _errorCode = ""; + CheckLocked(); + if(anObject.IsNull()) { + _errorCode = "Null object"; + return false; + } + + if(!_callbackOnRemove.IsNull()) _callbackOnRemove->OnRemoveSObject(anObject); + + TDF_Label Lab = anObject->GetLabel(); + + Handle(SALOMEDSImpl_AttributeReference) aReference; + if (Lab.FindAttribute(SALOMEDSImpl_AttributeReference::GetID(), aReference)) { + Handle(SALOMEDSImpl_AttributeTarget) aTarget; + if (aReference->Get().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID(),aTarget)) + aTarget->Remove(SALOMEDSImpl_Study::SObject(Lab)); + } + + Handle(SALOMEDSImpl_AttributeIOR) anAttr; // postponed removing of CORBA objects + if (Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID(), anAttr)) + SALOMEDSImpl_Study::GetStudy(_doc->Main())->AddPostponed(TCollection_AsciiString(anAttr->Value()).ToCString()); + + Lab.ForgetAllAttributes(); + return true; +} + +//============================================================================ +/*! Function : RemoveObjectWithChildren + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_StudyBuilder::RemoveObjectWithChildren(const Handle(SALOMEDSImpl_SObject)& anObject) +{ + _errorCode = ""; + CheckLocked(); + if(anObject.IsNull()) { + _errorCode = "Null object"; + return false; + } + + if(!_callbackOnRemove.IsNull()) _callbackOnRemove->OnRemoveSObject(anObject); + + TDF_Label Lab = anObject->GetLabel(); + + Handle(SALOMEDSImpl_AttributeReference) aReference; + if (Lab.FindAttribute(SALOMEDSImpl_AttributeReference::GetID(), aReference)) { + Handle(SALOMEDSImpl_AttributeTarget) aTarget; + if (aReference->Get().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID(),aTarget)) + aTarget->Remove(SALOMEDSImpl_Study::SObject(Lab)); + } + Handle(SALOMEDSImpl_AttributeIOR) anAttr; // postponed removing of CORBA objects + if (Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID(), anAttr)) + SALOMEDSImpl_Study::GetStudy(_doc->Main())->AddPostponed(TCollection_AsciiString(anAttr->Value()).ToCString()); + + TDF_ChildIterator it(Lab, Standard_True); + for(;it.More();it.Next()) { + TDF_Label aLabel = it.Value(); + if (aLabel.FindAttribute(SALOMEDSImpl_AttributeReference::GetID(), aReference)) { + Handle(SALOMEDSImpl_AttributeTarget) aTarget; + if (aReference->Get().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID(),aTarget)) + aTarget->Remove(SALOMEDSImpl_Study::SObject(aLabel)); + } + Handle(SALOMEDSImpl_AttributeIOR) anAttr; // postponed removing of CORBA objects + if (aLabel.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID(), anAttr)) + SALOMEDSImpl_Study::GetStudy(_doc->Main())->AddPostponed(TCollection_AsciiString(anAttr->Value()).ToCString()); + } + + Lab.ForgetAllAttributes(Standard_True); + return true; +} + +//============================================================================ +/*! Function : LoadWith + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_StudyBuilder::LoadWith(const Handle(SALOMEDSImpl_SComponent)& anSCO, SALOMEDSImpl_Driver* aDriver) +{ + _errorCode = ""; + + TDF_Label Lab = anSCO->GetLabel(); + Handle(SALOMEDSImpl_AttributePersistentRef) Att; + + //Find the current Url of the study + if (_doc->Main().FindAttribute(SALOMEDSImpl_AttributePersistentRef::GetID(),Att)) { + int aLocked = anSCO->GetStudy()->GetProperties()->IsLocked(); + if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(false); + + TCollection_ExtendedString Res(Att->Value()); + + Handle(SALOMEDSImpl_AttributeComment) type; + TCollection_ExtendedString DataType; + if (Lab.FindAttribute(SALOMEDSImpl_AttributeComment::GetID(),type)) + DataType = type->Value(); + + // associate the driver to the SComponent + if(aDriver == NULL) { + _errorCode = "Driver is null"; + return false; + } + + // mpv 06.03.2003: SAL1927 - if component data if already loaded, it is not necessary to do it again + Handle(SALOMEDSImpl_AttributeIOR) attrIOR; + if (Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID(), attrIOR)) { + if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(true); + return true; + } + + DefineComponentInstance (anSCO, aDriver->GetIOR()); + + TCollection_AsciiString aHDFPath(Res); + + char* aHDFUrl; + bool isASCII = false; + if (HDFascii::isASCII(aHDFPath.ToCString())) { + isASCII = true; + char* aResultPath = HDFascii::ConvertFromASCIIToHDF(aHDFPath.ToCString()); + aHDFUrl = new char[strlen(aResultPath) + 19]; + sprintf(aHDFUrl, "%shdf_from_ascii.hdf", aResultPath); + delete(aResultPath); + } else { + aHDFUrl = aHDFPath.ToCString(); + } + + //Open the Study HDF file + HDFfile *hdf_file = new HDFfile(aHDFUrl); + + char aMultifileState[2]; + char ASCIIfileState[2]; + try { + TCollection_AsciiString scoid = anSCO->GetID(); + hdf_file->OpenOnDisk(HDF_RDONLY); + HDFgroup *hdf_group = new HDFgroup("DATACOMPONENT",hdf_file); + hdf_group->OpenOnDisk(); + HDFgroup *hdf_sco_group = new HDFgroup(scoid.ToCString(), hdf_group); + hdf_sco_group->OpenOnDisk(); + + unsigned char* aStreamFile = NULL; + int aStreamSize = 0; + + if (hdf_sco_group->ExistInternalObject("FILE_STREAM")) { + HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group); + hdf_dataset->OpenOnDisk(); + aStreamSize = hdf_dataset->GetSize(); + aStreamFile = new unsigned char[aStreamSize]; + if(aStreamFile == NULL) throw HDFexception("Unable to open dataset FILE_STREAM"); + hdf_dataset->ReadFromDisk(aStreamFile); + hdf_dataset->CloseOnDisk(); + hdf_dataset = 0; + } else aStreamFile = NULL; + + HDFdataset *multifile_hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group); + multifile_hdf_dataset->OpenOnDisk(); + multifile_hdf_dataset->ReadFromDisk(aMultifileState); + + HDFdataset *ascii_hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group); + ascii_hdf_dataset->OpenOnDisk(); + ascii_hdf_dataset->ReadFromDisk(ASCIIfileState); + + // set path without file name from URL + int aFileNameSize = Res.Length(); + char* aDir = new char[aFileNameSize]; + memcpy(aDir, TCollection_AsciiString(Res).ToCString(), aFileNameSize); + for(int aCounter = aFileNameSize-1; aCounter>=0; aCounter--) + if (aDir[aCounter] == '/') { + aDir[aCounter+1] = 0; + break; + } + + bool aResult = (ASCIIfileState[0]=='A')? + aDriver->LoadASCII(anSCO, aStreamFile, aStreamSize, aDir, aMultifileState[0]=='M'): + aDriver->Load(anSCO, aStreamFile, aStreamSize, aDir, aMultifileState[0]=='M'); + + if(aStreamFile != NULL) delete []aStreamFile; + + if(!aResult) { + RemoveAttribute( anSCO, "AttributeIOR" ); + + _errorCode = "Can't load component"; + throw HDFexception("Unable to load component"); + } + + if(aDir != NULL) delete []aDir; + + multifile_hdf_dataset->CloseOnDisk(); + multifile_hdf_dataset = 0; + ascii_hdf_dataset->CloseOnDisk(); + ascii_hdf_dataset = 0; + + hdf_sco_group->CloseOnDisk(); + hdf_sco_group = 0; + hdf_group->CloseOnDisk(); + hdf_group = 0; + hdf_file->CloseOnDisk(); + delete hdf_file; + + if (isASCII) { + Handle(TColStd_HSequenceOfAsciiString) aFilesToRemove = new TColStd_HSequenceOfAsciiString; + aFilesToRemove->Append(aHDFUrl); + SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true); + } + + delete aHDFUrl; + } + catch (HDFexception) { + delete hdf_file; + + if (isASCII) { + Handle(TColStd_HSequenceOfAsciiString) aFilesToRemove = new TColStd_HSequenceOfAsciiString; + aFilesToRemove->Append(aHDFUrl); + SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true); + } + delete aHDFUrl; + + if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(true); + _errorCode = "No persistent file"; + return false; + } + + try { + Translate_persistentID_to_IOR (Lab, aDriver, aMultifileState[0]=='M', ASCIIfileState[0] == 'A'); + } catch(...) { + _errorCode = "Can not convert persistent IDs to IORs"; + return false; + } + + if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(true); + } else { + _errorCode = "No persistent file"; + } + + return true; +} + + +//============================================================================ +/*! Function : Load + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_StudyBuilder::Load(const Handle(SALOMEDSImpl_SObject)& sco) +{ + _errorCode = "Not implemented"; + return false; +} + +//============================================================================ +/*! Function : FindOrCreateAttribute + * Purpose : Add attribute of given type to SObject, if there is attribute of such type, returns + * existing one + */ +//============================================================================ +Handle(TDF_Attribute) SALOMEDSImpl_StudyBuilder::FindOrCreateAttribute(const Handle(SALOMEDSImpl_SObject)& anObject, + const TCollection_AsciiString& aTypeOfAttribute) +{ + _errorCode = ""; + if(anObject.IsNull()) { + _errorCode = "Invalid arguments"; + return NULL; + } + + TDF_Label Lab = anObject->GetLabel(); + if(Lab.IsNull()) { + _errorCode = "Null label"; + return NULL; + } + + //The macro adds all necessary checks for standardly behaiving attributes + __FindOrCreateAttributeForBuilder + + //Add checks for TreeNode and UserID attributes + if (strncmp(aTypeOfAttribute.ToCString(), "AttributeTreeNode",17) == 0 ) { + Standard_GUID aTreeNodeGUID; + if (strcmp(aTypeOfAttribute.ToCString(), "AttributeTreeNode") == 0) { + aTreeNodeGUID = SALOMEDSImpl_AttributeTreeNode::GetDefaultTreeID(); + } else { + char* aGUIDString = new char[40]; + char* aType = (char*)aTypeOfAttribute.ToCString(); + sprintf(aGUIDString, &(aType[21])); + aTreeNodeGUID = Standard_GUID(aGUIDString); // create tree node GUID by name + delete(aGUIDString); + } + Handle(SALOMEDSImpl_AttributeTreeNode) anAttr; + if (!Lab.FindAttribute(aTreeNodeGUID, anAttr)) { + CheckLocked(); + anAttr = SALOMEDSImpl_AttributeTreeNode::Set(Lab, aTreeNodeGUID); + } + return anAttr; + } + + if (strncmp(aTypeOfAttribute.ToCString(), "AttributeUserID",15) == 0 ) { + Handle(SALOMEDSImpl_AttributeUserID) anAttr; + if (!Lab.FindAttribute(SALOMEDSImpl_AttributeUserID::DefaultID(), anAttr)) { + CheckLocked(); + anAttr = SALOMEDSImpl_AttributeUserID::Set(Lab, SALOMEDSImpl_AttributeUserID::DefaultID()); + } + return anAttr; + } + _errorCode = "Can not create an attribute"; + + return NULL; +} + +//============================================================================ +/*! Function : FindAttribute + * Purpose : Find attribute of given type assigned SObject, returns Standard_True if it is found + */ +//============================================================================ + +bool SALOMEDSImpl_StudyBuilder::FindAttribute(const Handle(SALOMEDSImpl_SObject)& anObject, + Handle(TDF_Attribute)& anAttribute, + const TCollection_AsciiString& aTypeOfAttribute) +{ + _errorCode = ""; + if(anObject.IsNull()) { + _errorCode = "Invalid arguments"; + return false; + } + TDF_Label Lab = anObject->GetLabel(); + if (Lab.FindAttribute(SALOMEDSImpl_SObject::GetGUID(aTypeOfAttribute), anAttribute)) { + return Standard_True; + } + return Standard_False; +} + +//============================================================================ +/*! Function : RemoveAttribute + * Purpose : Remove attribute of given type assigned SObject + */ +//============================================================================ + +bool SALOMEDSImpl_StudyBuilder::RemoveAttribute(const Handle(SALOMEDSImpl_SObject)& anObject, + const TCollection_AsciiString& aTypeOfAttribute) +{ + _errorCode = ""; + CheckLocked(); + if(anObject.IsNull()) { + _errorCode = "Invalid arguments"; + return false; + } + TDF_Label Lab = anObject->GetLabel(); + + if (aTypeOfAttribute == "AttributeIOR") { // postponed removing of CORBA objects + Handle(SALOMEDSImpl_AttributeIOR) anAttr; + if (Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID(), anAttr)) + SALOMEDSImpl_Study::GetStudy(_doc->Main())->AddPostponed(anAttr->Value()); + } + + Lab.ForgetAttribute (SALOMEDSImpl_SObject::GetGUID(aTypeOfAttribute)); + return true; +} + +//============================================================================ +/*! Function : Addreference + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_StudyBuilder::Addreference(const Handle(SALOMEDSImpl_SObject)& me, + const Handle(SALOMEDSImpl_SObject)& theReferencedObject) +{ + _errorCode = ""; + if(me.IsNull() || theReferencedObject.IsNull()) { + _errorCode = "Invalid arguments"; + return false; + } + CheckLocked(); + TDF_Label Lab = me->GetLabel(); + TDF_Label RefLab = theReferencedObject->GetLabel(); + SALOMEDSImpl_AttributeReference::Set(Lab,RefLab); + + SALOMEDSImpl_AttributeTarget::Set(RefLab)->Add(SALOMEDSImpl_Study::SObject(Lab)); + + if(!_callbackOnRemove.IsNull() && Lab.IsDescendant(_doc->Main())) _callbackOnRemove->OnRemoveSObject(me); + return true; +} + +//============================================================================ +/*! Function : RemoveReference + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_StudyBuilder::RemoveReference(const Handle(SALOMEDSImpl_SObject)& me) +{ + _errorCode = ""; + Handle(SALOMEDSImpl_SObject) theReferencedObject; + if(!me->ReferencedObject(theReferencedObject)) return false; //No reference is found + + CheckLocked(); + TDF_Label Lab = me->GetLabel(); + + Lab.ForgetAttribute(SALOMEDSImpl_AttributeReference::GetID()); + + //SRN: 30 Aug, 2004 : fix from Ecole l'ete version + + TDF_Label RefLab = theReferencedObject->GetLabel(); + + Handle(SALOMEDSImpl_AttributeTarget) aTarget; + if(RefLab.FindAttribute(SALOMEDSImpl_AttributeTarget::GetID(), aTarget)) + aTarget->Remove(SALOMEDSImpl_Study::SObject(Lab)); + return true; +} + + + +//============================================================================ +/*! Function : AddDirectory + * Purpose : adds a new directory with a path = thePath + */ +//============================================================================ +bool SALOMEDSImpl_StudyBuilder::AddDirectory(const TCollection_AsciiString& thePath) +{ + _errorCode = ""; + CheckLocked(); + if(thePath.IsEmpty() || thePath == "") { + _errorCode = "Invalid path"; + return false; + } + + TCollection_AsciiString aPath(thePath), aContext(""), aFatherPath; + TDF_Label aLabel; + Handle(SALOMEDSImpl_Study) aStudy = SALOMEDSImpl_Study::GetStudy(_doc->Main()); + Handle(SALOMEDSImpl_SObject) anObject; + + try { + anObject = aStudy->FindObjectByPath(thePath); //Check if the directory already exists + } + catch(...) { } + + if(!anObject.IsNull()) { + _errorCode = "StudyNameAlreadyUsed"; + return false; + } + + if(aPath.Value(1) != '/') { //Relative path + aPath.Prepend('/'); + aPath = aStudy->GetContext() + aPath; + } + + TCollection_AsciiString aToken = aPath.Token("/", 1); + if(aToken.Length() == 0) aFatherPath = "/"; + + int i = 1; + while(aToken.Length() != 0) { + if(aPath.Token("/", i+1).Length() > 0) { + aFatherPath += "/"; + aFatherPath += aToken; + } + aToken = aPath.Token("/", ++i); + } + + anObject.Nullify(); + try { + anObject = aStudy->FindObjectByPath(aFatherPath); //Check if the father directory exists + } + catch(...) { ; } + if(anObject.IsNull()) { + _errorCode = "StudyInvalidDirectory"; + return false; + } + + Handle(SALOMEDSImpl_SObject) aNewObject = NewObject(anObject); + aLabel = aNewObject->GetLabel(); + if(aLabel.IsNull()) { + _errorCode = "StudyInvalidComponent"; + return false; + } + + SALOMEDSImpl_AttributeName::Set(aLabel, aPath.Token("/", i-1)); + + //Set LocalID attribute to identify the directory object + Handle(SALOMEDSImpl_AttributeLocalID) aLocalID = SALOMEDSImpl_AttributeLocalID::Set(aLabel, DIRECTORYID); + return true; +} + + +//============================================================================ +/*! Function : SetGUID + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_StudyBuilder::SetGUID(const Handle(SALOMEDSImpl_SObject)& anObject, + const TCollection_AsciiString& theGUID) +{ + _errorCode = ""; + CheckLocked(); + if(anObject.IsNull()) { + _errorCode = "Invalid arguments"; + return false; + } + + TDF_Label aLabel = anObject->GetLabel(); + SALOMEDSImpl_AttributeUserID::Set(aLabel, theGUID.ToCString()); + return true; +} + +//============================================================================ +/*! Function : IsGUID + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_StudyBuilder::IsGUID(const Handle(SALOMEDSImpl_SObject)& anObject, + const TCollection_AsciiString& theGUID) +{ + _errorCode = ""; + if(anObject.IsNull()) { + _errorCode = "Invalid arguments"; + return false; + } + TDF_Label aLabel = anObject->GetLabel(); + return aLabel.IsAttribute(theGUID.ToCString()); +} + + +//============================================================================ +/*! Function : NewCommand + * Purpose : + */ +//============================================================================ +void SALOMEDSImpl_StudyBuilder::NewCommand() +{ + _errorCode = ""; + // mpv: for SAL2114 - unset "lock changed" flag at the operation start + Handle(SALOMEDSImpl_AttributeStudyProperties) anAttr; + if (!_doc->Main().FindAttribute(SALOMEDSImpl_AttributeStudyProperties::GetID(), anAttr)) { + anAttr = new SALOMEDSImpl_AttributeStudyProperties; + _doc->Main().AddAttribute(anAttr); + } + anAttr->IsLockChanged(true); + + _doc->NewCommand(); +} + +//============================================================================ +/*! Function : CommitCommand + * Purpose : + */ +//============================================================================ +void SALOMEDSImpl_StudyBuilder::CommitCommand() +{ + _errorCode = ""; + Handle(SALOMEDSImpl_AttributeStudyProperties) anAttr; + if (!_doc->Main().FindAttribute(SALOMEDSImpl_AttributeStudyProperties::GetID(), anAttr)) { + anAttr = new SALOMEDSImpl_AttributeStudyProperties; + _doc->Main().AddAttribute(anAttr); + } + if (anAttr->IsLocked() && !anAttr->IsLockChanged(true)) { + AbortCommand(); + _errorCode = "LockProtection"; + throw LockProtection("LockProtection"); + } else { + SALOMEDSImpl_Study::GetStudy(_doc->Main())->RemovePostponed(_doc->GetUndoLimit()); + + int aModif = anAttr->GetModified(); + if (aModif < 0) aModif = 1000; // if user make undo and then - new transaction "modify" will never be zero + anAttr->SetModified(aModif+1); + _doc->CommitCommand(); + } +} + +//============================================================================ +/*! Function : HasOpenCommand + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_StudyBuilder::HasOpenCommand() +{ + _errorCode = ""; + return _doc->HasOpenCommand(); +} + +//============================================================================ +/*! Function : AbortCommand + * Purpose : + */ +//============================================================================ +void SALOMEDSImpl_StudyBuilder::AbortCommand() +{ + _errorCode = ""; + SALOMEDSImpl_Study::GetStudy(_doc->Main())->UndoPostponed(0); + + _doc->AbortCommand(); +} + +//============================================================================ +/*! Function : Undo + * Purpose : + */ +//============================================================================ +void SALOMEDSImpl_StudyBuilder::Undo() +{ + _errorCode = ""; + Handle(SALOMEDSImpl_AttributeStudyProperties) anAttr; + if (!_doc->Main().FindAttribute(SALOMEDSImpl_AttributeStudyProperties::GetID(), anAttr)) { + anAttr = new SALOMEDSImpl_AttributeStudyProperties; + _doc->Main().AddAttribute(anAttr); + } + if (anAttr->IsLocked()) { + _errorCode = "LockProtection"; + throw LockProtection("LockProtection"); + } else { + SALOMEDSImpl_Study::GetStudy(_doc->Main())->UndoPostponed(1); + _doc->Undo(); + anAttr->SetModified(anAttr->GetModified()-1); + } +} + +//============================================================================ +/*! Function : Redo + * Purpose : + */ +//============================================================================ +void SALOMEDSImpl_StudyBuilder::Redo() +{ + _errorCode = ""; + Handle(SALOMEDSImpl_AttributeStudyProperties) anAttr; + if (!_doc->Main().FindAttribute(SALOMEDSImpl_AttributeStudyProperties::GetID(), anAttr)) { + anAttr = new SALOMEDSImpl_AttributeStudyProperties; + _doc->Main().AddAttribute(anAttr); + } + + if (anAttr->IsLocked()) { + _errorCode = "LockProtection"; + throw LockProtection("LockProtection"); + } else { + _doc->Redo(); + SALOMEDSImpl_Study::GetStudy(_doc->Main())->UndoPostponed(-1); + anAttr->SetModified(anAttr->GetModified()+1); + } + } + +//============================================================================ +/*! Function : GetAvailableUndos + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_StudyBuilder::GetAvailableUndos() +{ + _errorCode = ""; + return _doc->GetAvailableUndos(); +} + +//============================================================================ +/*! Function : GetAvailableRedos + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_StudyBuilder::GetAvailableRedos() +{ + _errorCode = ""; + return _doc->GetAvailableRedos(); +} + +//============================================================================ +/*! Function : UndoLimit + * Purpose : + */ +//============================================================================ +int SALOMEDSImpl_StudyBuilder::UndoLimit() +{ + _errorCode = ""; + return _doc->GetUndoLimit(); +} + +//============================================================================ +/*! Function : UndoLimit + * Purpose : + */ +//============================================================================ +void SALOMEDSImpl_StudyBuilder::UndoLimit(int n) +{ + _errorCode = ""; + CheckLocked(); + _doc->SetUndoLimit (n); +} + +//============================================================================ +/*! Function : SetOnAddSObject + * Purpose : + */ +//============================================================================ +Handle(SALOMEDSImpl_Callback) +SALOMEDSImpl_StudyBuilder::SetOnAddSObject(const Handle(SALOMEDSImpl_Callback)& theCallback) +{ + _errorCode = ""; + Handle(SALOMEDSImpl_Callback) aRet = _callbackOnAdd; + _callbackOnAdd = theCallback; + return aRet; +} + +//============================================================================ +/*! Function : SetOnNewSObject + * Purpose : + */ +//============================================================================ +Handle(SALOMEDSImpl_Callback) +SALOMEDSImpl_StudyBuilder::SetOnRemoveSObject(const Handle(SALOMEDSImpl_Callback)& theCallback) +{ + _errorCode = ""; + Handle(SALOMEDSImpl_Callback) aRet = _callbackOnRemove; + _callbackOnRemove = theCallback; + return aRet; +} + +//============================================================================ +/*! Function : CheckLocked + * Purpose : + */ +//============================================================================ +void SALOMEDSImpl_StudyBuilder::CheckLocked() +{ + _errorCode = ""; + if (_doc->HasOpenCommand()) return; + Handle(SALOMEDSImpl_AttributeStudyProperties) anAttr; + if (!_doc->Main().FindAttribute(SALOMEDSImpl_AttributeStudyProperties::GetID(), anAttr)) { + anAttr = new SALOMEDSImpl_AttributeStudyProperties; + _doc->Main().AddAttribute(anAttr); + } + if (anAttr->IsLocked()) { + _errorCode = "LockProtection"; + throw LockProtection("LockProtection"); + } +} + +//============================================================================ +/*! Function : SetName + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_StudyBuilder::SetName(const Handle(SALOMEDSImpl_SObject)& theSO, + const TCollection_AsciiString& theValue) +{ + _errorCode = ""; + CheckLocked(); + if(theSO.IsNull()) { + _errorCode = "Invalid arguments"; + return false; + } + SALOMEDSImpl_AttributeName::Set(theSO->GetLabel(), theValue); + return true; +} + +//============================================================================ +/*! Function : SetComment + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_StudyBuilder::SetComment(const Handle(SALOMEDSImpl_SObject)& theSO, + const TCollection_AsciiString& theValue) +{ + _errorCode = ""; + CheckLocked(); + if(theSO.IsNull()) { + _errorCode = "Invalid arguments"; + return false; + } + SALOMEDSImpl_AttributeComment::Set(theSO->GetLabel(), theValue); + return true; +} + +//============================================================================ +/*! Function : SetIOR + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_StudyBuilder::SetIOR(const Handle(SALOMEDSImpl_SObject)& theSO, + const TCollection_AsciiString& theValue) +{ + _errorCode = ""; + CheckLocked(); + if(theSO.IsNull()) { + _errorCode = "Invalid arguments"; + return false; + } + SALOMEDSImpl_AttributeIOR::Set(theSO->GetLabel(), theValue); + return true; +} + + +//============================================================================ +/*! Function : Translate_persistentID_to_IOR + * Purpose : + */ +//============================================================================ +static void Translate_persistentID_to_IOR(TDF_Label& Lab, SALOMEDSImpl_Driver* driver, bool isMultiFile, bool isASCII) +{ + if(driver == NULL) return; + TDF_ChildIterator itchild (Lab); + + for (; itchild.More(); itchild.Next()) { + TDF_Label current = itchild.Value(); + Handle(SALOMEDSImpl_AttributePersistentRef) Att; + if (current.FindAttribute(SALOMEDSImpl_AttributePersistentRef::GetID(),Att)) { + + Handle(SALOMEDSImpl_AttributeLocalID) anID; + if (current.FindAttribute(SALOMEDSImpl_AttributeLocalID::GetID(), anID)) + if (anID->Value() == FILELOCALID) continue; //SRN: This attribute store a file name, skip it + + TCollection_AsciiString persist_ref(Att->Value()); + Handle(SALOMEDSImpl_SObject) so = SALOMEDSImpl_Study::SObject(current); + TCollection_AsciiString ior_string = driver->LocalPersistentIDToIOR(so, + persist_ref, + isMultiFile, + isASCII); + SALOMEDSImpl_AttributeIOR::Set (current, ior_string); + + } + Translate_persistentID_to_IOR (current, driver, isMultiFile, isASCII); + } +} + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.hxx new file mode 100644 index 000000000..6fc553ba3 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.hxx @@ -0,0 +1,106 @@ +// File : SALOMEDSImpl_StudyBuilder.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef __SALOMEDSImpl_STUDYBUILDER_H__ +#define __SALOMEDSImpl_STUDYBUILDER_H__ + +//Handle definition +#include +#include +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_StudyBuilder, MMgt_TShared ) + +// std C++ headers +#include + +// Cascade header +#include +#include + +#include "SALOMEDSImpl_Callback.hxx" +#include "SALOMEDSImpl_Driver.hxx" + +class SALOMEDSImpl_StudyBuilder : public MMgt_TShared +{ +private: + Handle(TDocStd_Document) _doc; + Handle(Standard_Transient) _study; + Handle(SALOMEDSImpl_Callback) _callbackOnAdd; + Handle(SALOMEDSImpl_Callback) _callbackOnRemove; + TCollection_AsciiString _errorCode; + +public: + + SALOMEDSImpl_StudyBuilder(const Handle(Standard_Transient)& theOwner); + + ~SALOMEDSImpl_StudyBuilder(); + + virtual Handle(SALOMEDSImpl_SComponent) NewComponent(const TCollection_AsciiString& ComponentDataType); + + virtual bool DefineComponentInstance (const Handle(SALOMEDSImpl_SComponent)&, const TCollection_AsciiString& ComponentIOR); + + virtual bool RemoveComponent(const Handle(SALOMEDSImpl_SComponent)& aComponent); + + virtual Handle(SALOMEDSImpl_SObject) NewObject(const Handle(SALOMEDSImpl_SObject)& theFatherObject); + + virtual Handle(SALOMEDSImpl_SObject) NewObjectToTag(const Handle(SALOMEDSImpl_SObject)& theFatherObject, + const int theTag); + + //! The methods adds a new subdirectory, the path can be absolute or relative (then the current context is used) + virtual bool AddDirectory(const TCollection_AsciiString& thePath); + + virtual bool LoadWith(const Handle(SALOMEDSImpl_SComponent)& sco, SALOMEDSImpl_Driver* Engine); + virtual bool Load(const Handle(SALOMEDSImpl_SObject)& sco); + + virtual bool RemoveObject(const Handle(SALOMEDSImpl_SObject)& anObject); + virtual bool RemoveObjectWithChildren(const Handle(SALOMEDSImpl_SObject)& anObject); + + virtual Handle(TDF_Attribute) FindOrCreateAttribute(const Handle(SALOMEDSImpl_SObject)& anObject, + const TCollection_AsciiString& aTypeOfAttribute); + virtual bool FindAttribute(const Handle(SALOMEDSImpl_SObject)& anObject, + Handle(TDF_Attribute)& anAttribute, + const TCollection_AsciiString& aTypeOfAttribute); + + virtual bool RemoveAttribute(const Handle(SALOMEDSImpl_SObject)& anObject, const TCollection_AsciiString& aTypeOfAttribute); + + virtual bool Addreference(const Handle(SALOMEDSImpl_SObject)& me, + const Handle(SALOMEDSImpl_SObject)& thereferencedObject); + + virtual bool RemoveReference(const Handle(SALOMEDSImpl_SObject)& me); + + virtual bool SetGUID(const Handle(SALOMEDSImpl_SObject)& anObject, const TCollection_AsciiString& theGUID); + virtual bool IsGUID(const Handle(SALOMEDSImpl_SObject)& anObject, const TCollection_AsciiString& theGUID); + + virtual void NewCommand(); + virtual void CommitCommand(); + virtual bool HasOpenCommand(); + virtual void AbortCommand(); + virtual void Undo(); + virtual void Redo(); + bool GetAvailableUndos(); + bool GetAvailableRedos(); + bool IsSaved(); + bool IsModified(); + virtual int UndoLimit(); + virtual void UndoLimit(const int); + + void CheckLocked(); + + virtual Handle(SALOMEDSImpl_Callback) SetOnAddSObject(const Handle(SALOMEDSImpl_Callback)& theCallback); + virtual Handle(SALOMEDSImpl_Callback) SetOnRemoveSObject(const Handle(SALOMEDSImpl_Callback)& theCallback); + + virtual bool SetName(const Handle(SALOMEDSImpl_SObject)& theSO, const TCollection_AsciiString& theValue); + + virtual bool SetComment(const Handle(SALOMEDSImpl_SObject)& theSO, const TCollection_AsciiString& theValue); + + virtual bool SetIOR(const Handle(SALOMEDSImpl_SObject)& theSO, const TCollection_AsciiString& theValue); + + virtual TCollection_AsciiString GetErrorCode() { return _errorCode; } + virtual bool IsError() { return _errorCode != ""; } + + virtual Handle(Standard_Transient) GetOwner() { return _study; } + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_StudyBuilder ) +}; +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_StudyHandle.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_StudyHandle.cxx new file mode 100644 index 000000000..4952318e6 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_StudyHandle.cxx @@ -0,0 +1,95 @@ +// File : SALOMEDSImpl_StudyHandle.cxx +// Author : Sergey LITONIN +// Module : SALOME + +#include "SALOMEDSImpl_StudyHandle.hxx" +#include +#include + +/* + Class : SALOMEDSImpl_StudyHandle + Description : This class is intended for storing information about + graphic representation of objects in dirrent views +*/ + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_StudyHandle, TDF_Attribute ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_StudyHandle, TDF_Attribute ) + +//======================================================================= +//function : GetID +//purpose : Get GUID of this attribute +//======================================================================= +const Standard_GUID& SALOMEDSImpl_StudyHandle::GetID() +{ + static Standard_GUID SALOMEDSImpl_StudyHandleID( "050C9555-4BA8-49bf-8F1C-086F0469A40B" ); + return SALOMEDSImpl_StudyHandleID; +} + +//======================================================================= +//function : SALOMEDSImpl_StudyHandle +//purpose : Empty Constructor +//======================================================================= +SALOMEDSImpl_StudyHandle::SALOMEDSImpl_StudyHandle() +{ + myHandle.Nullify(); +} + +//======================================================================= +//function : Set +//purpose : +//======================================================================= +Handle(SALOMEDSImpl_StudyHandle) SALOMEDSImpl_StudyHandle::Set(const TDF_Label& theLabel, + const Handle(SALOMEDSImpl_Study)& theStudy) +{ + Handle(SALOMEDSImpl_StudyHandle) A; + if (!theLabel.FindAttribute(GetID(), A)) { + A = new SALOMEDSImpl_StudyHandle(); + theLabel.AddAttribute(A); + } + + A->SetHandle(theStudy); + return A; +} + + +//======================================================================= +//function : ID +//purpose : Get GUID of this attribute +//======================================================================= +const Standard_GUID& SALOMEDSImpl_StudyHandle::ID () const +{ + return GetID(); +} + + +//======================================================================= +//function : NewEmpty +//purpose : Create new empty attribute +//======================================================================= +Handle(TDF_Attribute) SALOMEDSImpl_StudyHandle::NewEmpty () const +{ + return new SALOMEDSImpl_StudyHandle (); +} + + +//======================================================================= +//function : Restore +//purpose : Restore value of attribute with value of theWith one +//======================================================================= +void SALOMEDSImpl_StudyHandle::Restore( const Handle(TDF_Attribute)& theWith ) +{ + Handle(SALOMEDSImpl_StudyHandle) anAttr = Handle(SALOMEDSImpl_StudyHandle)::DownCast( theWith ); + if ( !anAttr.IsNull() ) SetHandle( anAttr->GetHandle() ); +} + +//======================================================================= +//function : Paste +//purpose : Paste value of current attribute to the value of entry one +//======================================================================= +void SALOMEDSImpl_StudyHandle::Paste( const Handle(TDF_Attribute)& theInto, + const Handle(TDF_RelocationTable)& ) const +{ + Handle(SALOMEDSImpl_StudyHandle) anAttr = Handle(SALOMEDSImpl_StudyHandle)::DownCast( theInto ); + if ( !anAttr.IsNull() ) anAttr->SetHandle( myHandle ); +} + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_StudyHandle.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_StudyHandle.hxx new file mode 100644 index 000000000..7b60940c9 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_StudyHandle.hxx @@ -0,0 +1,50 @@ +// File : SALOMEDSImpl_StudyHandle.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef SALOMEDSImpl_StudyHandle_HeaderFile +#define SALOMEDSImpl_StudyHandle_HeaderFile + +#include +#include +#include + +class Standard_GUID; +class Handle(TDF_Attribute); +class Handle(TDF_RelocationTable); + +/* + Class : SALOMEDSImpl_StudyHandle + Description : PRIVATE: This class is intended for storing of the study handle +*/ + +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_StudyHandle, TDF_Attribute ) + +#include "SALOMEDSImpl_Study.hxx" + +class Standard_EXPORT SALOMEDSImpl_StudyHandle : public TDF_Attribute +{ + +public: + SALOMEDSImpl_StudyHandle(); + ~SALOMEDSImpl_StudyHandle() { myHandle.Nullify(); } + + static Handle(SALOMEDSImpl_StudyHandle) Set(const TDF_Label& theLabel, const Handle(SALOMEDSImpl_Study)& theStudy); + static const Standard_GUID& GetID() ; + + void SetHandle(const Handle(SALOMEDSImpl_Study)& theStudy) { myHandle = theStudy; } + Handle(SALOMEDSImpl_Study) GetHandle() { return myHandle; } + const Standard_GUID& ID() const; + void Restore( const Handle(TDF_Attribute)& theWith ); + Handle(TDF_Attribute) NewEmpty() const; + void Paste( const Handle(TDF_Attribute)& theInto, + const Handle(TDF_RelocationTable)& ) const; + +private: + Handle(SALOMEDSImpl_Study) myHandle; + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_StudyHandle ) +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx new file mode 100644 index 000000000..71adf9b9b --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx @@ -0,0 +1,1258 @@ +// File : SALOMEDSImpl_StudyManager.cxx +// Author : Sergey RUIN +// Module : SALOME + +using namespace std; + +#include "SALOMEDSImpl_StudyManager.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "HDFexplorer.hxx" + +#include "SALOMEDSImpl_Attributes.hxx" +#include "SALOMEDSImpl_Tool.hxx" +#include "SALOMEDSImpl_SComponent.hxx" +#include + +#include "HDFOI.hxx" +#include +#include + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_StudyManager, MMgt_TShared ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_StudyManager, MMgt_TShared ) + +#define USE_CASE_LABEL_ID "0:2" +#define AUTO_SAVE_GUID "128268A3-71C9-4036-89B1-F81BD6A4FCF2" +#define AUTO_SAVE_TAG "0:8" +#define AUTO_SAVE_TIME_OUT_IN_SECONDS 1200 + +static void SaveAttributes(Handle(SALOMEDSImpl_SObject) SO, HDFgroup *hdf_group_sobject); +static void ReadAttributes(const Handle(SALOMEDSImpl_Study)&, const Handle(SALOMEDSImpl_SObject)&, HDFdataset* ); +static void BuildTree (const Handle(SALOMEDSImpl_Study)&, HDFgroup*); +static void Translate_IOR_to_persistentID (const Handle(SALOMEDSImpl_SObject)&, + SALOMEDSImpl_Driver*, bool isMultiFile, bool isASCII); + +//============================================================================ +/*! Function : SALOMEDSImpl_StudyManager + * Purpose : SALOMEDSImpl_StudyManager constructor + */ +//============================================================================ +SALOMEDSImpl_StudyManager::SALOMEDSImpl_StudyManager() +{ + _errorCode = ""; + _OCAFApp = new SALOMEDSImpl_OCAFApplication(); + _IDcounter = 0; + _OCAFApp->NewDocument("SALOME_STUDY", _clipboard); +} + +//============================================================================ +/*! Function : ~SALOMEDSImpl_StudyManager + * Purpose : SALOMEDSImpl_StudyManager destructor + */ +//============================================================================ +SALOMEDSImpl_StudyManager::~SALOMEDSImpl_StudyManager() +{ + // Destroy OCAF application + _OCAFApp.Nullify(); +} + + +//============================================================================ +/*! Function : NewStudy + * Purpose : Create a New Study of name study_name + */ +//==================================================T========================== +Handle(SALOMEDSImpl_Study) SALOMEDSImpl_StudyManager::NewStudy(const TCollection_AsciiString& study_name) +{ + _errorCode = ""; + + Handle(TDocStd_Document) Doc; + _OCAFApp->NewDocument("SALOME_STUDY",Doc); + + Handle(SALOMEDSImpl_Study) Study = new SALOMEDSImpl_Study(Doc, study_name); + + _IDcounter++; + Study->StudyId( _IDcounter ); + + // set Study properties + Handle(SALOMEDSImpl_AttributeStudyProperties) aProp = Study->GetProperties(); + OSD_Process aProcess; + Quantity_Date aDate = aProcess.SystemDate(); + aProp->SetModificationDate(aDate.Minute(), aDate.Hour(), aDate.Day(), aDate.Month(), aDate.Year()); + aProp->SetCreationMode(1); //"from scratch" + aProp->SetUserName(aProcess.UserName().ToCString()); + + return Study; +} + +//============================================================================ +/*! Function : Open + * Purpose : Open a Study from it's persistent reference + */ +//============================================================================ +Handle(SALOMEDSImpl_Study) SALOMEDSImpl_StudyManager::Open(const TCollection_AsciiString& aUrl) +{ + _errorCode = ""; + + // open the HDFFile + HDFfile *hdf_file =0; + HDFgroup *hdf_group_study_structure =0; + + char* aC_HDFUrl; + TCollection_AsciiString aHDFUrl; + bool isASCII = false; + if (HDFascii::isASCII(aUrl.ToCString())) { + isASCII = true; + char* aResultPath = HDFascii::ConvertFromASCIIToHDF(aUrl.ToCString()); + aC_HDFUrl = new char[strlen(aResultPath) + 19]; + sprintf(aC_HDFUrl, "%shdf_from_ascii.hdf", aResultPath); + delete(aResultPath); + aHDFUrl = aC_HDFUrl; + delete aC_HDFUrl; + } else { + aHDFUrl = aUrl; + } + + hdf_file = new HDFfile((char*)aHDFUrl.ToCString()); + try { + hdf_file->OpenOnDisk(HDF_RDONLY);// mpv: was RDWR, but opened file can be write-protected too + } + catch (HDFexception) + { + char eStr[strlen(aUrl.ToCString())+17]; + sprintf(eStr,"Can't open file %s",aUrl.ToCString()); + _errorCode = TCollection_AsciiString(eStr); + return NULL; + } + + // Temporary aStudyUrl in place of study name + Handle(TDocStd_Document) Doc; + _OCAFApp->NewDocument("SALOME_STUDY",Doc); + + Handle(SALOMEDSImpl_Study) Study = new SALOMEDSImpl_Study(Doc, aUrl); + + _IDcounter++; + Study->StudyId( _IDcounter ); + + // Assign the value of the URL in the study object + Study->URL (aUrl); + + SALOMEDSImpl_AttributePersistentRef::Set(Doc->Main(), aUrl); + + if (!hdf_file->ExistInternalObject("STUDY_STRUCTURE")) { + _errorCode = "Study is empty"; + return Study; + } + + //Create the Structure of the OCAF Document + hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file); + + Handle(TDF_Data) DF = Doc->GetData(); + try { + BuildTree (Study, hdf_group_study_structure); + } + catch (HDFexception) + { + char eStr[strlen(aUrl.ToCString())+17]; + sprintf(eStr,"Can't open file %s", aUrl.ToCString()); + _errorCode = TCollection_AsciiString(eStr); + return NULL; + } + + hdf_file->CloseOnDisk(); + + if (isASCII) { + Handle(TColStd_HSequenceOfAsciiString) aFilesToRemove = new TColStd_HSequenceOfAsciiString; + aFilesToRemove->Append(aHDFUrl); + SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true); + } + + delete hdf_file; // all related hdf objects will be deleted + + return Study; +} + + + +//============================================================================ +/*! Function : Close + * Purpose : Close a study. + * If the study hasn't been saved, ask the user to confirm the + * close action without saving + */ + +//============================================================================ +void SALOMEDSImpl_StudyManager::Close(const Handle(SALOMEDSImpl_Study)& aStudy) +{ + _errorCode = ""; + + if(aStudy.IsNull()) { + _errorCode = "Study is null"; + return; + } + + aStudy->Close(); +} + +//============================================================================ +/*! Function : Save + * Purpose : Save a Study to it's persistent reference + */ +//============================================================================ +bool SALOMEDSImpl_StudyManager::Save(const Handle(SALOMEDSImpl_Study)& aStudy, + SALOMEDSImpl_DriverFactory* aFactory, + bool theMultiFile) +{ + _errorCode = ""; + + TCollection_AsciiString url = aStudy->URL(); + if (url.IsEmpty()) { + _errorCode = "No path specified to save the study. Nothing done"; + return false; + } + else { + return Impl_SaveAs(url,aStudy, aFactory, theMultiFile, false); + } + + return false; +} + +bool SALOMEDSImpl_StudyManager::SaveASCII(const Handle(SALOMEDSImpl_Study)& aStudy, + SALOMEDSImpl_DriverFactory* aFactory, + bool theMultiFile) +{ + _errorCode = ""; + + TCollection_AsciiString url = aStudy->URL(); + if (url.IsEmpty()) { + _errorCode = "No path specified to save the study. Nothing done"; + return false; + } + else { + return Impl_SaveAs(url,aStudy, aFactory, theMultiFile, true); + } + + return false; +} + +//============================================================================= +/*! Function : SaveAs + * Purpose : Save a study to the persistent reference aUrl + */ +//============================================================================ +bool SALOMEDSImpl_StudyManager::SaveAs(const TCollection_AsciiString& aUrl, + const Handle(SALOMEDSImpl_Study)& aStudy, + SALOMEDSImpl_DriverFactory* aFactory, + bool theMultiFile) +{ + _errorCode = ""; + return Impl_SaveAs(aUrl,aStudy, aFactory, theMultiFile, false); +} + +bool SALOMEDSImpl_StudyManager::SaveAsASCII(const TCollection_AsciiString& aUrl, + const Handle(SALOMEDSImpl_Study)& aStudy, + SALOMEDSImpl_DriverFactory* aFactory, + bool theMultiFile) +{ + _errorCode = ""; + return Impl_SaveAs(aUrl,aStudy, aFactory, theMultiFile, true); +} + +//============================================================================ +/*! Function : GetOpenStudies + * Purpose : Get name list of open studies in the session + */ +//============================================================================ +Handle(TColStd_HSequenceOfTransient) SALOMEDSImpl_StudyManager::GetOpenStudies() +{ + _errorCode = ""; + Handle(TColStd_HSequenceOfTransient) aList = new TColStd_HSequenceOfTransient; + + int nbDocs = _OCAFApp->NbDocuments(); + + if(nbDocs == 0) { + _errorCode = "No active study in this session"; + return aList; + } + else { + Handle(SALOMEDSImpl_Study) aStudy; + Handle(CDF_Session) S = CDF_Session::CurrentSession(); + CDF_DirectoryIterator it (S->Directory()); + for (;it.MoreDocument();it.NextDocument()) { + Handle(TDocStd_Document) D = Handle(TDocStd_Document)::DownCast(it.Document()); + if(D == _clipboard) continue; + aStudy = SALOMEDSImpl_Study::GetStudy(D->Main()); + if(aStudy.IsNull()) continue; + aList->Append(aStudy); + } + } + + return aList; +} + +//============================================================================ +/*! Function : GetStudyByName + * Purpose : Get a study from its name + */ +//============================================================================ +Handle(SALOMEDSImpl_Study) SALOMEDSImpl_StudyManager::GetStudyByName(const TCollection_AsciiString& aStudyName) +{ + _errorCode = ""; + + Handle(SALOMEDSImpl_Study) aStudy; + int nbDocs = _OCAFApp->NbDocuments(); + + if(nbDocs == 0) { + _errorCode = "No active study in this session"; + return aStudy; + } + else { + Handle(CDF_Session) S = CDF_Session::CurrentSession(); + CDF_DirectoryIterator it (S->Directory()); + for (;it.MoreDocument();it.NextDocument()) { + Handle(TDocStd_Document) D = Handle(TDocStd_Document)::DownCast(it.Document()); + if(D == _clipboard) continue; + aStudy = SALOMEDSImpl_Study::GetStudy(D->Main()); + if(aStudy.IsNull()) continue; + if(aStudy->Name() == aStudyName) return aStudy; + } + } + + _errorCode = TCollection_AsciiString("Found no study with the name ")+aStudyName; + return aStudy; +} + +//============================================================================ +/*! Function : GetStudyByID + * Purpose : Get a study from its ID + */ +//============================================================================ +Handle(SALOMEDSImpl_Study) SALOMEDSImpl_StudyManager::GetStudyByID(int aStudyID) +{ + _errorCode = ""; + Handle(SALOMEDSImpl_Study) aStudy; + int nbDocs = _OCAFApp->NbDocuments(); + + if(nbDocs == 0) { + _errorCode = "No active study in this session"; + return aStudy; + } + else { + Handle(CDF_Session) S = CDF_Session::CurrentSession(); + CDF_DirectoryIterator it (S->Directory()); + for (;it.MoreDocument();it.NextDocument()) { + Handle(TDocStd_Document) D = Handle(TDocStd_Document)::DownCast(it.Document()); + if(D == _clipboard) continue; + aStudy = SALOMEDSImpl_Study::GetStudy(D->Main()); + if(aStudy.IsNull()) continue; + if(aStudy->StudyId() == aStudyID) return aStudy; + } + } + + _errorCode = "Found no study with the given ID"; + return aStudy; +} + +//============================================================================= +/*! Function : _SaveProperties + * Purpose : save the study properties in HDF file + */ +//============================================================================ +bool SALOMEDSImpl_StudyManager::Impl_SaveProperties(const Handle(SALOMEDSImpl_Study)& aStudy, HDFgroup *hdf_group) +{ + _errorCode = ""; + + HDFdataset *hdf_dataset = 0; + hdf_size size[1]; + hdf_int32 name_len; + + // add modifications list (user and date of save) + Handle(SALOMEDSImpl_AttributeStudyProperties) aProp = aStudy->GetProperties(); + Handle(SALOMEDSImpl_StudyBuilder) SB= aStudy->NewBuilder(); + int aLocked = aProp->IsLocked(); + if (aLocked) aProp->SetLocked(Standard_False); + + OSD_Process aProcess; + Quantity_Date aDate = aProcess.SystemDate(); + aProp->SetUserName(aProcess.UserName().ToCString()); + aProp->SetModificationDate(aDate.Minute(), aDate.Hour(), aDate.Day(), aDate.Month(), aDate.Year()); + + if (aLocked) aProp->SetLocked(Standard_True); + + Handle(TColStd_HSequenceOfExtendedString) aNames; + Handle(TColStd_HSequenceOfInteger) aMinutes, aHours, aDays, aMonths, aYears; + + aNames = aProp->GetUserNames(); + aProp->GetModificationDates(aMinutes, aHours, aDays, aMonths, aYears); + + int aLength = 0, anIndex, i; + for(i=1; i<=aNames->Length(); i++) + aLength += aNames->Value(i).Length() + 1; + + //string length: 1 byte = locked flag, 1 byte = modified flag, (12 + name length + 1) for each name and date, "zero" byte + char* aProperty = new char[3 + aLength + 12 * aNames->Length()]; + + + sprintf(aProperty,"%c%c", (char)aProp->GetCreationMode(), (aProp->IsLocked())?'l':'u'); + + aLength = aNames->Length(); + int a = 2; + for(anIndex = 1; anIndex <= aLength; anIndex++) { + sprintf(&(aProperty[a]),"%2d%2d%2d%2d%4d%s", + (int)(aMinutes->Value(anIndex)), + (int)(aHours->Value(anIndex)), + (int)(aDays->Value(anIndex)), + (int)(aMonths->Value(anIndex)), + (int)(aYears->Value(anIndex)), + TCollection_AsciiString(aNames->Value(anIndex)).ToCString()); + a = strlen(aProperty); + aProperty[a++] = 1; + } + aProperty[a] = 0; + + name_len = (hdf_int32) a; + size[0] = name_len + 1 ; + hdf_dataset = new HDFdataset("AttributeStudyProperties",hdf_group,HDF_STRING,size,1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk(aProperty); + hdf_dataset->CloseOnDisk(); + hdf_dataset=0; //will be deleted by hdf_sco_group destructor + delete [] aProperty; + + aProp->SetModified(0); + return true; +} + +//============================================================================= +/*! Function : _SaveAs + * Purpose : save the study in HDF file + */ +//============================================================================ +bool SALOMEDSImpl_StudyManager::Impl_SaveAs(const TCollection_AsciiString& aUrl, + const Handle(SALOMEDSImpl_Study)& aStudy, + SALOMEDSImpl_DriverFactory* aFactory, + bool theMultiFile, + bool theASCII) +{ + // HDF File will be composed of differents part : + // * For each ComponentDataType, all data created by the component + // Informations in data group hdf_group_datacomponent + // * Study Structure -> Exactly what is contained in OCAF document + // Informations in data group hdf_group_study_structure + + _errorCode = ""; + + HDFfile *hdf_file=0; + HDFgroup *hdf_group_study_structure =0; + HDFgroup *hdf_sco_group =0; + HDFgroup *hdf_sco_group2 =0; + + HDFgroup *hdf_group_datacomponent =0; + HDFdataset *hdf_dataset =0; + hdf_size size[1]; + hdf_int32 name_len = 0; + char *component_name = 0; + + int aLocked = aStudy->GetProperties()->IsLocked(); + if (aLocked) aStudy->GetProperties()->SetLocked(false); + + Handle(SALOMEDSImpl_StudyBuilder) SB= aStudy->NewBuilder(); + map aMapTypeDriver; + + if(aStudy.IsNull()) { + _errorCode = "Study is null"; + return false; + } + + try + { + // mpv 15.12.2003: for saving components we have to load all data from all modules + SALOMEDSImpl_SComponentIterator itcomponent1 = aStudy->NewComponentIterator(); + for (; itcomponent1.More(); itcomponent1.Next()) + { + Handle(SALOMEDSImpl_SComponent) sco = itcomponent1.Value(); + + // if there is an associated Engine call its method for saving + TCollection_AsciiString IOREngine; + try { + if (!sco->ComponentIOR(IOREngine)) { + TCollection_AsciiString aCompType = sco->GetComment(); + if (!aCompType.IsEmpty()) { + + SALOMEDSImpl_Driver* aDriver = aFactory->GetDriverByType(aCompType); + aMapTypeDriver[aCompType.ToCString()] = aDriver; + + if (aDriver != NULL) { + if(!SB->LoadWith(sco, aDriver)) { + _errorCode = SB->GetErrorCode(); + return false; + } + } + } + } + } catch(...) { + _errorCode = "Can not restore information to resave it"; + return false; + } + } + + TCollection_AsciiString anOldName = aStudy->Name(); + aStudy->URL(aUrl); + + // To change for Save + // Do not have to do a new file but just a Open??? Rewrite all informations after erasing evrything?? + hdf_file = new HDFfile(aUrl.ToCString()); + hdf_file->CreateOnDisk(); + + //----------------------------------------------------------------------- + // 1 - Create a groupe for each SComponent and Update the PersistanceRef + //----------------------------------------------------------------------- + hdf_group_datacomponent = new HDFgroup("DATACOMPONENT",hdf_file); + hdf_group_datacomponent->CreateOnDisk(); + + SALOMEDSImpl_SComponentIterator itcomponent = aStudy->NewComponentIterator(); + + //SRN: Added 17 Nov, 2003 + Handle(SALOMEDSImpl_SObject) anAutoSaveSO = aStudy->FindObjectID(AUTO_SAVE_TAG); + //SRN: End + for (; itcomponent.More(); itcomponent.Next()) + { + Handle(SALOMEDSImpl_SComponent) sco = itcomponent.Value(); + + TCollection_AsciiString scoid = sco->GetID(); + hdf_sco_group = new HDFgroup(scoid.ToCString(), hdf_group_datacomponent); + hdf_sco_group->CreateOnDisk(); + + TCollection_AsciiString componentDataType = sco->ComponentDataType(); + + //SRN: Added 17 Nov 2003: If there is a specified attribute, the component peforms a special save + if(!anAutoSaveSO.IsNull() && SB->IsGUID(sco, AUTO_SAVE_GUID)) { + + Handle(SALOMEDSImpl_AttributeTableOfString) aTable; + if(anAutoSaveSO->GetLabel().FindAttribute(SALOMEDSImpl_AttributeTableOfString::GetID(), aTable)) { + Standard_Integer nbRows = aTable->GetNbRows(), k, aTimeOut = 0; + if(nbRows > 0 && aTable->GetNbColumns() > 1) { + + Handle(TColStd_HSequenceOfExtendedString) aRow; + for(k=1; k<=nbRows; k++) { + aRow = aTable->GetRowData(k); + if (aRow->Value(1) == componentDataType) { + TCollection_AsciiString anEntry = TCollection_AsciiString(aRow->Value(2)); + Handle(SALOMEDSImpl_SObject) aCompSpecificSO = aStudy->FindObjectID(anEntry); + if(!aCompSpecificSO.IsNull()) { + Handle(SALOMEDSImpl_AttributeInteger) anInteger; + if(aCompSpecificSO->GetLabel().FindAttribute(SALOMEDSImpl_AttributeInteger::GetID(), anInteger)) { + anInteger->SetValue(-1); + while(anInteger->Value() < 0) { sleep(2); if(++aTimeOut > AUTO_SAVE_TIME_OUT_IN_SECONDS) break; } + } // if(aCompSpecificSO->FindAttribute(anInteger, "AttributeInteger")) + } // if(!CORBA::is_nil(aCompSpecificSO)) + } // if (strcmp(aRow[0], componentDataType) == 0) + } // for + + } // if(nbRows > 0 && aTable->GetNbColumns() > 1) + + } // if(anAutoSaveSO->FindAttribute(aTable, "AttributeTableOfString") + + } // if(SB->IsGUID(AUTO_SAVE_GUID) + + //SRN: End + TCollection_AsciiString IOREngine; + if (sco->ComponentIOR(IOREngine)) + { + SALOMEDSImpl_Driver* Engine = NULL; + if(aMapTypeDriver.find(componentDataType.ToCString()) != aMapTypeDriver.end()) { + // we have found the associated engine to write the data + Engine = aMapTypeDriver[componentDataType.ToCString()]; + } + else { + Engine = aFactory->GetDriverByIOR(IOREngine); + } + + if (Engine != NULL) + { + unsigned char* aStream; + long length; + + if (theASCII) aStream = Engine->SaveASCII(sco, + SALOMEDSImpl_Tool::GetDirFromPath(aUrl), + length, + theMultiFile); + else aStream = Engine->Save(sco, + SALOMEDSImpl_Tool::GetDirFromPath(aUrl), + length, + theMultiFile); + HDFdataset *hdf_dataset; + hdf_size aHDFSize[1]; + if(length > 0) { //The component saved some auxiliary files, then put them into HDF file + + aHDFSize[0] = length; + + HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group, HDF_STRING, aHDFSize, 1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk(aStream); //Save the stream in the HDF file + hdf_dataset->CloseOnDisk(); + } + + // store multifile state + aHDFSize[0] = 2; + hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group, HDF_STRING, aHDFSize, 1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk((void*)(theMultiFile?"M":"S")); // save: multi or single + hdf_dataset->CloseOnDisk(); + hdf_dataset=0; //will be deleted by hdf_sco_AuxFiles destructor + // store ASCII state + aHDFSize[0] = 2; + hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group, HDF_STRING, aHDFSize, 1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk((void*)(theASCII?"A":"B")); // save: ASCII or BINARY + hdf_dataset->CloseOnDisk(); + hdf_dataset=0; //will be deleted by hdf_sco_AuxFiles destructor + // Creation of the persistance reference attribute + Translate_IOR_to_persistentID (sco, Engine, theMultiFile, theASCII); + + if(aStream != NULL) delete [] aStream; + } + } + hdf_sco_group->CloseOnDisk(); + hdf_sco_group=0; // will be deleted by hdf_group_datacomponent destructor + } + hdf_group_datacomponent->CloseOnDisk(); + hdf_group_datacomponent =0; // will be deleted by hdf_file destructor + + //----------------------------------------------------------------------- + //3 - Write the Study Structure + //----------------------------------------------------------------------- + hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file); + hdf_group_study_structure->CreateOnDisk(); + // save component attributes + SALOMEDSImpl_SComponentIterator itcomp = aStudy->NewComponentIterator(); + for (; itcomp.More(); itcomp.Next()) + { + Handle(SALOMEDSImpl_SComponent) SC = itcomp.Value(); + TCollection_AsciiString scid = SC->GetID(); + hdf_sco_group2 = new HDFgroup(scid.ToCString(), hdf_group_study_structure); + hdf_sco_group2->CreateOnDisk(); + SaveAttributes(SC, hdf_sco_group2); + // ComponentDataType treatment + component_name = SC->ComponentDataType().ToCString(); + name_len = (hdf_int32)strlen(component_name); + size[0] = name_len +1 ; + hdf_dataset = new HDFdataset("COMPONENTDATATYPE",hdf_sco_group2,HDF_STRING,size,1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk(component_name); + hdf_dataset->CloseOnDisk(); + hdf_dataset=0; //will be deleted by hdf_sco_group destructor + Impl_SaveObject(SC, hdf_sco_group2); + hdf_sco_group2->CloseOnDisk(); + hdf_sco_group2=0; // will be deleted by hdf_group_study_structure destructor + } + + //----------------------------------------------------------------------- + //4 - Write the Study UseCases Structure + //----------------------------------------------------------------------- + Handle(SALOMEDSImpl_SObject) aSO = aStudy->FindObjectID(USE_CASE_LABEL_ID); + if (!aSO.IsNull()) { + HDFgroup *hdf_soo_group = new HDFgroup(USE_CASE_LABEL_ID,hdf_group_study_structure); + hdf_soo_group->CreateOnDisk(); + SaveAttributes(aSO, hdf_soo_group); + Impl_SaveObject(aSO, hdf_soo_group); + hdf_soo_group->CloseOnDisk(); + hdf_soo_group=0; // will be deleted by hdf_group_study_structure destructor + } + + if (aLocked) aStudy->GetProperties()->SetLocked(true); + //----------------------------------------------------------------------- + //5 - Write the Study Properties + //----------------------------------------------------------------------- + name_len = (hdf_int32) aStudy->Name().Length(); + size[0] = name_len +1 ; + hdf_dataset = new HDFdataset("STUDY_NAME",hdf_group_study_structure,HDF_STRING,size,1); + hdf_dataset->CreateOnDisk(); + char* studid = aStudy->Name().ToCString(); + hdf_dataset->WriteOnDisk(studid); + hdf_dataset->CloseOnDisk(); + hdf_dataset=0; // will be deleted by hdf_group_study_structure destructor + + Impl_SaveProperties(aStudy, hdf_group_study_structure); + + hdf_group_study_structure->CloseOnDisk(); + hdf_file->CloseOnDisk(); + + aStudy->IsSaved(true); + hdf_group_study_structure =0; // will be deleted by hdf_file destructor + delete hdf_file; // recursively deletes all hdf objects... + } + catch (HDFexception) + { + _errorCode = "HDFexception ! "; + return false; + } + if (theASCII) { // save file in ASCII format + HDFascii::ConvertFromHDFToASCII(aUrl.ToCString(), true); + } + + return true; +} + +//============================================================================ +/*! Function : Impl_SaveObject + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_StudyManager::Impl_SaveObject(const Handle(SALOMEDSImpl_SObject)& SC, + HDFgroup *hdf_group_datatype) +{ + _errorCode = ""; + + // Write in group hdf_group_datatype all informations of SObject SC + // Iterative function to parse all SObjects under a SComponent + + HDFgroup *hdf_group_sobject = 0; + + TDF_ChildIterator itchild(SC->GetLabel()); + for (; itchild.More(); itchild.Next()) + { + + // mpv: don't save empty labels + TDF_AttributeIterator AI1(itchild.Value()); + if (!AI1.More()) { //No attributes on the label + TDF_ChildIterator subchild(SC->GetLabel()); + if (!subchild.More()) { + continue; + } + subchild.Initialize(SC->GetLabel(), true); + bool anEmpty = true; + for (; subchild.More() && anEmpty; subchild.Next()) { + TDF_AttributeIterator AI2(subchild.Value()); + if (AI2.More()) anEmpty = false; //There are attributes on the child label + } + if (anEmpty) continue; + } + + Handle(SALOMEDSImpl_SObject) SO = SALOMEDSImpl_Study::SObject(itchild.Value()); + + char* scoid = (char*) SO->GetID().ToCString(); + hdf_group_sobject = new HDFgroup(scoid, hdf_group_datatype); + hdf_group_sobject->CreateOnDisk(); + SaveAttributes(SO, hdf_group_sobject); + Impl_SaveObject(SO, hdf_group_sobject); + hdf_group_sobject->CloseOnDisk(); + hdf_group_sobject =0; // will be deleted by father hdf object destructor + } + + return true; +} + +//============================================================================ +/*! Function : Impl_SubstituteSlash + * Purpose : + */ +//============================================================================ +TCollection_AsciiString SALOMEDSImpl_StudyManager::Impl_SubstituteSlash(const TCollection_AsciiString& aUrl) +{ + _errorCode = ""; + + TCollection_ExtendedString theUrl(aUrl); + Standard_ExtCharacter val1 = ToExtCharacter('/'); + Standard_ExtCharacter val2 = ToExtCharacter(':'); + theUrl.ChangeAll(val1,val2); + return theUrl; +} + +//============================================================================ +/*! Function : GetDocumentOfStudy + * Purpose : + */ +//============================================================================ +Handle(TDocStd_Document) SALOMEDSImpl_StudyManager::GetDocumentOfStudy(const Handle(SALOMEDSImpl_Study)& theStudy) +{ + _errorCode = ""; + return theStudy->_doc; +} + +//============================================================================ +/*! Function : CanCopy + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_StudyManager::CanCopy(const Handle(SALOMEDSImpl_SObject)& theObject, + SALOMEDSImpl_Driver* theEngine) +{ + _errorCode = ""; + Handle(SALOMEDSImpl_SComponent) aComponent = theObject->GetFatherComponent(); + if (aComponent.IsNull()) return false; + if (aComponent->GetLabel() == theObject->GetLabel()) return false; + TCollection_AsciiString IOREngine; + if (!aComponent->ComponentIOR(IOREngine)) return false; + if (theEngine == NULL) return false; + return theEngine->CanCopy(theObject); +} + +//============================================================================ +/*! Function : CopyLabel + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_StudyManager::CopyLabel(const Handle(SALOMEDSImpl_Study)& theSourceStudy, + SALOMEDSImpl_Driver* theEngine, + const Standard_Integer theSourceStartDepth, + const TDF_Label& theSource, + const TDF_Label& theDestinationMain) +{ + _errorCode = ""; + + int a; + TDF_Label aTargetLabel = theDestinationMain; + TDF_Label aAuxTargetLabel = theDestinationMain.Father().FindChild(2); + for(a = theSource.Depth() - theSourceStartDepth; a > 0 ; a--) { + TDF_Label aSourceLabel = theSource; + for(int aNbFather = 1; aNbFather < a; aNbFather++) aSourceLabel = aSourceLabel.Father(); + aTargetLabel = aTargetLabel.FindChild(aSourceLabel.Tag()); + aAuxTargetLabel = aAuxTargetLabel.FindChild(aSourceLabel.Tag()); + } + // iterate attributes + TDF_AttributeIterator anAttrIterator(theSource); + Handle(TDF_RelocationTable) aRT = new TDF_RelocationTable(); + for(; anAttrIterator.More(); anAttrIterator.Next()) { + Handle(TDF_Attribute) anAttr = anAttrIterator.Value(); + if (!Handle(SALOMEDSImpl_AttributeTreeNode)::DownCast(anAttr).IsNull()) continue; // never copy tree node attribute + if (!Handle(SALOMEDSImpl_AttributeTarget)::DownCast(anAttr).IsNull()) continue; // and target attribute + + if (!Handle(SALOMEDSImpl_AttributeReference)::DownCast(anAttr).IsNull()) { // reference copied as Comment in aux tree + TDF_Label aReferenced = Handle(SALOMEDSImpl_AttributeReference)::DownCast(anAttr)->Get(); + TCollection_AsciiString anEntry; + TDF_Tool::Entry(aReferenced, anEntry); + // store the value of name attribute of referenced label + Handle(SALOMEDSImpl_AttributeName) aNameAttribute; + if (aReferenced.FindAttribute(SALOMEDSImpl_AttributeName::GetID(), aNameAttribute)) { + anEntry += " "; + anEntry += aNameAttribute->Value(); + } + SALOMEDSImpl_AttributeComment::Set(aAuxTargetLabel, TCollection_ExtendedString(anEntry)); + continue; + } + + if (!Handle(SALOMEDSImpl_AttributeIOR)::DownCast(anAttr).IsNull()) { // IOR => ID and TMPFile of Engine + TCollection_AsciiString anEntry; + TDF_Tool::Entry(theSource, anEntry); + Handle(SALOMEDSImpl_SObject) aSO = theSourceStudy->FindObjectID(anEntry.ToCString()); + int anObjID; + long aLen; + unsigned char* aStream = theEngine->CopyFrom(aSO, anObjID, aLen); + TCollection_ExtendedString aResStr(""); + for(a = 0; a < aLen; a++) { + aResStr += TCollection_ExtendedString(ToExtCharacter((Standard_Character)aStream[a])); + } + if(aStream != NULL) delete [] aStream; + SALOMEDSImpl_AttributeInteger::Set(aAuxTargetLabel, anObjID); + SALOMEDSImpl_AttributeName::Set(aAuxTargetLabel, aResStr); + continue; + } + Handle(TDF_Attribute) aNewAttribute = anAttr->NewEmpty(); + aTargetLabel.AddAttribute(aNewAttribute); + anAttr->Paste(aNewAttribute, aRT); + } + + return true; +} + +//============================================================================ +/*! Function : Copy + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_StudyManager::Copy(const Handle(SALOMEDSImpl_SObject)& theObject, + SALOMEDSImpl_Driver* theEngine) +{ + _errorCode = ""; + + // adoptation for alliances datamodel copy: without IOR attributes !!! + bool aStructureOnly; // copy only SObjects and attributes without component help + aStructureOnly = !theObject->GetLabel().IsAttribute(SALOMEDSImpl_AttributeIOR::GetID()); + + // get component-engine + Handle(SALOMEDSImpl_Study) aStudy = theObject->GetStudy(); + + // CAF document of current study usage + Handle(TDocStd_Document) aDocument = GetDocumentOfStudy(aStudy); + if (aDocument.IsNull()) { + _errorCode = "OCAF document is null"; + return false; + } + + //Clear the clipboard + _clipboard->Main().Root().ForgetAllAttributes(Standard_True); + _OCAFApp->Close(_clipboard); + Handle(TDocStd_Document) aDoc; + _OCAFApp->NewDocument("SALOME_STUDY", aDoc); + _clipboard = aDoc; + + // set component data type to the name attribute of root label + if (!aStructureOnly) { + SALOMEDSImpl_AttributeComment::Set(_clipboard->Main().Root(), + TCollection_ExtendedString(theEngine->ComponentDataType())); + } + // set to the Root label integer attribute: study id + SALOMEDSImpl_AttributeInteger::Set(_clipboard->Main().Root(), aStudy->StudyId()); + // iterate all theObject's label children + TDF_Label aStartLabel = theObject->GetLabel(); + Standard_Integer aSourceStartDepth = aStartLabel.Depth(); + + // copy main source label + CopyLabel(aStudy, theEngine, aSourceStartDepth, aStartLabel, _clipboard->Main()); + + // copy all subchildren of the main source label (all levels) + TDF_ChildIterator anIterator(aStartLabel, Standard_True); + for(; anIterator.More(); anIterator.Next()) { + CopyLabel(aStudy, theEngine, aSourceStartDepth, anIterator.Value(), _clipboard->Main()); + } + + return true; +} +//============================================================================ +/*! Function : CanPaste + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_StudyManager::CanPaste(const Handle(SALOMEDSImpl_SObject)& theObject, + SALOMEDSImpl_Driver* theEngine) +{ + _errorCode = ""; + + if (_clipboard.IsNull()) { + _errorCode = "Clipboard is null"; + return false; + } + + Handle(SALOMEDSImpl_AttributeComment) aCompName; + if (!_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID(), aCompName)) { + _errorCode = "Clipboard has no component type"; + return false; + } + Handle(SALOMEDSImpl_AttributeInteger) anObjID; + if (!_clipboard->Main().Father().FindChild(2).FindAttribute(SALOMEDSImpl_AttributeInteger::GetID(), anObjID)) { + _errorCode = "Clipboard has no object id"; + return false; + } + Handle(SALOMEDSImpl_SComponent) aComponent = theObject->GetFatherComponent(); + if (aComponent.IsNull()) { + _errorCode = "Object doesn't belong to component"; + return false; + } + + TCollection_AsciiString IOREngine; + if (!aComponent->ComponentIOR(IOREngine)) { + _errorCode = "component has no IOR"; + return false; + } + return theEngine->CanPaste(aCompName->Value(), anObjID->Value()); +} + +//============================================================================ +/*! Function : PasteLabel + * Purpose : + */ +//============================================================================ +TDF_Label SALOMEDSImpl_StudyManager::PasteLabel(const Handle(SALOMEDSImpl_Study)& theDestinationStudy, + SALOMEDSImpl_Driver* theEngine, + const TDF_Label& theSource, + const TDF_Label& theDestinationStart, + const int theCopiedStudyID, + const bool isFirstElement) +{ + _errorCode = ""; + + // get corresponding source, target and auxiliary labels + TDF_Label aTargetLabel = theDestinationStart; + + TDF_Label aAuxSourceLabel = theSource.Root().FindChild(2); + int a; + if (!isFirstElement) { + for(a = theSource.Depth() - 1; a > 0 ; a--) { + TDF_Label aSourceLabel = theSource; + for(int aNbFather = 1; aNbFather < a; aNbFather++) aSourceLabel = aSourceLabel.Father(); + aTargetLabel = aTargetLabel.FindChild(aSourceLabel.Tag()); + aAuxSourceLabel = aAuxSourceLabel.FindChild(aSourceLabel.Tag()); + } + } + + // check auxiliary label for TMPFile => IOR + Handle(SALOMEDSImpl_AttributeName) aNameAttribute; + if (aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID(), aNameAttribute)) { + Handle(SALOMEDSImpl_AttributeInteger) anObjID; + + aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeInteger::GetID(), anObjID); + Handle(SALOMEDSImpl_AttributeComment) aComponentName; + theSource.Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID(), aComponentName); + TCollection_AsciiString aCompName = aComponentName->Value(); + + if (theEngine->CanPaste(aCompName, anObjID->Value())) { + TCollection_ExtendedString aTMPStr = aNameAttribute->Value(); + int aLen = aTMPStr.Length(); + unsigned char* aStream = NULL; + if(aLen > 0) { + aStream = new unsigned char[aLen+10]; + for(a = 0; a < aLen; a++) { + aStream[a] = ToCharacter(aTMPStr.Value(a+1)); + } + } + + TCollection_AsciiString anEntry; + TDF_Tool::Entry(aTargetLabel, anEntry); + Handle(SALOMEDSImpl_SObject) aPastedSO = theDestinationStudy->FindObjectID(anEntry); + + if (isFirstElement) { + TCollection_AsciiString aDestEntry = theEngine->PasteInto(aStream, + aLen, + anObjID->Value(), + aPastedSO->GetFatherComponent()); + TDF_Tool::Label(theDestinationStart.Data(), aDestEntry, aTargetLabel); + } else + theEngine->PasteInto(aStream, aLen, anObjID->Value(), aPastedSO); + + if(aStream != NULL) delete []aStream; + } + } + + // iterate attributes + TDF_AttributeIterator anAttrIterator(theSource); + Handle(TDF_RelocationTable) aRT = new TDF_RelocationTable(); + for(; anAttrIterator.More(); anAttrIterator.Next()) { + Handle(TDF_Attribute) anAttr = anAttrIterator.Value(); + if (aTargetLabel.FindAttribute(anAttr->ID(), anAttr)) { + aTargetLabel.ForgetAttribute(anAttr->ID()); + anAttr = anAttrIterator.Value(); + } + Handle(TDF_Attribute) aNewAttribute = anAttr->NewEmpty(); + aTargetLabel.AddAttribute(aNewAttribute); + anAttr->Paste(aNewAttribute, aRT); + } + + // check auxiliary label for Comment => reference or name attribute of the referenced object + Handle(SALOMEDSImpl_AttributeComment) aCommentAttribute; + if (aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeComment::GetID(), aCommentAttribute)) { + char * anEntry = new char[aCommentAttribute->Value().Length() + 1]; + strcpy(anEntry, TCollection_AsciiString(aCommentAttribute->Value()).ToCString()); + char* aNameStart = strchr(anEntry, ' '); + if (aNameStart) { + *aNameStart = '\0'; + aNameStart++; + } + if (theCopiedStudyID == theDestinationStudy->StudyId()) { // if copy to the same study, reanimate reference + TDF_Label aRefLabel; + TDF_Tool::Label(aTargetLabel.Data(), anEntry, aRefLabel); + SALOMEDSImpl_AttributeReference::Set(aTargetLabel, aRefLabel); + // target attributes structure support + SALOMEDSImpl_AttributeTarget::Set(aRefLabel)->Add(SALOMEDSImpl_Study::SObject(aTargetLabel)); + } else { + if (aNameStart) SALOMEDSImpl_AttributeName::Set(aTargetLabel, aNameStart); + else SALOMEDSImpl_AttributeName::Set(aTargetLabel, TCollection_ExtendedString("Reference to:")+anEntry); + } + delete [] anEntry; + } + + return aTargetLabel; +} + +//============================================================================ +/*! Function : Paste + * Purpose : + */ +//============================================================================ +Handle(SALOMEDSImpl_SObject) SALOMEDSImpl_StudyManager::Paste(const Handle(SALOMEDSImpl_SObject)& theObject, + SALOMEDSImpl_Driver* theEngine) +{ + _errorCode = ""; + + Handle(SALOMEDSImpl_Study) aStudy = theObject->GetStudy(); + + // if study is locked, then paste can't be done + if (aStudy->GetProperties()->IsLocked()) { + _errorCode = "LockProtection"; + throw LockProtection("LockProtection"); + } + + // if there is no component name, then paste only SObjects and attributes: without component help + Handle(SALOMEDSImpl_AttributeComment) aComponentName; + bool aStructureOnly = !_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID(), aComponentName); + + // get copied study ID + Handle(SALOMEDSImpl_AttributeInteger) aStudyIDAttribute; + if (!_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeInteger::GetID(), aStudyIDAttribute)) { + _errorCode = "No study ID was found"; + return NULL; + } + int aCStudyID = aStudyIDAttribute->Value(); + + // CAF document of current study usage + Handle(TDocStd_Document) aDocument = GetDocumentOfStudy(aStudy); + if (aDocument.IsNull()) { + _errorCode = "OCAF document is null"; + return NULL; + } + + Handle(SALOMEDSImpl_SComponent) aComponent = theObject->GetFatherComponent(); + + // fill root inserted SObject + TDF_Label aStartLabel; + if (aStructureOnly) { + TDF_Label anObjectLabel; + TDF_Tool::Label(aDocument->GetData(), theObject->GetID(), anObjectLabel); + aStartLabel = PasteLabel(aStudy, theEngine, _clipboard->Main(), anObjectLabel, aCStudyID, false); + } else { + TDF_Label aComponentLabel; + TDF_Tool::Label(aDocument->GetData(), aComponent->GetID(), aComponentLabel); + aStartLabel = PasteLabel(aStudy, theEngine, _clipboard->Main(), aComponentLabel, aCStudyID, true); + } + + // paste all sublebels + TDF_ChildIterator anIterator(_clipboard->Main(), Standard_True); + for(; anIterator.More(); anIterator.Next()) { + PasteLabel(aStudy, theEngine, anIterator.Value(), aStartLabel, aCStudyID, false); + } + + return SALOMEDSImpl_Study::SObject(aStartLabel); +} + +//####################################################################################################### +//# STATIC PRIVATE FUNCTIONS +//####################################################################################################### + +//============================================================================ +/*! Function : SaveAttributes + * Purpose : Save attributes for object + */ +//============================================================================ +static void SaveAttributes(Handle(SALOMEDSImpl_SObject) aSO, HDFgroup *hdf_group_sobject) +{ + hdf_size size[1]; + TDF_AttributeIterator Itr(aSO->GetLabel()); + Handle(TDF_Attribute) anAttr; + for(; Itr.More(); Itr.Next()) { + anAttr = Itr.Value(); + //The following attributes are not supposed to be written to the file + if(anAttr->DynamicType() == STANDARD_TYPE(SALOMEDSImpl_AttributeIOR)) continue; //IOR attribute is not saved + Handle(SALOMEDSImpl_GenericAttribute) ga = Handle(SALOMEDSImpl_GenericAttribute)::DownCast(anAttr); + TCollection_AsciiString aSaveStr = ga->Save(); + //cout << "Saving: " << aSO->GetID() << " "<< ga->Type() << " value: " << aSaveStr << endl; + size[0] = (hdf_int32) strlen(aSaveStr.ToCString()) + 1; + HDFdataset *hdf_dataset = new HDFdataset((char*)ga->Type().ToCString(), hdf_group_sobject,HDF_STRING,size,1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk((char*)aSaveStr.ToCString()); + hdf_dataset->CloseOnDisk(); + hdf_dataset=0; //will be deleted by hdf_sco_group destructor + } +} + +//=========================================================================== +//Function : ReadAttributes +//=========================================================================== +static void ReadAttributes(const Handle(SALOMEDSImpl_Study)& theStudy, + const Handle(SALOMEDSImpl_SObject)& aSO, + HDFdataset* hdf_dataset) +{ + hdf_dataset->OpenOnDisk(); + + Handle(TDF_Attribute) anAttr; + + char* current_string = new char[hdf_dataset->GetSize()]; + hdf_dataset->ReadFromDisk(current_string); + + if (!strcmp(hdf_dataset->GetName(),"COMPONENTDATATYPE")) { + anAttr = theStudy->NewBuilder()->FindOrCreateAttribute(aSO, "AttributeComment"); + } else if (!strcmp(hdf_dataset->GetName(),"AttributeReference")) { + theStudy->NewBuilder()->Addreference(aSO, theStudy->CreateObjectID(current_string)); + delete(current_string); + hdf_dataset->CloseOnDisk(); + return; + } else { + anAttr = theStudy->NewBuilder()->FindOrCreateAttribute(aSO, hdf_dataset->GetName()); + } + + if (!anAttr.IsNull()) { + + Handle(SALOMEDSImpl_GenericAttribute) ga = Handle(SALOMEDSImpl_GenericAttribute)::DownCast(anAttr); + ga->Load(current_string); + //cout << "Reading: " << aSO->GetID() << " "<< ga->Type() << " value: " << current_string << endl; + } + + delete(current_string); + hdf_dataset->CloseOnDisk(); +} + +//============================================================================ +//Function : BuildlTree +//============================================================================ +static void BuildTree (const Handle(SALOMEDSImpl_Study)& theStudy, HDFgroup* hdf_current_group) +{ + hdf_current_group->OpenOnDisk(); + Handle(SALOMEDSImpl_SObject) aSO; + char* Entry = hdf_current_group->GetName(); + if (strcmp(Entry,"STUDY_STRUCTURE") == 0) { + aSO = theStudy->CreateObjectID("0:1"); + } + else { + aSO = theStudy->CreateObjectID(Entry); + } + + char name[HDF_NAME_MAX_LEN+1]; + Standard_Integer nbsons = hdf_current_group->nInternalObjects(); + for (Standard_Integer i=0; iInternalObjectIndentify(i,name); + if (strncmp(name, "INTERNAL_COMPLEX",16) == 0) continue; + hdf_object_type type = hdf_current_group->InternalObjectType(name); + + if (type == HDF_DATASET) { + HDFdataset* new_dataset = new HDFdataset(name,hdf_current_group); + ReadAttributes(theStudy,aSO,new_dataset); + new_dataset = 0; // will be deleted by father destructor + + } + else if (type == HDF_GROUP) { + HDFgroup* new_group = new HDFgroup(name,hdf_current_group); + BuildTree (theStudy, new_group); + new_group = 0; // will be deleted by father destructor + } + } + hdf_current_group->CloseOnDisk(); +} + + +//============================================================================ +//Function : Translate_IOR_to_persistentID +//============================================================================ +static void Translate_IOR_to_persistentID (const Handle(SALOMEDSImpl_SObject)& so, + SALOMEDSImpl_Driver* engine, + bool isMultiFile, + bool isASCII) +{ + TDF_ChildIterator itchild(so->GetLabel()); + TCollection_AsciiString ior_string, persistent_string, curid; + + for (; itchild.More(); itchild.Next()) { + Handle(SALOMEDSImpl_SObject) current = SALOMEDSImpl_Study::SObject(itchild.Value()); + Handle(SALOMEDSImpl_AttributeIOR) IOR; + if (current->GetLabel().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID(), IOR)) { + ior_string = IOR->Value(); + + persistent_string = engine->IORToLocalPersistentID (current, ior_string, isMultiFile, isASCII); + SALOMEDSImpl_AttributePersistentRef::Set(current->GetLabel(), persistent_string); + } + Translate_IOR_to_persistentID (current, engine, isMultiFile, isASCII); + } +} diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.hxx new file mode 100644 index 000000000..7f8709f81 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.hxx @@ -0,0 +1,129 @@ +// File : SALOMEDSImpl_StudyManager.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef __SALOMEDSImpl_STUDYMANAGER_I_H__ +#define __SALOMEDSImpl_STUDYMANAGER_I_H__ + +//Handle definition +#include +#include +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_StudyManager, MMgt_TShared ) + +// std C++ headers +#include + +// Cascade headers +#include "SALOMEDSImpl_OCAFApplication.hxx" +#include "SALOMEDSImpl_Study.hxx" +#include "SALOMEDSImpl_SObject.hxx" +#include "SALOMEDSImpl_Driver.hxx" +#include +#include +#include +#include +#include + +class HDFgroup; + +class SALOMEDSImpl_StudyManager : public MMgt_TShared +{ + +private: + + Handle (SALOMEDSImpl_OCAFApplication) _OCAFApp; + int _IDcounter; + Handle(TDocStd_Document) _clipboard; + TCollection_AsciiString _errorCode; + +public: + + //! standard constructor + SALOMEDSImpl_StudyManager(); + + //! standard destructor + virtual ~SALOMEDSImpl_StudyManager(); + + //! method to Create a New Study of name study_name + virtual Handle(SALOMEDSImpl_Study) NewStudy(const TCollection_AsciiString& study_name); + + //! method to Open a Study from it's persistent reference + virtual Handle(SALOMEDSImpl_Study) Open(const TCollection_AsciiString& aStudyUrl); + + //! method to close a Study + virtual void Close(const Handle(SALOMEDSImpl_Study)& aStudy); + + //! method to save a Study + virtual bool Save(const Handle(SALOMEDSImpl_Study)& aStudy, SALOMEDSImpl_DriverFactory* aFactory, bool theMultiFile); + + virtual bool SaveASCII(const Handle(SALOMEDSImpl_Study)& aStudy, + SALOMEDSImpl_DriverFactory* aFactory, + bool theMultiFile); + + //! method to save a Study to the persistent reference aUrl + virtual bool SaveAs(const TCollection_AsciiString& aUrl, + const Handle(SALOMEDSImpl_Study)& aStudy, + SALOMEDSImpl_DriverFactory* aFactory, + bool theMultiFile); + + virtual bool SaveAsASCII(const TCollection_AsciiString& aUrl, + const Handle(SALOMEDSImpl_Study)& aStudy, + SALOMEDSImpl_DriverFactory* aFactory, + bool theMultiFile); + + //! method to Get name list of open studies in the session + virtual Handle(TColStd_HSequenceOfTransient) GetOpenStudies(); + + //! method to get a Study from it's name + virtual Handle(SALOMEDSImpl_Study) GetStudyByName(const TCollection_AsciiString& aStudyName) ; + + //! method to get a Study from it's ID + virtual Handle(SALOMEDSImpl_Study) GetStudyByID(int aStudyID) ; + + + Handle(TDocStd_Document) GetDocumentOfStudy(const Handle(SALOMEDSImpl_Study)& theStudy); + + Handle(TDocStd_Document) GetClipboard() { return _clipboard; } + + bool CopyLabel(const Handle(SALOMEDSImpl_Study)& theSourceStudy, + SALOMEDSImpl_Driver* theEngine, + const int theSourceStartDepth, + const TDF_Label& theSource, + const TDF_Label& theDestinationMain); + + TDF_Label PasteLabel(const Handle(SALOMEDSImpl_Study)& theDestinationStudy, + SALOMEDSImpl_Driver* theEngine, + const TDF_Label& theSource, + const TDF_Label& theDestinationStart, + const int theCopiedStudyID, + const bool isFirstElement); + + virtual bool CanCopy(const Handle(SALOMEDSImpl_SObject)& theObject, SALOMEDSImpl_Driver* Engine); + virtual bool Copy(const Handle(SALOMEDSImpl_SObject)& theObject, SALOMEDSImpl_Driver* Engine); + virtual bool CanPaste(const Handle(SALOMEDSImpl_SObject)& theObject, SALOMEDSImpl_Driver* Engine); + virtual Handle(SALOMEDSImpl_SObject) Paste(const Handle(SALOMEDSImpl_SObject)& theObject, SALOMEDSImpl_Driver* Engine); + + // _SaveAs private function called by Save and SaveAs + virtual bool Impl_SaveAs(const TCollection_AsciiString& aUrl, + const Handle(SALOMEDSImpl_Study)& aStudy, + SALOMEDSImpl_DriverFactory* aFactory, + bool theMultiFile, + bool theASCII); + + // _SaveObject private function called by _SaveAs + virtual bool Impl_SaveObject(const Handle(SALOMEDSImpl_SObject)& SC, HDFgroup *hdf_group_datatype); + + // _SubstituteSlash function called by Open and GetStudyByName + virtual TCollection_AsciiString Impl_SubstituteSlash(const TCollection_AsciiString& aUrl); + + virtual bool Impl_SaveProperties(const Handle(SALOMEDSImpl_Study)& aStudy, HDFgroup *hdf_group); + + TCollection_AsciiString GetErrorCode() { return _errorCode; } + virtual bool IsError() { return _errorCode != ""; } + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_StudyManager ) + +}; + +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Tool.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_Tool.cxx new file mode 100644 index 000000000..4a823fd36 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Tool.cxx @@ -0,0 +1,150 @@ +using namespace std; +// File : SALOMEDSImpl_Tool.cxx +// Created : Mon Oct 21 16:24:34 2002 +// Author : Sergey RUIN + +// Project : SALOME +// Module : SALOMEDSImpl +// Copyright : Open CASCADE + +#include "SALOMEDSImpl_Tool.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + + +//============================================================================ +// function : GetTempDir +// purpose : Return a temp directory to store created files like "/tmp/sub_dir/" +//============================================================================ +TCollection_AsciiString SALOMEDSImpl_Tool::GetTmpDir() +{ + //Find a temporary directory to store a file + + TCollection_AsciiString aTmpDir; + + char *Tmp_dir = getenv("SALOME_TMP_DIR"); + if(Tmp_dir != NULL) { + aTmpDir = TCollection_AsciiString(Tmp_dir); +#ifdef WIN32 + if(aTmpDir.Value(aTmpDir.Length()) != '\\') aTmpDir+='\\'; +#else + if(aTmpDir.Value(aTmpDir.Length()) != '/') aTmpDir+='/'; +#endif + } + else { +#ifdef WIN32 + aTmpDir = TCollection_AsciiString("C:\\"); +#else + aTmpDir = TCollection_AsciiString("/tmp/"); +#endif + } + + srand((unsigned int)time(NULL)); + int aRND = 999 + (int)(100000.0*rand()/(RAND_MAX+1.0)); //Get a random number to present a name of a sub directory + TCollection_AsciiString aSubDir(aRND); + if(aSubDir.Length() <= 1) aSubDir = TCollection_AsciiString("123409876"); + + aTmpDir += aSubDir; //Get RND sub directory + +#ifdef WIN32 + if(aTmpDir.Value(aTmpDir.Length()) != '\\') aTmpDir+='\\'; +#else + if(aTmpDir.Value(aTmpDir.Length()) != '/') aTmpDir+='/'; +#endif + + OSD_Path aPath(aTmpDir); + OSD_Directory aDir(aPath); + + for(aRND = 0; aDir.Exists(); aRND++) { + aTmpDir.Insert((aTmpDir.Length() - 1), TCollection_AsciiString(aRND)); //Build a unique directory name + aPath = OSD_Path(aTmpDir); + aDir = OSD_Directory(aPath); + } + + OSD_Protection aProtection(OSD_RW, OSD_RWX, OSD_RX, OSD_RX); + aDir.Build(aProtection); + + return aTmpDir; +} + +//============================================================================ +// function : RemoveTemporaryFiles +// purpose : Removes files listed in theFileList +//============================================================================ +void SALOMEDSImpl_Tool::RemoveTemporaryFiles(const TCollection_AsciiString& theDirectory, + const Handle(TColStd_HSequenceOfAsciiString)& theFiles, + const bool IsDirDeleted) +{ + TCollection_AsciiString aDirName = theDirectory; + + int i, aLength = theFiles->Length(); + for(i=1; i<=aLength; i++) { + TCollection_AsciiString aFile(aDirName); + aFile += theFiles->Value(i); + OSD_Path anOSDPath(aFile); + OSD_File anOSDFile(anOSDPath); + if(!anOSDFile.Exists()) continue; + + OSD_Protection aProtection = anOSDFile.Protection(); + aProtection.SetUser(OSD_RW); + anOSDFile.SetProtection(aProtection); + + anOSDFile.Remove(); + } + + if(IsDirDeleted) { + OSD_Path aPath(aDirName); + OSD_Directory aDir(aPath); + OSD_FileIterator anIterator(aPath, '*'); + + if(aDir.Exists() && !anIterator.More()) aDir.Remove(); + } + +} + +//============================================================================ +// function : GetNameFromPath +// purpose : Returns the name by the path +//============================================================================ +TCollection_AsciiString SALOMEDSImpl_Tool::GetNameFromPath(const TCollection_AsciiString& thePath) { + if (thePath.IsEmpty()) return ""; + OSD_Path aPath = OSD_Path(thePath); + TCollection_AsciiString aNameString(aPath.Name()); + return aNameString; +} + +//============================================================================ +// function : GetDirFromPath +// purpose : Returns the dir by the path +//============================================================================ +TCollection_AsciiString SALOMEDSImpl_Tool::GetDirFromPath(const TCollection_AsciiString& thePath) { + if (thePath.IsEmpty()) return ""; + OSD_Path aPath = OSD_Path(thePath); + TCollection_AsciiString aDirString(aPath.Trek()); + aDirString.ChangeAll('|','/'); + return aDirString; +} + + + + + + + + + + + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Tool.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_Tool.hxx new file mode 100644 index 000000000..f842370cd --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Tool.hxx @@ -0,0 +1,62 @@ +// File : SALOMEDSImpl_Tool.hxx +// Created : Mon Oct 21 16:24:50 2002 +// Author : Sergey RUIN + +// Project : SALOME +// Module : SALOMEDSImpl +// Copyright : Open CASCADE + + +#ifndef __SALOMEDSIMPL_TOOL_H__ +#define __SALOMEDSIMPL_TOOL_H__ + +#include +#include +#include + +class SALOMEDSImpl_Tool +{ + +public: + + // Returns the unique temporary directory, that is defined in SALOME_TMP_DIR if this variable is set + // otherwise return /tmp/something/ for Unix or c:\something\ for WNT + static TCollection_AsciiString GetTmpDir(); + + + // Removes files which are in , the files for deletion are listed in + // if is true is also deleted if it is empty + static void RemoveTemporaryFiles(const TCollection_AsciiString& theDirectory, + const Handle(TColStd_HSequenceOfAsciiString)& theFiles, + const bool IsDirDeleted); + + // Returns the name by the path + // for an example: if thePath = "/tmp/aaa/doc1.hdf" the function returns "doc1" + static TCollection_AsciiString GetNameFromPath(const TCollection_AsciiString& thePath); + + // Returns the directory by the path + // for an example: if thePath = "/tmp/aaa/doc1.hdf" the function returns "/tmp/aaa" + static TCollection_AsciiString GetDirFromPath(const TCollection_AsciiString& thePath); + +}; +#endif + + + + + + + + + + + + + + + + + + + + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseBuilder.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseBuilder.cxx new file mode 100644 index 000000000..db1b9bcd1 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseBuilder.cxx @@ -0,0 +1,389 @@ +// File : SALOMEDSImpl_UseCaseBuilder.cxx +// Author : Sergey RUIN +// Module : SALOME + +using namespace std; +#include "SALOMEDSImpl_UseCaseBuilder.hxx" +#include "SALOMEDSImpl_SObject.hxx" +#include "SALOMEDSImpl_SComponent.hxx" +#include "SALOMEDSImpl_Study.hxx" +#include "SALOMEDSImpl_Attributes.hxx" + +#include +#include +#include +#include +#include +#include +#include + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_UseCaseBuilder, MMgt_TShared ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_UseCaseBuilder, MMgt_TShared ) + + +#define USE_CASE_LABEL_TAG 2 +#define USE_CASE_GUID "AA43BB12-D9CD-11d6-945D-0050DA506788" + + +//============================================================================ +/*! Function : constructor + * Purpose : + */ +//============================================================================ +SALOMEDSImpl_UseCaseBuilder::SALOMEDSImpl_UseCaseBuilder(const Handle(TDocStd_Document)& theDocument) +:_doc(theDocument) +{ + if(_doc.IsNull()) return; + + TDF_Label aLabel = _doc->Main().Root().FindChild(USE_CASE_LABEL_TAG); //Iterate all use cases + if(!aLabel.FindAttribute(Standard_GUID(USE_CASE_GUID), _root)) { + _root = SALOMEDSImpl_AttributeTreeNode::Set(aLabel, Standard_GUID(USE_CASE_GUID)); + } + + Handle(SALOMEDSImpl_AttributeReference) aRef; + if(!_root->FindAttribute(SALOMEDSImpl_AttributeReference::GetID(), aRef)) { + aRef = SALOMEDSImpl_AttributeReference::Set(_root->Label(), _root->Label()); + } + + Handle(SALOMEDSImpl_AttributeName) aNameAttr; + if(!aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID(), aNameAttr)) { + aNameAttr = SALOMEDSImpl_AttributeName::Set(aLabel, "Use cases"); + } +} + +//============================================================================ +/*! Function : destructor + * Purpose : + */ +//============================================================================ +SALOMEDSImpl_UseCaseBuilder::~SALOMEDSImpl_UseCaseBuilder() +{ +} + + +//============================================================================ +/*! Function : Append + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_UseCaseBuilder::Append(const Handle(SALOMEDSImpl_SObject)& theObject) +{ + if(_root.IsNull() || theObject.IsNull()) return false; + + TDF_Label aLabel = theObject->GetLabel(); + if(aLabel.IsNull()) return false; + + Handle(SALOMEDSImpl_AttributeTreeNode) aNode, aCurrentNode; + aNode = SALOMEDSImpl_AttributeTreeNode::Set(aLabel, _root->ID()); + aNode->Remove(); + + Handle(SALOMEDSImpl_AttributeReference) aRef; + if(!_root->FindAttribute(SALOMEDSImpl_AttributeReference::GetID(), aRef)) { + aRef = SALOMEDSImpl_AttributeReference::Set(_root->Label(), _root->Label()); + } + + TDF_Label aCurrent = aRef->Get(); + if(aCurrent.IsNull() || !aCurrent.FindAttribute(_root->ID(), aCurrentNode)) + aCurrentNode = _root; + + aCurrentNode->Append(aNode); + + return true; +} + + //============================================================================ +/*! Function : Remove + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_UseCaseBuilder::Remove(const Handle(SALOMEDSImpl_SObject)& theObject) +{ + if(_root.IsNull() || theObject.IsNull()) return false; + + TDF_Label aLabel = theObject->GetLabel(); + if(aLabel.IsNull()) return false; + + Handle(SALOMEDSImpl_AttributeTreeNode) aNode; + if(!aLabel.FindAttribute(_root->ID(), aNode)) return false; + + aNode->Remove(); + + TDF_AttributeList aList; + aList.Append(aNode); + + Handle(SALOMEDSImpl_AttributeReference) aRef; + if(!_root->FindAttribute(SALOMEDSImpl_AttributeReference::GetID(), aRef)) { + aRef = SALOMEDSImpl_AttributeReference::Set(_root->Label(), _root->Label()); + } + TDF_Label aCurrent = aRef->Get(); + + SALOMEDSImpl_ChildNodeIterator aChildItr(aNode, Standard_True); + for(; aChildItr.More(); aChildItr.Next()) + aList.Append(aChildItr.Value()); + + TDF_ListIteratorOfAttributeList anIterator(aList); + for(; anIterator.More(); anIterator.Next()) { + if(anIterator.Value()->Label() == aCurrent) { //The current node is removed + aRef->Set(_root->Label()); //Reset the current node to the root + } + anIterator.Value()->Label().ForgetAttribute(_root->ID()); + } + + return true; +} + + +//============================================================================ +/*! Function : AppendTo + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_UseCaseBuilder::AppendTo(const Handle(SALOMEDSImpl_SObject)& theFather, + const Handle(SALOMEDSImpl_SObject)& theObject) +{ + if(_root.IsNull() || theFather.IsNull() || theObject.IsNull()) return false; + + TDF_Label aFatherLabel = theFather->GetLabel(), aLabel = theObject->GetLabel(); + Handle(SALOMEDSImpl_AttributeTreeNode) aFather, aNode; + + if(aFatherLabel.IsNull()) return false; + if(!aFatherLabel.FindAttribute(_root->ID(), aFather)) return false; + + if(aLabel.IsNull()) return false; + if(!aLabel.FindAttribute(_root->ID(), aNode)) { + aNode = SALOMEDSImpl_AttributeTreeNode::Set(aLabel, _root->ID()); + } + + aNode->Remove(); + + return aFather->Append(aNode); +} + +//============================================================================ +/*! Function : InsertBefore + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_UseCaseBuilder::InsertBefore(const Handle(SALOMEDSImpl_SObject)& theFirst, + const Handle(SALOMEDSImpl_SObject)& theNext) +{ + if(_root.IsNull() || theFirst.IsNull() || theNext.IsNull()) return false; + + TDF_Label aFirstLabel = theFirst->GetLabel(), aLabel= theNext->GetLabel(); + Handle(SALOMEDSImpl_AttributeTreeNode) aFirstNode, aNode; + + if(aFirstLabel.IsNull()) return false; + if(aFirstLabel.FindAttribute(_root->ID(), aFirstNode)) { + aFirstNode->Remove(); + aFirstLabel.ForgetAttribute(aFirstNode->ID()); + } + + aFirstNode = SALOMEDSImpl_AttributeTreeNode::Set(aFirstLabel, _root->ID()); + + if(aLabel.IsNull()) return false; + if(!aLabel.FindAttribute(_root->ID(), aNode)) return false; + + aFirstNode->Remove(); + + return aNode->InsertBefore(aFirstNode); +} + + +//============================================================================ +/*! Function : SetCurrentObject + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_UseCaseBuilder::SetCurrentObject(const Handle(SALOMEDSImpl_SObject)& theObject) +{ + if(_root.IsNull() || theObject.IsNull()) return false; + + TDF_Label aLabel = theObject->GetLabel(); + Handle(SALOMEDSImpl_AttributeTreeNode) aNode; + if(aLabel.IsNull()) return false; + if(!aLabel.FindAttribute(_root->ID(), aNode)) return false; + + + Handle(SALOMEDSImpl_AttributeReference) aRef; + if(!_root->FindAttribute(SALOMEDSImpl_AttributeReference::GetID(), aRef)) { + aRef = SALOMEDSImpl_AttributeReference::Set(_root->Label(), aNode->Label()); + } + + aRef->Set(aNode->Label()); + + return true; +} + +//============================================================================ +/*! Function : SetRootCurrent + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_UseCaseBuilder::SetRootCurrent() +{ + if(_root.IsNull()) return false; + + Handle(SALOMEDSImpl_AttributeReference) aRef; + if(!_root->FindAttribute(SALOMEDSImpl_AttributeReference::GetID(), aRef)) + aRef = SALOMEDSImpl_AttributeReference::Set(_root->Label(), _root->Label()); + + aRef->Set(_root->Label()); + return true; +} + +//============================================================================ +/*! Function : HasChildren + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_UseCaseBuilder::HasChildren(const Handle(SALOMEDSImpl_SObject)& theObject) +{ + if(_root.IsNull()) return false; + + TDF_Label aLabel; + if (theObject.IsNull()) aLabel = _root->Label(); + else + aLabel = theObject->GetLabel(); + if(aLabel.IsNull()) return false; + + Handle(SALOMEDSImpl_AttributeTreeNode) aNode; + if(!aLabel.FindAttribute(_root->ID(), aNode)) return false; + + return !(aNode->GetFirst().IsNull()); +} + +//============================================================================ +/*! Function : SetName + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_UseCaseBuilder::SetName(const TCollection_AsciiString& theName) { + if(_root.IsNull()) return false; + + Handle(SALOMEDSImpl_AttributeName) aNameAttrib; + + if (!_root->FindAttribute(SALOMEDSImpl_AttributeName::GetID(), aNameAttrib)) + aNameAttrib = SALOMEDSImpl_AttributeName::Set(_root->Label(), theName); + else + aNameAttrib->SetValue(theName); + + return true; +} + + +//============================================================================ +/*! Function : GetCurrentObject + * Purpose : + */ +//============================================================================ +Handle(SALOMEDSImpl_SObject) SALOMEDSImpl_UseCaseBuilder::GetCurrentObject() +{ + if(_root.IsNull()) return NULL; + + Handle(SALOMEDSImpl_AttributeReference) aRef; + if(!_root->FindAttribute(SALOMEDSImpl_AttributeReference::GetID(), aRef)) { + aRef = SALOMEDSImpl_AttributeReference::Set(_root->Label(), _root->Label()); + } + TDF_Label aCurrent = aRef->Get(); + if(aCurrent.IsNull()) return NULL; + + return SALOMEDSImpl_Study::SObject(aCurrent); +} + +//============================================================================ +/*! Function : GetName + * Purpose : + */ +//============================================================================ +TCollection_AsciiString SALOMEDSImpl_UseCaseBuilder::GetName() +{ + TCollection_AsciiString aString; + if(_root.IsNull()) return aString; + + Handle(SALOMEDSImpl_AttributeName) aName; + if (!_root->FindAttribute(SALOMEDSImpl_AttributeName::GetID(), aName)) return aString; + aString = TCollection_AsciiString(aName->Value()); + return aString; +} + +//============================================================================ +/*! Function : IsUseCase + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_UseCaseBuilder::IsUseCase(const Handle(SALOMEDSImpl_SObject)& theObject) +{ + if(theObject.IsNull()) return false; + TDF_Label aFather, aLabel = theObject->GetLabel(); + aFather = _doc->Main().Root().FindChild(USE_CASE_LABEL_TAG); + if(aLabel.Father() == aFather) return true; + return false; +} + +//============================================================================ +/*! Function : NewUseCase + * Purpose : + */ +//============================================================================ +Handle(SALOMEDSImpl_SObject) SALOMEDSImpl_UseCaseBuilder::AddUseCase(const TCollection_AsciiString& theName) +{ + Standard_GUID aBasicGUID(USE_CASE_GUID); + + //Create a use cases structure if it not exists + + Handle(SALOMEDSImpl_AttributeTreeNode) aFatherNode, aNode; + Handle(SALOMEDSImpl_AttributeInteger) anInteger; + Handle(SALOMEDSImpl_AttributeReference) aRef; + + TDF_Label aLabel = _doc->Main().Root().FindChild(USE_CASE_LABEL_TAG); + + if(!_root->FindAttribute(SALOMEDSImpl_AttributeReference::GetID(), aRef)) { + aRef = SALOMEDSImpl_AttributeReference::Set(aLabel, aLabel); + } + + if(!aRef->Get().FindAttribute(aBasicGUID, aFatherNode)) { + aFatherNode = SALOMEDSImpl_AttributeTreeNode::Set(aRef->Get(), aBasicGUID); + } + + if(!_root->FindAttribute(SALOMEDSImpl_AttributeInteger::GetID(), anInteger)) { + anInteger = SALOMEDSImpl_AttributeInteger::Set(aLabel, 0); + } + + //Create a new use case + anInteger->SetValue(anInteger->Value()+1); + TDF_Label aChild = aLabel.FindChild(anInteger->Value()); + aNode = SALOMEDSImpl_AttributeTreeNode::Set(aChild, aBasicGUID); + aNode->Remove(); + aFatherNode->Append(aNode); + SALOMEDSImpl_AttributeName::Set(aChild, theName); + + return SALOMEDSImpl_Study::SObject(aChild); +} + +//============================================================================ +/*! Function : GetUseCaseIterator + * Purpose : Creates a new UseCase iterator, if anObject is null all use cases are iterated + */ +//============================================================================ +Handle(SALOMEDSImpl_UseCaseIterator) +SALOMEDSImpl_UseCaseBuilder::GetUseCaseIterator(const Handle(SALOMEDSImpl_SObject)& theObject) +{ + TDF_Label aLabel; + + if(!theObject.IsNull()) { + aLabel = theObject->GetLabel(); //Iterate only sub tree in the use case + } + else { + aLabel = _doc->Main().Root().FindChild(USE_CASE_LABEL_TAG); //Iterate all use cases + } + + return new SALOMEDSImpl_UseCaseIterator(aLabel, USE_CASE_GUID, false); +} + + +Handle(SALOMEDSImpl_SObject) SALOMEDSImpl_UseCaseBuilder::GetSObject(const TCollection_AsciiString& theEntry) +{ + TDF_Label aLabel; + TDF_Tool::Label(_doc->GetData(), theEntry, aLabel); + return SALOMEDSImpl_Study::SObject(aLabel); +} diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseBuilder.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseBuilder.hxx new file mode 100644 index 000000000..12e46468f --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseBuilder.hxx @@ -0,0 +1,67 @@ +// File : SALOMEDSImpl_UseCaseBuilder.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef __SALOMEDSIMPL_USECaseBuilder_H__ +#define __SALOMEDSIMPL_USECaseBuilder_H__ + +//Handle definition +#include +#include +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_UseCaseBuilder, MMgt_TShared ) + +// Cascade headers +#include +#include +#include +#include + +#include "SALOMEDSImpl_UseCaseIterator.hxx" + +class SALOMEDSImpl_UseCaseBuilder : public MMgt_TShared +{ +private: + + Handle(SALOMEDSImpl_AttributeTreeNode) _root; + Handle(TDocStd_Document) _doc; + +public: + + //! standard constructor + SALOMEDSImpl_UseCaseBuilder(const Handle(TDocStd_Document)& theDocument); + + //! standard destructor + ~SALOMEDSImpl_UseCaseBuilder(); + + virtual bool Append(const Handle(SALOMEDSImpl_SObject)& theObject); + + virtual bool Remove(const Handle(SALOMEDSImpl_SObject)& theObject); + + virtual bool AppendTo(const Handle(SALOMEDSImpl_SObject)& theFather, const Handle(SALOMEDSImpl_SObject)& theObject); + + virtual bool InsertBefore(const Handle(SALOMEDSImpl_SObject)& theFirst, const Handle(SALOMEDSImpl_SObject)& theNext); + + virtual bool SetCurrentObject(const Handle(SALOMEDSImpl_SObject)& theObject); + + virtual bool SetRootCurrent(); + + virtual bool HasChildren(const Handle(SALOMEDSImpl_SObject)& theObject); + + virtual bool IsUseCase(const Handle(SALOMEDSImpl_SObject)& theObject); + + virtual bool SetName(const TCollection_AsciiString& theName); + + virtual Handle(SALOMEDSImpl_SObject) GetCurrentObject(); + + virtual TCollection_AsciiString GetName(); + + virtual Handle(SALOMEDSImpl_SObject) AddUseCase(const TCollection_AsciiString& theName); + + virtual Handle(SALOMEDSImpl_UseCaseIterator) GetUseCaseIterator(const Handle(SALOMEDSImpl_SObject)& anObject); + + Handle(SALOMEDSImpl_SObject) GetSObject(const TCollection_AsciiString& theEntry); + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_UseCaseBuilder ) +}; +#endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseIterator.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseIterator.cxx new file mode 100644 index 000000000..7021609c0 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseIterator.cxx @@ -0,0 +1,79 @@ +// File : SALOMEDSImpl_UseCaseIterator.cxx +// Author : Serge RUIN +// Module : SALOME + +using namespace std; +#include "SALOMEDSImpl_UseCaseIterator.hxx" +#include "SALOMEDSImpl_SObject.hxx" +#include "SALOMEDSImpl_Study.hxx" + +IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_UseCaseIterator, MMgt_TShared ) +IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_UseCaseIterator, MMgt_TShared ) + +//============================================================================ +/*! Function : constructor + * Purpose : + */ +//============================================================================ +SALOMEDSImpl_UseCaseIterator::SALOMEDSImpl_UseCaseIterator(const TDF_Label& theLabel, + const Standard_GUID& theGUID, + const bool allLevels) +:_guid(theGUID), _levels(allLevels) +{ + if(theLabel.FindAttribute(_guid, _node)) { + _it.Initialize (_node, _levels); + } +} + +//============================================================================ +/*! Function : destructor + * Purpose : + */ +//============================================================================ +SALOMEDSImpl_UseCaseIterator::~SALOMEDSImpl_UseCaseIterator() +{ +} + +//============================================================================ +/*! Function :Init + * + */ +//============================================================================ +void SALOMEDSImpl_UseCaseIterator::Init(bool allLevels) +{ + _it.Initialize (_node, allLevels); +} + +//============================================================================ +/*! Function : More + * + */ +//============================================================================ +bool SALOMEDSImpl_UseCaseIterator::More() +{ + return _it.More(); +} + + //============================================================================ +/*! Function : Next + * + */ +//============================================================================ +void SALOMEDSImpl_UseCaseIterator::Next() +{ + _it.Next(); +} + + +//============================================================================ +/*! Function : + * Purpose : + */ +//============================================================================ + +Handle(SALOMEDSImpl_SObject) SALOMEDSImpl_UseCaseIterator::Value() +{ + TDF_Label L = _it.Value()->Label(); + return SALOMEDSImpl_Study::SObject(L); +} + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseIterator.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseIterator.hxx new file mode 100644 index 000000000..171bcc571 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_UseCaseIterator.hxx @@ -0,0 +1,47 @@ +// File : SALOMEDSImpl_UseCaseIterator.hxx +// Author : Sergey RUIN +// Module : SALOME + +#ifndef __SALOMEDSIMPL_USECASEITERATOR_H__ +#define __SALOMEDSIMPL_USECASEITERATOR_H__ + +//Handle definition +#include +#include +DEFINE_STANDARD_HANDLE( SALOMEDSImpl_UseCaseIterator, MMgt_TShared ) + +#include "SALOMEDSImpl_SObject.hxx" + +// Cascade headers +#include +#include +#include + +class SALOMEDSImpl_UseCaseIterator : public MMgt_TShared +{ + +private: + Standard_GUID _guid; + bool _levels; + Handle(SALOMEDSImpl_AttributeTreeNode) _node; + SALOMEDSImpl_ChildNodeIterator _it; + +public: + + //! standard constructor + SALOMEDSImpl_UseCaseIterator(const TDF_Label& theLabel, + const Standard_GUID& theGUID, + const bool allLevels); + + //! standard destructor + ~SALOMEDSImpl_UseCaseIterator(); + + virtual void Init(bool); + virtual bool More(); + virtual void Next(); + virtual Handle(SALOMEDSImpl_SObject) Value(); + +public: + DEFINE_STANDARD_RTTI( SALOMEDSImpl_UseCaseIterator ) +}; +#endif diff --git a/src/SALOMEDSImpl/testDS.cxx b/src/SALOMEDSImpl/testDS.cxx new file mode 100644 index 000000000..eaf801d98 --- /dev/null +++ b/src/SALOMEDSImpl/testDS.cxx @@ -0,0 +1,78 @@ +//File: testDS.cxx +//Author: Sergey RUIN + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "SALOMEDSImpl_Attributes.hxx" +#include "SALOMEDSImpl_StudyManager.hxx" +#include "SALOMEDSImpl_Study.hxx" +#include "SALOMEDSImpl_StudyBuilder.hxx" +#include "SALOMEDSImpl_SObject.hxx" +#include "SALOMEDSImpl_SComponent.hxx" +//#include "SALOMEDSImpl_.hxx" + +int main (int argc, char * argv[]) +{ + cout << "Test started " << endl; + + Handle(SALOMEDSImpl_StudyManager) aSM = new SALOMEDSImpl_StudyManager(); + cout << "Manager is created " << endl; + Handle(SALOMEDSImpl_Study) aStudy = aSM->NewStudy("SRN"); + cout << "Study with id = " << aStudy->StudyId() << " is created " << endl; + Handle(SALOMEDSImpl_StudyBuilder) aBuilder = aStudy->NewBuilder(); + cout << "StudyBuilder is created " << endl; + Handle(SALOMEDSImpl_SComponent) aSC = aBuilder->NewComponent("TEST"); + cout << "New component with type " << aSC->ComponentDataType() << " is created " << endl; + Handle(SALOMEDSImpl_SObject) aSO = aBuilder->NewObject(aSC); + cout << "New SObject with ID = " << aSO->GetID() << " is created" << endl; + TCollection_AsciiString anEntry; + TDF_Tool::Entry(aSO->GetLabel(), anEntry); + cout << "An entry of newly created SO is " << anEntry << endl; + Handle(SALOMEDSImpl_AttributeIOR) aIORA = SALOMEDSImpl_AttributeIOR::Set(aSO->GetLabel(), "ior1234"); + cout << "New AttributeIOR is created, it contains " << aIORA->Value() << endl; + Handle(SALOMEDSImpl_GenericAttribute) ga = Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aIORA); + cout << "Attribute has type: " << ga->Type() << " and value: " << ga->Save() << endl; + cout << "Just another way to create an attribute: official one :) " << endl; + Handle(TDF_Attribute) aTDFAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeName"); + Handle(SALOMEDSImpl_AttributeName) aRN = Handle(SALOMEDSImpl_AttributeName)::DownCast(aTDFAttr); + aRN->SetValue("name_attribute"); + cout << " The type = " << aRN->Type() << endl; + ga = Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aRN); + cout << "Attribute has type: " << ga->Type() << " and value: " << ga->Save() << endl; + cout << "Check GetObjectPath: " << aStudy->GetObjectPath(aSO) << endl; + + Handle(SALOMEDSImpl_SObject) aSubSO = aBuilder->NewObject(aSO); + aTDFAttr = aBuilder->FindOrCreateAttribute(aSubSO, "AttributeIOR"); + Handle(SALOMEDSImpl_AttributeIOR) aIOR2 = Handle(SALOMEDSImpl_AttributeIOR)::DownCast(aTDFAttr); + aIOR2->SetValue("some ior"); + aBuilder->Addreference(aSubSO, aSO); + Handle(SALOMEDSImpl_SObject) aRefObject; + aSubSO->ReferencedObject(aRefObject); + cout << "Check reference : ReferencedObject is " << aRefObject->GetID() << endl; + cout << "Check : Remove object: " << endl; + aBuilder->RemoveObject(aSubSO); + cout << "Remove: done" << endl; + + cout << "Check the attributes on SObject" << endl; + Handle(TColStd_HSequenceOfTransient) aSeq = aSO->GetAllAttributes(); + for(int i = 1; i <= aSeq->Length(); i++) + cout << "Found: " << Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aSeq->Value(i))->Type() << endl; + + cout << "Check AttributeTreeNode " << endl; + aTDFAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeTreeNode"); + cout << Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aTDFAttr)->Type() << endl; + cout << "Check AttributeTreeNode : done " << endl; + + cout << "Test finished " << endl; + return 0; +} +