From: eap Date: Mon, 17 Jun 2013 12:18:52 +0000 (+0000) Subject: 0021684: EDF 2221 : Display the arguments and the name of the operations X-Git-Tag: BR_hydro_v_0_3_1~198 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=37873fd2a1c82842e51d5c74d51da5ebb78ad99d;p=modules%2Fgeom.git 0021684: EDF 2221 : Display the arguments and the name of the operations + GEOM_BaseDriver.cxx \ --- diff --git a/src/GEOM/GEOM_BaseDriver.cxx b/src/GEOM/GEOM_BaseDriver.cxx new file mode 100644 index 000000000..5308e55ff --- /dev/null +++ b/src/GEOM/GEOM_BaseDriver.cxx @@ -0,0 +1,186 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : GEOM_BaseDriver.cxx +// Created : Thu Jun 6 15:44:27 2013 +// Author : Edward AGAPOV (eap) + +#include "GEOM_BaseDriver.hxx" + +#include "GEOM_Function.hxx" +#include "GEOM_Object.hxx" + +#include +#include + +IMPLEMENT_STANDARD_HANDLE (GEOM_BaseDriver,TFunction_Driver); +IMPLEMENT_STANDARD_RTTIEXT(GEOM_BaseDriver,TFunction_Driver); + + +//================================================================================ +/*! + * \brief Returns a name of creation operation and names and values of creation parameters + */ +//================================================================================ + +// bool GEOM_BaseDriver::GetCreationInformation(std::string& theOperationName, +// std::vector& theParams) = 0; + +//================================================================================ +/*! + * \brief Adds GEOM_Param to params and sets its name + * + * This method is safer than resizing the params vector and accessing to its items + */ +//================================================================================ + +GEOM_Param& GEOM_BaseDriver::AddParam(std::vector& params, + const char* name) +{ + GEOM_Param p; + p.Set( name ); + params.push_back( p ); + return params.back(); +} + +//================================================================================ +/*! + * \brief Appends a GEOM_Function value + */ +//================================================================================ + +GEOM_Param & GEOM_Param::operator<<( const Handle(Standard_Transient)& fun ) +{ + return *this << Handle(GEOM_Function)::DownCast( fun ); +} + +//================================================================================ +/*! + * \brief Appends a GEOM_Function value + */ +//================================================================================ + +GEOM_Param & GEOM_Param::operator<<( const Handle(GEOM_Function)& fun ) +{ + if ( !fun.IsNull() ) + { + TDF_Label label = fun->GetOwnerEntry(); + Handle(GEOM_Object) obj = GEOM_Object::GetObject( label ); + if ( !obj.IsNull() ) + { + TopoDS_Shape s = obj->GetValue(); + (*this) << ( s.IsNull() ? TopAbs_SHAPE : s.ShapeType() ); + + TCollection_AsciiString entry = obj->GetAuxData(); + TCollection_ExtendedString name; + { + Handle(TDataStd_Name) aNameAttr; + if( obj->GetEntry().FindAttribute(TDataStd_Name::GetID(), aNameAttr)) + name = aNameAttr->Get(); + } + if ( name.Length() > 0 && entry.Length() > 0 ) + (*this) << "('" << name << "'," << entry << ")"; + else if ( name.Length() > 0 ) + (*this) << "('" << name << "')"; + else if ( entry.Length() > 0 ) + (*this) << "(" << entry << ")"; + } + } + return *this; +} + +//================================================================================ +/*! + * \brief Appends several GEOM_Function's to the value + */ +//================================================================================ + +GEOM_Param & GEOM_Param::operator<<( const Handle(TColStd_HSequenceOfTransient)& funs ) +{ + if ( !funs.IsNull() ) + { + if ( funs->Length() > 1 ) + (*this) << funs->Length() << " objects: "; + for ( int i = 1; i <= funs->Length(); ++i ) + (*this) << funs->Value( i ) << " "; + } + return *this; +} + +template void appendSeq( GEOM_Param& param, + const HSEQ& seq, + int iLow, + int iUp) +{ + int len = 1 + iUp - iLow; + if ( len > 1 ) + param << len << " items: "; + for ( ; iLow <= iUp; ++iLow ) + param << seq->Value( iLow ) << " "; +} + +//================================================================================ +/*! + * \brief Appends several int's to the value + */ +//================================================================================ + +GEOM_Param & GEOM_Param::operator<<( const Handle(TColStd_HArray1OfInteger)& vals ) +{ + if ( !vals.IsNull() ) + appendSeq( *this, vals, vals->Lower(), vals->Upper() ); + return *this; +} + +//================================================================================ +/*! + * \brief Appends TopAbs_ShapeEnum to the value + */ +//================================================================================ + +GEOM_Param & GEOM_Param::operator<<( TopAbs_ShapeEnum type ) +{ + const char* str[] = { + "Compound","Compsolid","Solid","Shell","Face","Wire","Edge","Vertex","Shape" + }; + if ( 0 <= type && type <= TopAbs_SHAPE ) + (*this) << str[type]; + else + (*this) << "TopAbs_ShapeEnum(" << type << ")"; + return *this; +} + +//================================================================================ +/*! + * \brief Appends TopAbs_State to the value + */ +//================================================================================ + +GEOM_Param & GEOM_Param::operator<<( TopAbs_State state ) +{ + const char* str[] = {"IN","OUT","ON","UNKNOWN"}; + if ( 0 <= state && state <= TopAbs_UNKNOWN ) + (*this) << str[state]; + else + (*this) << "TopAbs_State(" << state << ")"; + return *this; +} diff --git a/src/GEOM/GEOM_BaseDriver.hxx b/src/GEOM/GEOM_BaseDriver.hxx new file mode 100644 index 000000000..045b7509e --- /dev/null +++ b/src/GEOM/GEOM_BaseDriver.hxx @@ -0,0 +1,103 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : GEOM_BaseDriver.hxx +// Created : Thu Jun 6 15:27:50 2013 +// Author : Edward AGAPOV (eap) + +#ifndef __GEOM_BaseDriver_HXX__ +#define __GEOM_BaseDriver_HXX__ + +#include +#include +#include + +#include +#include +#include + +class Handle(GEOM_Function); +class Handle(TColStd_HSequenceOfTransient); +class Handle(TColStd_HArray1OfInteger); + +struct GEOM_Param +{ + std::string name; + std::string value; + + void Set(const char* nm) { name = nm; } + template + void Set(const char* nm, const T& value) { name = nm; (*this)< GEOM_Param & operator<<( const T &anything ) + { + std::ostringstream str; + str << anything; + value += str.str() ; + return *this ; + } + GEOM_Param & operator<<( const Handle(GEOM_Function)& fun ); + GEOM_Param & operator<<( const Handle(Standard_Transient)& fun ); + GEOM_Param & operator<<( const Handle(TColStd_HSequenceOfTransient)& funs ); + GEOM_Param & operator<<( const Handle(TColStd_HArray1OfInteger)& vals ); + GEOM_Param & operator<<( TopAbs_ShapeEnum type ); + GEOM_Param & operator<<( TopAbs_State state ); +}; + + +class GEOM_BaseDriver : public TFunction_Driver +{ +public: + + // Returns a name of creation operation and names and values of creation parameters + // (Use AddParam() methods declared below to fill params vector while implementing + // this method in derived drivers) + Standard_EXPORT virtual + bool GetCreationInformation(std::string& theOperationName, + std::vector& params) = 0; + + // Adds GEOM_Param to params and sets its name + // This method is safer than resizing the params vector and accessing to its items + GEOM_Param& AddParam(std::vector& params, + const char* name); + + // Adds GEOM_Param to params vector and sets its name and value + // This method is safer than resizing the params vector and accessing to its items + template GEOM_Param& AddParam(std::vector& params, + const char* name, + const T& value, + const char* dfltValue = 0) + { + GEOM_Param p; + p.Set( name, value ); + if ( dfltValue && p.value.empty() ) + p << dfltValue; + params.push_back( p ); + return params.back(); + } + + DEFINE_STANDARD_RTTI (GEOM_BaseDriver) +}; + +DEFINE_STANDARD_HANDLE (GEOM_BaseDriver,TFunction_Driver); + +#endif diff --git a/src/GEOM/Makefile.am b/src/GEOM/Makefile.am index 872f785f9..1ad106618 100644 --- a/src/GEOM/Makefile.am +++ b/src/GEOM/Makefile.am @@ -35,6 +35,7 @@ dist_libGEOMbasic_la_SOURCES = \ GEOM_Object.cxx \ GEOM_IOperations.cxx \ GEOM_Solver.cxx \ + GEOM_BaseDriver.cxx \ GEOM_SubShapeDriver.cxx \ GEOM_PythonDump.cxx \ GEOM_DataMapNodeOfDataMapOfAsciiStringTransient_0.cxx \ @@ -50,6 +51,7 @@ salomeinclude_HEADERS = \ GEOM_Engine.hxx \ GEOM_Function.hxx \ GEOM_Object.hxx \ + GEOM_BaseDriver.hxx \ GEOM_SubShapeDriver.hxx \ GEOM_IOperations.hxx \ GEOM_ISubShape.hxx \