1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "GEOM_PythonDump.hxx"
22 #include <TDF_Tool.hxx>
26 #include <TColStd_ListOfInteger.hxx>
27 #include <TColStd_ListIteratorOfListOfInteger.hxx>
31 size_t TPythonDump::myCounter = 0;
33 TPythonDump::TPythonDump (Handle(GEOM_Function)& theFunction, bool theAppend)
35 myFunction = theFunction;
40 TPythonDump::~TPythonDump()
42 if (--myCounter == 0) {
43 TCollection_AsciiString aDescr;
45 aDescr = myFunction->GetDescription() + "\n\t";
46 std::string aString = myStream.str();
47 aDescr += (char *)aString.c_str();
48 myFunction->SetDescription( aDescr );
52 TPythonDump& TPythonDump::operator<< (long int theArg)
58 TPythonDump& TPythonDump::operator<< (int theArg)
64 TPythonDump& TPythonDump::operator<< (double theArg)
66 myStream.precision(16);
71 TPythonDump& TPythonDump::operator<< (float theArg)
73 myStream.precision(8);
78 TPythonDump& TPythonDump::operator<< (const void* theArg)
84 TPythonDump& TPythonDump::operator<< (const char* theArg)
90 TPythonDump& TPythonDump::operator<< (const TopAbs_ShapeEnum theArg)
92 myStream<<"geompy.ShapeType[\"";
93 TopAbs::Print(theArg, myStream);
98 TPythonDump& TPythonDump::operator<< (const Handle(GEOM_Object)& theObject)
100 if (theObject.IsNull()) {
103 TCollection_AsciiString anEntry;
104 TDF_Tool::Entry(theObject->GetEntry(), anEntry);
105 myStream << anEntry.ToCString();
110 Handle(GEOM_Object) GetCreatedLast(const Handle(GEOM_Object)& theObj1,
111 const Handle(GEOM_Object)& theObj2)
113 if (theObj1.IsNull()) return theObj2;
114 if (theObj2.IsNull()) return theObj1;
116 TColStd_ListOfInteger aTags1, aTags2;
117 TDF_Tool::TagList(theObj1->GetEntry(), aTags1);
118 TDF_Tool::TagList(theObj2->GetEntry(), aTags2);
119 TColStd_ListIteratorOfListOfInteger aListIter1(aTags1), aListIter2(aTags2);
120 for (; aListIter1.More(); aListIter1.Next()) {
121 if (!aListIter2.More())
122 return theObj1; // anObj1 is stored under anObj2
124 if (aListIter1.Value() > aListIter2.Value())
126 else if (aListIter1.Value() < aListIter2.Value())
132 Handle(GEOM_Object) GetCreatedLast(const Handle(TColStd_HSequenceOfTransient)& theObjects)
134 Handle(GEOM_Object) anObject, aLatest;
135 int i, aLen = theObjects->Length();
139 for (i = 1; i <= aLen; i++) {
140 anObject = Handle(GEOM_Object)::DownCast(theObjects->Value(i));
141 aLatest = GetCreatedLast(aLatest, anObject);