Salome HOME
Merge master branch into V9_dev.
[modules/geom.git] / src / GEOM / GEOM_BaseDriver.cxx
1 // Copyright (C) 2007-2016  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, or (at your option) any later version.
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 #include "GEOM_Engine.hxx"
32
33 #include <TDataStd_Name.hxx>
34 #include <TDocStd_Owner.hxx>
35
36 IMPLEMENT_STANDARD_RTTIEXT(GEOM_BaseDriver,TFunction_Driver);
37
38 //================================================================================
39 /*!
40  * \brief Returns a name of creation operation and names and values of creation parameters
41  */
42 //================================================================================
43
44 // bool GEOM_BaseDriver::GetCreationInformation(std::string&             theOperationName,
45 //                                              std::vector<GEOM_Param>& theParams) = 0;
46
47 //================================================================================
48 /*!
49  * \brief Adds GEOM_Param to params and sets its name
50  *
51  * This method is safer than resizing the params vector and accessing to its items
52  */
53 //================================================================================
54
55 GEOM_Param& GEOM_BaseDriver::AddParam(std::vector<GEOM_Param>& params,
56                                       const char*              name)
57 {
58   GEOM_Param p;
59   p.Set( name );
60   params.push_back( p );
61   return params.back();
62 }
63
64 //================================================================================
65 /*!
66  * \brief Appends a GEOM_Function value
67  */
68 //================================================================================
69
70 GEOM_Param & GEOM_Param::operator<<( const Handle(Standard_Transient)& fun )
71 {
72   return *this << Handle(GEOM_Function)::DownCast( fun );
73 }
74
75 //================================================================================
76 /*!
77  * \brief Appends a GEOM_Function value
78  */
79 //================================================================================
80
81 GEOM_Param & GEOM_Param::operator<<( const Handle(GEOM_Function)& fun )
82 {
83   if ( !fun.IsNull() )
84   {
85     TDF_Label label = fun->GetOwnerEntry();
86     Handle(GEOM_Object) obj = GEOM_Object::GetObject( label );
87     if ( !obj.IsNull() )
88     {
89       TopoDS_Shape s = obj->GetValue();
90       (*this) << ( s.IsNull() ? TopAbs_SHAPE : s.ShapeType() );
91
92       TCollection_AsciiString entry = obj->GetAuxData();
93       TCollection_ExtendedString name;
94       {
95         Handle(TDataStd_Name) aNameAttr;
96         if( obj->GetEntry().FindAttribute(TDataStd_Name::GetID(), aNameAttr))
97           name = aNameAttr->Get();
98       }
99       if ( name.Length() > 0 && entry.Length() > 0 )
100         (*this) << "('" <<  name << "'," << entry << ")";
101       else if ( name.Length() > 0 )
102         (*this) << "('" << name << "')";
103       else if ( entry.Length() > 0 )
104         (*this) << "(" << entry << ")";
105     }
106   }
107   return *this;
108 }
109
110 //================================================================================
111 /*!
112  * \brief Appends several GEOM_Function's to the value
113  */
114 //================================================================================
115
116 GEOM_Param & GEOM_Param::operator<<( const Handle(TColStd_HSequenceOfTransient)& funs )
117 {
118   if ( !funs.IsNull() )
119   {
120     if ( funs->Length() > 1 )
121       (*this) << funs->Length() << " objects: ";
122     for ( int i = 1; i <= funs->Length(); ++i )
123       (*this) << funs->Value( i ) << " ";
124   }
125   return *this;
126 }
127
128 template <class HSEQ> void appendSeq( GEOM_Param& param,
129                                       const HSEQ& seq,
130                                       int         iLow,
131                                       int         iUp)
132 {
133   int len = 1 + iUp - iLow;
134   if ( len > 1 )
135     param << len << " items: ";
136   for ( ; iLow <= iUp; ++iLow )
137     param << seq->Value( iLow ) << " ";
138 }
139
140 //================================================================================
141 /*!
142  * \brief Appends several int's to the value
143  */
144 //================================================================================
145
146 GEOM_Param & GEOM_Param::operator<<( const Handle(TColStd_HArray1OfInteger)& vals )
147 {
148   if ( !vals.IsNull() )
149     appendSeq( *this, vals, vals->Lower(), vals->Upper() );
150   return *this;
151 }
152
153 //================================================================================
154 /*!
155  * \brief Appends TopAbs_ShapeEnum to the value
156  */
157 //================================================================================
158
159 GEOM_Param & GEOM_Param::operator<<( TopAbs_ShapeEnum type )
160 {
161   const char* str[] = {
162     "Compound","Compsolid","Solid","Shell","Face","Wire","Edge","Vertex","Shape"
163   };
164   if ( 0 <= type && type <= TopAbs_SHAPE )
165     (*this) << str[type];
166   else
167     (*this) << "TopAbs_ShapeEnum(" << type << ")";
168   return *this;
169 }
170
171 //================================================================================
172 /*!
173  * \brief Appends TopAbs_State to the value
174  */
175 //================================================================================
176
177 GEOM_Param & GEOM_Param::operator<<( TopAbs_State state )
178 {
179   const char* str[] = {"IN","OUT","ON","UNKNOWN"};
180   if ( 0 <= state && state <= TopAbs_UNKNOWN )
181     (*this) << str[state];
182   else
183     (*this) << "TopAbs_State(" << state << ")";
184   return *this;
185 }