Salome HOME
6b71e1551be95042c69ae183b21f716eb7aca6a7
[modules/geom.git] / src / GEOM_I / GEOM_DumpPython.cc
1 #ifdef WNT
2 #pragma warning( disable:4786 )
3 #endif
4
5 #include <Standard_Stream.hxx>
6
7 #include "GEOM_Gen_i.hh"
8 #include <TCollection_AsciiString.hxx>
9 #include <TCollection_ExtendedString.hxx>
10 #include <TColStd_HSequenceOfAsciiString.hxx>
11 #include <Resource_DataMapOfAsciiStringAsciiString.hxx>
12
13 //=======================================================================
14 //function : DumpPython
15 //purpose  : 
16 //=======================================================================
17
18 Engines::TMPFile* GEOM_Gen_i::DumpPython(CORBA::Object_ptr theStudy, 
19                                          CORBA::Boolean isPublished, 
20                                          CORBA::Boolean& isValidScript)
21 {
22   SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
23   if(CORBA::is_nil(aStudy))
24     return new Engines::TMPFile(0);   
25
26   SALOMEDS::SObject_var aSO = aStudy->FindComponent(ComponentDataType());
27   if(CORBA::is_nil(aSO))
28     return new Engines::TMPFile(0);  
29
30   Resource_DataMapOfAsciiStringAsciiString aMap;
31
32   SALOMEDS::ChildIterator_var Itr = aStudy->NewChildIterator(aSO);
33   for(Itr->InitEx(true); Itr->More(); Itr->Next()) {
34     SALOMEDS::SObject_var aValue = Itr->Value();
35     CORBA::String_var IOR = aValue->GetIOR();
36     if(strlen(IOR.in()) > 0) {
37       CORBA::Object_var obj = _orb->string_to_object(IOR);
38       GEOM::GEOM_Object_var GO = GEOM::GEOM_Object::_narrow(obj);
39       if(!CORBA::is_nil(GO)) {
40         CORBA::String_var aName = aValue->GetName();
41         CORBA::String_var anEntry = GO->GetEntry();
42         aMap.Bind( (char*)anEntry.in(), (char*)aName.in() );
43       }
44     }
45   }
46
47   TCollection_AsciiString aScript =
48     "### This file is generated by SALOME automatically by dump python funcitonality\n"
49       "### of GEOM component\n\n";
50   aScript += _impl->DumpPython(aStudy->StudyId(), aMap, isPublished, isValidScript);
51
52   int aLen = aScript.Length(); 
53   unsigned char* aBuffer = new unsigned char[aLen+1];
54   strcpy((char*)aBuffer, aScript.ToCString());
55
56   CORBA::Octet* anOctetBuf =  (CORBA::Octet*)aBuffer;
57   Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1); 
58
59   return aStreamFile._retn(); 
60 }
61
62 //=======================================================================
63 //function : GetDumpName
64 //purpose  : 
65 //=======================================================================
66
67 char* GEOM_Gen_i::GetDumpName (const char* theStudyEntry)
68 {
69   const char* name = _impl->GetDumpName( theStudyEntry );
70   if ( name && strlen( name ) > 0 )
71     return strdup( name );
72
73   return NULL;
74 }
75
76 //=======================================================================
77 //function : GetAllDumpNames
78 //purpose  : 
79 //=======================================================================
80
81 GEOM::string_array* GEOM_Gen_i::GetAllDumpNames()
82 {
83   Handle(TColStd_HSequenceOfAsciiString) aHSeq = _impl->GetAllDumpNames();
84   int i = 0, aLen = aHSeq->Length();
85
86   GEOM::string_array_var seq = new GEOM::string_array();
87   seq->length(aLen);
88
89   for (; i < aLen; i++) {
90     seq[i] = CORBA::string_dup(aHSeq->Value(i + 1).ToCString());
91   }
92
93   return seq._retn();
94 }