1 // Copyright (C) 2007-2014 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 #include "GEOM_PythonDump.hxx"
25 #include <TDF_Tool.hxx>
29 #include <TColStd_ListOfInteger.hxx>
30 #include <TColStd_ListIteratorOfListOfInteger.hxx>
34 size_t TPythonDump::myCounter = 0;
36 TPythonDump::TPythonDump (const Handle(GEOM_Function)& theFunction, bool theAppend)
38 myFunction = theFunction;
43 TPythonDump::~TPythonDump()
45 if (--myCounter == 0) {
46 TCollection_AsciiString aDescr;
48 aDescr = myFunction->GetDescription();
49 if ( !aDescr.IsEmpty() ) aDescr += "\n\t";
51 std::string aString = myStream.str();
52 aDescr += (char *)aString.c_str();
53 myFunction->SetDescription( aDescr );
57 TPythonDump& TPythonDump::operator<< (bool theArg)
66 TPythonDump& TPythonDump::operator<< (long int theArg)
72 TPythonDump& TPythonDump::operator<< (int theArg)
78 TPythonDump& TPythonDump::operator<< (double theArg)
80 myStream.precision(16);
85 TPythonDump& TPythonDump::operator<< (float theArg)
87 myStream.precision(8);
92 TPythonDump& TPythonDump::operator<< (const void* theArg)
98 TPythonDump& TPythonDump::operator<< (const char* theArg)
104 TPythonDump& TPythonDump::operator<< (const TCollection_AsciiString theArg)
110 TPythonDump& TPythonDump::operator<< (const TopAbs_ShapeEnum theArg)
112 myStream<<"geompy.ShapeType[\"";
113 TopAbs::Print(theArg, myStream);
118 TPythonDump& TPythonDump::operator<< (const Handle(GEOM_BaseObject)& theObject)
120 if (theObject.IsNull()) {
123 *this << theObject.operator->();
128 TPythonDump& TPythonDump::operator<< (const Handle(TColStd_HSequenceOfTransient)& theObjects)
130 Standard_Integer aLength = theObjects->Length();
134 for ( Standard_Integer i = 1; i <= aLength; i++ ) {
135 *this << Handle(GEOM_Object)::DownCast(theObjects->Value(i));
136 if ( i < aLength ) myStream << ", ";
143 Standard_EXPORT TPythonDump&
144 TPythonDump::operator<< (const std::list<Handle(GEOM_Object)>& theObjects)
146 Standard_Integer aLength = theObjects.size();
150 std::list<Handle(GEOM_Object)>::const_iterator obj = theObjects.begin();
151 for ( Standard_Integer i = 1; i <= aLength; i++, ++obj ) {
153 if ( i < aLength ) myStream << ", ";
161 TPythonDump& TPythonDump::operator<< (const GEOM_BaseObject* theObject)
166 TCollection_AsciiString anEntry;
167 TDF_Tool::Entry(theObject->GetEntry(), anEntry);
168 myStream << anEntry.ToCString();
173 Handle(GEOM_Object) GetCreatedLast(const Handle(GEOM_Object)& theObj1,
174 const Handle(GEOM_Object)& theObj2)
176 if (theObj1.IsNull()) return theObj2;
177 if (theObj2.IsNull()) return theObj1;
179 TColStd_ListOfInteger aTags1, aTags2;
180 TDF_Tool::TagList(theObj1->GetEntry(), aTags1);
181 TDF_Tool::TagList(theObj2->GetEntry(), aTags2);
182 TColStd_ListIteratorOfListOfInteger aListIter1(aTags1), aListIter2(aTags2);
183 for (; aListIter1.More(); aListIter1.Next(), aListIter2.Next()) {
184 if (!aListIter2.More())
185 return theObj1; // anObj1 is stored under anObj2
187 if (aListIter1.Value() > aListIter2.Value())
189 else if (aListIter1.Value() < aListIter2.Value())
195 Handle(GEOM_Object) GetCreatedLast(const Handle(TColStd_HSequenceOfTransient)& theObjects)
197 Handle(GEOM_Object) anObject, aLatest;
198 int i, aLen = theObjects->Length();
202 for (i = 1; i <= aLen; i++) {
203 anObject = Handle(GEOM_Object)::DownCast(theObjects->Value(i));
204 aLatest = GetCreatedLast(aLatest, anObject);