1 // VISU OBJECT : interactive object for VISU entities implementation
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
23 // File : VISU_Table_i.cc
24 // Author : Vadim SANDLER
27 #include "VISU_Table_i.hh"
29 #include "QAD_Application.h"
30 #include "QAD_Desktop.h"
31 #include "QAD_Study.h"
33 #include "VISU_CutLines_i.hh"
39 #include <qfileinfo.h>
44 static int MYDEBUG = 0;
46 static int MYDEBUG = 0;
49 //----------------------------------------------------------------
51 //----------------------------------------------------------------
52 int VISU::Table_i::myNbPresent = 0;
53 const string VISU::Table_i::myComment = "TABLE";
57 const char* VISU::Table_i::GenerateName()
59 return VISU::GenerateName( "Table", ++myNbPresent );
64 const char* VISU::Table_i::GetComment() const
66 return myComment.c_str();
71 VISU::Table_i::Table_i( SALOMEDS::Study_ptr theStudy, const char* theObjectEntry )
72 : PrsObject_i(theStudy)
74 myObjectEntry = theObjectEntry;
75 myOrientation = VISU::Table::HORIZONTAL;
80 VISU::Table_i::~Table_i()
84 Gets number of rows in table
86 CORBA::Long VISU::Table_i::GetNbRows()
88 SALOMEDS::SObject_var SO = myStudy->FindObjectID( myObjectEntry.c_str() );
89 SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
90 if ( !SO->_is_nil() ) {
91 SALOMEDS::GenericAttribute_var anAttr;
92 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
93 SALOMEDS::AttributeTableOfInteger_var anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
94 return anInt->GetNbRows();
96 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
97 SALOMEDS::AttributeTableOfReal_var aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
98 return aReal->GetNbRows();
104 Gets number of columns in table
106 CORBA::Long VISU::Table_i::GetNbColumns()
108 SALOMEDS::SObject_var SO = myStudy->FindObjectID( myObjectEntry.c_str() );
109 SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
110 if ( !SO->_is_nil() ) {
111 SALOMEDS::GenericAttribute_var anAttr;
112 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
113 SALOMEDS::AttributeTableOfInteger_var anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
114 return anInt->GetNbColumns();
116 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
117 SALOMEDS::AttributeTableOfReal_var aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
118 return aReal->GetNbColumns();
126 VISU::Storable* VISU::Table_i::Create()
129 myName = GetTableTitle();
131 myName = GenerateName();
132 // ... and build the object
133 return Build( false );
136 Builds presentation of table
138 VISU::Storable* VISU::Table_i::Build( int theRestoring )
140 // look for reference SObject with table attribute
141 SALOMEDS::SObject_var SO = myStudy->FindObjectID( myObjectEntry.c_str() );
142 if ( !SO->_is_nil() ) {
143 CutLines_i* pCutLines = NULL;
144 CORBA::Object_var anObj = SObjectToObject(SO);
145 if(!CORBA::is_nil(anObj)){
146 VISU::CutLines_var aCutLines = VISU::CutLines::_narrow(anObj);
147 if(!aCutLines->_is_nil())
148 pCutLines = dynamic_cast<CutLines_i*>(GetServant(aCutLines));
150 SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
151 SALOMEDS::GenericAttribute_var anAttr;
152 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ||
153 Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) || pCutLines) {
154 // look for component
155 if ( !theRestoring ) {
156 SALOMEDS::SComponent_var SComponent = VISU::FindOrCreateVisuComponent( myStudy );
157 // create SObject and set attributes
159 aComment.sprintf("myComment=%s;myType=%d",GetComment(),VISU::TTABLE);
160 string anEntry = CreateAttributes( myStudy,
168 // create SObject referenced to real table object
169 SALOMEDS::SObject_var newSO = myStudy->FindObjectID( anEntry.c_str() );
171 pCutLines->BuildTableOfReal(newSO);
172 myObjectEntry = anEntry;
174 SALOMEDS::SObject_var refSO = Builder->NewObject( newSO );
175 Builder->Addreference( refSO, SO );
183 Restores table object from stream
185 VISU::Storable* VISU::Table_i::Restore( const Storable::TRestoringMap& theMap )
186 throw( std::logic_error& )
188 if(MYDEBUG) MESSAGE(GetComment());
189 myName = (const char*)(VISU::Storable::FindValue(theMap,"myName"));
190 myObjectEntry = (const char *)(VISU::Storable::FindValue(theMap,"myObjectEntry"));
191 myTitle = (const char*)(VISU::Storable::FindValue(theMap,"myTitle"));
192 myOrientation = ( VISU::Table::Orientation )( VISU::Storable::FindValue(theMap,"myOrientation").toInt() );
193 return Build( true );
196 Flushes table data into stream
198 void VISU::Table_i::ToStream( std::ostringstream& theStr )
200 Storable::DataToStream( theStr, "myName", myName.c_str() );
201 Storable::DataToStream( theStr, "myObjectEntry", myObjectEntry.c_str() );
202 Storable::DataToStream( theStr, "myTitle", myTitle.c_str() );
203 Storable::DataToStream( theStr, "myOrientation", myOrientation );
206 Called from engine to restore table from the file
208 VISU::Storable* VISU::Table_i::Restore(SALOMEDS::SObject_ptr theSObject,
209 const string& thePrefix, const Storable::TRestoringMap& theMap)
210 throw(std::logic_error&)
212 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
213 VISU::Table_i* pResent = new VISU::Table_i( aStudy, "" );
214 return pResent->Restore( theMap );
217 Gets title for the original table object
219 const char* VISU::Table_i::GetTableTitle()
221 SALOMEDS::SObject_var SO = myStudy->FindObjectID( GetObjectEntry() );
222 SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
223 SALOMEDS::GenericAttribute_var anAttr;
224 SALOMEDS::AttributeTableOfInteger_var anInt;
225 SALOMEDS::AttributeTableOfReal_var aReal;
226 if ( !SO->_is_nil() ) {
227 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
228 anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
229 return anInt->GetTitle();
231 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
232 aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
233 return aReal->GetTitle();
239 //----------------------------------------------------------------
241 //----------------------------------------------------------------
243 Restores table object from the stream [ static ]
245 static VISU::Table_i* GetTable( SALOMEDS::Study_var& theStudy, const VISU::Storable::TRestoringMap& theMap ) {
246 string anEntry = VISU::Storable::FindValue( theMap, "TableID" ).latin1();
247 SALOMEDS::SObject_var aSObject = theStudy->FindObjectID( anEntry.c_str() );
248 CORBA::Object_var anObject = VISU::SObjectToObject( aSObject );
249 if( !CORBA::is_nil( anObject ) ) {
250 CORBA::Object_ptr aTable = VISU::Table::_narrow( anObject );
251 if( !CORBA::is_nil( aTable ) )
252 return dynamic_cast<VISU::Table_i*>( VISU::GetServant( aTable ) );
257 int VISU::Curve_i::myNbPresent = 0;
258 const string VISU::Curve_i::myComment = "CURVE";
262 const char* VISU::Curve_i::GenerateName()
264 return VISU::GenerateName( "Curve", ++myNbPresent );
269 const char* VISU::Curve_i::GetComment() const
271 return myComment.c_str();
275 NB : theHRow, theVRow are the indexes of rows in the Table object and numbered from the 1 to GetNbRows()
277 VISU::Curve_i::Curve_i(SALOMEDS::Study_ptr theStudy, Table_i* theTable, CORBA::Long theHRow, CORBA::Long theVRow )
278 : PrsObject_i(theStudy), myTable( theTable ), myHRow( theHRow ), myVRow( theVRow )
281 myLine = VISU::Curve::SOLIDLINE;
283 myMarker = VISU::Curve::CIRCLE;
284 myColor.R = 0.0; myColor.G = 0.0; myColor.B = 0.0;
289 VISU::Curve_i::~Curve_i()
295 VISU::Storable* VISU::Curve_i::Create()
298 myName = GetVerTitle();
300 myName = GenerateName();
301 // ... and build the object
302 return Build( false );
305 Builds presentation of curve
307 VISU::Storable* VISU::Curve_i::Build( int theRestoring )
309 if ( myTable != NULL ) {
310 // getting table SObject by it's entry
311 SALOMEDS::SObject_var SO = myStudy->FindObjectID( myTable->GetEntry() );
312 int nbRows = myTable->GetNbRows();
313 if ( !SO->_is_nil() && myHRow > 0 && myHRow <= nbRows && myVRow > 0 && myVRow <= nbRows ) {
314 if ( !theRestoring ) {
315 // look for component
316 SALOMEDS::SComponent_var SComponent = VISU::FindOrCreateVisuComponent( myStudy );
317 // create SObject and set attributes
319 aComment.sprintf("myComment=%s;myType=%d",GetComment(),VISU::TCURVE);
320 string anEntry = CreateAttributes( myStudy,
336 Returns CORBA::True if curve refers to valid table data
338 CORBA::Boolean VISU::Curve_i::IsValid()
340 // getting table SObject by it's entry
341 SALOMEDS::SObject_var SO = myStudy->FindObjectID( myTable->GetObjectEntry() );
342 SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
343 SALOMEDS::GenericAttribute_var anAttr;
344 SALOMEDS::AttributeTableOfInteger_var anInt;
345 SALOMEDS::AttributeTableOfReal_var aReal;
346 if ( !SO->_is_nil() ) {
347 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
348 anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
349 if ( myHRow > 0 && myHRow <= anInt->GetNbRows() && myVRow > 0 && myVRow <= anInt->GetNbRows() ) {
353 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
354 aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
355 if ( myHRow > 0 && myHRow <= aReal->GetNbRows() && myVRow > 0 && myVRow <= aReal->GetNbRows() ) {
363 Returns hor.axis title
365 string VISU::Curve_i::GetHorTitle()
368 // getting table SObject by it's entry
369 SALOMEDS::SObject_var SO = myStudy->FindObjectID( myTable->GetObjectEntry() );
370 SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
371 SALOMEDS::GenericAttribute_var anAttr;
372 SALOMEDS::AttributeTableOfInteger_var anInt;
373 SALOMEDS::AttributeTableOfReal_var aReal;
374 if ( !SO->_is_nil() ) {
375 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
376 anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
377 SALOMEDS::StringSeq_var rowTitles = anInt->GetRowTitles();
378 if ( rowTitles->length() > 0 && myHRow > 0 && myHRow <= anInt->GetNbRows() ) {
379 title = strdup( rowTitles[ myHRow-1 ] );
382 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
383 aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
384 SALOMEDS::StringSeq_var rowTitles = aReal->GetRowTitles();
385 if ( rowTitles->length() > 0 && myHRow > 0 && myHRow <= aReal->GetNbRows() ) {
386 title = strdup( rowTitles[ myHRow-1 ] );
393 Returns ver.axis title
395 string VISU::Curve_i::GetVerTitle()
398 // getting table SObject by it's entry
399 SALOMEDS::SObject_var SO = myStudy->FindObjectID( myTable->GetObjectEntry() );
400 SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
401 SALOMEDS::GenericAttribute_var anAttr;
402 SALOMEDS::AttributeTableOfInteger_var anInt;
403 SALOMEDS::AttributeTableOfReal_var aReal;
404 if ( !SO->_is_nil() ) {
405 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
406 anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
407 SALOMEDS::StringSeq_var rowTitles = anInt->GetRowTitles();
408 if ( rowTitles->length() > 0 && myVRow > 0 && myVRow <= anInt->GetNbRows() )
409 title = strdup( rowTitles[ myVRow-1 ] );
411 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
412 aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
413 SALOMEDS::StringSeq_var rowTitles = aReal->GetRowTitles();
414 if ( rowTitles->length() > 0 && myVRow > 0 && myVRow <= aReal->GetNbRows() )
415 title = strdup( rowTitles[ myVRow-1 ] );
421 Returns hor.axis units
423 string VISU::Curve_i::GetHorUnits()
426 // getting table SObject by it's entry
427 SALOMEDS::SObject_var SO = myStudy->FindObjectID( myTable->GetObjectEntry() );
428 SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
429 SALOMEDS::GenericAttribute_var anAttr;
430 SALOMEDS::AttributeTableOfInteger_var anInt;
431 SALOMEDS::AttributeTableOfReal_var aReal;
432 if ( !SO->_is_nil() ) {
433 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
434 anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
435 SALOMEDS::StringSeq_var rowUnits = anInt->GetRowUnits();
436 if ( rowUnits->length() > 0 && myHRow > 0 && myHRow <= anInt->GetNbRows() )
437 units = strdup( rowUnits[ myHRow-1 ] );
439 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
440 aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
441 SALOMEDS::StringSeq_var rowUnits = aReal->GetRowUnits();
442 if ( rowUnits->length() > 0 && myHRow > 0 && myHRow <= aReal->GetNbRows() )
443 units = strdup( rowUnits[ myHRow-1 ] );
449 Returns ver.axis units
451 string VISU::Curve_i::GetVerUnits()
454 // getting table SObject by it's entry
455 SALOMEDS::SObject_var SO = myStudy->FindObjectID( myTable->GetObjectEntry() );
456 SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
457 SALOMEDS::GenericAttribute_var anAttr;
458 SALOMEDS::AttributeTableOfInteger_var anInt;
459 SALOMEDS::AttributeTableOfReal_var aReal;
460 if ( !SO->_is_nil() ) {
461 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
462 anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
463 SALOMEDS::StringSeq_var rowUnits = anInt->GetRowUnits();
464 if ( rowUnits->length() > 0 && myVRow > 0 && myVRow <= anInt->GetNbRows() )
465 units = strdup( rowUnits[ myVRow-1] );
467 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
468 aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
469 SALOMEDS::StringSeq_var rowUnits = aReal->GetRowUnits();
470 if ( rowUnits->length() > 0 && myVRow > 0 && myVRow <= aReal->GetNbRows() )
471 units = strdup( rowUnits[ myVRow-1 ] );
479 int VISU::Curve_i::GetData( double*& theHorList, double*& theVerList )
481 theHorList = 0; theVerList = 0;
482 // getting table SObject by it's entry
483 SALOMEDS::SObject_var SO = myStudy->FindObjectID( myTable->GetObjectEntry() );
484 SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
485 SALOMEDS::GenericAttribute_var anAttr;
486 SALOMEDS::AttributeTableOfInteger_var anInt;
487 SALOMEDS::AttributeTableOfReal_var aReal;
488 if ( !SO->_is_nil() ) {
489 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
490 anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
491 int nbCols = anInt->GetNbColumns() ;
492 if ( nbCols > 0 && myHRow > 0 && myHRow <= anInt->GetNbRows() && myVRow > 0 && myVRow <= anInt->GetNbRows() ) {
494 for ( int j = 1; j <= nbCols; j++ ) {
495 if ( anInt->HasValue( myHRow, j ) && anInt->HasValue( myVRow, j ) )
498 if ( nbPoints > 0 ) {
499 theHorList = new double[ nbPoints ];
500 theVerList = new double[ nbPoints ];
502 for ( int j = 1; j <= nbCols; j++ ) {
503 if ( anInt->HasValue( myHRow, j ) && anInt->HasValue( myVRow, j ) ) {
504 theHorList[k] = anInt->GetValue( myHRow, j );
505 theVerList[k] = anInt->GetValue( myVRow, j );
513 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
514 aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
515 int nbCols = aReal->GetNbColumns() ;
516 if ( nbCols > 0 && myHRow > 0 && myHRow <= aReal->GetNbRows() && myVRow > 0 && myVRow <= aReal->GetNbRows() ) {
518 for ( int j = 1; j <= nbCols; j++ ) {
519 if ( aReal->HasValue( myHRow, j ) && aReal->HasValue( myVRow, j ) )
522 if ( nbPoints > 0 ) {
523 theHorList = new double[ nbPoints ];
524 theVerList = new double[ nbPoints ];
526 for ( int j = 1; j <= nbCols; j++ ) {
527 if ( aReal->HasValue( myHRow, j ) && aReal->HasValue( myVRow, j ) ) {
528 theHorList[k] = aReal->GetValue( myHRow, j );
529 theVerList[k] = aReal->GetValue( myVRow, j );
541 Creates curve Plot2d presentation object
543 Plot2d_Curve* VISU::Curve_i::CreatePresentation()
545 Plot2d_Curve* crv = new Plot2d_Curve();
546 crv->setHorTitle( GetHorTitle().c_str() );
547 string tlt = GetTitle();
548 if ( tlt.length() <= 0 )
550 //crv->setVerTitle( strdup( GetVerTitle().c_str() ) );
551 //crv->setVerTitle( strdup( GetName() ) );
552 crv->setVerTitle( tlt.c_str() );
553 crv->setHorUnits( GetHorUnits().c_str() );
554 crv->setVerUnits( GetVerUnits().c_str() );
557 int nbPoints = GetData( xList, yList );
558 if ( nbPoints > 0 && xList && yList ) {
559 crv->setData( xList, yList, nbPoints );
561 //cout << "********** Number of points: " << nbPoints <<endl;
562 //for ( int i =0 ; i < nbPoints; i++ ) {
563 // cout << i<<"\t"<<xList[i] << "\t"<< yList[i] << endl;
565 crv->setLine( (Plot2d_Curve::LineType)GetLine(), GetLineWidth() );
566 crv->setMarker( (Plot2d_Curve::MarkerType)GetMarker() );
567 SALOMEDS::Color color = GetColor();
568 crv->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
569 crv->setAutoAssign( IsAuto() );
570 crv->setIO(new SALOME_InteractiveObject(strdup(GetEntry()),"VISU",strdup(GetName())));
572 crv->setTableIO(new SALOME_InteractiveObject(strdup(myTable->GetEntry()),"VISU",strdup(myTable->GetName())));
576 Restores curve object from stream
578 VISU::Storable* VISU::Curve_i::Restore( const Storable::TRestoringMap& theMap )
579 throw( std::logic_error& )
581 if(MYDEBUG) MESSAGE(GetComment());
582 myName = (const char*)(VISU::Storable::FindValue(theMap,"myName"));
583 myHRow = VISU::Storable::FindValue(theMap,"myHRow").toInt();
584 myVRow = VISU::Storable::FindValue(theMap,"myVRow").toInt();
585 myColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble();
586 myColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble();
587 myColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble();
588 myMarker = ( VISU::Curve::MarkerType )( VISU::Storable::FindValue(theMap,"myMarker").toInt() );
589 myLine = ( VISU::Curve::LineType )( VISU::Storable::FindValue(theMap,"myLine").toInt() );
590 return Build( true );
593 Flushes curve data into stream
595 void VISU::Curve_i::ToStream( std::ostringstream& theStr )
597 Storable::DataToStream( theStr, "TableID", GetTableID());
598 Storable::DataToStream( theStr, "myName", myName.c_str() );
599 Storable::DataToStream( theStr, "myHRow", myHRow );
600 Storable::DataToStream( theStr, "myVRow", myVRow );
601 Storable::DataToStream( theStr, "myColor.R", myColor.R );
602 Storable::DataToStream( theStr, "myColor.G", myColor.G );
603 Storable::DataToStream( theStr, "myColor.B", myColor.B );
604 Storable::DataToStream( theStr, "myMarker", myMarker );
605 Storable::DataToStream( theStr, "myLine", myLine );
608 Gets reference table's entry
610 const char* VISU::Curve_i::GetTableID() {
611 return CORBA::string_dup(myTable->GetEntry());
614 Called from engine to restore curve from the file
616 VISU::Storable* VISU::Curve_i::Restore(SALOMEDS::SObject_ptr theSObject,
617 const string& thePrefix, const Storable::TRestoringMap& theMap)
618 throw(std::logic_error&)
620 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
621 VISU::Table_i* pTable = GetTable( aStudy, theMap );
622 if( pTable != NULL ) {
623 VISU::Curve_i* pResent = new VISU::Curve_i( aStudy, pTable, 0, 0 );
624 return pResent->Restore( theMap );
629 //----------------------------------------------------------------
631 //----------------------------------------------------------------
632 int VISU::Container_i::myNbPresent = 0;
633 const string VISU::Container_i::myComment = "CONTAINER";
637 const char* VISU::Container_i::GenerateName()
639 return VISU::GenerateName( "Container", ++myNbPresent );
644 const char* VISU::Container_i::GetComment() const
646 return myComment.c_str();
651 VISU::Container_i::Container_i( SALOMEDS::Study_ptr theStudy )
652 : PrsObject_i( theStudy )
658 VISU::Container_i::~Container_i()
663 Inserts curve into the container
665 void VISU::Container_i::AddCurve( Curve_ptr theCurve )
667 if ( myStudy->_is_nil() )
669 SALOMEDS::SObject_var mySO = myStudy->FindObjectID( GetEntry() );
670 if ( mySO->_is_nil() )
672 PortableServer::POA_ptr aPOA = GetPOA();
673 Curve_i* pCurve = dynamic_cast<Curve_i*>( aPOA->reference_to_servant( theCurve ) );
675 QString entry = pCurve->GetEntry();
676 SALOMEDS::SObject_var SO = myStudy->FindObjectID( entry.latin1() );
677 if ( !SO->_is_nil() && myCurves.find( entry ) == myCurves.end() ) {
678 myCurves.append( entry );
679 SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
680 SALOMEDS::SObject_var newSO = Builder->NewObject( mySO );
681 Builder->Addreference( newSO, SO );
686 Removes curve from the container
688 void VISU::Container_i::RemoveCurve( Curve_ptr theCurve )
690 if ( myStudy->_is_nil() )
692 SALOMEDS::SObject_var mySO = myStudy->FindObjectID( GetEntry() );
693 if ( mySO->_is_nil() )
695 PortableServer::POA_ptr aPOA = GetPOA();
696 Curve_i* pCurve = dynamic_cast<Curve_i*>( aPOA->reference_to_servant( theCurve ) );
698 QString entry = pCurve->GetEntry();
699 if ( myCurves.find( entry ) != myCurves.end() ) {
701 myCurves.remove( entry );
702 SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
703 SALOMEDS::ChildIterator_var CI = myStudy->NewChildIterator( mySO );
704 for ( ; CI->More(); CI->Next() ) {
705 SALOMEDS::SObject_var childSO = CI->Value();
706 SALOMEDS::SObject_var refSO;
707 if ( childSO->ReferencedObject( refSO ) && !refSO->_is_nil() && entry == QString( refSO->GetID() ) ) {
708 Builder->RemoveObject( childSO );
715 Gets number of curves in the container
717 CORBA::Long VISU::Container_i::GetNbCurves()
719 return myCurves.count();
724 void VISU::Container_i::Clear()
726 if ( myStudy->_is_nil() )
728 SALOMEDS::SObject_var mySO = myStudy->FindObjectID( GetEntry() );
729 if ( mySO->_is_nil() )
731 QStringList toDelete;
732 SALOMEDS::ChildIterator_var CI = myStudy->NewChildIterator( mySO );
733 for ( ; CI->More(); CI->Next() ) {
734 toDelete.append( CI->Value()->GetID() );
736 SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
737 for ( int i = 0; i < toDelete.count(); i++ ) {
738 SALOMEDS::SObject_var SO = myStudy->FindObjectID( toDelete[i].latin1() );
739 Builder->RemoveObject( SO );
744 Creates container object
746 VISU::Storable* VISU::Container_i::Create()
749 myName = GenerateName();
750 // ... and build the object
751 return Build( false );
754 Builds presentation of container
756 VISU::Storable* VISU::Container_i::Build( int theRestoring )
758 if ( !theRestoring ) {
759 // looking for component
760 SALOMEDS::SComponent_var SComponent = VISU::FindOrCreateVisuComponent( myStudy );
761 // create SObject and set attributes
763 aComment.sprintf("myComment=%s;myType=%d",GetComment(),VISU::TCONTAINER);
764 string anEntry = CreateAttributes( myStudy,
776 Updates presentation of container
778 void VISU::Container_i::Update()
780 if ( myStudy->_is_nil() )
782 SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
783 SALOMEDS::SObject_var mySO = myStudy->FindObjectID( GetEntry() );
784 SALOMEDS::GenericAttribute_var anAttr;
785 if ( !mySO->_is_nil() ) {
786 QStringList toDelete;
788 for ( i = 0; i < myCurves.count(); i++ ) {
789 SALOMEDS::SObject_var SO = myStudy->FindObjectID( myCurves[i].latin1() );
790 if ( !SO->_is_nil() && Builder->FindAttribute( SO, anAttr, "AttributeIOR" ) ) {
791 // if real Curve Object still exists
792 SALOMEDS::ChildIterator_var CI = myStudy->NewChildIterator( mySO );
794 for ( ; CI->More(); CI->Next() ) {
795 SALOMEDS::SObject_var childSO = CI->Value();
796 SALOMEDS::SObject_var refSO;
797 if ( childSO->ReferencedObject( refSO ) && !refSO->_is_nil() && myCurves[i] == QString( refSO->GetID() ) ) {
798 bFound = true; break;
802 // create SObject referenced to real curve object if is not yet added
803 SALOMEDS::SObject_var newSO = Builder->NewObject( mySO );
804 Builder->Addreference( newSO, SO );
808 // real Curve Object doesn't exist (might be removed)
809 toDelete.append( myCurves[i] );
812 for ( i = 0; i < toDelete.count(); i++ ) {
813 myCurves.remove( toDelete[i] );
816 SALOMEDS::ChildIterator_var CI = myStudy->NewChildIterator( mySO );
817 for ( ; CI->More(); CI->Next() ) {
818 SALOMEDS::SObject_var childSO = CI->Value();
819 SALOMEDS::SObject_var refSO;
820 if ( childSO->ReferencedObject( refSO ) && ( refSO->_is_nil() || !Builder->FindAttribute( refSO, anAttr, "AttributeIOR" ) ||
821 myCurves.find( refSO->GetID() ) == myCurves.end() ) ) {
822 toDelete.append( childSO->GetID() );
825 for ( i = 0; i < toDelete.count(); i++ ) {
826 SALOMEDS::ChildIterator_var CI = myStudy->NewChildIterator( mySO );
827 for ( ; CI->More(); CI->Next() ) {
828 SALOMEDS::SObject_var childSO = CI->Value();
829 if ( toDelete[i] == CI->Value()->GetID() ) {
830 Builder->RemoveObject( childSO );
837 Gets curve from container by index
838 NB : curves are numbered from 1
840 VISU::Curve_i* VISU::Container_i::GetCurve( CORBA::Long theIndex )
842 if ( theIndex > 0 && theIndex <= myCurves.count() ) {
843 SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder();
844 SALOMEDS::GenericAttribute_var anAttr;
845 SALOMEDS::SObject_var SO = myStudy->FindObjectID( myCurves[ theIndex-1 ].latin1() );
846 CORBA::Object_var anObject = VISU::SObjectToObject( SO );
847 if( !CORBA::is_nil( anObject ) ) {
848 // if real Curve Object exists
849 CORBA::Object_ptr aCurve = VISU::Curve::_narrow( anObject );
850 if( !CORBA::is_nil( aCurve ) )
851 return dynamic_cast<VISU::Curve_i*>(VISU::GetServant( aCurve ) );
857 Restores container data from the stream
859 VISU::Storable* VISU::Container_i::Restore( const Storable::TRestoringMap& theMap )
860 throw( std::logic_error& )
862 if(MYDEBUG) MESSAGE(GetComment());
863 myName = (const char*)(VISU::Storable::FindValue( theMap, "myName" ));
864 QString val = VISU::Storable::FindValue( theMap, "myCurves" );
865 myCurves = QStringList::split( QString( "*" ), val, false );
866 return Build( true );
869 Flushes container data into the stream
871 void VISU::Container_i::ToStream( std::ostringstream& theStr )
873 Storable::DataToStream( theStr, "myName", myName.c_str() );
874 Storable::DataToStream( theStr, "myCurves", myCurves.join( QString( "*" ) ) );
875 // theStr<<" myName "<<myName;
876 // theStr<<" myCurves "<<myCurves.join( QString( "*" ) ).latin1()<<"* ";
879 Called from engine to restore container from the file
881 VISU::Storable* VISU::Container_i::Restore(SALOMEDS::SObject_ptr theSObject,
882 const string& thePrefix, const Storable::TRestoringMap& theMap)
883 throw(std::logic_error&)
885 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
886 VISU::Container_i* pResent = new VISU::Container_i( aStudy );
887 return pResent->Restore( theMap );
890 //-------------------------------------------------------------
891 // Implementation of reading from file
892 //-------------------------------------------------------------
893 typedef double TValue;
894 typedef vector<TValue> TValues;
902 typedef vector<TRow> TRows;
906 vector<string> myColumnUnits;
907 vector<string> myColumnTitles;
910 if(myRows.empty()) return 0;
911 int iEnd = myRows[0].myValues.size();
912 if(iEnd == 0) return 0;
913 if(myColumnTitles.size() != iEnd) myColumnTitles.resize(iEnd);
914 if(myColumnUnits.size() != iEnd) myColumnUnits.resize(iEnd);
915 int jEnd = myRows.size();
916 for(int j = 0; j < jEnd; j++)
917 if(myRows[j].myValues.size() != iEnd)
921 void getColumns(TTable2D& theTable2D) const {
922 TRows& aRows = theTable2D.myRows;
924 if(myRows.empty()) return;
925 int jEnd = myRows.size();
926 //Define Titles & Units
927 theTable2D.myColumnTitles.resize(jEnd);
928 theTable2D.myColumnUnits.resize(jEnd);
929 for(int j = 0; j < jEnd; j++){
930 theTable2D.myColumnTitles[j] = myRows[j].myTitle;
931 theTable2D.myColumnUnits[j] = myRows[j].myUnit;
934 int iEnd = myRows[0].myValues.size();
935 for(int i = 0; i < iEnd; i++){
937 aNewRow.myTitle = myColumnTitles[i];
938 aNewRow.myUnit = myColumnUnits[i];
939 aNewRow.myValues.resize(jEnd);
940 for(int j = 0; j < jEnd; j++){
941 aNewRow.myValues[j] = myRows[j].myValues[i];
943 aRows.push_back(aNewRow);
948 typedef vector<TTable2D> TTableCont;
950 int getLine(ifstream& theStmIn, QString& theString){
953 while(theStmIn.get(tmp)){
955 if(tmp == '\n') break;
958 theString = aStrOut.str();
959 return !theStmIn.eof();
962 void ImportTables(const char* theFileName, TTableCont& theTableCont){
963 static int STRPRECISION = 12;
965 QFileInfo aFileInfo(theFileName);
966 if(!aFileInfo.isFile() || !aFileInfo.isReadable() || !aFileInfo.size()) return;
967 aStmIn.open(theFileName);
970 //Find beginning of Table
971 while(getLine(aStmIn,aTmp) && aTmp == "\n");
972 if(MYDEBUG) cout<<"\n There is new Table2D with Title = ";
974 while(!aStmIn.eof() && aTmp != "\n"){
975 if(aTmp.find("#TITLE:") == 0){
976 int aLen = aTmp.find(":") + 1;
978 QString aTitle = aTmp.stripWhiteSpace();
979 aTable2D.myTitle = aTitle.latin1();
980 if(MYDEBUG) cout<<aTitle<<endl;
981 }else if(aTmp.find("#COLUMN_TITLES:") == 0){
982 int aLen = aTmp.find(":") + 1;
984 QStringList aStrList = QStringList::split("|",aTmp);
985 if(MYDEBUG) cout<<"Its Column Titles : ";
986 for(int i = 0; i < aStrList.count(); i++){
987 aTmp = aStrList[i].stripWhiteSpace();
988 aTable2D.myColumnTitles.push_back(aTmp.latin1());
989 if(MYDEBUG) cout<<"\t"<<aTmp;
991 if(MYDEBUG) cout<<endl;
992 }else if(aTmp.find("#COLUMN_UNITS:") == 0){
993 int aLen = aTmp.find(":") + 1;
995 QStringList aStrList = QStringList::split(" ",aTmp);
996 if(MYDEBUG) cout<<"Its Column Units : ";
997 for(int i = 0; i < aStrList.count(); i++){
998 aTmp = aStrList[i].stripWhiteSpace();
999 aTable2D.myColumnUnits.push_back(aTmp.latin1());
1000 if(MYDEBUG) cout<<"\t"<<aTmp;
1002 if(MYDEBUG) cout<<endl;
1003 }else if(aTmp.find("#") == 0){
1005 }else if(aTmp.find("#TITLE:") > 0){
1006 QStringList aStrList = QStringList::split("#TITLE:",aTmp);
1007 QString aTitle = aStrList[1].stripWhiteSpace();
1009 aRow.myTitle = aTitle.latin1();
1010 if(MYDEBUG) cout<<aTitle<<" : ";
1011 QStringList aValList = QStringList::split(" ",aStrList[0]);
1012 for(int i = 0; i < aValList.count(); i++){
1013 float aVal = aValList[i].toFloat();
1014 aRow.myValues.push_back(aVal);
1015 if(MYDEBUG) cout<<"\t"<<aVal;
1017 aTable2D.myRows.push_back(aRow);
1018 if(MYDEBUG) cout<<endl;
1022 istrstream aStream(aTmp);
1023 aStream.precision(STRPRECISION);
1024 while(aStream>>aVal){
1025 aRow.myValues.push_back(aVal);
1026 if(MYDEBUG) cout<<"\t"<<aVal;
1028 if(aRow.myValues.size() > 0)
1029 aTable2D.myRows.push_back(aRow);
1030 if(MYDEBUG) cout<<endl;
1032 getLine(aStmIn,aTmp);
1034 if(aTable2D.Check()){
1035 if(MYDEBUG) cout<<"aTable2D checked "<<aTable2D.myTitle<<endl;
1036 theTableCont.push_back(aTable2D);
1038 }while(!aStmIn.eof());
1040 if(MYDEBUG) cout<<"After close"<<endl;
1043 SALOMEDS::SObject_var VISU::ImportTables(const char* theFileName, SALOMEDS::Study_ptr theStudy){
1044 TTableCont aTableCont;
1045 ImportTables(theFileName,aTableCont);
1046 if(aTableCont.empty()) return SALOMEDS::SObject::_nil();
1047 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1048 SALOMEDS::SComponent_var theSComponent = VISU::FindOrCreateVisuComponent(theStudy);
1049 SALOMEDS::SObject_var aFileObject = aStudyBuilder->NewObject(theSComponent);
1050 SALOMEDS::GenericAttribute_var anAttr =
1051 aStudyBuilder->FindOrCreateAttribute(aFileObject, "AttributeName");
1052 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
1053 QFileInfo aFileInfo(theFileName);
1054 aName->SetValue(aFileInfo.fileName().latin1());
1055 int iEnd = aTableCont.size();
1056 for(int i = 0, iEnd = aTableCont.size(); i < iEnd; i++){
1057 const TTable2D& aTable2D = aTableCont[i];
1058 SALOMEDS::SObject_var aRealObject = aStudyBuilder->NewObject(aFileObject);
1059 anAttr = aStudyBuilder->FindOrCreateAttribute(aRealObject, "AttributeName");
1060 aName = SALOMEDS::AttributeName::_narrow(anAttr);
1061 if(MYDEBUG) cout<<"aTable2D.myTitle = "<<aTable2D.myTitle<<endl;
1062 if(aTable2D.myTitle != "")
1063 aName->SetValue(aTable2D.myTitle.c_str());
1066 aNewName.sprintf("Table:%d",i);
1067 aName->SetValue(aNewName.latin1());
1069 anAttr = aStudyBuilder->FindOrCreateAttribute(aRealObject, "AttributeTableOfReal");
1070 SALOMEDS::AttributeTableOfReal_var aTableOfReal = SALOMEDS::AttributeTableOfReal::_narrow(anAttr);
1071 aTableOfReal->SetTitle(aTable2D.myTitle.c_str());
1072 TTable2D aNewTable2D;
1073 aTable2D.getColumns(aNewTable2D);
1074 int kEnd = aNewTable2D.myRows[0].myValues.size();
1075 aTableOfReal->SetNbColumns(kEnd);
1076 for(int j = 0, jEnd = aNewTable2D.myRows.size(); j < jEnd; j++){
1077 if(MYDEBUG) cout<<"j = "<<j<<endl;
1078 SALOMEDS::DoubleSeq_var aDoubleSeq = new SALOMEDS::DoubleSeq();
1079 aDoubleSeq->length(kEnd);
1080 if(MYDEBUG) cout<<"kEnd = "<<kEnd<<endl;
1081 for(int k = 0; k < kEnd; k++) aDoubleSeq[k] = aNewTable2D.myRows[j].myValues[k];
1082 aTableOfReal->AddRow(aDoubleSeq.in());
1083 aTableOfReal->SetRowTitle(j+1,aNewTable2D.myRows[j].myTitle.c_str());
1084 aTableOfReal->SetRowUnit(j+1,aNewTable2D.myRows[j].myUnit.c_str());
1086 for(int k = 0; k < kEnd; k++)
1087 aTableOfReal->SetColumnTitle(k+1,aNewTable2D.myColumnTitles[k].c_str());