1 // Copyright (C) 2003 CEA/DEN, EDF R&D
5 // File : VISU_Table_i.cc
6 // Author : Vadim SANDLER
10 #include "VISU_Table_i.hh"
12 #include "QAD_Application.h"
13 #include "QAD_Desktop.h"
14 #include "QAD_Study.h"
17 #include <qfileinfo.h>
18 #include <qstringlist.h>
22 static int MYDEBUG = 1;
24 static int MYDEBUG = 0;
27 //----------------------------------------------------------------
29 //----------------------------------------------------------------
30 int VISU::Table_i::myNbPresent = 0;
31 const string VISU::Table_i::myComment = "TABLE";
35 const char* VISU::Table_i::GenerateName()
37 return VISU::GenerateName( "Table", ++myNbPresent );
42 const char* VISU::Table_i::GetComment() const
44 return myComment.c_str();
49 VISU::Table_i::Table_i( SALOMEDS::Study_ptr theStudy, const char* theObjectEntry )
50 : PrsObject_i(theStudy)
52 myObjectEntry = theObjectEntry;
53 myOrientation = VISU::Table::HORIZONTAL;
58 VISU::Table_i::~Table_i()
62 Gets number of rows in table
64 CORBA::Long VISU::Table_i::GetNbRows()
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();
74 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
75 SALOMEDS::AttributeTableOfReal_var aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
76 return aReal->GetNbRows();
82 Gets number of columns in table
84 CORBA::Long VISU::Table_i::GetNbColumns()
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();
94 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
95 SALOMEDS::AttributeTableOfReal_var aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
96 return aReal->GetNbColumns();
104 VISU::Storable* VISU::Table_i::Create()
107 myName = GetTableTitle();
109 myName = GenerateName();
110 // ... and build the object
111 return Build( false );
114 Builds presentation of table
116 VISU::Storable* VISU::Table_i::Build( int theRestoring )
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));
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
137 aComment.sprintf("myComment=%s;myType=%d",GetComment(),VISU::TTABLE);
138 string anEntry = CreateAttributes( myStudy,
146 // create SObject referenced to real table object
147 SALOMEDS::SObject_var newSO = myStudy->FindObjectID( anEntry.c_str() );
149 pCutLines->BuildTableOfReal(newSO);
150 myObjectEntry = anEntry;
152 SALOMEDS::SObject_var refSO = Builder->NewObject( newSO );
153 Builder->Addreference( refSO, SO );
161 Restores table object from stream
163 VISU::Storable* VISU::Table_i::Restore( const Storable::TRestoringMap& theMap )
164 throw( std::logic_error& )
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 );
174 Flushes table data into stream
176 void VISU::Table_i::ToStream( std::ostringstream& theStr )
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 );
184 Called from engine to restore table from the file
186 VISU::Storable* VISU::TableRestore(SALOMEDS::SObject_ptr theSObject,
187 const string& thePrefix, const Storable::TRestoringMap& theMap)
189 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
190 VISU::Table_i* pResent = new VISU::Table_i( aStudy, "" );
191 return pResent->Restore( theMap );
194 Gets title for the original table object
196 const char* VISU::Table_i::GetTableTitle()
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();
208 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
209 aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
210 return aReal->GetTitle();
216 //----------------------------------------------------------------
218 //----------------------------------------------------------------
220 Restores table object from the stream [ static ]
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 ) );
234 int VISU::Curve_i::myNbPresent = 0;
235 const string VISU::Curve_i::myComment = "CURVE";
239 const char* VISU::Curve_i::GenerateName()
241 return VISU::GenerateName( "Curve", ++myNbPresent );
246 const char* VISU::Curve_i::GetComment() const
248 return myComment.c_str();
252 NB : theHRow, theVRow are the indexes of rows in the Table object and numbered from the 1 to GetNbRows()
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 )
258 myLine = VISU::Curve::SOLIDLINE;
260 myMarker = VISU::Curve::CIRCLE;
261 myColor.R = 0.0; myColor.G = 0.0; myColor.B = 0.0;
266 VISU::Curve_i::~Curve_i()
272 VISU::Storable* VISU::Curve_i::Create()
275 myName = GetVerTitle();
277 myName = GenerateName();
278 // ... and build the object
279 return Build( false );
282 Builds presentation of curve
284 VISU::Storable* VISU::Curve_i::Build( int theRestoring )
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
296 aComment.sprintf("myComment=%s;myType=%d",GetComment(),VISU::TCURVE);
297 string anEntry = CreateAttributes( myStudy,
313 Returns CORBA::True if curve refers to valid table data
315 CORBA::Boolean VISU::Curve_i::IsValid()
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() ) {
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() ) {
340 Returns hor.axis title
342 string VISU::Curve_i::GetHorTitle()
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 ] );
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 ] );
370 Returns ver.axis title
372 string VISU::Curve_i::GetVerTitle()
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 ] );
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 ] );
398 Returns hor.axis units
400 string VISU::Curve_i::GetHorUnits()
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 ] );
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 ] );
426 Returns ver.axis units
428 string VISU::Curve_i::GetVerUnits()
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] );
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 ] );
456 int VISU::Curve_i::GetData( double*& theHorList, double*& theVerList )
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() ) {
471 for ( int j = 1; j <= nbCols; j++ ) {
472 if ( anInt->HasValue( myHRow, j ) && anInt->HasValue( myVRow, j ) )
475 if ( nbPoints > 0 ) {
476 theHorList = new double[ nbPoints ];
477 theVerList = new double[ nbPoints ];
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 );
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() ) {
495 for ( int j = 1; j <= nbCols; j++ ) {
496 if ( aReal->HasValue( myHRow, j ) && aReal->HasValue( myVRow, j ) )
499 if ( nbPoints > 0 ) {
500 theHorList = new double[ nbPoints ];
501 theVerList = new double[ nbPoints ];
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 );
518 Creates curve Plot2d presentation object
520 Plot2d_Curve* VISU::Curve_i::CreatePresentation()
522 Plot2d_Curve* crv = new Plot2d_Curve();
523 crv->setHorTitle( GetHorTitle().c_str() );
524 string tlt = GetTitle();
525 if ( tlt.length() <= 0 )
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() );
534 int nbPoints = GetData( xList, yList );
535 if ( nbPoints > 0 && xList && yList ) {
536 crv->setData( xList, yList, nbPoints );
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;
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())));
549 crv->setTableIO(new SALOME_InteractiveObject(strdup(myTable->GetEntry()),"VISU",strdup(myTable->GetName())));
553 Restores curve object from stream
555 VISU::Storable* VISU::Curve_i::Restore( const Storable::TRestoringMap& theMap )
556 throw( std::logic_error& )
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 );
570 Flushes curve data into stream
572 void VISU::Curve_i::ToStream( std::ostringstream& theStr )
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 );
585 Gets reference table's entry
587 const char* VISU::Curve_i::GetTableID() {
588 return CORBA::string_dup(myTable->GetEntry());
591 Called from engine to restore curve from the file
593 VISU::Storable* VISU::CurveRestore(SALOMEDS::SObject_ptr theSObject,
594 const string& thePrefix, const Storable::TRestoringMap& theMap)
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 );
605 //----------------------------------------------------------------
607 //----------------------------------------------------------------
608 int VISU::Container_i::myNbPresent = 0;
609 const string VISU::Container_i::myComment = "CONTAINER";
613 const char* VISU::Container_i::GenerateName()
615 return VISU::GenerateName( "Container", ++myNbPresent );
620 const char* VISU::Container_i::GetComment() const
622 return myComment.c_str();
627 VISU::Container_i::Container_i( SALOMEDS::Study_ptr theStudy )
628 : PrsObject_i( theStudy )
634 VISU::Container_i::~Container_i()
639 Inserts curve into the container
641 void VISU::Container_i::AddCurve( Curve_ptr theCurve )
643 if ( myStudy->_is_nil() )
645 SALOMEDS::SObject_var mySO = myStudy->FindObjectID( GetEntry() );
646 if ( mySO->_is_nil() )
648 PortableServer::POA_ptr aPOA = GetPOA();
649 Curve_i* pCurve = dynamic_cast<Curve_i*>( aPOA->reference_to_servant( theCurve ) );
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 );
662 Removes curve from the container
664 void VISU::Container_i::RemoveCurve( Curve_ptr theCurve )
666 if ( myStudy->_is_nil() )
668 SALOMEDS::SObject_var mySO = myStudy->FindObjectID( GetEntry() );
669 if ( mySO->_is_nil() )
671 PortableServer::POA_ptr aPOA = GetPOA();
672 Curve_i* pCurve = dynamic_cast<Curve_i*>( aPOA->reference_to_servant( theCurve ) );
674 QString entry = pCurve->GetEntry();
675 if ( myCurves.find( entry ) != myCurves.end() ) {
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 );
691 Gets number of curves in the container
693 CORBA::Long VISU::Container_i::GetNbCurves()
695 return myCurves.count();
700 void VISU::Container_i::Clear()
702 if ( myStudy->_is_nil() )
704 SALOMEDS::SObject_var mySO = myStudy->FindObjectID( GetEntry() );
705 if ( mySO->_is_nil() )
707 QStringList toDelete;
708 SALOMEDS::ChildIterator_var CI = myStudy->NewChildIterator( mySO );
709 for ( ; CI->More(); CI->Next() ) {
710 toDelete.append( CI->Value()->GetID() );
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 );
720 Creates container object
722 VISU::Storable* VISU::Container_i::Create()
725 myName = GenerateName();
726 // ... and build the object
727 return Build( false );
730 Builds presentation of container
732 VISU::Storable* VISU::Container_i::Build( int theRestoring )
734 if ( !theRestoring ) {
735 // looking for component
736 SALOMEDS::SComponent_var SComponent = VISU::FindOrCreateVisuComponent( myStudy );
737 // create SObject and set attributes
739 aComment.sprintf("myComment=%s;myType=%d",GetComment(),VISU::TCONTAINER);
740 string anEntry = CreateAttributes( myStudy,
752 Updates presentation of container
754 void VISU::Container_i::Update()
756 if ( myStudy->_is_nil() )
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;
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 );
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;
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 );
784 // real Curve Object doesn't exist (might be removed)
785 toDelete.append( myCurves[i] );
788 for ( i = 0; i < toDelete.count(); i++ ) {
789 myCurves.remove( toDelete[i] );
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() );
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 );
813 Gets curve from container by index
814 NB : curves are numbered from 1
816 VISU::Curve_i* VISU::Container_i::GetCurve( CORBA::Long theIndex )
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 ) );
833 Restores container data from the stream
835 VISU::Storable* VISU::Container_i::Restore( const Storable::TRestoringMap& theMap )
836 throw( std::logic_error& )
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 );
845 Flushes container data into the stream
847 void VISU::Container_i::ToStream( std::ostringstream& theStr )
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()<<"* ";
855 Called from engine to restore container from the file
857 VISU::Storable* VISU::ContainerRestore(SALOMEDS::SObject_ptr theSObject,
858 const string& thePrefix, const Storable::TRestoringMap& theMap)
860 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
861 VISU::Container_i* pResent = new VISU::Container_i( aStudy );
862 return pResent->Restore( theMap );
865 //-------------------------------------------------------------
866 // Implementation of reading from file
867 //-------------------------------------------------------------
868 typedef vector<float> TValues;
876 typedef vector<TRow> TRows;
880 vector<string> myColumnUnits;
881 vector<string> myColumnTitles;
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;
894 void getColumns(TTable2D& theTable2D) const {
895 TRows& aRows = theTable2D.myRows;
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;
907 int iEnd = myRows[0].myValues.size();
908 for(int i = 0; i < iEnd; i++){
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];
916 aRows.push_back(aNewRow);
921 typedef vector<TTable2D> TTableCont;
923 int getLine(ifstream& theStmIn, QString& theString){
926 while(theStmIn.get(tmp)){
928 if(tmp == '\n') break;
931 auto_ptr<char> aRet(aStrOut.str());
932 theString = aRet.get();
933 return !theStmIn.eof();
936 void ImportTables(const char* theFileName, TTableCont& theTableCont){
938 QFileInfo aFileInfo(theFileName);
939 if(!aFileInfo.isFile() || !aFileInfo.isReadable() || !aFileInfo.size()) return;
940 aStmIn.open(theFileName);
943 //Find beginning of Table
944 while(getLine(aStmIn,aTmp) && aTmp == "\n");
945 //cout<<"\n There is new Table2D with Title = ";
947 while(!aStmIn.eof() && aTmp != "\n"){
948 if(aTmp.find("#TITLE:") == 0){
949 int aLen = aTmp.find(":") + 1;
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;
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());
965 }else if(aTmp.find("#COLUMN_UNITS:") == 0){
966 int aLen = aTmp.find(":") + 1;
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());
976 }else if(aTmp.find("#") == 0){
978 }else if(aTmp.find("#TITLE:") > 0){
979 QStringList aStrList = QStringList::split("#TITLE:",aTmp);
980 QString aTitle = aStrList[1].stripWhiteSpace();
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);
990 aTable2D.myRows.push_back(aRow);
993 QStringList aValList = QStringList::split(" ",aTmp);
995 for(int i = 0; i < aValList.count(); i++){
996 float aVal = aValList[i].toFloat();
997 aRow.myValues.push_back(aVal);
1000 aTable2D.myRows.push_back(aRow);
1003 getLine(aStmIn,aTmp);
1005 if(aTable2D.Check()){
1006 //cout<<"aTable2D checked "<<aTable2D.myTitle<<endl;
1007 theTableCont.push_back(aTable2D);
1009 }while(!aStmIn.eof());
1011 //cout<<"After close"<<endl;
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();
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());
1038 aNewName.sprintf("Table:%d",i);
1039 aName->SetValue(aNewName.latin1());
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());
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());
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());
1076 aNewName.sprintf("Table:%d",i);
1077 aName->SetValue(aNewName.latin1());
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());
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());