Salome HOME
5308e55ff335071c52dd28edc30f8f3b6d808e3b
[modules/geom.git] / src / GEOM / GEOM_BaseDriver.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File      : GEOM_BaseDriver.cxx
24 // Created   : Thu Jun  6 15:44:27 2013
25 // Author    : Edward AGAPOV (eap)
26
27 #include "GEOM_BaseDriver.hxx"
28
29 #include "GEOM_Function.hxx"
30 #include "GEOM_Object.hxx"
31
32 #include <TColStd_HArray1OfInteger.hxx>
33 #include <TDataStd_Name.hxx>
34
35 IMPLEMENT_STANDARD_HANDLE (GEOM_BaseDriver,TFunction_Driver);
36 IMPLEMENT_STANDARD_RTTIEXT(GEOM_BaseDriver,TFunction_Driver);
37
38
39 //================================================================================
40 /*!
41  * \brief Returns a name of creation operation and names and values of creation parameters
42  */
43 //================================================================================
44
45 // bool GEOM_BaseDriver::GetCreationInformation(std::string&             theOperationName,
46 //                                              std::vector<GEOM_Param>& theParams) = 0;
47
48 //================================================================================
49 /*!
50  * \brief Adds GEOM_Param to params and sets its name
51  *
52  * This method is safer than resizing the params vector and accessing to its items
53  */
54 //================================================================================
55
56 GEOM_Param& GEOM_BaseDriver::AddParam(std::vector<GEOM_Param>& params,
57                                       const char*              name)
58 {
59   GEOM_Param p;
60   p.Set( name );
61   params.push_back( p );
62   return params.back();
63 }
64
65 //================================================================================
66 /*!
67  * \brief Appends a GEOM_Function value
68  */
69 //================================================================================
70
71 GEOM_Param & GEOM_Param::operator<<( const Handle(Standard_Transient)& fun )
72 {
73   return *this << Handle(GEOM_Function)::DownCast( fun );
74 }
75
76 //================================================================================
77 /*!
78  * \brief Appends a GEOM_Function value
79  */
80 //================================================================================
81
82 GEOM_Param & GEOM_Param::operator<<( const Handle(GEOM_Function)& fun )
83 {
84   if ( !fun.IsNull() )
85   {
86     TDF_Label label = fun->GetOwnerEntry();
87     Handle(GEOM_Object) obj = GEOM_Object::GetObject( label );
88     if ( !obj.IsNull() )
89     {
90       TopoDS_Shape s = obj->GetValue();
91       (*this) << ( s.IsNull() ? TopAbs_SHAPE : s.ShapeType() );
92
93       TCollection_AsciiString entry = obj->GetAuxData();
94       TCollection_ExtendedString name;
95       {
96         Handle(TDataStd_Name) aNameAttr;
97         if( obj->GetEntry().FindAttribute(TDataStd_Name::GetID(), aNameAttr))
98           name = aNameAttr->Get();
99       }
100       if ( name.Length() > 0 && entry.Length() > 0 )
101         (*this) << "('" <<  name << "'," << entry << ")";
102       else if ( name.Length() > 0 )
103         (*this) << "('" << name << "')";
104       else if ( entry.Length() > 0 )
105         (*this) << "(" << entry << ")";
106     }
107   }
108   return *this;
109 }
110
111 //================================================================================
112 /*!
113  * \brief Appends several GEOM_Function's to the value
114  */
115 //================================================================================
116
117 GEOM_Param & GEOM_Param::operator<<( const Handle(TColStd_HSequenceOfTransient)& funs )
118 {
119   if ( !funs.IsNull() )
120   {
121     if ( funs->Length() > 1 )
122       (*this) << funs->Length() << " objects: ";
123     for ( int i = 1; i <= funs->Length(); ++i )
124       (*this) << funs->Value( i ) << " ";
125   }
126   return *this;
127 }
128
129 template <class HSEQ> void appendSeq( GEOM_Param& param,
130                                       const HSEQ& seq,
131                                       int         iLow,
132                                       int         iUp)
133 {
134   int len = 1 + iUp - iLow;
135   if ( len > 1 )
136     param << len << " items: ";
137   for ( ; iLow <= iUp; ++iLow )
138     param << seq->Value( iLow ) << " ";
139 }
140
141 //================================================================================
142 /*!
143  * \brief Appends several int's to the value
144  */
145 //================================================================================
146
147 GEOM_Param & GEOM_Param::operator<<( const Handle(TColStd_HArray1OfInteger)& vals )
148 {
149   if ( !vals.IsNull() )
150     appendSeq( *this, vals, vals->Lower(), vals->Upper() );
151   return *this;
152 }
153
154 //================================================================================
155 /*!
156  * \brief Appends TopAbs_ShapeEnum to the value
157  */
158 //================================================================================
159
160 GEOM_Param & GEOM_Param::operator<<( TopAbs_ShapeEnum type )
161 {
162   const char* str[] = {
163     "Compound","Compsolid","Solid","Shell","Face","Wire","Edge","Vertex","Shape"
164   };
165   if ( 0 <= type && type <= TopAbs_SHAPE )
166     (*this) << str[type];
167   else
168     (*this) << "TopAbs_ShapeEnum(" << type << ")";
169   return *this;
170 }
171
172 //================================================================================
173 /*!
174  * \brief Appends TopAbs_State to the value
175  */
176 //================================================================================
177
178 GEOM_Param & GEOM_Param::operator<<( TopAbs_State state )
179 {
180   const char* str[] = {"IN","OUT","ON","UNKNOWN"};
181   if ( 0 <= state && state <= TopAbs_UNKNOWN )
182     (*this) << str[state];
183   else
184     (*this) << "TopAbs_State(" << state << ")";
185   return *this;
186 }