1 // Copyright (C) 2007-2010 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
23 // VISU OBJECT : interactive object for VISU entities implementation
24 // File : VISU_Table_i.cc
25 // Author : Vadim SANDLER
28 #include "VISU_Table_i.hh"
30 #include "VISU_Tools.h"
31 #include "VISU_CutLinesBase_i.hh"
32 #include "VISU_CutSegment_i.hh"
33 #include "VISU_Result_i.hh"
34 #include "VISU_ViewManager_i.hh"
36 #include "SALOME_Event.h"
37 #include "SPlot2d_Curve.h"
39 #include "VISU_TableReader.hxx"
40 #include "VISU_ConvertorUtils.hxx"
42 #include "utilities.h"
44 #include <Basics_Utils.hxx>
49 static int MYDEBUG = 0;
51 static int MYDEBUG = 0;
53 //----------------------------------------------------------------
55 //----------------------------------------------------------------
56 int VISU::Table_i::myNbPresent = 0;
57 const string VISU::Table_i::myComment = "TABLE";
61 QString VISU::Table_i::GenerateName()
63 return VISU::GenerateName( "Table", ++myNbPresent );
68 const char* VISU::Table_i::GetComment() const
70 return myComment.c_str();
75 VISU::Table_i::Table_i( SALOMEDS::Study_ptr theStudy, const char* theObjectEntry )
76 : PrsObject_i(theStudy)
78 MESSAGE("Table_i::Table_i - "<<this);
79 mySObj = theStudy->FindObjectID(theObjectEntry);
80 myOrientation = VISU::Table::HORIZONTAL;
85 VISU::Table_i::~Table_i()
87 MESSAGE("Table_i::~Table_i - "<<this);
90 //----------------------------------------------------------------------------
93 ::SetTitle( const char* theTitle )
95 SetName( theTitle, true );
98 //----------------------------------------------------------------------------
103 return CORBA::string_dup( GetName().c_str() );
106 //----------------------------------------------------------------------------
109 ::SetOrientation( VISU::Table::Orientation theOrientation )
111 myOrientation = theOrientation;
114 //----------------------------------------------------------------------------
115 VISU::Table::Orientation
119 return myOrientation;
123 //----------------------------------------------------------------------------
126 ::SortRow(CORBA::Long theRow, VISU::SortOrder theSortOrder, VISU::SortPolicy theSortPolicy)
128 SALOMEDS::SObject_var SO = mySObj;
129 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
130 if ( !SO->_is_nil() ) {
131 SALOMEDS::GenericAttribute_var anAttr;
132 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
133 SALOMEDS::AttributeTableOfInteger_var anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
134 anInt->SortRow( theRow, (SALOMEDS::AttributeTable::SortOrder)theSortOrder,
135 (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy );
137 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
138 SALOMEDS::AttributeTableOfReal_var aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
139 aReal->SortRow( theRow, (SALOMEDS::AttributeTable::SortOrder)theSortOrder,
140 (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy );
142 UpdateCurves( std::map<int, int>() );
146 //----------------------------------------------------------------------------
149 ::SortColumn(CORBA::Long theColumn, VISU::SortOrder theSortOrder, VISU::SortPolicy theSortPolicy)
151 SALOMEDS::SObject_var SO = mySObj;
152 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
153 if ( !SO->_is_nil() ) {
154 SALOMEDS::GenericAttribute_var anAttr;
155 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
156 SALOMEDS::AttributeTableOfInteger_var anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
157 anInt->SortColumn( theColumn, (SALOMEDS::AttributeTable::SortOrder)theSortOrder,
158 (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy );
160 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
161 SALOMEDS::AttributeTableOfReal_var aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
162 aReal->SortColumn( theColumn, (SALOMEDS::AttributeTable::SortOrder)theSortOrder,
163 (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy );
165 UpdateCurves( std::map<int, int>() );
169 //----------------------------------------------------------------------------
172 ::SortByRow(CORBA::Long theRow, VISU::SortOrder theSortOrder, VISU::SortPolicy theSortPolicy)
174 SALOMEDS::SObject_var SO = mySObj;
175 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
176 if ( !SO->_is_nil() ) {
177 SALOMEDS::GenericAttribute_var anAttr;
178 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
179 SALOMEDS::AttributeTableOfInteger_var anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
180 anInt->SortByRow( theRow, (SALOMEDS::AttributeTable::SortOrder)theSortOrder,
181 (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy );
183 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
184 SALOMEDS::AttributeTableOfReal_var aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
185 aReal->SortByRow( theRow, (SALOMEDS::AttributeTable::SortOrder)theSortOrder,
186 (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy );
188 UpdateCurves( std::map<int, int>() );
192 //----------------------------------------------------------------------------
195 ::SortByColumn(CORBA::Long theColumn, VISU::SortOrder theSortOrder, VISU::SortPolicy theSortPolicy)
197 SALOMEDS::SObject_var SO = mySObj;
198 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
199 if ( !SO->_is_nil() ) {
200 SALOMEDS::LongSeq_var aRowIndices;
201 SALOMEDS::GenericAttribute_var anAttr;
202 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
203 SALOMEDS::AttributeTableOfInteger_var anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
204 aRowIndices = anInt->SortByColumn( theColumn, (SALOMEDS::AttributeTable::SortOrder)theSortOrder,
205 (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy );
207 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
208 SALOMEDS::AttributeTableOfReal_var aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
209 aRowIndices = aReal->SortByColumn( theColumn, (SALOMEDS::AttributeTable::SortOrder)theSortOrder,
210 (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy );
212 std::map<int, int> aMixData;
213 for ( int i = 0, n = aRowIndices->length(); i < n; i++ )
214 aMixData[ aRowIndices[i] ] = i+1;
215 UpdateCurves( aMixData );
219 //----------------------------------------------------------------------------
222 ::UpdateCurves(std::map<int,int> theMixData)
224 SALOMEDS::SObject_var SO = mySObj;
225 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
226 SALOMEDS::ChildIterator_var CI = GetStudyDocument()->NewChildIterator( SO );
227 for ( CI->InitEx( true ); CI->More(); CI->Next() ) {
228 CORBA::Object_var anObj = SObjectToObject( CI->Value() );
229 VISU::Curve_var aCurve = VISU::Curve::_narrow( anObj );
230 if ( !aCurve->_is_nil() ) {
231 if ( VISU::Curve_i* pCurve = dynamic_cast<VISU::Curve_i*>( GetServant( aCurve ).in() ) ) {
232 int aHRow = pCurve->GetHRow(), aVRow = pCurve->GetVRow();
233 if ( theMixData.find( aHRow ) != theMixData.end() )
234 pCurve->SetHRow( theMixData[ aHRow ] );
235 if ( theMixData.find( aVRow ) != theMixData.end() )
236 pCurve->SetVRow( theMixData[ aVRow ] );
237 UpdatePlot2d( pCurve, eUpdateData );
243 //----------------------------------------------------------------------------
244 SALOMEDS::SObject_var
251 //----------------------------------------------------------------------------
256 CORBA::String_var anEntry = mySObj->GetID();
260 //----------------------------------------------------------------------------
262 Gets number of rows in table
264 CORBA::Long VISU::Table_i::GetNbRows()
266 SALOMEDS::SObject_var SO = mySObj;
267 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
268 if ( !SO->_is_nil() ) {
269 SALOMEDS::GenericAttribute_var anAttr;
270 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
271 SALOMEDS::AttributeTableOfInteger_var anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
272 return anInt->GetNbRows();
274 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
275 SALOMEDS::AttributeTableOfReal_var aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
276 return aReal->GetNbRows();
282 Gets number of columns in table
284 CORBA::Long VISU::Table_i::GetNbColumns()
286 SALOMEDS::SObject_var SO = mySObj;
287 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
288 if ( !SO->_is_nil() ) {
289 SALOMEDS::GenericAttribute_var anAttr;
290 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
291 SALOMEDS::AttributeTableOfInteger_var anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
292 return anInt->GetNbColumns();
294 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
295 SALOMEDS::AttributeTableOfReal_var aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
296 return aReal->GetNbColumns();
304 VISU::Storable* VISU::Table_i::Create()
307 SetName(GetTableTitle().toLatin1().data(), false);
309 // mpv (PAL 5357): if name attribute already exist at this label, use it as name of table
310 if ( GetName() == "" )
311 if ( !mySObj->_is_nil() ) {
312 CutLinesBase_i* pCutLines = NULL;
313 CORBA::Object_var anObj = SObjectToObject(mySObj);
314 if(!CORBA::is_nil(anObj)){
315 VISU::CutLinesBase_var aCutLines = VISU::CutLinesBase::_narrow(anObj);
316 if(!aCutLines->_is_nil())
317 pCutLines = dynamic_cast<CutLinesBase_i*>(GetServant(aCutLines).in());
320 if (mySObj->GetName()) SetName(mySObj->GetName(), false);
323 if ( GetName() == "" )
324 SetName(GenerateName().toLatin1().data(), false);
325 // ... and build the object
326 return Build( false );
329 Builds presentation of table
331 VISU::Storable* VISU::Table_i::Build( int theRestoring )
334 // look for reference SObject with table attribute
335 SALOMEDS::SObject_var SO = mySObj;
337 if ( !SO->_is_nil() ) {
338 CutLinesBase_i* pCutLines = NULL;
339 CORBA::Object_var anObj = SObjectToObject(SO);
340 if(!CORBA::is_nil(anObj)){
341 VISU::CutLinesBase_var aCutLines = VISU::CutLinesBase::_narrow(anObj);
342 if(!aCutLines->_is_nil())
343 pCutLines = dynamic_cast<CutLinesBase_i*>(GetServant(aCutLines).in());
345 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
346 SALOMEDS::GenericAttribute_var anAttr;
347 // look for component
348 if ( !theRestoring ) {
349 SALOMEDS::SComponent_var SComponent = VISU::FindOrCreateVisuComponent( GetStudyDocument() );
350 // create SObject and set attributes
353 aComment.sprintf("myComment=%s;mySourceId=CutLines",GetComment());
355 aComment.sprintf("myComment=%s;mySourceId=TableAttr",GetComment());
356 SALOMEDS::SObject_var aFatherSObject = SO->GetFather();
357 if(aFatherSObject->FindAttribute(anAttr,"AttributeString")){
358 SALOMEDS::AttributeString_var aCommentAttr =
359 SALOMEDS::AttributeString::_narrow(anAttr);
360 CORBA::String_var aValue = aCommentAttr->Value();
361 Storable::TRestoringMap aMap;
362 Storable::StringToMap(aValue.in(),aMap);
364 QString aMethodName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist);
366 if( aMethodName == "ImportTables" ){
367 aComment.sprintf("myComment=%s;mySourceId=TableFile",GetComment());
373 string anEntry = CreateAttributes( GetStudyDocument(),
374 SO->GetID(),//SComponent->GetID(),
379 aComment.toLatin1().data(),
381 // create SObject referenced to real table object
382 mySObj = SALOMEDS::SObject::_duplicate(GetStudyDocument()->FindObjectID( anEntry.c_str() ));
384 bool isCutSegment = dynamic_cast<CutSegment_i*>(pCutLines);
385 pCutLines->BuildTableOfReal(mySObj, isCutSegment);
387 // mpv (PAL5357): reference attributes are unnecessary now
388 //SALOMEDS::SObject_var refSO = Builder->NewObject( mySObj );
389 //Builder->Addreference( refSO, SO );
397 Restores table object from stream
399 VISU::Storable* VISU::Table_i::Restore( const Storable::TRestoringMap& theMap, SALOMEDS::SObject_ptr SO)
401 if(MYDEBUG) MESSAGE(GetComment());
402 SetName(VISU::Storable::FindValue(theMap,"myName").toLatin1().data(), false);
403 myTitle = VISU::Storable::FindValue(theMap,"myTitle").toLatin1().data();
404 myOrientation = ( VISU::Table::Orientation )( VISU::Storable::FindValue(theMap,"myOrientation").toInt() );
405 mySObj = SALOMEDS::SObject::_duplicate(SO);
406 return Build( true );
409 Flushes table data into stream
411 void VISU::Table_i::ToStream( std::ostringstream& theStr )
413 Storable::DataToStream( theStr, "myName", GetName().c_str() );
414 Storable::DataToStream( theStr, "myTitle", myTitle.c_str() );
415 Storable::DataToStream( theStr, "myOrientation", myOrientation );
418 Called from engine to restore table from the file
420 VISU::Storable* VISU::Table_i::StorableEngine(SALOMEDS::SObject_ptr theSObject,
421 const Storable::TRestoringMap& theMap,
422 const std::string& thePrefix,
423 CORBA::Boolean theIsMultiFile)
425 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
426 VISU::Table_i* pResent = new VISU::Table_i( aStudy, "" );
427 return pResent->Restore( theMap, theSObject);
430 Gets title for the original table object
432 QString VISU::Table_i::GetTableTitle()
434 SALOMEDS::SObject_var SO = mySObj;
435 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
436 SALOMEDS::GenericAttribute_var anAttr;
437 SALOMEDS::AttributeTableOfInteger_var anInt;
438 SALOMEDS::AttributeTableOfReal_var aReal;
439 if ( !SO->_is_nil() ) {
440 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
441 anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
442 CORBA::String_var aString = anInt->GetTitle();
445 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
446 aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
447 CORBA::String_var aString = aReal->GetTitle();
454 //---------------------------------------------------------------
455 void VISU::Table_i::RemoveFromStudy()
457 struct TRemoveFromStudy: public SALOME_Event
459 VISU::Table_i* myRemovable;
460 TRemoveFromStudy(VISU::Table_i* theRemovable):
461 myRemovable(theRemovable)
468 VISU::RemoveFromStudy(myRemovable->GetSObject(),false);
472 // Remove the table with all curves
473 ProcessVoidEvent(new TRemoveFromStudy(this));
476 //----------------------------------------------------------------
478 //----------------------------------------------------------------
480 Restores table object from the stream [ static ]
482 static VISU::Table_i* GetTable( SALOMEDS::Study_ptr theStudy, SALOMEDS::SObject_ptr theSO ) {
483 CORBA::Object_var anObject = VISU::SObjectToObject( theSO );
484 if( !CORBA::is_nil( anObject ) ) {
485 CORBA::Object_ptr aTable = VISU::Table::_narrow( anObject );
486 if( !CORBA::is_nil( aTable ) )
487 return dynamic_cast<VISU::Table_i*>(VISU::GetServant(aTable).in());
492 int VISU::Curve_i::myNbPresent = 0;
493 const string VISU::Curve_i::myComment = "CURVE";
497 QString VISU::Curve_i::GenerateName()
499 return VISU::GenerateName( "Curve", ++myNbPresent ).toLatin1().data();
504 const char* VISU::Curve_i::GetComment() const
506 return myComment.c_str();
510 NB : theHRow, theVRow are the indexes of rows in the Table object and numbered from the 1 to GetNbRows()
512 VISU::Curve_i::Curve_i( SALOMEDS::Study_ptr theStudy, Table_i* theTable,
513 CORBA::Long theHRow, CORBA::Long theVRow,
514 CORBA::Long theZRow, CORBA::Boolean theIsV2 )
515 : PrsObject_i(theStudy), myTable( theTable ), myHRow( theHRow ),
516 myVRow( theVRow ), myZRow( theZRow ), myIsV2( theIsV2 )
519 myLine = VISU::Curve::SOLIDLINE;
521 myMarker = VISU::Curve::CIRCLE;
522 myColor.R = 0.0; myColor.G = 0.0; myColor.B = 0.0;
527 VISU::Curve_i::~Curve_i()
529 MESSAGE("Curve_i::~Curve_i");
532 //----------------------------------------------------------------------------
535 ::SetTitle( const char* theTitle )
537 SetName( theTitle, true );
540 //----------------------------------------------------------------------------
545 return CORBA::string_dup( GetName().c_str() );
548 //----------------------------------------------------------------------------
551 ::SetColor( const SALOMEDS::Color& theColor )
557 //----------------------------------------------------------------------------
565 //----------------------------------------------------------------------------
568 ::SetMarker( VISU::Curve::MarkerType theType )
574 //----------------------------------------------------------------------------
575 VISU::Curve::MarkerType
582 //----------------------------------------------------------------------------
585 ::SetLine( VISU::Curve::LineType theType, CORBA::Long theWidth )
588 myLineWidth = theWidth;
592 //----------------------------------------------------------------------------
593 VISU::Curve::LineType
600 //----------------------------------------------------------------------------
608 //----------------------------------------------------------------------------
612 VISU::Storable* VISU::Curve_i::Create()
615 SetName(GetVerTitle(), false);
616 if ( GetName() == "" )
617 SetName(GenerateName().toLatin1().data(), false);
618 // ... and build the object
619 return Build( false );
622 Builds presentation of curve
624 VISU::Storable* VISU::Curve_i::Build(int theRestoring )
626 if ( myTable != NULL ) {
627 // getting table SObject by it's entry
628 int nbRows = myTable->GetNbRows();
629 if ( myHRow > 0 && myHRow <= nbRows && myVRow > 0 && myVRow <= nbRows ) {
630 if ( !theRestoring ) {
631 // look for component
632 SALOMEDS::SComponent_var SComponent = VISU::FindOrCreateVisuComponent( GetStudyDocument() );
633 // create SObject and set attributes
635 aComment.sprintf("myComment=%s",GetComment());
636 string anEntry = CreateAttributes( GetStudyDocument(),
637 myTable->GetObjectEntry(),
642 aComment.toLatin1().data(),
644 // create SObject referenced to real table object
645 mySObj = SALOMEDS::SObject::_duplicate(GetStudyDocument()->FindObjectID(anEntry.c_str()));
648 SALOMEDS::StudyBuilder_var aStudyBuilder = GetStudyDocument()->NewBuilder();
649 SALOMEDS::GenericAttribute_var anAttr;
650 SALOMEDS::AttributePixMap_var aPixmap;
651 anAttr = aStudyBuilder->FindOrCreateAttribute( mySObj, "AttributePixMap" );
652 aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
653 aPixmap ->SetPixMap("ICON_TREE_CURVE");
662 Returns CORBA::True if curve refers to valid table data
664 CORBA::Boolean VISU::Curve_i::IsValid()
666 // getting table SObject by it's entry
667 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID(myTable->GetObjectEntry().c_str());
668 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
669 SALOMEDS::GenericAttribute_var anAttr;
670 SALOMEDS::AttributeTableOfInteger_var anInt;
671 SALOMEDS::AttributeTableOfReal_var aReal;
672 if ( !SO->_is_nil() ) {
673 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
674 anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
675 if ( myHRow > 0 && myHRow <= anInt->GetNbRows() && myVRow > 0 && myVRow <= anInt->GetNbRows() ) {
679 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
680 aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
681 if ( myHRow > 0 && myHRow <= aReal->GetNbRows() && myVRow > 0 && myVRow <= aReal->GetNbRows() ) {
689 Returns hor.axis title
691 string VISU::Curve_i::GetHorTitle()
694 // getting table SObject by it's entry
695 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID(myTable->GetObjectEntry().c_str());
696 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
697 SALOMEDS::GenericAttribute_var anAttr;
698 SALOMEDS::AttributeTableOfInteger_var anInt;
699 SALOMEDS::AttributeTableOfReal_var aReal;
700 if ( !SO->_is_nil() ) {
701 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
702 anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
703 SALOMEDS::StringSeq_var rowTitles = anInt->GetRowTitles();
704 if ( rowTitles->length() > 0 && myHRow > 0 && myHRow <= anInt->GetNbRows() ) {
705 title = rowTitles[ myHRow-1 ];
708 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
709 aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
710 SALOMEDS::StringSeq_var rowTitles = aReal->GetRowTitles();
711 if ( rowTitles->length() > 0 && myHRow > 0 && myHRow <= aReal->GetNbRows() ) {
712 title = rowTitles[ myHRow-1 ];
719 Returns ver.axis title
721 string VISU::Curve_i::GetVerTitle()
724 // getting table SObject by it's entry
725 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID(myTable->GetObjectEntry().c_str());
726 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
727 SALOMEDS::GenericAttribute_var anAttr;
728 SALOMEDS::AttributeTableOfInteger_var anInt;
729 SALOMEDS::AttributeTableOfReal_var aReal;
730 if ( !SO->_is_nil() ) {
731 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
732 anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
733 SALOMEDS::StringSeq_var rowTitles = anInt->GetRowTitles();
734 if ( rowTitles->length() > 0 && myVRow > 0 && myVRow <= anInt->GetNbRows() )
735 title = rowTitles[ myVRow-1 ];
737 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
738 aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
739 SALOMEDS::StringSeq_var rowTitles = aReal->GetRowTitles();
740 if ( rowTitles->length() > 0 && myVRow > 0 && myVRow <= aReal->GetNbRows() )
741 title = rowTitles[ myVRow-1 ];
747 Returns hor.axis units
749 string VISU::Curve_i::GetHorUnits()
752 // getting table SObject by it's entry
753 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID(myTable->GetObjectEntry().c_str());
754 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
755 SALOMEDS::GenericAttribute_var anAttr;
756 SALOMEDS::AttributeTableOfInteger_var anInt;
757 SALOMEDS::AttributeTableOfReal_var aReal;
758 if ( !SO->_is_nil() ) {
759 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
760 anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
761 SALOMEDS::StringSeq_var rowUnits = anInt->GetRowUnits();
762 if ( rowUnits->length() > 0 && myHRow > 0 && myHRow <= anInt->GetNbRows() )
763 units = rowUnits[ myHRow-1 ];
765 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
766 aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
767 SALOMEDS::StringSeq_var rowUnits = aReal->GetRowUnits();
768 if ( rowUnits->length() > 0 && myHRow > 0 && myHRow <= aReal->GetNbRows() )
769 units = rowUnits[ myHRow-1 ];
775 Returns ver.axis units
777 string VISU::Curve_i::GetVerUnits()
780 // getting table SObject by it's entry
781 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID(myTable->GetObjectEntry().c_str());
782 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
783 SALOMEDS::GenericAttribute_var anAttr;
784 SALOMEDS::AttributeTableOfInteger_var anInt;
785 SALOMEDS::AttributeTableOfReal_var aReal;
786 if ( !SO->_is_nil() ) {
787 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
788 anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
789 SALOMEDS::StringSeq_var rowUnits = anInt->GetRowUnits();
790 if ( rowUnits->length() > 0 && myVRow > 0 && myVRow <= anInt->GetNbRows() )
791 units = rowUnits[ myVRow-1];
793 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
794 aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
795 SALOMEDS::StringSeq_var rowUnits = aReal->GetRowUnits();
796 if ( rowUnits->length() > 0 && myVRow > 0 && myVRow <= aReal->GetNbRows() )
797 units = rowUnits[ myVRow-1 ];
805 int VISU::Curve_i::GetData( double*& theHorList, double*& theVerList, QStringList& zList )
807 theHorList = 0; theVerList = 0;
808 // getting table SObject by it's entry
809 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID(myTable->GetObjectEntry().c_str());
810 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
811 SALOMEDS::GenericAttribute_var anAttr;
812 SALOMEDS::AttributeTableOfInteger_var anInt;
813 SALOMEDS::AttributeTableOfReal_var aReal;
815 QString tip = "%1: %2", z_data;
817 if ( !SO->_is_nil() ) {
818 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
819 anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
820 int nbCols = anInt->GetNbColumns(), nbRows = anInt->GetNbRows();
821 if ( nbCols > 0 && myHRow > 0 && myHRow <= anInt->GetNbRows() && myVRow > 0 && myVRow <= anInt->GetNbRows() ) {
823 for ( int j = 1; j <= nbCols; j++ ) {
824 if ( anInt->HasValue( myHRow, j ) && anInt->HasValue( myVRow, j ) )
827 if ( nbPoints > 0 ) {
828 theHorList = new double[ nbPoints ];
829 theVerList = new double[ nbPoints ];
832 SALOMEDS::StringSeq_var rowTitles = anInt->GetRowTitles();
834 for ( int j = 1; j <= nbCols; j++ ) {
835 if ( anInt->HasValue( myHRow, j ) && anInt->HasValue( myVRow, j ) ) {
836 theHorList[k] = anInt->GetValue( myHRow, j );
837 theVerList[k] = anInt->GetValue( myVRow, j );
839 z_data = tip.arg( GetHorTitle().c_str() ).arg( theHorList[k] ) + "\n";
840 z_data += tip.arg( GetVerTitle().c_str() ).arg( theVerList[k] );
842 if( myZRow>0 && myZRow<=nbRows && anInt->HasValue( myZRow, j ) )
845 title = rowTitles[ myZRow-1 ];
846 z_data += "\n" + tip.arg( title.c_str() ).arg( anInt->GetValue( myZRow, j ) );
848 zList.append( z_data );
856 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
857 aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
858 int nbCols = aReal->GetNbColumns(), nbRows = aReal->GetNbRows();
859 if ( nbCols > 0 && myHRow > 0 && myHRow <= aReal->GetNbRows() && myVRow > 0 && myVRow <= aReal->GetNbRows() ) {
861 for ( int j = 1; j <= nbCols; j++ ) {
862 if ( aReal->HasValue( myHRow, j ) && aReal->HasValue( myVRow, j ) )
865 if ( nbPoints > 0 ) {
866 theHorList = new double[ nbPoints ];
867 theVerList = new double[ nbPoints ];
870 SALOMEDS::StringSeq_var rowTitles = aReal->GetRowTitles();
872 for ( int j = 1; j <= nbCols; j++ ) {
873 if ( aReal->HasValue( myHRow, j ) && aReal->HasValue( myVRow, j ) ) {
874 theHorList[k] = aReal->GetValue( myHRow, j );
875 theVerList[k] = aReal->GetValue( myVRow, j );
877 z_data = tip.arg( GetHorTitle().c_str() ).arg( theHorList[k] ) + "\n";
878 z_data += tip.arg( GetVerTitle().c_str() ).arg( theVerList[k] );
880 if( myZRow>0 && myZRow<=nbRows && aReal->HasValue( myZRow, j ) )
883 title = rowTitles[ myZRow-1 ];
884 z_data += "\n" + tip.arg( title.c_str() ).arg( aReal->GetValue( myZRow, j ) );
886 zList.append( z_data );
898 Creates curve Plot2d presentation object
900 SPlot2d_Curve* VISU::Curve_i::CreatePresentation()
902 SPlot2d_Curve* crv = new SPlot2d_Curve();
903 crv->setYAxis( myIsV2 ? QwtPlot::yRight : QwtPlot::yLeft );
904 crv->setHorTitle( GetHorTitle().c_str() );
905 string tlt = GetTitle();
906 if ( tlt.length() <= 0 )
908 //crv->setVerTitle( strdup( GetVerTitle().c_str() ) );
909 //crv->setVerTitle( strdup( GetName() ) );
910 crv->setVerTitle( tlt.c_str() );
911 crv->setHorUnits( GetHorUnits().c_str() );
912 crv->setVerUnits( GetVerUnits().c_str() );
916 int nbPoints = GetData( xList, yList, zList );
917 if ( nbPoints > 0 && xList && yList ) {
918 crv->setData( xList, yList, nbPoints, zList );
920 //cout << "********** Number of points: " << nbPoints <<endl;
921 //for ( int i =0 ; i < nbPoints; i++ ) {
922 // cout << i<<"\t"<<xList[i] << "\t"<< yList[i] << endl;
924 crv->setLine( (Plot2d::LineType)GetLine(), GetLineWidth() );
925 crv->setMarker( (Plot2d::MarkerType)GetMarker() );
926 SALOMEDS::Color color = GetColor();
927 crv->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
928 crv->setAutoAssign( IsAuto() );
929 CORBA::String_var aString = mySObj->GetID();
930 crv->setIO(new SALOME_InteractiveObject(aString.in(), "VISU", GetName().c_str()));
932 crv->setTableIO(new SALOME_InteractiveObject(myTable->GetObjectEntry().c_str(), "VISU", myTable->GetName().c_str()));
934 if(!myContainers.isEmpty())
935 crv->addOwners(myContainers);
939 Restores curve object from stream
941 VISU::Storable* VISU::Curve_i::Restore( const Storable::TRestoringMap& theMap, SALOMEDS::SObject_ptr theSO)
943 if(MYDEBUG) MESSAGE(GetComment());
944 mySObj = SALOMEDS::SObject::_duplicate(theSO);
945 SetName(VISU::Storable::FindValue(theMap,"myName").toLatin1().data(), false);
946 myHRow = VISU::Storable::FindValue(theMap,"myHRow").toInt();
947 myVRow = VISU::Storable::FindValue(theMap,"myVRow").toInt();
949 QString z_str = VISU::Storable::FindValue(theMap,"myZRow", &ok);
950 myZRow = ok ? z_str.toInt() : 0;
952 QString v2_str = VISU::Storable::FindValue(theMap,"myIsV2", &ok);
953 myIsV2 = ok ? v2_str.toInt() : false;
955 myColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble();
956 myColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble();
957 myColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble();
958 myMarker = ( VISU::Curve::MarkerType )( VISU::Storable::FindValue(theMap,"myMarker").toInt() );
959 myLine = ( VISU::Curve::LineType )( VISU::Storable::FindValue(theMap,"myLine").toInt() );
960 myLineWidth = VISU::Storable::FindValue(theMap,"myLineWidth").toInt();
961 myAuto = VISU::Storable::FindValue(theMap,"myAuto").toInt();
962 return Build( true );
965 Flushes curve data into stream
967 void VISU::Curve_i::ToStream( std::ostringstream& theStr )
969 Storable::DataToStream( theStr, "myName", GetName().c_str() );
970 Storable::DataToStream( theStr, "myHRow", myHRow );
971 Storable::DataToStream( theStr, "myVRow", myVRow );
972 Storable::DataToStream( theStr, "myZRow", myZRow );
973 Storable::DataToStream( theStr, "myIsV2", myIsV2 );
974 Storable::DataToStream( theStr, "myColor.R", myColor.R );
975 Storable::DataToStream( theStr, "myColor.G", myColor.G );
976 Storable::DataToStream( theStr, "myColor.B", myColor.B );
977 Storable::DataToStream( theStr, "myMarker", myMarker );
978 Storable::DataToStream( theStr, "myLine", myLine );
979 Storable::DataToStream( theStr, "myLineWidth", myLineWidth );
980 Storable::DataToStream( theStr, "myAuto", myAuto );
983 Gets reference table's entry
985 std::string VISU::Curve_i::GetTableID() {
986 return myTable->GetObjectEntry();
989 Called from engine to restore curve from the file
991 VISU::Storable* VISU::Curve_i::StorableEngine(SALOMEDS::SObject_ptr theSObject,
992 const Storable::TRestoringMap& theMap,
993 const std::string& thePrefix,
994 CORBA::Boolean theIsMultiFile)
996 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
997 VISU::Table_i* pTable = GetTable(aStudy, theSObject->GetFather());
998 if( pTable != NULL ) {
999 VISU::Curve_i* pResent = new VISU::Curve_i( aStudy, pTable, 0, 0, 0, false );
1000 return pResent->Restore( theMap, theSObject);
1005 void VISU::Curve_i::RemoveFromStudy()
1007 struct TRemoveFromStudy: public SALOME_Event
1009 VISU::Curve_i* myRemovable;
1010 TRemoveFromStudy(VISU::Curve_i* theRemovable):
1011 myRemovable(theRemovable)
1018 VISU::DeleteActors(myRemovable);
1019 VISU::RemoveFromStudy(myRemovable->GetSObject(),false);
1023 ProcessVoidEvent(new TRemoveFromStudy(this));
1026 SALOMEDS::SObject_var VISU::Curve_i::GetSObject()
1034 id - owner of the curve
1036 void VISU::Curve_i::addContainer(const QString& id) {
1037 myContainers.insert(id);
1042 id - entry of the container
1044 void VISU::Curve_i::removeContainer(const QString& id) {
1045 myContainers.insert(id);
1049 Get all owners of the curve.
1050 \return owners of the curve.
1052 VISU::ContainerSet VISU::Curve_i::getContainers() const {
1053 return myContainers;
1057 //----------------------------------------------------------------
1059 //----------------------------------------------------------------
1060 int VISU::Container_i::myNbPresent = 0;
1061 const string VISU::Container_i::myComment = "CONTAINER";
1063 Generate unique name
1065 QString VISU::Container_i::GenerateName()
1067 return VISU::GenerateName( "Plot2DView", ++myNbPresent ).toLatin1().data();
1072 const char* VISU::Container_i::GetComment() const
1074 return myComment.c_str();
1079 VISU::Container_i::Container_i( SALOMEDS::Study_ptr theStudy )
1080 : PrsObject_i( theStudy )
1086 VISU::Container_i::~Container_i()
1088 MESSAGE("Container_i::~Container_i");
1092 Inserts curve into the container
1094 void VISU::Container_i::AddCurve( Curve_ptr theCurve )
1096 if ( GetStudyDocument()->_is_nil() )
1098 SALOMEDS::SObject_var mySO = GetStudyDocument()->FindObjectID( GetEntry().c_str() );
1099 if ( mySO->_is_nil() )
1101 PortableServer::POA_ptr aPOA = GetPOA();
1102 Curve_i* pCurve = dynamic_cast<Curve_i*>( aPOA->reference_to_servant( theCurve ) );
1104 QString entry( pCurve->GetEntry().c_str() );
1105 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID( entry.toLatin1().data() );
1106 if ( !SO->_is_nil() && myCurves.indexOf( entry ) == -1 ) {
1107 myCurves.append( entry );
1108 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
1109 SALOMEDS::SObject_var newSO = Builder->NewObject( mySO );
1110 Builder->Addreference( newSO, SO );
1111 pCurve->addContainer(GetEntry().c_str());
1116 Removes curve from the container
1118 void VISU::Container_i::RemoveCurve( Curve_ptr theCurve )
1120 if ( GetStudyDocument()->_is_nil() )
1122 SALOMEDS::SObject_var mySO = GetStudyDocument()->FindObjectID( GetEntry().c_str() );
1123 if ( mySO->_is_nil() )
1125 PortableServer::POA_ptr aPOA = GetPOA();
1126 Curve_i* pCurve = dynamic_cast<Curve_i*>( aPOA->reference_to_servant( theCurve ) );
1128 QString entry( pCurve->GetEntry().c_str() );
1129 if ( myCurves.indexOf( entry ) != -1 ) {
1131 myCurves.removeAll( entry );
1132 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
1133 SALOMEDS::ChildIterator_var CI = GetStudyDocument()->NewChildIterator( mySO );
1134 for ( ; CI->More(); CI->Next() ) {
1135 SALOMEDS::SObject_var childSO = CI->Value();
1136 SALOMEDS::SObject_var refSO;
1137 if ( childSO->ReferencedObject( refSO ) && !refSO->_is_nil() && entry == QString( refSO->GetID() ) ) {
1138 Builder->RemoveObject( childSO );
1141 pCurve->removeContainer(GetEntry().c_str());
1146 Gets number of curves in the container
1148 CORBA::Long VISU::Container_i::GetNbCurves()
1151 return myCurves.count();
1156 void VISU::Container_i::Clear()
1158 if ( GetStudyDocument()->_is_nil() )
1160 SALOMEDS::SObject_var mySO = GetStudyDocument()->FindObjectID( GetEntry().c_str() );
1161 if ( mySO->_is_nil() )
1163 QStringList toDelete;
1164 SALOMEDS::ChildIterator_var CI = GetStudyDocument()->NewChildIterator( mySO );
1165 for ( ; CI->More(); CI->Next() ) {
1166 toDelete.append( CI->Value()->GetID() );
1168 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
1169 for ( int i = 0; i < toDelete.count(); i++ ) {
1170 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID( toDelete[i].toLatin1().data() );
1171 Builder->RemoveObject( SO );
1176 Creates container object
1178 VISU::Storable* VISU::Container_i::Create()
1180 // generate name ...
1181 SetName(GenerateName().toLatin1().data(), false);
1182 // ... and build the object
1183 return Build( false );
1186 Builds presentation of container
1188 VISU::Storable* VISU::Container_i::Build( int theRestoring )
1190 if ( !theRestoring ) {
1191 // looking for component
1192 SALOMEDS::SComponent_var SComponent = VISU::FindOrCreateVisuComponent( GetStudyDocument() );
1193 // create SObject and set attributes
1195 aComment.sprintf("myComment=%s",GetComment());
1196 string anEntry = CreateAttributes( GetStudyDocument(),
1197 SComponent->GetID(),
1202 aComment.toLatin1().data(),
1204 mySObj = SALOMEDS::SObject::_duplicate(GetStudyDocument()->FindObjectID(anEntry.c_str()));
1207 SALOMEDS::StudyBuilder_var aStudyBuilder = GetStudyDocument()->NewBuilder();
1208 SALOMEDS::GenericAttribute_var anAttr;
1209 SALOMEDS::AttributePixMap_var aPixmap;
1210 anAttr = aStudyBuilder->FindOrCreateAttribute( mySObj, "AttributePixMap" );
1211 aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
1212 aPixmap ->SetPixMap("ICON_TREE_CONTAINER");
1217 Updates presentation of container
1219 void VISU::Container_i::Update()
1221 if ( GetStudyDocument()->_is_nil() )
1223 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
1224 SALOMEDS::SObject_var mySO = GetStudyDocument()->FindObjectID( GetEntry().c_str() );
1225 SALOMEDS::GenericAttribute_var anAttr;
1226 if ( !mySO->_is_nil() ) {
1227 QStringList toDelete;
1229 for ( i = 0; i < myCurves.count(); i++ ) {
1230 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID( myCurves[i].toLatin1().data() );
1231 if ( !SO->_is_nil() && Builder->FindAttribute( SO, anAttr, "AttributeIOR" ) ) {
1232 // if real Curve Object still exists
1233 SALOMEDS::ChildIterator_var CI = GetStudyDocument()->NewChildIterator( mySO );
1234 bool bFound = false;
1235 for ( ; CI->More(); CI->Next() ) {
1236 SALOMEDS::SObject_var childSO = CI->Value();
1237 SALOMEDS::SObject_var refSO;
1238 if ( childSO->ReferencedObject( refSO ) && !refSO->_is_nil() && myCurves[i] == QString( refSO->GetID() ) ) {
1239 bFound = true; break;
1243 // create SObject referenced to real curve object if is not yet added
1244 SALOMEDS::SObject_var newSO = Builder->NewObject( mySO );
1245 Builder->Addreference( newSO, SO );
1249 // real Curve Object doesn't exist (might be removed)
1250 toDelete.append( myCurves[i] );
1253 for ( i = 0; i < toDelete.count(); i++ ) {
1254 myCurves.removeAll( toDelete[i] );
1257 SALOMEDS::ChildIterator_var CI = GetStudyDocument()->NewChildIterator( mySO );
1258 for ( ; CI->More(); CI->Next() ) {
1259 SALOMEDS::SObject_var childSO = CI->Value();
1260 SALOMEDS::SObject_var refSO;
1261 if ( childSO->ReferencedObject( refSO ) && ( refSO->_is_nil() || !Builder->FindAttribute( refSO, anAttr, "AttributeIOR" ) ||
1262 myCurves.indexOf( refSO->GetID() ) == -1 ) ) {
1263 toDelete.append( childSO->GetID() );
1266 for ( i = 0; i < toDelete.count(); i++ ) {
1267 SALOMEDS::ChildIterator_var CI = GetStudyDocument()->NewChildIterator( mySO );
1268 for ( ; CI->More(); CI->Next() ) {
1269 SALOMEDS::SObject_var childSO = CI->Value();
1270 if ( toDelete[i] == CI->Value()->GetID() ) {
1271 Builder->RemoveObject( childSO );
1278 Gets curve from container by index
1279 NB : curves are numbered from 1
1281 VISU::Curve_i* VISU::Container_i::GetCurve( CORBA::Long theIndex )
1283 if ( theIndex > 0 && theIndex <= myCurves.count() ) {
1284 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
1285 SALOMEDS::GenericAttribute_var anAttr;
1286 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID(myCurves[ theIndex-1 ].toLatin1().data() );
1287 CORBA::Object_var anObject = VISU::SObjectToObject( SO );
1288 if( !CORBA::is_nil( anObject ) ) {
1289 // if real Curve Object exists
1290 CORBA::Object_ptr aCurve = VISU::Curve::_narrow( anObject );
1291 if( !CORBA::is_nil( aCurve ) )
1292 return dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
1298 Restores container data from the stream
1300 VISU::Storable* VISU::Container_i::Restore( const Storable::TRestoringMap& theMap, SALOMEDS::SObject_ptr SO )
1302 if(MYDEBUG) MESSAGE(GetComment());
1303 mySObj = SALOMEDS::SObject::_duplicate(SO);
1304 SetName(VISU::Storable::FindValue( theMap, "myName" ).toLatin1().data(), false);
1305 QString val = VISU::Storable::FindValue( theMap, "myCurves" );
1306 myCurves = val.split( "*", QString::SkipEmptyParts );
1307 return Build( true );
1310 Flushes container data into the stream
1312 void VISU::Container_i::ToStream( std::ostringstream& theStr )
1314 Storable::DataToStream( theStr, "myName", GetName().c_str() );
1315 Storable::DataToStream( theStr, "myCurves", myCurves.join( QString( "*" ) ) );
1316 // theStr<<" myName "<<myName;
1317 // theStr<<" myCurves "<<myCurves.join( QString( "*" ) ).latin1()<<"* ";
1320 Called from engine to restore container from the file
1322 VISU::Storable* VISU::Container_i::StorableEngine(SALOMEDS::SObject_ptr theSObject,
1323 const Storable::TRestoringMap& theMap,
1324 const std::string& thePrefix,
1325 CORBA::Boolean theIsMultiFile)
1327 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
1328 VISU::Container_i* pResent = new VISU::Container_i( aStudy );
1329 return pResent->Restore( theMap, theSObject );
1332 void VISU::Container_i::RemoveFromStudy()
1334 struct TRemoveFromStudy: public SALOME_Event
1336 VISU::Container_i* myRemovable;
1337 TRemoveFromStudy(VISU::Container_i* theRemovable):
1338 myRemovable(theRemovable)
1345 VISU::RemoveFromStudy(myRemovable->GetSObject(),false);
1349 ProcessVoidEvent(new TRemoveFromStudy(this));
1352 SALOMEDS::SObject_var VISU::Container_i::GetSObject()
1357 SALOMEDS::SObject_var
1358 VISU::ImportTables(const char* theFileName, SALOMEDS::Study_ptr theStudy,
1359 bool theFirstStrAsTitle)
1361 // Set "C" numeric locale to import numbers correctly
1362 Kernel_Utils::Localizer loc;
1364 TTableContainer aContainer;
1365 ImportTables( theFileName, aContainer, theFirstStrAsTitle );
1366 if ( aContainer.empty() )
1367 return SALOMEDS::SObject::_nil();
1369 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1370 SALOMEDS::SComponent_var theSComponent = VISU::FindOrCreateVisuComponent(theStudy);
1371 SALOMEDS::SObject_var aFileObject = aStudyBuilder->NewObject(theSComponent);
1372 SALOMEDS::GenericAttribute_var anAttr =
1373 aStudyBuilder->FindOrCreateAttribute(aFileObject, "AttributeName");
1374 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
1375 QFileInfo aFileInfo(theFileName);
1376 aName->SetValue( aFileInfo.fileName().toLatin1().data());
1377 anAttr = aStudyBuilder->FindOrCreateAttribute(aFileObject, "AttributeString");
1378 SALOMEDS::AttributeString_var aComment = SALOMEDS::AttributeString::_narrow(anAttr);
1380 aString.sprintf("myComment=ImportTables;myFileName=%s;myFirstStrAsTitle=%d",
1381 aFileInfo.absoluteFilePath().toLatin1().data(),theFirstStrAsTitle);
1382 aComment->SetValue(aString.toLatin1().data());
1383 for(int i = 0, iEnd = aContainer.size(); i < iEnd; i++) {
1384 PTableIDMapper aTableIDMapper = aContainer[i];
1385 const TTable2D& aTable2D = *aTableIDMapper;
1386 SALOMEDS::SObject_var aRealObject = aStudyBuilder->NewObject(aFileObject);
1387 anAttr = aStudyBuilder->FindOrCreateAttribute(aRealObject, "AttributeName");
1388 aName = SALOMEDS::AttributeName::_narrow(anAttr);
1389 if(MYDEBUG) MESSAGE("aTable2D.myTitle = "<<aTable2D.myTitle);
1390 if ( aTable2D.myTitle != "" ) {
1391 aName->SetValue(aTable2D.myTitle.c_str());
1395 aNewName.sprintf("Table:%d",i);
1396 aName->SetValue(aNewName.toLatin1().data());
1399 anAttr = aStudyBuilder->FindOrCreateAttribute(aRealObject, "AttributeTableOfReal");
1400 SALOMEDS::AttributeTableOfReal_var aTableOfReal = SALOMEDS::AttributeTableOfReal::_narrow(anAttr);
1401 aTableOfReal->SetTitle(aTable2D.myTitle.c_str());
1402 TTable2D aNewTable2D;
1403 aTable2D.getColumns(aNewTable2D);
1404 int kEnd = aNewTable2D.myRows[0].myValues.size();
1405 // check empty columns
1406 TColStd_MapOfInteger EmptyColumns;
1407 for(int j = 0, jEnd = aNewTable2D.myRows.size(); j < jEnd; j++) {
1408 bool hasVal = false;
1409 for(int k = 0; k < kEnd; k++) {
1410 QString aVal = aNewTable2D.myRows[j].myValues[k].c_str();
1411 bool anIsOk = false;
1412 double aValue = aVal.toDouble(&anIsOk);
1419 EmptyColumns.Add(j);
1422 // create table of real
1423 aTableOfReal->SetNbColumns( kEnd - EmptyColumns.Extent() );
1425 for(int j = 0, jEnd = aNewTable2D.myRows.size(); j < jEnd; j++) {
1426 if( EmptyColumns.Contains(j) ) continue;
1428 if(MYDEBUG) MESSAGE("j = "<<j<<"; kEnd = "<<kEnd);
1429 for(int k = 0; k < kEnd; k++) {
1430 QString aVal = aNewTable2D.myRows[j].myValues[k].c_str();
1431 bool anIsOk = false;
1432 double aValue = aVal.toDouble(&anIsOk);
1433 if( anIsOk && !aVal.contains("NAN",Qt::CaseInsensitive) &&
1434 !aVal.contains("INF",Qt::CaseInsensitive) ) {
1435 aTableOfReal->PutValue(aValue,currNum+1,k+1);
1438 aTableOfReal->SetRowTitle(currNum+1,aNewTable2D.myRows[j].myTitle.c_str());
1439 aTableOfReal->SetRowUnit(currNum+1,aNewTable2D.myRows[j].myUnit.c_str());
1441 for(int k = 0; k < kEnd; k++)
1442 aTableOfReal->SetColumnTitle(k+1,aNewTable2D.myColumnTitles[k].c_str());
1448 //=======================================================================
1449 //function : updateStrForCSV
1450 //purpose : auxilary for ExportTableToFile
1451 //=======================================================================
1452 void updateStrForCSV(QString& aStr, const char aSep)
1454 int index = aStr.indexOf('"');
1456 aStr.insert(index,'"');
1457 if( index+2 >= aStr.size() ) break;
1458 index = aStr.indexOf('"',index+2);
1460 index = aStr.indexOf(aSep);
1462 // current string contains separator => need to use "..."
1464 aStr.push_back('"');
1469 //=======================================================================
1470 //function : ExportTableToFile
1472 //=======================================================================
1473 template<class TTableAttr> bool ExportTableToFile(const TTableAttr& aTabAttr,
1474 const char* theFileName)
1476 if (CORBA::is_nil(aTabAttr))
1479 // Set "C" numeric locale to save numbers correctly
1480 Kernel_Utils::Localizer loc;
1482 QFile aFile(theFileName);
1483 aFile.open(QIODevice::WriteOnly);
1485 /* extract the table info and write it into file */
1487 QString aTitle(aTabAttr->GetTitle()); /*Table title*/
1488 int aRowsNb = aTabAttr->GetNbRows();
1489 int aColNb = aTabAttr->GetNbColumns();
1491 SALOMEDS::StringSeq_var aRowTitles = aTabAttr->GetRowTitles();
1492 SALOMEDS::StringSeq_var aRowUnits = aTabAttr->GetRowUnits();
1493 SALOMEDS::StringSeq_var aColumnTitles = aTabAttr->GetColumnTitles();
1495 //--------------------------------------------------
1496 // write as *.csv file if it is needed
1497 //--------------------------------------------------
1498 QString tmp(theFileName);
1499 tmp = tmp.trimmed();
1500 tmp = tmp.right(3).trimmed();
1501 if( tmp == QString("csv") ) {
1502 const char aSep = ',';
1503 // write column titles
1504 QString aLine(aRowTitles[0]);
1505 updateStrForCSV(aLine,aSep);
1506 for(int i=1; i<aRowsNb; i++) {
1508 QString aTmp(aRowTitles[i]);
1509 updateStrForCSV(aTmp,aSep);
1513 aFile.write(aLine.toLatin1() );
1516 for (int j = 1; j <= aColNb; j++) {
1518 if(aTabAttr->HasValue(j,1)) {
1519 aLine = aValue.sprintf("%.16g",(double)aTabAttr->GetValue(1,j));
1521 for (int i = 2; i <= aRowsNb; i++) {
1522 if(aTabAttr->HasValue(i,j)) {
1523 aLine += aSep + aValue.sprintf("%.16g",(double)aTabAttr->GetValue(i,j));
1528 aFile.write(aLine.toLatin1() );
1534 //--------------------------------------------------
1535 // end of writing as *.csv file
1536 //--------------------------------------------------
1538 /* The given table is rare (some cells is empty) or not? */
1539 bool isRareTable = false;
1540 for (int i = 1; i <= aRowsNb; i++)
1541 for (int j = 1; j <= aColNb && !isRareTable; j++)
1542 isRareTable = !aTabAttr->HasValue(i,j);
1546 /* Separate the given table to 2D tables and write these ones to the file */
1547 QString anAbscissTitle(aRowTitles[0]); /*Absciss row title (X coord)*/
1548 anAbscissTitle.trimmed();
1549 QString anAbscissUnit(aRowUnits[0]);
1550 anAbscissUnit.trimmed();
1551 if (aRowsNb > 2 && aTitle.length() ) aTitle = aTitle + " - ";
1553 for (int i = 2; i <= aRowsNb; i++ )
1556 QString anOrdinate(aRowTitles[i-1]), aTail;
1557 anOrdinate.trimmed();
1559 aLine = "#TITLE: " + aTitle +
1560 ((anOrdinate.length())? anOrdinate :
1561 (aRowsNb>2)? aTail.sprintf("%d",i-1) : aTail.sprintf("") ) + "\n";
1562 aFile.write(aLine.toLatin1() );
1565 if ( anAbscissTitle.length() || anOrdinate.length() ) {
1566 aLine = "#COLUMN_TITLES: " + anAbscissTitle + " | " + anOrdinate;
1567 int tmpind = aLine.indexOf("\n");
1569 aLine.remove(tmpind,1);
1570 tmpind = aLine.indexOf("\n");
1573 aFile.write(aLine.toLatin1() );
1577 aLine = anAbscissUnit + " " +aRowUnits[i-1];
1578 if (!aLine.trimmed().isEmpty()) {
1579 aLine = "#COLUMN_UNITS: " + aLine + "\n";
1580 aFile.write(aLine.toLatin1() );
1583 /* CURVE COORDINATES */
1584 for (int j = 1; j <= aColNb; j++)
1586 if ( aTabAttr -> HasValue(i,j) && aTabAttr -> HasValue(1, j)) {
1587 aLine = aLine.sprintf("%.16g %.16g",
1588 (double)(aTabAttr->GetValue(1,j)),
1589 (double)(aTabAttr->GetValue(i,j))); /* aTabAttr->GetValue(1,j) - X coord */
1590 if ( !aLine.trimmed().isEmpty() ) {
1591 QString aColTitle(aColumnTitles[j-1]);
1592 if ( !aColTitle.trimmed().isEmpty() )
1593 aLine = aLine + " #TITLE: " + aColTitle ;
1594 aFile.write(QString(aLine + "\n").toLatin1() );
1598 aFile.write("\n", 1);
1600 }//end of if (isRareTable)
1602 /* Write the table in the file without separating */
1604 aLine = "#TITLE: " + aTitle + "\n";
1605 aFile.write(aLine.toLatin1());
1607 /* COLUMN_TITLES and COLUMN_UNITS */
1608 QString aTitlesSep = "";
1609 QString aUnitsSep = "";
1610 QString aTitlesStr = "#COLUMN_TITLES: ";
1611 QString aUnitsStr = "#COLUMN_UNITS: ";
1612 for (int i = 1; i <= aRowsNb; i++) {
1613 if (!QString(aRowTitles[i-1]).trimmed().isEmpty()) {
1614 aTitlesStr += (aTitlesSep + aRowTitles[i-1]);
1615 if (aTitlesSep.isEmpty()) aTitlesSep = " | ";
1617 if (!QString(aRowUnits[i-1]).trimmed().isEmpty()) {
1618 aUnitsStr += (aUnitsSep + aRowUnits[i-1]);
1619 if (aUnitsSep.isEmpty()) aUnitsSep = " ";
1622 int tmpind = aTitlesStr.indexOf("\n");
1624 aTitlesStr.remove(tmpind,1);
1625 tmpind = aTitlesStr.indexOf("\n");
1629 aFile.write(aTitlesStr.toLatin1());
1630 aFile.write(aUnitsStr.toLatin1());
1632 /* CURVE COORDINATES */
1633 QString aSep, aValue, aColTitle;
1634 for (int j = 1; j <= aColNb; j++) {
1635 aLine = ""; aSep = "";
1636 for (int i = 1; i <= aRowsNb; i++) {
1637 aLine += (aSep + aValue.sprintf("%.16g", (double)(aTabAttr->GetValue(i,j))));
1638 if (aSep.isEmpty()) aSep = " ";
1640 if (!aLine.trimmed().isEmpty()) {
1641 aColTitle = aColumnTitles[j-1];
1642 if (!aColTitle.trimmed().isEmpty())
1643 aLine = aLine + " #TITLE: " + aColTitle;
1645 aFile.write(aLine.toLatin1());
1654 bool VISU::ExportTableToFile(SALOMEDS::SObject_ptr theTable, const char* theFileName)
1657 SALOMEDS::GenericAttribute_var anAttr ;
1658 if (theTable->FindAttribute(anAttr, "AttributeTableOfReal")) {
1659 SALOMEDS::AttributeTableOfReal_var aTabAttr =
1660 SALOMEDS::AttributeTableOfReal ::_narrow(anAttr);
1661 return ExportTableToFile ( aTabAttr , theFileName);
1663 else if (theTable->FindAttribute(anAttr, "AttributeTableOfInteger")) {
1664 SALOMEDS::AttributeTableOfInteger_var aTabAttr =
1665 SALOMEDS::AttributeTableOfInteger ::_narrow(anAttr);
1666 return ExportTableToFile ( aTabAttr , theFileName);