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