1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : GEOM_BaseDriver.cxx
24 // Created : Thu Jun 6 15:44:27 2013
25 // Author : Edward AGAPOV (eap)
27 #include "GEOM_BaseDriver.hxx"
29 #include "GEOM_Function.hxx"
30 #include "GEOM_Object.hxx"
31 #include "GEOM_Engine.hxx"
33 #include <TDataStd_Name.hxx>
34 #include <TDocStd_Owner.hxx>
36 OCCT_IMPLEMENT_STANDARD_RTTIEXT(GEOM_BaseDriver,TFunction_Driver);
38 //================================================================================
42 //================================================================================
43 int GEOM_BaseDriver::GetDocID() const
46 if (!Label().IsNull()) {
47 Handle(TDocStd_Document) aDoc = TDocStd_Owner::GetDocument(Label().Data());
48 docId = GEOM_Engine::GetEngine()->GetDocID(aDoc);
53 //================================================================================
55 * \brief Returns a name of creation operation and names and values of creation parameters
57 //================================================================================
59 // bool GEOM_BaseDriver::GetCreationInformation(std::string& theOperationName,
60 // std::vector<GEOM_Param>& theParams) = 0;
62 //================================================================================
64 * \brief Adds GEOM_Param to params and sets its name
66 * This method is safer than resizing the params vector and accessing to its items
68 //================================================================================
70 GEOM_Param& GEOM_BaseDriver::AddParam(std::vector<GEOM_Param>& params,
75 params.push_back( p );
79 //================================================================================
81 * \brief Appends a GEOM_Function value
83 //================================================================================
85 GEOM_Param & GEOM_Param::operator<<( const Handle(Standard_Transient)& fun )
87 return *this << Handle(GEOM_Function)::DownCast( fun );
90 //================================================================================
92 * \brief Appends a GEOM_Function value
94 //================================================================================
96 GEOM_Param & GEOM_Param::operator<<( const Handle(GEOM_Function)& fun )
100 TDF_Label label = fun->GetOwnerEntry();
101 Handle(GEOM_Object) obj = GEOM_Object::GetObject( label );
104 TopoDS_Shape s = obj->GetValue();
105 (*this) << ( s.IsNull() ? TopAbs_SHAPE : s.ShapeType() );
107 TCollection_AsciiString entry = obj->GetAuxData();
108 TCollection_ExtendedString name;
110 Handle(TDataStd_Name) aNameAttr;
111 if( obj->GetEntry().FindAttribute(TDataStd_Name::GetID(), aNameAttr))
112 name = aNameAttr->Get();
114 if ( name.Length() > 0 && entry.Length() > 0 )
115 (*this) << "('" << name << "'," << entry << ")";
116 else if ( name.Length() > 0 )
117 (*this) << "('" << name << "')";
118 else if ( entry.Length() > 0 )
119 (*this) << "(" << entry << ")";
125 //================================================================================
127 * \brief Appends several GEOM_Function's to the value
129 //================================================================================
131 GEOM_Param & GEOM_Param::operator<<( const Handle(TColStd_HSequenceOfTransient)& funs )
133 if ( !funs.IsNull() )
135 if ( funs->Length() > 1 )
136 (*this) << funs->Length() << " objects: ";
137 for ( int i = 1; i <= funs->Length(); ++i )
138 (*this) << funs->Value( i ) << " ";
143 template <class HSEQ> void appendSeq( GEOM_Param& param,
148 int len = 1 + iUp - iLow;
150 param << len << " items: ";
151 for ( ; iLow <= iUp; ++iLow )
152 param << seq->Value( iLow ) << " ";
155 //================================================================================
157 * \brief Appends several int's to the value
159 //================================================================================
161 GEOM_Param & GEOM_Param::operator<<( const Handle(TColStd_HArray1OfInteger)& vals )
163 if ( !vals.IsNull() )
164 appendSeq( *this, vals, vals->Lower(), vals->Upper() );
168 //================================================================================
170 * \brief Appends TopAbs_ShapeEnum to the value
172 //================================================================================
174 GEOM_Param & GEOM_Param::operator<<( TopAbs_ShapeEnum type )
176 const char* str[] = {
177 "Compound","Compsolid","Solid","Shell","Face","Wire","Edge","Vertex","Shape"
179 if ( 0 <= type && type <= TopAbs_SHAPE )
180 (*this) << str[type];
182 (*this) << "TopAbs_ShapeEnum(" << type << ")";
186 //================================================================================
188 * \brief Appends TopAbs_State to the value
190 //================================================================================
192 GEOM_Param & GEOM_Param::operator<<( TopAbs_State state )
194 const char* str[] = {"IN","OUT","ON","UNKNOWN"};
195 if ( 0 <= state && state <= TopAbs_UNKNOWN )
196 (*this) << str[state];
198 (*this) << "TopAbs_State(" << state << ")";