Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/visu.git] / src / VISU_I / VISU_Table_i.cc
1 //  Copyright (C) 2003  CEA/DEN, EDF R&D
2 //
3 //
4 //
5 //  File   : VISU_Table_i.cc
6 //  Author : Vadim SANDLER
7 //  Module : VISU
8
9 using namespace std;
10 #include "VISU_Table_i.hh"
11
12 #include "QAD_Application.h"
13 #include "QAD_Desktop.h"
14 #include "QAD_Study.h"
15 #include <fstream>      
16 #include <strstream>
17 #include <qfileinfo.h>
18 #include <qstringlist.h>
19 #include <memory>       
20
21 #ifdef DEBUG
22 static int MYDEBUG = 1;
23 #else
24 static int MYDEBUG = 0;
25 #endif
26
27 //----------------------------------------------------------------
28 //                      Table Object
29 //----------------------------------------------------------------
30 int VISU::Table_i::myNbPresent = 0;
31 const string VISU::Table_i::myComment  = "TABLE";
32 /*! 
33   Generate unique name
34 */
35 const char* VISU::Table_i::GenerateName() 
36
37   return VISU::GenerateName( "Table", ++myNbPresent ); 
38 }
39 /*!
40   Gets comment string
41 */
42 const char* VISU::Table_i::GetComment() const 
43
44   return myComment.c_str(); 
45 }
46 /*!
47   Constructor
48 */
49 VISU::Table_i::Table_i( SALOMEDS::Study_ptr theStudy, const char* theObjectEntry )
50      : PrsObject_i(theStudy)
51 {
52   myObjectEntry = theObjectEntry; 
53   myOrientation = VISU::Table::HORIZONTAL;
54 }
55 /*!
56   Destructor
57 */
58 VISU::Table_i::~Table_i()
59 {
60 }
61 /*!
62   Gets number of rows in table
63 */
64 CORBA::Long VISU::Table_i::GetNbRows()
65 {
66   SALOMEDS::SObject_var SO = myStudy->FindObjectID( myObjectEntry.c_str() );
67   SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
68   if ( !SO->_is_nil() ) {
69     SALOMEDS::GenericAttribute_var        anAttr;
70     if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
71       SALOMEDS::AttributeTableOfInteger_var anInt =  SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
72       return anInt->GetNbRows();
73     }
74     else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
75       SALOMEDS::AttributeTableOfReal_var aReal =  SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
76       return aReal->GetNbRows();
77     }
78   }
79   return 0;
80 }
81 /*!
82   Gets number of columns in table
83 */
84 CORBA::Long VISU::Table_i::GetNbColumns()
85 {
86   SALOMEDS::SObject_var SO = myStudy->FindObjectID( myObjectEntry.c_str() );
87   SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
88   if ( !SO->_is_nil() ) {
89     SALOMEDS::GenericAttribute_var        anAttr;
90     if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
91       SALOMEDS::AttributeTableOfInteger_var anInt =  SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
92       return anInt->GetNbColumns();
93     }
94     else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
95       SALOMEDS::AttributeTableOfReal_var aReal =  SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
96       return aReal->GetNbColumns();
97     }
98   }
99   return 0;
100 }
101 /*!
102   Creates table object
103 */
104 VISU::Storable* VISU::Table_i::Create()
105 {
106   // generate name ... 
107   myName = GetTableTitle(); 
108   if ( myName == "" )
109     myName = GenerateName();
110   // ... and build the object
111   return Build( false );
112 }
113 /*!
114   Builds presentation of table
115 */
116 VISU::Storable* VISU::Table_i::Build( int theRestoring ) 
117 {
118   // look for reference SObject with table attribute
119   SALOMEDS::SObject_var SO = myStudy->FindObjectID( myObjectEntry.c_str() );
120   if ( !SO->_is_nil() ) {
121     CutLines_i* pCutLines = NULL;
122     CORBA::Object_var anObj = SObjectToObject(SO);
123     if(!CORBA::is_nil(anObj)){
124       VISU::CutLines_var aCutLines = VISU::CutLines::_narrow(anObj);
125       if(!aCutLines->_is_nil())
126         pCutLines = dynamic_cast<CutLines_i*>(GetServant(aCutLines));
127     }
128     SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
129     SALOMEDS::GenericAttribute_var anAttr;
130     if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) || 
131          Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) || pCutLines) {
132       // look for component
133       if ( !theRestoring ) {
134         SALOMEDS::SComponent_var SComponent = VISU::FindOrCreateVisuComponent( myStudy );
135         // create SObject and set attributes
136         QString aComment;
137         aComment.sprintf("myComment=%s;myType=%d",GetComment(),VISU::TTABLE);
138         string anEntry = CreateAttributes( myStudy, 
139                                            SComponent->GetID(),
140                                            "",
141                                            GetID(),
142                                            GetName(),
143                                            "",
144                                            aComment.latin1(), 
145                                            true );
146         // create SObject referenced to real table object
147         SALOMEDS::SObject_var newSO = myStudy->FindObjectID( anEntry.c_str() );
148         if(pCutLines) {
149           pCutLines->BuildTableOfReal(newSO);
150           myObjectEntry = anEntry;
151         }
152         SALOMEDS::SObject_var refSO = Builder->NewObject( newSO );
153         Builder->Addreference( refSO, SO );
154       }
155       return this;
156     }
157   }
158   return NULL;
159 }
160 /*!
161   Restores table object from stream
162 */
163 VISU::Storable* VISU::Table_i::Restore( const Storable::TRestoringMap& theMap )
164      throw( std::logic_error& )
165 {
166   if(MYDEBUG) MESSAGE(GetComment());
167   myName = (const char*)(VISU::Storable::FindValue(theMap,"myName"));
168   myObjectEntry = (const char *)(VISU::Storable::FindValue(theMap,"myObjectEntry"));
169   myTitle = (const char*)(VISU::Storable::FindValue(theMap,"myTitle"));
170   myOrientation = ( VISU::Table::Orientation )( VISU::Storable::FindValue(theMap,"myOrientation").toInt() );
171   return Build( true );
172 }
173 /*!
174   Flushes table data into stream
175 */
176 void VISU::Table_i::ToStream( std::ostringstream& theStr )
177 {
178   Storable::DataToStream( theStr, "myName",        myName.c_str() );
179   Storable::DataToStream( theStr, "myObjectEntry", myObjectEntry.c_str() );
180   Storable::DataToStream( theStr, "myTitle",       myTitle.c_str() );
181   Storable::DataToStream( theStr, "myOrientation", myOrientation );
182 }
183 /*!
184   Called from engine to restore table from the file
185 */
186 VISU::Storable* VISU::TableRestore(SALOMEDS::SObject_ptr theSObject, 
187                                    const string& thePrefix, const Storable::TRestoringMap& theMap)
188 {
189   SALOMEDS::Study_var aStudy = theSObject->GetStudy();
190   VISU::Table_i* pResent = new VISU::Table_i( aStudy, "" );
191   return pResent->Restore( theMap );
192 }
193 /*!
194   Gets title for the original table object
195 */
196 const char* VISU::Table_i::GetTableTitle()
197 {
198   SALOMEDS::SObject_var SO = myStudy->FindObjectID( GetObjectEntry() );
199   SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
200   SALOMEDS::GenericAttribute_var        anAttr;
201   SALOMEDS::AttributeTableOfInteger_var anInt;
202   SALOMEDS::AttributeTableOfReal_var    aReal;
203   if ( !SO->_is_nil() ) { 
204     if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
205       anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
206       return anInt->GetTitle();
207     }
208     else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
209       aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
210       return aReal->GetTitle();
211     }
212   }
213   return ""; 
214 }
215
216 //----------------------------------------------------------------
217 //                      Curve Object
218 //----------------------------------------------------------------
219 /*!
220   Restores table object from the stream [ static ]
221 */
222 static VISU::Table_i* GetTable( SALOMEDS::Study_var& theStudy, const VISU::Storable::TRestoringMap& theMap ) {
223   string anEntry = VISU::Storable::FindValue( theMap, "TableID" ).latin1();
224   SALOMEDS::SObject_var aSObject = theStudy->FindObjectID( anEntry.c_str() );
225   CORBA::Object_var anObject = VISU::SObjectToObject( aSObject );
226   if( !CORBA::is_nil( anObject ) ) {
227     CORBA::Object_ptr aTable = VISU::Table::_narrow( anObject );
228     if( !CORBA::is_nil( aTable ) )
229       return dynamic_cast<VISU::Table_i*>( VISU::GetServant( aTable ) );
230   }
231   return NULL;
232 }
233
234 int VISU::Curve_i::myNbPresent = 0;
235 const string VISU::Curve_i::myComment  = "CURVE";
236 /*! 
237   Generate unique name
238 */
239 const char* VISU::Curve_i::GenerateName() 
240
241   return VISU::GenerateName( "Curve", ++myNbPresent ); 
242 }
243 /*!
244   Gets comment string
245 */
246 const char* VISU::Curve_i::GetComment() const 
247
248   return myComment.c_str(); 
249 }
250 /*!
251   Constructor
252   NB : theHRow, theVRow are the indexes of rows in the Table object and numbered from the 1 to GetNbRows()
253 */
254 VISU::Curve_i::Curve_i(SALOMEDS::Study_ptr theStudy, Table_i* theTable, CORBA::Long theHRow, CORBA::Long theVRow )
255      : PrsObject_i(theStudy), myTable( theTable ), myHRow( theHRow ), myVRow( theVRow )
256 {
257   myAuto = true;
258   myLine = VISU::Curve::SOLIDLINE;
259   myLineWidth = 0;
260   myMarker = VISU::Curve::CIRCLE;
261   myColor.R = 0.0; myColor.G = 0.0; myColor.B = 0.0;
262 }
263 /*!
264   Destructor
265 */
266 VISU::Curve_i::~Curve_i()
267 {
268 }
269 /*!
270   Creates curve object
271 */
272 VISU::Storable* VISU::Curve_i::Create()
273 {
274   // generate name ... 
275   myName = GetVerTitle(); 
276   if ( myName == "" )
277     myName = GenerateName();
278   // ... and build the object
279   return Build( false );
280 }
281 /*!
282   Builds presentation of curve
283 */
284 VISU::Storable* VISU::Curve_i::Build( int theRestoring ) 
285 {
286   if ( myTable != NULL ) {
287     // getting table SObject by it's entry
288     SALOMEDS::SObject_var SO = myStudy->FindObjectID( myTable->GetEntry() );
289     int nbRows = myTable->GetNbRows();
290     if ( !SO->_is_nil() && myHRow > 0 && myHRow <= nbRows && myVRow > 0 && myVRow <= nbRows ) {
291       if ( !theRestoring ) {
292         // look for component
293         SALOMEDS::SComponent_var SComponent = VISU::FindOrCreateVisuComponent( myStudy );
294         // create SObject and set attributes
295         QString aComment;
296         aComment.sprintf("myComment=%s;myType=%d",GetComment(),VISU::TCURVE);
297         string anEntry = CreateAttributes( myStudy, 
298                                            myTable->GetEntry(),
299                                            "",
300                                            GetID(),
301                                            GetName(),
302                                            "",
303                                            aComment.latin1(),
304                                            true );
305       }
306       return this;
307     }
308   }
309   return NULL;
310 }
311
312 /*!
313   Returns CORBA::True if curve refers to valid table data
314 */
315 CORBA::Boolean VISU::Curve_i::IsValid()
316 {
317   // getting table SObject by it's entry
318   SALOMEDS::SObject_var SO = myStudy->FindObjectID( myTable->GetObjectEntry() );
319   SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
320   SALOMEDS::GenericAttribute_var        anAttr;
321   SALOMEDS::AttributeTableOfInteger_var anInt;
322   SALOMEDS::AttributeTableOfReal_var    aReal;
323   if ( !SO->_is_nil() ) { 
324     if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
325       anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
326       if ( myHRow > 0 && myHRow <= anInt->GetNbRows() && myVRow > 0 && myVRow <= anInt->GetNbRows() ) {
327         return true;
328       }
329     }
330     else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
331       aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
332       if ( myHRow > 0 && myHRow <= aReal->GetNbRows() && myVRow > 0 && myVRow <= aReal->GetNbRows() ) {
333         return true;
334       }
335     }
336   }
337   return false;
338 }
339 /*!
340   Returns hor.axis title
341 */
342 string VISU::Curve_i::GetHorTitle()
343 {
344   string title;
345   // getting table SObject by it's entry
346   SALOMEDS::SObject_var SO = myStudy->FindObjectID( myTable->GetObjectEntry() );
347   SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
348   SALOMEDS::GenericAttribute_var        anAttr;
349   SALOMEDS::AttributeTableOfInteger_var anInt;
350   SALOMEDS::AttributeTableOfReal_var    aReal;
351   if ( !SO->_is_nil() ) { 
352     if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
353       anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
354       SALOMEDS::StringSeq_var rowTitles = anInt->GetRowTitles();
355       if ( rowTitles->length() > 0 && myHRow > 0 && myHRow <= anInt->GetNbRows() ) {
356         title = strdup( rowTitles[ myHRow-1 ] );
357       }
358     }
359     else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
360       aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
361       SALOMEDS::StringSeq_var rowTitles = aReal->GetRowTitles();
362       if ( rowTitles->length() > 0 && myHRow > 0 && myHRow <= aReal->GetNbRows() ) {
363         title = strdup( rowTitles[ myHRow-1 ] );
364       }
365     }
366   }
367   return title;
368 }
369 /*!
370   Returns ver.axis title
371 */
372 string VISU::Curve_i::GetVerTitle()
373 {
374   string title;
375   // getting table SObject by it's entry
376   SALOMEDS::SObject_var SO = myStudy->FindObjectID( myTable->GetObjectEntry() );
377   SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
378   SALOMEDS::GenericAttribute_var        anAttr;
379   SALOMEDS::AttributeTableOfInteger_var anInt;
380   SALOMEDS::AttributeTableOfReal_var    aReal;
381   if ( !SO->_is_nil() ) { 
382     if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
383       anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
384       SALOMEDS::StringSeq_var rowTitles = anInt->GetRowTitles();
385       if ( rowTitles->length() > 0 && myVRow > 0 && myVRow <= anInt->GetNbRows() )
386         title = strdup( rowTitles[ myVRow-1 ] );
387     }
388     else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
389       aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
390       SALOMEDS::StringSeq_var rowTitles = aReal->GetRowTitles();
391       if ( rowTitles->length() > 0 && myVRow > 0 && myVRow <= aReal->GetNbRows() )
392         title = strdup( rowTitles[ myVRow-1 ] );
393     }
394   }
395   return title;
396 }
397 /*!
398   Returns hor.axis units
399 */
400 string VISU::Curve_i::GetHorUnits()
401 {
402   string units;
403   // getting table SObject by it's entry
404   SALOMEDS::SObject_var SO = myStudy->FindObjectID( myTable->GetObjectEntry() );
405   SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
406   SALOMEDS::GenericAttribute_var        anAttr;
407   SALOMEDS::AttributeTableOfInteger_var anInt;
408   SALOMEDS::AttributeTableOfReal_var    aReal;
409   if ( !SO->_is_nil()  ) { 
410     if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
411       anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
412       SALOMEDS::StringSeq_var rowUnits = anInt->GetRowUnits();
413       if ( rowUnits->length() > 0 && myHRow > 0 && myHRow <= anInt->GetNbRows() )
414         units = strdup( rowUnits[ myHRow-1 ] );
415     }
416     else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
417       aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
418       SALOMEDS::StringSeq_var rowUnits = aReal->GetRowUnits();
419       if ( rowUnits->length() > 0 && myHRow > 0 && myHRow <= aReal->GetNbRows() )
420         units = strdup( rowUnits[ myHRow-1 ] );
421     }
422   }
423   return units;
424 }
425 /*!
426   Returns ver.axis units
427 */
428 string VISU::Curve_i::GetVerUnits()
429 {
430   string units;
431   // getting table SObject by it's entry
432   SALOMEDS::SObject_var SO = myStudy->FindObjectID( myTable->GetObjectEntry() );
433   SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
434   SALOMEDS::GenericAttribute_var        anAttr;
435   SALOMEDS::AttributeTableOfInteger_var anInt;
436   SALOMEDS::AttributeTableOfReal_var    aReal;
437   if ( !SO->_is_nil() ) { 
438     if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
439       anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
440       SALOMEDS::StringSeq_var rowUnits = anInt->GetRowUnits();
441       if ( rowUnits->length() > 0 && myVRow > 0 && myVRow <= anInt->GetNbRows() )
442         units = strdup( rowUnits[ myVRow-1] );
443     }
444     else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
445       aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
446       SALOMEDS::StringSeq_var rowUnits = aReal->GetRowUnits();
447       if ( rowUnits->length() > 0 && myVRow > 0 && myVRow <= aReal->GetNbRows() )
448         units = strdup( rowUnits[ myVRow-1 ] );
449     }
450   }
451   return units;
452 }
453 /*!
454   Gets curve data
455 */
456 int VISU::Curve_i::GetData( double*& theHorList, double*& theVerList )
457 {
458   theHorList = 0; theVerList = 0;
459   // getting table SObject by it's entry
460   SALOMEDS::SObject_var SO = myStudy->FindObjectID( myTable->GetObjectEntry() );
461   SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
462   SALOMEDS::GenericAttribute_var        anAttr;
463   SALOMEDS::AttributeTableOfInteger_var anInt;
464   SALOMEDS::AttributeTableOfReal_var    aReal;
465   if ( !SO->_is_nil() ) { 
466     if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
467       anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
468       int nbCols = anInt->GetNbColumns() ; 
469       if ( nbCols > 0 && myHRow > 0 && myHRow <= anInt->GetNbRows() && myVRow > 0 && myVRow <= anInt->GetNbRows() ) {
470         int nbPoints = 0;
471         for ( int j = 1; j <= nbCols; j++ ) {
472           if ( anInt->HasValue( myHRow, j ) && anInt->HasValue( myVRow, j ) )
473             nbPoints++;
474         }
475         if ( nbPoints > 0 ) {
476           theHorList = new double[ nbPoints ];
477           theVerList = new double[ nbPoints ];
478           int k = 0;
479           for ( int j = 1; j <= nbCols; j++ ) {
480             if ( anInt->HasValue( myHRow, j ) && anInt->HasValue( myVRow, j ) ) {
481               theHorList[k] = anInt->GetValue( myHRow, j );
482               theVerList[k] = anInt->GetValue( myVRow, j );
483               k++;
484             }
485           }
486         }
487         return nbPoints;
488       }
489     }
490     else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
491       aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
492       int nbCols = aReal->GetNbColumns() ; 
493       if ( nbCols > 0 && myHRow > 0 && myHRow <= aReal->GetNbRows() && myVRow > 0 && myVRow <= aReal->GetNbRows() ) {
494         int nbPoints = 0;
495         for ( int j = 1; j <= nbCols; j++ ) {
496           if ( aReal->HasValue( myHRow, j ) && aReal->HasValue( myVRow, j ) )
497             nbPoints++;
498         }
499         if ( nbPoints > 0 ) {
500           theHorList = new double[ nbPoints ];
501           theVerList = new double[ nbPoints ];
502           int k = 0;
503           for ( int j = 1; j <= nbCols; j++ ) {
504             if ( aReal->HasValue( myHRow, j ) && aReal->HasValue( myVRow, j ) ) {
505               theHorList[k] = aReal->GetValue( myHRow, j );
506               theVerList[k] = aReal->GetValue( myVRow, j );
507               k++;
508             }
509           }
510         }
511         return nbPoints;
512       }
513     }
514   }
515   return 0;
516 }
517 /*!
518   Creates curve Plot2d presentation object
519 */
520 Plot2d_Curve* VISU::Curve_i::CreatePresentation()
521 {
522   Plot2d_Curve* crv = new Plot2d_Curve();
523   crv->setHorTitle( GetHorTitle().c_str() );
524   string tlt = GetTitle(); 
525   if ( tlt.length() <= 0 )
526     tlt = GetVerTitle();
527   //crv->setVerTitle( strdup( GetVerTitle().c_str() ) );
528   //crv->setVerTitle( strdup( GetName() ) );
529   crv->setVerTitle( tlt.c_str() );
530   crv->setHorUnits( GetHorUnits().c_str() );
531   crv->setVerUnits( GetVerUnits().c_str() );
532   double* xList = 0;
533   double* yList = 0;
534   int     nbPoints = GetData( xList, yList );
535   if ( nbPoints > 0 && xList && yList ) {
536     crv->setData( xList, yList, nbPoints );
537   }
538   //cout << "********** Number of points: " << nbPoints <<endl;
539   //for ( int i =0 ; i < nbPoints; i++ ) {
540   //  cout << i<<"\t"<<xList[i] << "\t"<< yList[i] << endl;
541   //}
542   crv->setLine( (Plot2d_Curve::LineType)GetLine(), GetLineWidth() );
543   crv->setMarker( (Plot2d_Curve::MarkerType)GetMarker() ); 
544   SALOMEDS::Color color = GetColor();
545   crv->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
546   crv->setAutoAssign( IsAuto() );
547   crv->setIO(new SALOME_InteractiveObject(strdup(GetEntry()),"VISU",strdup(GetName()))); 
548   if ( myTable )
549     crv->setTableIO(new SALOME_InteractiveObject(strdup(myTable->GetEntry()),"VISU",strdup(myTable->GetName()))); 
550   return crv;
551 }
552 /*!
553   Restores curve object from stream
554 */
555 VISU::Storable* VISU::Curve_i::Restore( const Storable::TRestoringMap& theMap )
556      throw( std::logic_error& )
557 {
558   if(MYDEBUG) MESSAGE(GetComment());
559   myName = (const char*)(VISU::Storable::FindValue(theMap,"myName"));
560   myHRow = VISU::Storable::FindValue(theMap,"myHRow").toInt();
561   myVRow = VISU::Storable::FindValue(theMap,"myVRow").toInt();
562   myColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble();
563   myColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble();
564   myColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble();
565   myMarker = ( VISU::Curve::MarkerType )( VISU::Storable::FindValue(theMap,"myMarker").toInt() );
566   myLine = ( VISU::Curve::LineType )( VISU::Storable::FindValue(theMap,"myLine").toInt() );
567   return Build( true );
568 }
569 /*!
570   Flushes curve data into stream
571 */
572 void VISU::Curve_i::ToStream( std::ostringstream& theStr )
573 {
574   Storable::DataToStream( theStr, "TableID",   GetTableID());
575   Storable::DataToStream( theStr, "myName",    myName.c_str() );
576   Storable::DataToStream( theStr, "myHRow",    myHRow );
577   Storable::DataToStream( theStr, "myVRow",    myVRow );
578   Storable::DataToStream( theStr, "myColor.R", myColor.R );
579   Storable::DataToStream( theStr, "myColor.G", myColor.G );
580   Storable::DataToStream( theStr, "myColor.B", myColor.B );
581   Storable::DataToStream( theStr, "myMarker",  myMarker );
582   Storable::DataToStream( theStr, "myLine",    myLine );
583 }
584 /*!
585   Gets reference table's entry
586 */
587 const char* VISU::Curve_i::GetTableID() { 
588   return CORBA::string_dup(myTable->GetEntry());
589 }
590 /*!
591   Called from engine to restore curve from the file
592 */
593 VISU::Storable* VISU::CurveRestore(SALOMEDS::SObject_ptr theSObject, 
594                                    const string& thePrefix, const Storable::TRestoringMap& theMap)
595 {
596   SALOMEDS::Study_var aStudy = theSObject->GetStudy();
597   VISU::Table_i* pTable = GetTable( aStudy, theMap );
598   if( pTable != NULL ) {
599     VISU::Curve_i* pResent = new VISU::Curve_i( aStudy, pTable, 0, 0 );
600     return pResent->Restore( theMap );
601   }
602   return NULL;
603 }
604
605 //----------------------------------------------------------------
606 //                      Container Object
607 //----------------------------------------------------------------
608 int VISU::Container_i::myNbPresent = 0;
609 const string VISU::Container_i::myComment  = "CONTAINER";
610 /*! 
611   Generate unique name
612 */
613 const char* VISU::Container_i::GenerateName() 
614
615   return VISU::GenerateName( "Container", ++myNbPresent ); 
616 }
617 /*!
618   Gets comment string
619 */
620 const char* VISU::Container_i::GetComment() const 
621
622   return myComment.c_str(); 
623 }
624 /*!
625   Constructor
626 */
627 VISU::Container_i::Container_i( SALOMEDS::Study_ptr theStudy )
628      : PrsObject_i( theStudy )
629 {
630 }
631 /*!
632   Destructor
633 */
634 VISU::Container_i::~Container_i()
635 {
636   myCurves.clear();
637 }
638 /*!
639   Inserts curve into the container
640 */
641 void VISU::Container_i::AddCurve( Curve_ptr theCurve )
642 {
643   if ( myStudy->_is_nil() )
644     return;
645   SALOMEDS::SObject_var mySO = myStudy->FindObjectID( GetEntry() );
646   if ( mySO->_is_nil() )
647     return;
648   PortableServer::POA_ptr aPOA = GetPOA();
649   Curve_i* pCurve = dynamic_cast<Curve_i*>( aPOA->reference_to_servant( theCurve ) );
650   if( pCurve ) {
651     QString entry = pCurve->GetEntry();
652     SALOMEDS::SObject_var SO = myStudy->FindObjectID( entry.latin1() );
653     if ( !SO->_is_nil() && myCurves.find( entry ) == myCurves.end() ) {
654       myCurves.append( entry );
655       SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
656       SALOMEDS::SObject_var newSO = Builder->NewObject( mySO );
657       Builder->Addreference( newSO, SO );
658     }
659   }
660 }
661 /*!
662   Removes curve from the container
663 */
664 void VISU::Container_i::RemoveCurve( Curve_ptr theCurve )
665 {
666   if ( myStudy->_is_nil() )
667     return;
668   SALOMEDS::SObject_var mySO = myStudy->FindObjectID( GetEntry() );
669   if ( mySO->_is_nil() )
670     return;
671   PortableServer::POA_ptr aPOA = GetPOA();
672   Curve_i* pCurve = dynamic_cast<Curve_i*>( aPOA->reference_to_servant( theCurve ) );
673   if( pCurve ) {
674     QString entry = pCurve->GetEntry();
675     if ( myCurves.find( entry ) != myCurves.end() ) {
676       // found !!!
677       myCurves.remove( entry );
678       SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
679       SALOMEDS::ChildIterator_var CI = myStudy->NewChildIterator( mySO );
680       for ( ; CI->More(); CI->Next() ) {
681         SALOMEDS::SObject_var childSO = CI->Value();
682         SALOMEDS::SObject_var refSO;
683         if ( childSO->ReferencedObject( refSO ) && !refSO->_is_nil() && entry == QString( refSO->GetID() ) ) {
684           Builder->RemoveObject( childSO );
685         }
686       }
687     }
688   }
689 }
690 /*!
691   Gets number of curves in the container
692 */
693 CORBA::Long VISU::Container_i::GetNbCurves()
694 {
695   return myCurves.count();
696 }
697 /*!
698   Clears container
699 */
700 void VISU::Container_i::Clear()
701 {
702   if ( myStudy->_is_nil() )
703     return;
704   SALOMEDS::SObject_var mySO = myStudy->FindObjectID( GetEntry() );
705   if ( mySO->_is_nil() )
706     return;
707   QStringList toDelete;
708   SALOMEDS::ChildIterator_var CI = myStudy->NewChildIterator( mySO );
709   for ( ; CI->More(); CI->Next() ) {
710     toDelete.append( CI->Value()->GetID() );
711   }
712   SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
713   for ( int i = 0; i < toDelete.count(); i++ ) {
714     SALOMEDS::SObject_var SO = myStudy->FindObjectID( toDelete[i].latin1() );
715     Builder->RemoveObject( SO );
716   }
717   myCurves.clear();
718 }
719 /*!
720   Creates container object
721 */
722 VISU::Storable* VISU::Container_i::Create()
723 {
724   // generate name ... 
725   myName = GenerateName();
726   // ... and build the object
727   return Build( false );
728 }
729 /*!
730   Builds presentation of container
731 */
732 VISU::Storable* VISU::Container_i::Build( int theRestoring ) 
733 {
734   if ( !theRestoring ) {
735     // looking for component
736     SALOMEDS::SComponent_var SComponent = VISU::FindOrCreateVisuComponent( myStudy );
737     // create SObject and set attributes
738     QString aComment;
739     aComment.sprintf("myComment=%s;myType=%d",GetComment(),VISU::TCONTAINER);
740     string anEntry = CreateAttributes( myStudy, 
741                                        SComponent->GetID(),
742                                        "",
743                                        GetID(),
744                                        GetName(),
745                                        "",
746                                        aComment.latin1(),
747                                        true );
748   }
749   return this;
750 }
751 /*!
752   Updates presentation of container
753 */
754 void VISU::Container_i::Update()
755 {
756   if ( myStudy->_is_nil() )
757     return;
758   SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
759   SALOMEDS::SObject_var mySO = myStudy->FindObjectID( GetEntry() );
760   SALOMEDS::GenericAttribute_var anAttr;
761   if ( !mySO->_is_nil() ) {
762     QStringList toDelete;
763     int i;
764     for ( i = 0; i < myCurves.count(); i++ ) {
765       SALOMEDS::SObject_var SO = myStudy->FindObjectID( myCurves[i].latin1() );
766       if ( !SO->_is_nil() && Builder->FindAttribute( SO, anAttr, "AttributeIOR" ) ) {
767         // if real Curve Object still exists 
768         SALOMEDS::ChildIterator_var CI = myStudy->NewChildIterator( mySO );
769         bool bFound = false;
770         for ( ; CI->More(); CI->Next() ) {
771           SALOMEDS::SObject_var childSO = CI->Value();
772           SALOMEDS::SObject_var refSO;
773           if ( childSO->ReferencedObject( refSO ) && !refSO->_is_nil() && myCurves[i] == QString( refSO->GetID() ) ) {
774             bFound = true; break;
775           }
776         }
777         if (! bFound ) {
778           // create SObject referenced to real curve object if is not yet added
779           SALOMEDS::SObject_var newSO = Builder->NewObject( mySO );
780           Builder->Addreference( newSO, SO );
781         }
782       }
783       else {
784         // real Curve Object doesn't exist (might be removed)
785         toDelete.append( myCurves[i] );
786       }
787     }
788     for ( i = 0; i < toDelete.count(); i++ ) { 
789       myCurves.remove( toDelete[i] );
790     }
791     toDelete.clear();
792     SALOMEDS::ChildIterator_var CI = myStudy->NewChildIterator( mySO );
793     for ( ; CI->More(); CI->Next() ) {
794       SALOMEDS::SObject_var childSO = CI->Value();
795       SALOMEDS::SObject_var refSO;
796       if ( childSO->ReferencedObject( refSO ) && ( refSO->_is_nil() || !Builder->FindAttribute( refSO, anAttr, "AttributeIOR" ) ||
797                                                    myCurves.find( refSO->GetID() ) == myCurves.end() ) ) {
798         toDelete.append( childSO->GetID() );
799       }
800     }
801     for ( i = 0; i < toDelete.count(); i++ ) { 
802       SALOMEDS::ChildIterator_var CI = myStudy->NewChildIterator( mySO );
803       for ( ; CI->More(); CI->Next() ) {
804         SALOMEDS::SObject_var childSO = CI->Value();
805         if ( toDelete[i] == CI->Value()->GetID() ) {
806           Builder->RemoveObject( childSO );
807         }
808       }
809     }
810   }
811 }
812 /*!
813   Gets curve from container by index
814   NB : curves are numbered from 1
815 */
816 VISU::Curve_i* VISU::Container_i::GetCurve( CORBA::Long theIndex )
817 {
818   if ( theIndex > 0 && theIndex <= myCurves.count()  ) {
819     SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
820     SALOMEDS::GenericAttribute_var anAttr;
821     SALOMEDS::SObject_var SO = myStudy->FindObjectID( myCurves[  theIndex-1 ].latin1() );
822     CORBA::Object_var anObject = VISU::SObjectToObject( SO );
823     if( !CORBA::is_nil( anObject ) ) {
824       // if real Curve Object exists 
825       CORBA::Object_ptr aCurve = VISU::Curve::_narrow( anObject );
826       if( !CORBA::is_nil( aCurve ) )
827       return dynamic_cast<VISU::Curve_i*>(VISU::GetServant( aCurve ) );
828     }
829   }
830   return NULL;
831 }
832 /*!
833   Restores container data from the stream
834 */
835 VISU::Storable* VISU::Container_i::Restore( const Storable::TRestoringMap& theMap )
836      throw( std::logic_error& )
837 {
838   if(MYDEBUG) MESSAGE(GetComment());
839   myName = (const char*)(VISU::Storable::FindValue( theMap, "myName" )); 
840   QString val = VISU::Storable::FindValue( theMap, "myCurves" );
841   myCurves = QStringList::split( QString( "*" ), val, false );
842   return Build( true );
843 }
844 /*!
845   Flushes container data into the stream
846 */
847 void VISU::Container_i::ToStream( std::ostringstream& theStr )
848 {
849   Storable::DataToStream( theStr, "myName",   myName.c_str() );
850   Storable::DataToStream( theStr, "myCurves", myCurves.join( QString( "*" ) ) );
851 //  theStr<<" myName "<<myName;
852 //  theStr<<" myCurves "<<myCurves.join( QString( "*" ) ).latin1()<<"* ";
853 }
854 /*!
855   Called from engine to restore container from the file
856 */
857 VISU::Storable* VISU::ContainerRestore(SALOMEDS::SObject_ptr theSObject, 
858                                        const string& thePrefix, const Storable::TRestoringMap& theMap)
859 {
860   SALOMEDS::Study_var aStudy = theSObject->GetStudy();
861   VISU::Container_i* pResent = new VISU::Container_i( aStudy );
862   return pResent->Restore( theMap );
863 }
864
865 //-------------------------------------------------------------
866 //             Implementation of reading from file
867 //-------------------------------------------------------------
868 typedef vector<float> TValues;
869
870 struct TRow{
871   string myTitle;
872   string myUnit;
873   TValues myValues;
874 };
875
876 typedef vector<TRow> TRows;
877
878 struct TTable2D{
879   string myTitle;
880   vector<string> myColumnUnits;
881   vector<string> myColumnTitles;
882   TRows myRows;
883   int Check(){
884     if(myRows.empty()) return 0;
885     int iEnd = myRows[0].myValues.size();
886     if(iEnd == 0) return 0;
887     if(myColumnTitles.size() != iEnd) myColumnTitles.resize(iEnd);
888     if(myColumnUnits.size() != iEnd) myColumnUnits.resize(iEnd);
889     int jEnd = myRows.size();
890     for(int j = 0; j < jEnd; j++)
891       if(myRows[j].myValues.size() != iEnd) return 0;
892     return 1;
893   }
894   void getColumns(TTable2D& theTable2D) const {
895     TRows& aRows = theTable2D.myRows;
896     aRows.clear();
897     if(myRows.empty()) return;
898     int jEnd = myRows.size();
899     //Define Titles & Units
900     theTable2D.myColumnTitles.resize(jEnd);
901     theTable2D.myColumnUnits.resize(jEnd);
902     for(int j = 0; j < jEnd; j++){
903       theTable2D.myColumnTitles[j] = myRows[j].myTitle;
904       theTable2D.myColumnUnits[j] = myRows[j].myUnit;
905     }
906     //Define Rows
907     int iEnd = myRows[0].myValues.size();
908     for(int i = 0; i < iEnd; i++){
909       TRow aNewRow;
910       aNewRow.myTitle = myColumnTitles[i];
911       aNewRow.myUnit = myColumnUnits[i];
912       aNewRow.myValues.resize(jEnd);
913       for(int j = 0; j < jEnd; j++){
914         aNewRow.myValues[j] = myRows[j].myValues[i];
915       }
916       aRows.push_back(aNewRow);
917     }
918   }
919 };
920
921 typedef vector<TTable2D> TTableCont;
922
923 int getLine(ifstream& theStmIn, QString& theString){
924   char tmp;
925   ostrstream aStrOut;
926   while(theStmIn.get(tmp)){
927     aStrOut<<tmp;
928     if(tmp == '\n') break;
929   }
930   aStrOut<<ends;
931   auto_ptr<char> aRet(aStrOut.str());
932   theString = aRet.get();
933   return !theStmIn.eof();
934 }
935
936 void ImportTables(const char* theFileName, TTableCont& theTableCont){
937   ifstream aStmIn;
938   QFileInfo aFileInfo(theFileName);
939   if(!aFileInfo.isFile() || !aFileInfo.isReadable() || !aFileInfo.size()) return;
940   aStmIn.open(theFileName);
941   QString aTmp;
942   do{
943     //Find beginning of Table
944     while(getLine(aStmIn,aTmp) && aTmp == "\n");
945     //cout<<"\n There is new Table2D with Title = ";
946     TTable2D aTable2D;
947     while(!aStmIn.eof() && aTmp != "\n"){
948       if(aTmp.find("#TITLE:") == 0){
949         int aLen = aTmp.find(":") + 1;
950         aTmp.remove(0,aLen);
951         QString aTitle = aTmp.stripWhiteSpace();
952         aTable2D.myTitle = (const char*)aTitle;
953         //cout<<aTitle<<endl;
954       }else if(aTmp.find("#COLUMN_TITLES:") == 0){
955         int aLen = aTmp.find(":") + 1;
956         aTmp.remove(0,aLen);
957         QStringList aStrList = QStringList::split("|",aTmp);
958         //cout<<"Its Column Titles : ";
959         for(int i = 0; i < aStrList.count(); i++){
960           aTmp = aStrList[i].stripWhiteSpace();
961           aTable2D.myColumnTitles.push_back(aTmp.latin1());
962           //cout<<"\t"<<aTmp;
963         }
964         //cout<<endl;
965       }else if(aTmp.find("#COLUMN_UNITS:") == 0){
966         int aLen = aTmp.find(":") + 1;
967         aTmp.remove(0,aLen);
968         QStringList aStrList = QStringList::split(" ",aTmp);
969         //cout<<"Its Column Units : ";
970         for(int i = 0; i < aStrList.count(); i++){
971           aTmp = aStrList[i].stripWhiteSpace();
972           aTable2D.myColumnUnits.push_back(aTmp.latin1());
973           //cout<<"\t"<<aTmp;
974         }
975         //cout<<endl;
976       }else if(aTmp.find("#") == 0){
977         //It is a comment
978       }else if(aTmp.find("#TITLE:") > 0){
979         QStringList aStrList = QStringList::split("#TITLE:",aTmp);
980         QString aTitle = aStrList[1].stripWhiteSpace();
981         TRow aRow; 
982         aRow.myTitle = (const char*)aTitle;
983         //cout<<aTitle<<" : ";
984         QStringList aValList = QStringList::split(" ",aStrList[0]);
985         for(int i = 0; i < aValList.count(); i++){
986           float aVal = aValList[i].toFloat();
987           aRow.myValues.push_back(aVal);
988           //cout<<"\t"<<aVal;
989         }
990         aTable2D.myRows.push_back(aRow);
991         //cout<<endl;
992       }else{
993         QStringList aValList = QStringList::split(" ",aTmp);
994         TRow aRow; 
995         for(int i = 0; i < aValList.count(); i++){
996           float aVal = aValList[i].toFloat();
997           aRow.myValues.push_back(aVal);
998           //cout<<"\t"<<aVal;
999         }
1000         aTable2D.myRows.push_back(aRow);
1001         //cout<<endl;
1002       }
1003       getLine(aStmIn,aTmp);
1004     }
1005     if(aTable2D.Check()){
1006       //cout<<"aTable2D checked "<<aTable2D.myTitle<<endl;
1007       theTableCont.push_back(aTable2D);
1008     }
1009   }while(!aStmIn.eof());
1010   aStmIn.close();
1011   //cout<<"After close"<<endl;
1012 }
1013
1014 SALOMEDS::SObject_var VISU::ImportTables(const char* theFileName, SALOMEDS::Study_ptr theStudy){
1015   TTableCont aTableCont;
1016   ImportTables(theFileName,aTableCont);
1017   if(aTableCont.empty()) return SALOMEDS::SObject::_nil();
1018   SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1019   SALOMEDS::SComponent_var theSComponent = VISU::FindOrCreateVisuComponent(theStudy);
1020   SALOMEDS::SObject_var aFileObject = aStudyBuilder->NewObject(theSComponent);
1021   SALOMEDS::GenericAttribute_var anAttr = 
1022     aStudyBuilder->FindOrCreateAttribute(aFileObject, "AttributeName");
1023   SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
1024   QFileInfo aFileInfo(theFileName);
1025   aName->SetValue(aFileInfo.fileName().latin1());
1026   int iEnd = aTableCont.size();
1027   /*
1028   for(int i = 0, iEnd = aTableCont.size(); i < iEnd; i++){
1029     const TTable2D& aTable2D = aTableCont[i];
1030     SALOMEDS::SObject_var aRealObject = aStudyBuilder->NewObject(aFileObject);
1031     anAttr = aStudyBuilder->FindOrCreateAttribute(aRealObject, "AttributeName");
1032     aName = SALOMEDS::AttributeName::_narrow(anAttr);
1033     cout<<"aTable2D.myTitle = "<<aTable2D.myTitle<<endl;
1034     if(aTable2D.myTitle != "")
1035       aName->SetValue(aTable2D.myTitle.c_str());
1036     else{
1037       QString aNewName;
1038       aNewName.sprintf("Table:%d",i);
1039       aName->SetValue(aNewName.latin1());
1040     }
1041     anAttr = aStudyBuilder->FindOrCreateAttribute(aRealObject, "AttributeTableOfReal");
1042     SALOMEDS::AttributeTableOfReal_var aTableOfReal = SALOMEDS::AttributeTableOfReal::_narrow(anAttr);
1043     aTableOfReal->SetTitle(aTable2D.myTitle.c_str());
1044     const TRows& aRows = aTable2D.myRows;
1045     //aTable2D.getColumns(aRows);
1046     int kEnd = aRows[0].myValues.size();
1047     aTableOfReal->SetNbColumns(kEnd);
1048     for(int j = 0, jEnd = aRows.size(); j < jEnd; j++){
1049       cout<<"j = "<<j<<endl;
1050       const TRow& aRow = aRows[j];
1051       SALOMEDS::DoubleSeq_var aDoubleSeq = new SALOMEDS::DoubleSeq();
1052       int kEnd = aRow.myValues.size();
1053       aDoubleSeq->length(kEnd);
1054       cout<<"kEnd = "<<kEnd<<endl;
1055       for(int k = 0; k < kEnd; k++) aDoubleSeq[k] = aRow.myValues[k];
1056       aTableOfReal->AddRow(aDoubleSeq.in());
1057       aTableOfReal->SetRowTitle(j+1,aRow.myTitle.c_str());
1058       aTableOfReal->SetRowUnit(j+1,aRow.myUnit.c_str());
1059     }
1060     for(int k = 0; k < kEnd; k++){
1061       aTableOfReal->SetColumnTitle(k+1,aTable2D.myColumnTitles[k].c_str());
1062       //aTableOfReal->SetColumnUnit(k+1,aTable2D.myColumnUnits[k].c_str());
1063     }
1064   }
1065   */
1066   for(int i = 0, iEnd = aTableCont.size(); i < iEnd; i++){
1067     const TTable2D& aTable2D = aTableCont[i];
1068     SALOMEDS::SObject_var aRealObject = aStudyBuilder->NewObject(aFileObject);
1069     anAttr = aStudyBuilder->FindOrCreateAttribute(aRealObject, "AttributeName");
1070     aName = SALOMEDS::AttributeName::_narrow(anAttr);
1071     //cout<<"aTable2D.myTitle = "<<aTable2D.myTitle<<endl;
1072     if(aTable2D.myTitle != "")
1073       aName->SetValue(aTable2D.myTitle.c_str());
1074     else{
1075       QString aNewName;
1076       aNewName.sprintf("Table:%d",i);
1077       aName->SetValue(aNewName.latin1());
1078     }
1079     anAttr = aStudyBuilder->FindOrCreateAttribute(aRealObject, "AttributeTableOfReal");
1080     SALOMEDS::AttributeTableOfReal_var aTableOfReal = SALOMEDS::AttributeTableOfReal::_narrow(anAttr);
1081     aTableOfReal->SetTitle(aTable2D.myTitle.c_str());
1082     TTable2D aNewTable2D;
1083     aTable2D.getColumns(aNewTable2D);
1084     int kEnd = aNewTable2D.myRows[0].myValues.size();
1085     aTableOfReal->SetNbColumns(kEnd);
1086     for(int j = 0, jEnd = aNewTable2D.myRows.size(); j < jEnd; j++){
1087       //cout<<"j = "<<j<<endl;
1088       SALOMEDS::DoubleSeq_var aDoubleSeq = new SALOMEDS::DoubleSeq();
1089       aDoubleSeq->length(kEnd);
1090       //cout<<"kEnd = "<<kEnd<<endl;
1091       for(int k = 0; k < kEnd; k++) aDoubleSeq[k] = aNewTable2D.myRows[j].myValues[k];
1092       aTableOfReal->AddRow(aDoubleSeq.in());
1093       aTableOfReal->SetRowTitle(j+1,aNewTable2D.myRows[j].myTitle.c_str());
1094       aTableOfReal->SetRowUnit(j+1,aNewTable2D.myRows[j].myUnit.c_str());
1095     }
1096     for(int k = 0; k < kEnd; k++){
1097       aTableOfReal->SetColumnTitle(k+1,aNewTable2D.myColumnTitles[k].c_str());
1098       //aTableOfReal->SetColumnUnit(k+1,aTable2D.myColumnUnits[k].c_str());
1099     }
1100   }
1101   return aFileObject;
1102 }