1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // VISU OBJECT : interactive object for VISU entities implementation
23 // File : VISU_Table_i.cc
24 // Author : Vadim SANDLER
27 #include "VISU_Table_i.hh"
29 #include "VISU_CutLinesBase_i.hh"
30 #include "VISU_CutSegment_i.hh"
31 #include "VISU_Result_i.hh"
32 #include "VISU_ViewManager_i.hh"
34 #include "SALOME_Event.h"
35 #include "SPlot2d_Curve.h"
37 #include "VISU_TableReader.hxx"
38 #include "VISU_ConvertorUtils.hxx"
40 #include "utilities.h"
42 #include <Basics_Utils.hxx>
47 static int MYDEBUG = 0;
49 static int MYDEBUG = 0;
51 //----------------------------------------------------------------
53 //----------------------------------------------------------------
54 int VISU::Table_i::myNbPresent = 0;
55 const string VISU::Table_i::myComment = "TABLE";
59 QString VISU::Table_i::GenerateName()
61 return VISU::GenerateName( "Table", ++myNbPresent );
66 const char* VISU::Table_i::GetComment() const
68 return myComment.c_str();
73 VISU::Table_i::Table_i( SALOMEDS::Study_ptr theStudy, const char* theObjectEntry )
74 : PrsObject_i(theStudy)
76 MESSAGE("Table_i::Table_i - "<<this);
77 mySObj = theStudy->FindObjectID(theObjectEntry);
78 myOrientation = VISU::Table::HORIZONTAL;
83 VISU::Table_i::~Table_i()
85 MESSAGE("Table_i::~Table_i - "<<this);
88 //----------------------------------------------------------------------------
91 ::SetTitle( const char* theTitle )
93 SetName( theTitle, true );
96 //----------------------------------------------------------------------------
101 return CORBA::string_dup( GetName().c_str() );
104 //----------------------------------------------------------------------------
107 ::SetOrientation( VISU::Table::Orientation theOrientation )
109 myOrientation = theOrientation;
112 //----------------------------------------------------------------------------
113 VISU::Table::Orientation
117 return myOrientation;
120 //----------------------------------------------------------------------------
121 SALOMEDS::SObject_var
128 //----------------------------------------------------------------------------
133 CORBA::String_var anEntry = mySObj->GetID();
137 //----------------------------------------------------------------------------
139 Gets number of rows in table
141 CORBA::Long VISU::Table_i::GetNbRows()
143 SALOMEDS::SObject_var SO = mySObj;
144 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
145 if ( !SO->_is_nil() ) {
146 SALOMEDS::GenericAttribute_var anAttr;
147 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
148 SALOMEDS::AttributeTableOfInteger_var anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
149 return anInt->GetNbRows();
151 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
152 SALOMEDS::AttributeTableOfReal_var aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
153 return aReal->GetNbRows();
159 Gets number of columns in table
161 CORBA::Long VISU::Table_i::GetNbColumns()
163 SALOMEDS::SObject_var SO = mySObj;
164 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
165 if ( !SO->_is_nil() ) {
166 SALOMEDS::GenericAttribute_var anAttr;
167 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
168 SALOMEDS::AttributeTableOfInteger_var anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
169 return anInt->GetNbColumns();
171 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
172 SALOMEDS::AttributeTableOfReal_var aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
173 return aReal->GetNbColumns();
181 VISU::Storable* VISU::Table_i::Create()
184 SetName(GetTableTitle().toLatin1().data(), false);
186 // mpv (PAL 5357): if name attribute already exist at this label, use it as name of table
187 if ( GetName() == "" )
188 if ( !mySObj->_is_nil() ) {
189 CutLinesBase_i* pCutLines = NULL;
190 CORBA::Object_var anObj = SObjectToObject(mySObj);
191 if(!CORBA::is_nil(anObj)){
192 VISU::CutLinesBase_var aCutLines = VISU::CutLinesBase::_narrow(anObj);
193 if(!aCutLines->_is_nil())
194 pCutLines = dynamic_cast<CutLinesBase_i*>(GetServant(aCutLines).in());
197 if (mySObj->GetName()) SetName(mySObj->GetName(), false);
200 if ( GetName() == "" )
201 SetName(GenerateName().toLatin1().data(), false);
202 // ... and build the object
203 return Build( false );
206 Builds presentation of table
208 VISU::Storable* VISU::Table_i::Build( int theRestoring )
211 // look for reference SObject with table attribute
212 SALOMEDS::SObject_var SO = mySObj;
214 if ( !SO->_is_nil() ) {
215 CutLinesBase_i* pCutLines = NULL;
216 CORBA::Object_var anObj = SObjectToObject(SO);
217 if(!CORBA::is_nil(anObj)){
218 VISU::CutLinesBase_var aCutLines = VISU::CutLinesBase::_narrow(anObj);
219 if(!aCutLines->_is_nil())
220 pCutLines = dynamic_cast<CutLinesBase_i*>(GetServant(aCutLines).in());
222 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
223 SALOMEDS::GenericAttribute_var anAttr;
224 // look for component
225 if ( !theRestoring ) {
226 SALOMEDS::SComponent_var SComponent = VISU::FindOrCreateVisuComponent( GetStudyDocument() );
227 // create SObject and set attributes
230 aComment.sprintf("myComment=%s;mySourceId=CutLines",GetComment());
232 aComment.sprintf("myComment=%s;mySourceId=TableAttr",GetComment());
233 SALOMEDS::SObject_var aFatherSObject = SO->GetFather();
234 if(aFatherSObject->FindAttribute(anAttr,"AttributeString")){
235 SALOMEDS::AttributeString_var aCommentAttr =
236 SALOMEDS::AttributeString::_narrow(anAttr);
237 CORBA::String_var aValue = aCommentAttr->Value();
238 Storable::TRestoringMap aMap;
239 Storable::StringToMap(aValue.in(),aMap);
241 QString aMethodName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist);
243 if( aMethodName == "ImportTables" ){
244 aComment.sprintf("myComment=%s;mySourceId=TableFile",GetComment());
250 string anEntry = CreateAttributes( GetStudyDocument(),
251 SO->GetID(),//SComponent->GetID(),
256 aComment.toLatin1().data(),
258 // create SObject referenced to real table object
259 mySObj = SALOMEDS::SObject::_duplicate(GetStudyDocument()->FindObjectID( anEntry.c_str() ));
261 bool isCutSegment = dynamic_cast<CutSegment_i*>(pCutLines);
262 pCutLines->BuildTableOfReal(mySObj, isCutSegment);
264 // mpv (PAL5357): reference attributes are unnecessary now
265 //SALOMEDS::SObject_var refSO = Builder->NewObject( mySObj );
266 //Builder->Addreference( refSO, SO );
274 Restores table object from stream
276 VISU::Storable* VISU::Table_i::Restore( const Storable::TRestoringMap& theMap, SALOMEDS::SObject_ptr SO)
278 if(MYDEBUG) MESSAGE(GetComment());
279 SetName(VISU::Storable::FindValue(theMap,"myName").toLatin1().data(), false);
280 myTitle = VISU::Storable::FindValue(theMap,"myTitle").toLatin1().data();
281 myOrientation = ( VISU::Table::Orientation )( VISU::Storable::FindValue(theMap,"myOrientation").toInt() );
282 mySObj = SALOMEDS::SObject::_duplicate(SO);
283 return Build( true );
286 Flushes table data into stream
288 void VISU::Table_i::ToStream( std::ostringstream& theStr )
290 Storable::DataToStream( theStr, "myName", GetName().c_str() );
291 Storable::DataToStream( theStr, "myTitle", myTitle.c_str() );
292 Storable::DataToStream( theStr, "myOrientation", myOrientation );
295 Called from engine to restore table from the file
297 VISU::Storable* VISU::Table_i::StorableEngine(SALOMEDS::SObject_ptr theSObject,
298 const Storable::TRestoringMap& theMap,
299 const std::string& thePrefix,
300 CORBA::Boolean theIsMultiFile)
302 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
303 VISU::Table_i* pResent = new VISU::Table_i( aStudy, "" );
304 return pResent->Restore( theMap, theSObject);
307 Gets title for the original table object
309 QString VISU::Table_i::GetTableTitle()
311 SALOMEDS::SObject_var SO = mySObj;
312 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
313 SALOMEDS::GenericAttribute_var anAttr;
314 SALOMEDS::AttributeTableOfInteger_var anInt;
315 SALOMEDS::AttributeTableOfReal_var aReal;
316 if ( !SO->_is_nil() ) {
317 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
318 anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
319 CORBA::String_var aString = anInt->GetTitle();
322 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
323 aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
324 CORBA::String_var aString = aReal->GetTitle();
331 //---------------------------------------------------------------
332 void VISU::Table_i::RemoveFromStudy()
334 struct TRemoveFromStudy: public SALOME_Event
336 VISU::Table_i* myRemovable;
337 TRemoveFromStudy(VISU::Table_i* theRemovable):
338 myRemovable(theRemovable)
345 VISU::RemoveFromStudy(myRemovable->GetSObject(),false);
349 // Remove the table with all curves
350 ProcessVoidEvent(new TRemoveFromStudy(this));
353 //----------------------------------------------------------------
355 //----------------------------------------------------------------
357 Restores table object from the stream [ static ]
359 static VISU::Table_i* GetTable( SALOMEDS::Study_ptr theStudy, SALOMEDS::SObject_ptr theSO ) {
360 CORBA::Object_var anObject = VISU::SObjectToObject( theSO );
361 if( !CORBA::is_nil( anObject ) ) {
362 CORBA::Object_ptr aTable = VISU::Table::_narrow( anObject );
363 if( !CORBA::is_nil( aTable ) )
364 return dynamic_cast<VISU::Table_i*>(VISU::GetServant(aTable).in());
369 int VISU::Curve_i::myNbPresent = 0;
370 const string VISU::Curve_i::myComment = "CURVE";
374 QString VISU::Curve_i::GenerateName()
376 return VISU::GenerateName( "Curve", ++myNbPresent ).toLatin1().data();
381 const char* VISU::Curve_i::GetComment() const
383 return myComment.c_str();
387 NB : theHRow, theVRow are the indexes of rows in the Table object and numbered from the 1 to GetNbRows()
389 VISU::Curve_i::Curve_i( SALOMEDS::Study_ptr theStudy, Table_i* theTable,
390 CORBA::Long theHRow, CORBA::Long theVRow,
391 CORBA::Long theZRow )
392 : PrsObject_i(theStudy), myTable( theTable ), myHRow( theHRow ),
393 myVRow( theVRow ), myZRow( theZRow )
396 myLine = VISU::Curve::SOLIDLINE;
398 myMarker = VISU::Curve::CIRCLE;
399 myColor.R = 0.0; myColor.G = 0.0; myColor.B = 0.0;
404 VISU::Curve_i::~Curve_i()
406 MESSAGE("Curve_i::~Curve_i");
409 //----------------------------------------------------------------------------
412 ::SetTitle( const char* theTitle )
414 SetName( theTitle, true );
417 //----------------------------------------------------------------------------
422 return CORBA::string_dup( GetName().c_str() );
425 //----------------------------------------------------------------------------
428 ::SetColor( const SALOMEDS::Color& theColor )
434 //----------------------------------------------------------------------------
442 //----------------------------------------------------------------------------
445 ::SetMarker( VISU::Curve::MarkerType theType )
451 //----------------------------------------------------------------------------
452 VISU::Curve::MarkerType
459 //----------------------------------------------------------------------------
462 ::SetLine( VISU::Curve::LineType theType, CORBA::Long theWidth )
465 myLineWidth = theWidth;
469 //----------------------------------------------------------------------------
470 VISU::Curve::LineType
477 //----------------------------------------------------------------------------
485 //----------------------------------------------------------------------------
489 VISU::Storable* VISU::Curve_i::Create()
492 SetName(GetVerTitle(), false);
493 if ( GetName() == "" )
494 SetName(GenerateName().toLatin1().data(), false);
495 // ... and build the object
496 return Build( false );
499 Builds presentation of curve
501 VISU::Storable* VISU::Curve_i::Build(int theRestoring )
503 if ( myTable != NULL ) {
504 // getting table SObject by it's entry
505 int nbRows = myTable->GetNbRows();
506 if ( myHRow > 0 && myHRow <= nbRows && myVRow > 0 && myVRow <= nbRows ) {
507 if ( !theRestoring ) {
508 // look for component
509 SALOMEDS::SComponent_var SComponent = VISU::FindOrCreateVisuComponent( GetStudyDocument() );
510 // create SObject and set attributes
512 aComment.sprintf("myComment=%s",GetComment());
513 string anEntry = CreateAttributes( GetStudyDocument(),
514 myTable->GetObjectEntry(),
519 aComment.toLatin1().data(),
521 // create SObject referenced to real table object
522 mySObj = SALOMEDS::SObject::_duplicate(GetStudyDocument()->FindObjectID(anEntry.c_str()));
525 SALOMEDS::StudyBuilder_var aStudyBuilder = GetStudyDocument()->NewBuilder();
526 SALOMEDS::GenericAttribute_var anAttr;
527 SALOMEDS::AttributePixMap_var aPixmap;
528 anAttr = aStudyBuilder->FindOrCreateAttribute( mySObj, "AttributePixMap" );
529 aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
530 aPixmap ->SetPixMap("ICON_TREE_CURVE");
539 Returns CORBA::True if curve refers to valid table data
541 CORBA::Boolean VISU::Curve_i::IsValid()
543 // getting table SObject by it's entry
544 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID(myTable->GetObjectEntry().c_str());
545 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
546 SALOMEDS::GenericAttribute_var anAttr;
547 SALOMEDS::AttributeTableOfInteger_var anInt;
548 SALOMEDS::AttributeTableOfReal_var aReal;
549 if ( !SO->_is_nil() ) {
550 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
551 anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
552 if ( myHRow > 0 && myHRow <= anInt->GetNbRows() && myVRow > 0 && myVRow <= anInt->GetNbRows() ) {
556 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
557 aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
558 if ( myHRow > 0 && myHRow <= aReal->GetNbRows() && myVRow > 0 && myVRow <= aReal->GetNbRows() ) {
566 Returns hor.axis title
568 string VISU::Curve_i::GetHorTitle()
571 // getting table SObject by it's entry
572 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID(myTable->GetObjectEntry().c_str());
573 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
574 SALOMEDS::GenericAttribute_var anAttr;
575 SALOMEDS::AttributeTableOfInteger_var anInt;
576 SALOMEDS::AttributeTableOfReal_var aReal;
577 if ( !SO->_is_nil() ) {
578 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
579 anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
580 SALOMEDS::StringSeq_var rowTitles = anInt->GetRowTitles();
581 if ( rowTitles->length() > 0 && myHRow > 0 && myHRow <= anInt->GetNbRows() ) {
582 title = rowTitles[ myHRow-1 ];
585 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
586 aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
587 SALOMEDS::StringSeq_var rowTitles = aReal->GetRowTitles();
588 if ( rowTitles->length() > 0 && myHRow > 0 && myHRow <= aReal->GetNbRows() ) {
589 title = rowTitles[ myHRow-1 ];
596 Returns ver.axis title
598 string VISU::Curve_i::GetVerTitle()
601 // getting table SObject by it's entry
602 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID(myTable->GetObjectEntry().c_str());
603 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
604 SALOMEDS::GenericAttribute_var anAttr;
605 SALOMEDS::AttributeTableOfInteger_var anInt;
606 SALOMEDS::AttributeTableOfReal_var aReal;
607 if ( !SO->_is_nil() ) {
608 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
609 anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
610 SALOMEDS::StringSeq_var rowTitles = anInt->GetRowTitles();
611 if ( rowTitles->length() > 0 && myVRow > 0 && myVRow <= anInt->GetNbRows() )
612 title = rowTitles[ myVRow-1 ];
614 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
615 aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
616 SALOMEDS::StringSeq_var rowTitles = aReal->GetRowTitles();
617 if ( rowTitles->length() > 0 && myVRow > 0 && myVRow <= aReal->GetNbRows() )
618 title = rowTitles[ myVRow-1 ];
624 Returns hor.axis units
626 string VISU::Curve_i::GetHorUnits()
629 // getting table SObject by it's entry
630 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID(myTable->GetObjectEntry().c_str());
631 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
632 SALOMEDS::GenericAttribute_var anAttr;
633 SALOMEDS::AttributeTableOfInteger_var anInt;
634 SALOMEDS::AttributeTableOfReal_var aReal;
635 if ( !SO->_is_nil() ) {
636 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
637 anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
638 SALOMEDS::StringSeq_var rowUnits = anInt->GetRowUnits();
639 if ( rowUnits->length() > 0 && myHRow > 0 && myHRow <= anInt->GetNbRows() )
640 units = rowUnits[ myHRow-1 ];
642 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
643 aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
644 SALOMEDS::StringSeq_var rowUnits = aReal->GetRowUnits();
645 if ( rowUnits->length() > 0 && myHRow > 0 && myHRow <= aReal->GetNbRows() )
646 units = rowUnits[ myHRow-1 ];
652 Returns ver.axis units
654 string VISU::Curve_i::GetVerUnits()
657 // getting table SObject by it's entry
658 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID(myTable->GetObjectEntry().c_str());
659 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
660 SALOMEDS::GenericAttribute_var anAttr;
661 SALOMEDS::AttributeTableOfInteger_var anInt;
662 SALOMEDS::AttributeTableOfReal_var aReal;
663 if ( !SO->_is_nil() ) {
664 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
665 anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
666 SALOMEDS::StringSeq_var rowUnits = anInt->GetRowUnits();
667 if ( rowUnits->length() > 0 && myVRow > 0 && myVRow <= anInt->GetNbRows() )
668 units = rowUnits[ myVRow-1];
670 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
671 aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
672 SALOMEDS::StringSeq_var rowUnits = aReal->GetRowUnits();
673 if ( rowUnits->length() > 0 && myVRow > 0 && myVRow <= aReal->GetNbRows() )
674 units = rowUnits[ myVRow-1 ];
682 int VISU::Curve_i::GetData( double*& theHorList, double*& theVerList, QStringList& zList )
684 theHorList = 0; theVerList = 0;
685 // getting table SObject by it's entry
686 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID(myTable->GetObjectEntry().c_str());
687 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
688 SALOMEDS::GenericAttribute_var anAttr;
689 SALOMEDS::AttributeTableOfInteger_var anInt;
690 SALOMEDS::AttributeTableOfReal_var aReal;
692 QString tip = "%1: %2", z_data;
694 if ( !SO->_is_nil() ) {
695 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
696 anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
697 int nbCols = anInt->GetNbColumns(), nbRows = anInt->GetNbRows();
698 if ( nbCols > 0 && myHRow > 0 && myHRow <= anInt->GetNbRows() && myVRow > 0 && myVRow <= anInt->GetNbRows() ) {
700 for ( int j = 1; j <= nbCols; j++ ) {
701 if ( anInt->HasValue( myHRow, j ) && anInt->HasValue( myVRow, j ) )
704 if ( nbPoints > 0 ) {
705 theHorList = new double[ nbPoints ];
706 theVerList = new double[ nbPoints ];
709 SALOMEDS::StringSeq_var rowTitles = anInt->GetRowTitles();
711 for ( int j = 1; j <= nbCols; j++ ) {
712 if ( anInt->HasValue( myHRow, j ) && anInt->HasValue( myVRow, j ) ) {
713 theHorList[k] = anInt->GetValue( myHRow, j );
714 theVerList[k] = anInt->GetValue( myVRow, j );
716 z_data = tip.arg( GetHorTitle().c_str() ).arg( theHorList[k] ) + "\n";
717 z_data += tip.arg( GetVerTitle().c_str() ).arg( theVerList[k] );
719 if( myZRow>0 && myZRow<=nbRows && anInt->HasValue( myZRow, j ) )
722 title = rowTitles[ myZRow-1 ];
723 z_data += "\n" + tip.arg( title.c_str() ).arg( anInt->GetValue( myZRow, j ) );
725 zList.append( z_data );
733 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
734 aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
735 int nbCols = aReal->GetNbColumns(), nbRows = aReal->GetNbRows();
736 if ( nbCols > 0 && myHRow > 0 && myHRow <= aReal->GetNbRows() && myVRow > 0 && myVRow <= aReal->GetNbRows() ) {
738 for ( int j = 1; j <= nbCols; j++ ) {
739 if ( aReal->HasValue( myHRow, j ) && aReal->HasValue( myVRow, j ) )
742 if ( nbPoints > 0 ) {
743 theHorList = new double[ nbPoints ];
744 theVerList = new double[ nbPoints ];
747 SALOMEDS::StringSeq_var rowTitles = aReal->GetRowTitles();
749 for ( int j = 1; j <= nbCols; j++ ) {
750 if ( aReal->HasValue( myHRow, j ) && aReal->HasValue( myVRow, j ) ) {
751 theHorList[k] = aReal->GetValue( myHRow, j );
752 theVerList[k] = aReal->GetValue( myVRow, j );
754 z_data = tip.arg( GetHorTitle().c_str() ).arg( theHorList[k] ) + "\n";
755 z_data += tip.arg( GetVerTitle().c_str() ).arg( theVerList[k] );
757 if( myZRow>0 && myZRow<=nbRows && aReal->HasValue( myZRow, j ) )
760 title = rowTitles[ myZRow-1 ];
761 z_data += "\n" + tip.arg( title.c_str() ).arg( aReal->GetValue( myZRow, j ) );
763 zList.append( z_data );
775 Creates curve Plot2d presentation object
777 SPlot2d_Curve* VISU::Curve_i::CreatePresentation()
779 SPlot2d_Curve* crv = new SPlot2d_Curve();
780 crv->setHorTitle( GetHorTitle().c_str() );
781 string tlt = GetTitle();
782 if ( tlt.length() <= 0 )
784 //crv->setVerTitle( strdup( GetVerTitle().c_str() ) );
785 //crv->setVerTitle( strdup( GetName() ) );
786 crv->setVerTitle( tlt.c_str() );
787 crv->setHorUnits( GetHorUnits().c_str() );
788 crv->setVerUnits( GetVerUnits().c_str() );
792 int nbPoints = GetData( xList, yList, zList );
793 if ( nbPoints > 0 && xList && yList ) {
794 crv->setData( xList, yList, nbPoints, zList );
796 //cout << "********** Number of points: " << nbPoints <<endl;
797 //for ( int i =0 ; i < nbPoints; i++ ) {
798 // cout << i<<"\t"<<xList[i] << "\t"<< yList[i] << endl;
800 crv->setLine( (Plot2d::LineType)GetLine(), GetLineWidth() );
801 crv->setMarker( (Plot2d::MarkerType)GetMarker() );
802 SALOMEDS::Color color = GetColor();
803 crv->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
804 crv->setAutoAssign( IsAuto() );
805 CORBA::String_var aString = mySObj->GetID();
806 crv->setIO(new SALOME_InteractiveObject(aString.in(), "VISU", GetName().c_str()));
808 crv->setTableIO(new SALOME_InteractiveObject(myTable->GetObjectEntry().c_str(), "VISU", myTable->GetName().c_str()));
812 Restores curve object from stream
814 VISU::Storable* VISU::Curve_i::Restore( const Storable::TRestoringMap& theMap, SALOMEDS::SObject_ptr theSO)
816 if(MYDEBUG) MESSAGE(GetComment());
817 mySObj = SALOMEDS::SObject::_duplicate(theSO);
818 SetName(VISU::Storable::FindValue(theMap,"myName").toLatin1().data(), false);
819 myHRow = VISU::Storable::FindValue(theMap,"myHRow").toInt();
820 myVRow = VISU::Storable::FindValue(theMap,"myVRow").toInt();
822 QString z_str = VISU::Storable::FindValue(theMap,"myZRow", &ok);
823 myZRow = ok ? z_str.toInt() : 0;
825 myColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble();
826 myColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble();
827 myColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble();
828 myMarker = ( VISU::Curve::MarkerType )( VISU::Storable::FindValue(theMap,"myMarker").toInt() );
829 myLine = ( VISU::Curve::LineType )( VISU::Storable::FindValue(theMap,"myLine").toInt() );
830 myLineWidth = VISU::Storable::FindValue(theMap,"myLineWidth").toInt();
831 myAuto = VISU::Storable::FindValue(theMap,"myAuto").toInt();
832 return Build( true );
835 Flushes curve data into stream
837 void VISU::Curve_i::ToStream( std::ostringstream& theStr )
839 Storable::DataToStream( theStr, "myName", GetName().c_str() );
840 Storable::DataToStream( theStr, "myHRow", myHRow );
841 Storable::DataToStream( theStr, "myVRow", myVRow );
842 Storable::DataToStream( theStr, "myZRow", myZRow );
843 Storable::DataToStream( theStr, "myColor.R", myColor.R );
844 Storable::DataToStream( theStr, "myColor.G", myColor.G );
845 Storable::DataToStream( theStr, "myColor.B", myColor.B );
846 Storable::DataToStream( theStr, "myMarker", myMarker );
847 Storable::DataToStream( theStr, "myLine", myLine );
848 Storable::DataToStream( theStr, "myLineWidth", myLineWidth );
849 Storable::DataToStream( theStr, "myAuto", myAuto );
852 Gets reference table's entry
854 std::string VISU::Curve_i::GetTableID() {
855 return myTable->GetObjectEntry();
858 Called from engine to restore curve from the file
860 VISU::Storable* VISU::Curve_i::StorableEngine(SALOMEDS::SObject_ptr theSObject,
861 const Storable::TRestoringMap& theMap,
862 const std::string& thePrefix,
863 CORBA::Boolean theIsMultiFile)
865 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
866 VISU::Table_i* pTable = GetTable(aStudy, theSObject->GetFather());
867 if( pTable != NULL ) {
868 VISU::Curve_i* pResent = new VISU::Curve_i( aStudy, pTable, 0, 0, 0 );
869 return pResent->Restore( theMap, theSObject);
874 void VISU::Curve_i::RemoveFromStudy()
876 struct TRemoveFromStudy: public SALOME_Event
878 VISU::Curve_i* myRemovable;
879 TRemoveFromStudy(VISU::Curve_i* theRemovable):
880 myRemovable(theRemovable)
887 VISU::DeleteActors(myRemovable);
888 VISU::RemoveFromStudy(myRemovable->GetSObject(),false);
892 ProcessVoidEvent(new TRemoveFromStudy(this));
895 SALOMEDS::SObject_var VISU::Curve_i::GetSObject()
900 //----------------------------------------------------------------
902 //----------------------------------------------------------------
903 int VISU::Container_i::myNbPresent = 0;
904 const string VISU::Container_i::myComment = "CONTAINER";
908 QString VISU::Container_i::GenerateName()
910 return VISU::GenerateName( "Plot2DView", ++myNbPresent ).toLatin1().data();
915 const char* VISU::Container_i::GetComment() const
917 return myComment.c_str();
922 VISU::Container_i::Container_i( SALOMEDS::Study_ptr theStudy )
923 : PrsObject_i( theStudy )
929 VISU::Container_i::~Container_i()
931 MESSAGE("Container_i::~Container_i");
935 Inserts curve into the container
937 void VISU::Container_i::AddCurve( Curve_ptr theCurve )
939 if ( GetStudyDocument()->_is_nil() )
941 SALOMEDS::SObject_var mySO = GetStudyDocument()->FindObjectID( GetEntry().c_str() );
942 if ( mySO->_is_nil() )
944 PortableServer::POA_ptr aPOA = GetPOA();
945 Curve_i* pCurve = dynamic_cast<Curve_i*>( aPOA->reference_to_servant( theCurve ) );
947 QString entry( pCurve->GetEntry().c_str() );
948 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID( entry.toLatin1().data() );
949 if ( !SO->_is_nil() && myCurves.indexOf( entry ) == -1 ) {
950 myCurves.append( entry );
951 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
952 SALOMEDS::SObject_var newSO = Builder->NewObject( mySO );
953 Builder->Addreference( newSO, SO );
958 Removes curve from the container
960 void VISU::Container_i::RemoveCurve( Curve_ptr theCurve )
962 if ( GetStudyDocument()->_is_nil() )
964 SALOMEDS::SObject_var mySO = GetStudyDocument()->FindObjectID( GetEntry().c_str() );
965 if ( mySO->_is_nil() )
967 PortableServer::POA_ptr aPOA = GetPOA();
968 Curve_i* pCurve = dynamic_cast<Curve_i*>( aPOA->reference_to_servant( theCurve ) );
970 QString entry( pCurve->GetEntry().c_str() );
971 if ( myCurves.indexOf( entry ) != -1 ) {
973 myCurves.removeAll( entry );
974 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
975 SALOMEDS::ChildIterator_var CI = GetStudyDocument()->NewChildIterator( mySO );
976 for ( ; CI->More(); CI->Next() ) {
977 SALOMEDS::SObject_var childSO = CI->Value();
978 SALOMEDS::SObject_var refSO;
979 if ( childSO->ReferencedObject( refSO ) && !refSO->_is_nil() && entry == QString( refSO->GetID() ) ) {
980 Builder->RemoveObject( childSO );
987 Gets number of curves in the container
989 CORBA::Long VISU::Container_i::GetNbCurves()
992 return myCurves.count();
997 void VISU::Container_i::Clear()
999 if ( GetStudyDocument()->_is_nil() )
1001 SALOMEDS::SObject_var mySO = GetStudyDocument()->FindObjectID( GetEntry().c_str() );
1002 if ( mySO->_is_nil() )
1004 QStringList toDelete;
1005 SALOMEDS::ChildIterator_var CI = GetStudyDocument()->NewChildIterator( mySO );
1006 for ( ; CI->More(); CI->Next() ) {
1007 toDelete.append( CI->Value()->GetID() );
1009 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
1010 for ( int i = 0; i < toDelete.count(); i++ ) {
1011 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID( toDelete[i].toLatin1().data() );
1012 Builder->RemoveObject( SO );
1017 Creates container object
1019 VISU::Storable* VISU::Container_i::Create()
1021 // generate name ...
1022 SetName(GenerateName().toLatin1().data(), false);
1023 // ... and build the object
1024 return Build( false );
1027 Builds presentation of container
1029 VISU::Storable* VISU::Container_i::Build( int theRestoring )
1031 if ( !theRestoring ) {
1032 // looking for component
1033 SALOMEDS::SComponent_var SComponent = VISU::FindOrCreateVisuComponent( GetStudyDocument() );
1034 // create SObject and set attributes
1036 aComment.sprintf("myComment=%s",GetComment());
1037 string anEntry = CreateAttributes( GetStudyDocument(),
1038 SComponent->GetID(),
1043 aComment.toLatin1().data(),
1045 mySObj = SALOMEDS::SObject::_duplicate(GetStudyDocument()->FindObjectID(anEntry.c_str()));
1048 SALOMEDS::StudyBuilder_var aStudyBuilder = GetStudyDocument()->NewBuilder();
1049 SALOMEDS::GenericAttribute_var anAttr;
1050 SALOMEDS::AttributePixMap_var aPixmap;
1051 anAttr = aStudyBuilder->FindOrCreateAttribute( mySObj, "AttributePixMap" );
1052 aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
1053 aPixmap ->SetPixMap("ICON_TREE_CONTAINER");
1058 Updates presentation of container
1060 void VISU::Container_i::Update()
1062 if ( GetStudyDocument()->_is_nil() )
1064 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
1065 SALOMEDS::SObject_var mySO = GetStudyDocument()->FindObjectID( GetEntry().c_str() );
1066 SALOMEDS::GenericAttribute_var anAttr;
1067 if ( !mySO->_is_nil() ) {
1068 QStringList toDelete;
1070 for ( i = 0; i < myCurves.count(); i++ ) {
1071 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID( myCurves[i].toLatin1().data() );
1072 if ( !SO->_is_nil() && Builder->FindAttribute( SO, anAttr, "AttributeIOR" ) ) {
1073 // if real Curve Object still exists
1074 SALOMEDS::ChildIterator_var CI = GetStudyDocument()->NewChildIterator( mySO );
1075 bool bFound = false;
1076 for ( ; CI->More(); CI->Next() ) {
1077 SALOMEDS::SObject_var childSO = CI->Value();
1078 SALOMEDS::SObject_var refSO;
1079 if ( childSO->ReferencedObject( refSO ) && !refSO->_is_nil() && myCurves[i] == QString( refSO->GetID() ) ) {
1080 bFound = true; break;
1084 // create SObject referenced to real curve object if is not yet added
1085 SALOMEDS::SObject_var newSO = Builder->NewObject( mySO );
1086 Builder->Addreference( newSO, SO );
1090 // real Curve Object doesn't exist (might be removed)
1091 toDelete.append( myCurves[i] );
1094 for ( i = 0; i < toDelete.count(); i++ ) {
1095 myCurves.removeAll( toDelete[i] );
1098 SALOMEDS::ChildIterator_var CI = GetStudyDocument()->NewChildIterator( mySO );
1099 for ( ; CI->More(); CI->Next() ) {
1100 SALOMEDS::SObject_var childSO = CI->Value();
1101 SALOMEDS::SObject_var refSO;
1102 if ( childSO->ReferencedObject( refSO ) && ( refSO->_is_nil() || !Builder->FindAttribute( refSO, anAttr, "AttributeIOR" ) ||
1103 myCurves.indexOf( refSO->GetID() ) == -1 ) ) {
1104 toDelete.append( childSO->GetID() );
1107 for ( i = 0; i < toDelete.count(); i++ ) {
1108 SALOMEDS::ChildIterator_var CI = GetStudyDocument()->NewChildIterator( mySO );
1109 for ( ; CI->More(); CI->Next() ) {
1110 SALOMEDS::SObject_var childSO = CI->Value();
1111 if ( toDelete[i] == CI->Value()->GetID() ) {
1112 Builder->RemoveObject( childSO );
1119 Gets curve from container by index
1120 NB : curves are numbered from 1
1122 VISU::Curve_i* VISU::Container_i::GetCurve( CORBA::Long theIndex )
1124 if ( theIndex > 0 && theIndex <= myCurves.count() ) {
1125 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
1126 SALOMEDS::GenericAttribute_var anAttr;
1127 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID(myCurves[ theIndex-1 ].toLatin1().data() );
1128 CORBA::Object_var anObject = VISU::SObjectToObject( SO );
1129 if( !CORBA::is_nil( anObject ) ) {
1130 // if real Curve Object exists
1131 CORBA::Object_ptr aCurve = VISU::Curve::_narrow( anObject );
1132 if( !CORBA::is_nil( aCurve ) )
1133 return dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
1139 Restores container data from the stream
1141 VISU::Storable* VISU::Container_i::Restore( const Storable::TRestoringMap& theMap, SALOMEDS::SObject_ptr SO )
1143 if(MYDEBUG) MESSAGE(GetComment());
1144 mySObj = SALOMEDS::SObject::_duplicate(SO);
1145 SetName(VISU::Storable::FindValue( theMap, "myName" ).toLatin1().data(), false);
1146 QString val = VISU::Storable::FindValue( theMap, "myCurves" );
1147 myCurves = val.split( "*", QString::SkipEmptyParts );
1148 return Build( true );
1151 Flushes container data into the stream
1153 void VISU::Container_i::ToStream( std::ostringstream& theStr )
1155 Storable::DataToStream( theStr, "myName", GetName().c_str() );
1156 Storable::DataToStream( theStr, "myCurves", myCurves.join( QString( "*" ) ) );
1157 // theStr<<" myName "<<myName;
1158 // theStr<<" myCurves "<<myCurves.join( QString( "*" ) ).latin1()<<"* ";
1161 Called from engine to restore container from the file
1163 VISU::Storable* VISU::Container_i::StorableEngine(SALOMEDS::SObject_ptr theSObject,
1164 const Storable::TRestoringMap& theMap,
1165 const std::string& thePrefix,
1166 CORBA::Boolean theIsMultiFile)
1168 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
1169 VISU::Container_i* pResent = new VISU::Container_i( aStudy );
1170 return pResent->Restore( theMap, theSObject );
1173 void VISU::Container_i::RemoveFromStudy()
1175 struct TRemoveFromStudy: public SALOME_Event
1177 VISU::Container_i* myRemovable;
1178 TRemoveFromStudy(VISU::Container_i* theRemovable):
1179 myRemovable(theRemovable)
1186 VISU::RemoveFromStudy(myRemovable->GetSObject(),false);
1190 ProcessVoidEvent(new TRemoveFromStudy(this));
1193 SALOMEDS::SObject_var VISU::Container_i::GetSObject()
1198 SALOMEDS::SObject_var
1199 VISU::ImportTables(const char* theFileName, SALOMEDS::Study_ptr theStudy)
1201 // Set "C" numeric locale to import numbers correctly
1202 Kernel_Utils::Localizer loc;
1204 TTableContainer aContainer;
1205 ImportTables( theFileName, aContainer );
1206 if ( aContainer.empty() )
1207 return SALOMEDS::SObject::_nil();
1209 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1210 SALOMEDS::SComponent_var theSComponent = VISU::FindOrCreateVisuComponent(theStudy);
1211 SALOMEDS::SObject_var aFileObject = aStudyBuilder->NewObject(theSComponent);
1212 SALOMEDS::GenericAttribute_var anAttr =
1213 aStudyBuilder->FindOrCreateAttribute(aFileObject, "AttributeName");
1214 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
1215 QFileInfo aFileInfo(theFileName);
1216 aName->SetValue( aFileInfo.fileName().toLatin1().data());
1217 anAttr = aStudyBuilder->FindOrCreateAttribute(aFileObject, "AttributeString");
1218 SALOMEDS::AttributeString_var aComment = SALOMEDS::AttributeString::_narrow(anAttr);
1220 aString.sprintf("myComment=ImportTables;myFileName=%s",
1221 aFileInfo.absoluteFilePath().toLatin1().data());
1222 aComment->SetValue(aString.toLatin1().data());
1223 for(int i = 0, iEnd = aContainer.size(); i < iEnd; i++){
1224 PTableIDMapper aTableIDMapper = aContainer[i];
1225 const TTable2D& aTable2D = *aTableIDMapper;
1226 SALOMEDS::SObject_var aRealObject = aStudyBuilder->NewObject(aFileObject);
1227 anAttr = aStudyBuilder->FindOrCreateAttribute(aRealObject, "AttributeName");
1228 aName = SALOMEDS::AttributeName::_narrow(anAttr);
1229 if(MYDEBUG) MESSAGE("aTable2D.myTitle = "<<aTable2D.myTitle);
1230 if ( aTable2D.myTitle != "" ) {
1231 aName->SetValue(aTable2D.myTitle.c_str());
1234 aNewName.sprintf("Table:%d",i);
1235 aName->SetValue(aNewName.toLatin1().data());
1238 anAttr = aStudyBuilder->FindOrCreateAttribute(aRealObject, "AttributeTableOfReal");
1239 SALOMEDS::AttributeTableOfReal_var aTableOfReal = SALOMEDS::AttributeTableOfReal::_narrow(anAttr);
1240 aTableOfReal->SetTitle(aTable2D.myTitle.c_str());
1241 TTable2D aNewTable2D;
1242 aTable2D.getColumns(aNewTable2D);
1243 int kEnd = aNewTable2D.myRows[0].myValues.size();
1244 aTableOfReal->SetNbColumns(kEnd);
1245 for(int j = 0, jEnd = aNewTable2D.myRows.size(); j < jEnd; j++){
1246 if(MYDEBUG) MESSAGE("j = "<<j<<"; kEnd = "<<kEnd);
1248 for(int k = 0; k < kEnd; k++){
1249 QString aVal = aNewTable2D.myRows[j].myValues[k].c_str();
1250 bool anIsOk = false;
1251 double aValue = aVal.toDouble(&anIsOk);
1252 if(anIsOk && !aVal.contains("NAN",Qt::CaseInsensitive) && !aVal.contains("INF",Qt::CaseInsensitive))
1253 aTableOfReal->PutValue(aValue,j+1,k+1);
1256 aTableOfReal->SetRowTitle(j+1,aNewTable2D.myRows[j].myTitle.c_str());
1257 aTableOfReal->SetRowUnit(j+1,aNewTable2D.myRows[j].myUnit.c_str());
1259 for(int k = 0; k < kEnd; k++)
1260 aTableOfReal->SetColumnTitle(k+1,aNewTable2D.myColumnTitles[k].c_str());
1265 template<class TTableAttr> bool ExportTableToFile(const TTableAttr& aTabAttr,
1266 const char* theFileName)
1268 if (CORBA::is_nil(aTabAttr))
1271 // Set "C" numeric locale to save numbers correctly
1272 Kernel_Utils::Localizer loc;
1274 QFile aFile(theFileName);
1275 aFile.open(QIODevice::WriteOnly);
1277 /* extract the table info and write it into file */
1279 QString aTitle(aTabAttr->GetTitle()); /*Table title*/
1280 int aRowsNb = aTabAttr->GetNbRows();
1281 int aColNb = aTabAttr->GetNbColumns();
1283 SALOMEDS::StringSeq_var aRowTitles = aTabAttr->GetRowTitles();
1284 SALOMEDS::StringSeq_var aRowUnits = aTabAttr->GetRowUnits();
1285 SALOMEDS::StringSeq_var aColumnTitles = aTabAttr->GetColumnTitles();
1287 /* The given table is rare (some cells is empty) or not? */
1288 bool isRareTable = false;
1289 for (int i = 1; i <= aRowsNb; i++)
1290 for (int j = 1; j <= aColNb && !isRareTable; j++)
1291 isRareTable = !aTabAttr->HasValue(i,j);
1295 /* Separate the given table to 2D tables and write these ones to the file */
1296 QString anAbscissTitle(aRowTitles[0]); /*Absciss row title (X coord)*/
1297 anAbscissTitle.trimmed();
1298 QString anAbscissUnit(aRowUnits[0]);
1299 anAbscissUnit.trimmed();
1300 if (aRowsNb > 2 && aTitle.length() ) aTitle = aTitle + " - ";
1302 for (int i = 2; i <= aRowsNb; i++ )
1305 QString anOrdinate(aRowTitles[i-1]), aTail;
1306 anOrdinate.trimmed();
1308 aLine = "#TITLE: " + aTitle +
1309 ((anOrdinate.length())? anOrdinate :
1310 (aRowsNb>2)? aTail.sprintf("%d",i-1) : aTail.sprintf("") ) + "\n";
1311 aFile.write(aLine.toLatin1() );
1314 if ( anAbscissTitle.length() || anOrdinate.length() ) {
1315 aLine = "#COLUMN_TITLES: " + anAbscissTitle + " | " + anOrdinate + "\n";
1316 aFile.write(aLine.toLatin1() );
1320 aLine = anAbscissUnit + " " +aRowUnits[i-1];
1321 if (!aLine.trimmed().isEmpty()) {
1322 aLine = "#COLUMN_UNITS: " + aLine + "\n";
1323 aFile.write(aLine.toLatin1() );
1326 /* CURVE COORDINATES */
1327 for (int j = 1; j <= aColNb; j++)
1329 if ( aTabAttr -> HasValue(i,j) && aTabAttr -> HasValue(1, j)) {
1330 aLine = aLine.sprintf("%.16g %.16g",
1331 (double)(aTabAttr->GetValue(1,j)),
1332 (double)(aTabAttr->GetValue(i,j))); /* aTabAttr->GetValue(1,j) - X coord */
1333 if ( !aLine.trimmed().isEmpty() ) {
1334 QString aColTitle(aColumnTitles[j-1]);
1335 if ( !aColTitle.trimmed().isEmpty() )
1336 aLine = aLine + " #TITLE: " + aColTitle ;
1337 aFile.write(QString(aLine + "\n").toLatin1() );
1341 aFile.write("\n", 1);
1343 }//end of if (isRareTable)
1345 /* Write the table in the file without separating */
1347 aLine = "#TITLE: " + aTitle + "\n";
1348 aFile.write(aLine.toLatin1());
1350 /* COLUMN_TITLES and COLUMN_UNITS */
1351 QString aTitlesSep = "";
1352 QString aUnitsSep = "";
1353 QString aTitlesStr = "#COLUMN_TITLES: ";
1354 QString aUnitsStr = "#COLUMN_UNITS: ";
1355 for (int i = 1; i <= aRowsNb; i++)
1357 if (!QString(aRowTitles[i-1]).trimmed().isEmpty()) {
1358 aTitlesStr += (aTitlesSep + aRowTitles[i-1]);
1359 if (aTitlesSep.isEmpty()) aTitlesSep = " | ";
1361 if (!QString(aRowUnits[i-1]).trimmed().isEmpty()) {
1362 aUnitsStr += (aUnitsSep + aRowUnits[i-1]);
1363 if (aUnitsSep.isEmpty()) aUnitsSep = " ";
1368 aFile.write(aTitlesStr.toLatin1());
1369 aFile.write(aUnitsStr.toLatin1());
1371 /* CURVE COORDINATES */
1372 QString aSep, aValue, aColTitle;
1373 for (int j = 1; j <= aColNb; j++)
1375 aLine = ""; aSep = "";
1376 for (int i = 1; i <= aRowsNb; i++)
1378 aLine += (aSep + aValue.sprintf("%.16g", (double)(aTabAttr->GetValue(i,j))));
1379 if (aSep.isEmpty()) aSep = " ";
1381 if (!aLine.trimmed().isEmpty()) {
1382 aColTitle = aColumnTitles[j-1];
1383 if (!aColTitle.trimmed().isEmpty())
1384 aLine = aLine + " #TITLE: " + aColTitle;
1386 aFile.write(aLine.toLatin1());
1395 bool VISU::ExportTableToFile(SALOMEDS::SObject_ptr theTable, const char* theFileName)
1398 SALOMEDS::GenericAttribute_var anAttr ;
1399 if (theTable->FindAttribute(anAttr, "AttributeTableOfReal"))
1401 SALOMEDS::AttributeTableOfReal_var aTabAttr = SALOMEDS::AttributeTableOfReal ::_narrow(anAttr);
1402 return ExportTableToFile ( aTabAttr , theFileName);
1405 else if (theTable->FindAttribute(anAttr, "AttributeTableOfInteger")) {
1407 SALOMEDS::AttributeTableOfInteger_var aTabAttr = SALOMEDS::AttributeTableOfInteger ::_narrow(anAttr);
1408 return ExportTableToFile ( aTabAttr , theFileName);