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_CutLinesBase_i.hh"
31 #include "VISU_CutSegment_i.hh"
32 #include "VISU_Result_i.hh"
33 #include "VISU_ViewManager_i.hh"
35 #include "SALOME_Event.h"
36 #include "SPlot2d_Curve.h"
38 #include "VISU_TableReader.hxx"
39 #include "VISU_ConvertorUtils.hxx"
41 #include "utilities.h"
43 #include <Basics_Utils.hxx>
48 static int MYDEBUG = 0;
50 static int MYDEBUG = 0;
52 //----------------------------------------------------------------
54 //----------------------------------------------------------------
55 int VISU::Table_i::myNbPresent = 0;
56 const string VISU::Table_i::myComment = "TABLE";
60 QString VISU::Table_i::GenerateName()
62 return VISU::GenerateName( "Table", ++myNbPresent );
67 const char* VISU::Table_i::GetComment() const
69 return myComment.c_str();
74 VISU::Table_i::Table_i( SALOMEDS::Study_ptr theStudy, const char* theObjectEntry )
75 : PrsObject_i(theStudy)
77 MESSAGE("Table_i::Table_i - "<<this);
78 mySObj = theStudy->FindObjectID(theObjectEntry);
79 myOrientation = VISU::Table::HORIZONTAL;
84 VISU::Table_i::~Table_i()
86 MESSAGE("Table_i::~Table_i - "<<this);
89 //----------------------------------------------------------------------------
92 ::SetTitle( const char* theTitle )
94 SetName( theTitle, true );
97 //----------------------------------------------------------------------------
102 return CORBA::string_dup( GetName().c_str() );
105 //----------------------------------------------------------------------------
108 ::SetOrientation( VISU::Table::Orientation theOrientation )
110 myOrientation = theOrientation;
113 //----------------------------------------------------------------------------
114 VISU::Table::Orientation
118 return myOrientation;
122 //----------------------------------------------------------------------------
125 ::SortRow(CORBA::Long theRow, VISU::SortOrder theSortOrder, VISU::SortPolicy theSortPolicy)
127 SALOMEDS::SObject_var SO = mySObj;
128 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
129 if ( !SO->_is_nil() ) {
130 SALOMEDS::GenericAttribute_var anAttr;
131 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
132 SALOMEDS::AttributeTableOfInteger_var anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
133 anInt->SortRow( theRow, (SALOMEDS::AttributeTable::SortOrder)theSortOrder,
134 (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy );
136 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
137 SALOMEDS::AttributeTableOfReal_var aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
138 aReal->SortRow( theRow, (SALOMEDS::AttributeTable::SortOrder)theSortOrder,
139 (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy );
141 UpdateCurves( std::map<int, int>() );
145 //----------------------------------------------------------------------------
148 ::SortColumn(CORBA::Long theColumn, VISU::SortOrder theSortOrder, VISU::SortPolicy theSortPolicy)
150 SALOMEDS::SObject_var SO = mySObj;
151 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
152 if ( !SO->_is_nil() ) {
153 SALOMEDS::GenericAttribute_var anAttr;
154 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
155 SALOMEDS::AttributeTableOfInteger_var anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
156 anInt->SortColumn( theColumn, (SALOMEDS::AttributeTable::SortOrder)theSortOrder,
157 (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy );
159 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
160 SALOMEDS::AttributeTableOfReal_var aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
161 aReal->SortColumn( theColumn, (SALOMEDS::AttributeTable::SortOrder)theSortOrder,
162 (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy );
164 UpdateCurves( std::map<int, int>() );
168 //----------------------------------------------------------------------------
171 ::SortByRow(CORBA::Long theRow, VISU::SortOrder theSortOrder, VISU::SortPolicy theSortPolicy)
173 SALOMEDS::SObject_var SO = mySObj;
174 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
175 if ( !SO->_is_nil() ) {
176 SALOMEDS::GenericAttribute_var anAttr;
177 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
178 SALOMEDS::AttributeTableOfInteger_var anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
179 anInt->SortByRow( theRow, (SALOMEDS::AttributeTable::SortOrder)theSortOrder,
180 (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy );
182 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
183 SALOMEDS::AttributeTableOfReal_var aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
184 aReal->SortByRow( theRow, (SALOMEDS::AttributeTable::SortOrder)theSortOrder,
185 (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy );
187 UpdateCurves( std::map<int, int>() );
191 //----------------------------------------------------------------------------
194 ::SortByColumn(CORBA::Long theColumn, VISU::SortOrder theSortOrder, VISU::SortPolicy theSortPolicy)
196 SALOMEDS::SObject_var SO = mySObj;
197 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
198 if ( !SO->_is_nil() ) {
199 SALOMEDS::LongSeq_var aRowIndices;
200 SALOMEDS::GenericAttribute_var anAttr;
201 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
202 SALOMEDS::AttributeTableOfInteger_var anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
203 aRowIndices = anInt->SortByColumn( theColumn, (SALOMEDS::AttributeTable::SortOrder)theSortOrder,
204 (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy );
206 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
207 SALOMEDS::AttributeTableOfReal_var aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
208 aRowIndices = aReal->SortByColumn( theColumn, (SALOMEDS::AttributeTable::SortOrder)theSortOrder,
209 (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy );
211 std::map<int, int> aMixData;
212 for ( int i = 0, n = aRowIndices->length(); i < n; i++ )
213 aMixData[ aRowIndices[i] ] = i+1;
214 UpdateCurves( aMixData );
218 //----------------------------------------------------------------------------
221 ::UpdateCurves(std::map<int,int> theMixData)
223 SALOMEDS::SObject_var SO = mySObj;
224 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
225 SALOMEDS::ChildIterator_var CI = GetStudyDocument()->NewChildIterator( SO );
226 for ( CI->InitEx( true ); CI->More(); CI->Next() ) {
227 CORBA::Object_var anObj = SObjectToObject( CI->Value() );
228 VISU::Curve_var aCurve = VISU::Curve::_narrow( anObj );
229 if ( !aCurve->_is_nil() ) {
230 if ( VISU::Curve_i* pCurve = dynamic_cast<VISU::Curve_i*>( GetServant( aCurve ).in() ) ) {
231 int aHRow = pCurve->GetHRow(), aVRow = pCurve->GetVRow();
232 if ( theMixData.find( aHRow ) != theMixData.end() )
233 pCurve->SetHRow( theMixData[ aHRow ] );
234 if ( theMixData.find( aVRow ) != theMixData.end() )
235 pCurve->SetVRow( theMixData[ aVRow ] );
236 UpdatePlot2d( pCurve, eUpdateData );
242 //----------------------------------------------------------------------------
243 SALOMEDS::SObject_var
250 //----------------------------------------------------------------------------
255 CORBA::String_var anEntry = mySObj->GetID();
259 //----------------------------------------------------------------------------
261 Gets number of rows in table
263 CORBA::Long VISU::Table_i::GetNbRows()
265 SALOMEDS::SObject_var SO = mySObj;
266 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
267 if ( !SO->_is_nil() ) {
268 SALOMEDS::GenericAttribute_var anAttr;
269 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
270 SALOMEDS::AttributeTableOfInteger_var anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
271 return anInt->GetNbRows();
273 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
274 SALOMEDS::AttributeTableOfReal_var aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
275 return aReal->GetNbRows();
281 Gets number of columns in table
283 CORBA::Long VISU::Table_i::GetNbColumns()
285 SALOMEDS::SObject_var SO = mySObj;
286 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
287 if ( !SO->_is_nil() ) {
288 SALOMEDS::GenericAttribute_var anAttr;
289 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
290 SALOMEDS::AttributeTableOfInteger_var anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
291 return anInt->GetNbColumns();
293 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
294 SALOMEDS::AttributeTableOfReal_var aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
295 return aReal->GetNbColumns();
303 VISU::Storable* VISU::Table_i::Create()
306 SetName(GetTableTitle().toLatin1().data(), false);
308 // mpv (PAL 5357): if name attribute already exist at this label, use it as name of table
309 if ( GetName() == "" )
310 if ( !mySObj->_is_nil() ) {
311 CutLinesBase_i* pCutLines = NULL;
312 CORBA::Object_var anObj = SObjectToObject(mySObj);
313 if(!CORBA::is_nil(anObj)){
314 VISU::CutLinesBase_var aCutLines = VISU::CutLinesBase::_narrow(anObj);
315 if(!aCutLines->_is_nil())
316 pCutLines = dynamic_cast<CutLinesBase_i*>(GetServant(aCutLines).in());
319 if (mySObj->GetName()) SetName(mySObj->GetName(), false);
322 if ( GetName() == "" )
323 SetName(GenerateName().toLatin1().data(), false);
324 // ... and build the object
325 return Build( false );
328 Builds presentation of table
330 VISU::Storable* VISU::Table_i::Build( int theRestoring )
333 // look for reference SObject with table attribute
334 SALOMEDS::SObject_var SO = mySObj;
336 if ( !SO->_is_nil() ) {
337 CutLinesBase_i* pCutLines = NULL;
338 CORBA::Object_var anObj = SObjectToObject(SO);
339 if(!CORBA::is_nil(anObj)){
340 VISU::CutLinesBase_var aCutLines = VISU::CutLinesBase::_narrow(anObj);
341 if(!aCutLines->_is_nil())
342 pCutLines = dynamic_cast<CutLinesBase_i*>(GetServant(aCutLines).in());
344 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
345 SALOMEDS::GenericAttribute_var anAttr;
346 // look for component
347 if ( !theRestoring ) {
348 SALOMEDS::SComponent_var SComponent = VISU::FindOrCreateVisuComponent( GetStudyDocument() );
349 // create SObject and set attributes
352 aComment.sprintf("myComment=%s;mySourceId=CutLines",GetComment());
354 aComment.sprintf("myComment=%s;mySourceId=TableAttr",GetComment());
355 SALOMEDS::SObject_var aFatherSObject = SO->GetFather();
356 if(aFatherSObject->FindAttribute(anAttr,"AttributeString")){
357 SALOMEDS::AttributeString_var aCommentAttr =
358 SALOMEDS::AttributeString::_narrow(anAttr);
359 CORBA::String_var aValue = aCommentAttr->Value();
360 Storable::TRestoringMap aMap;
361 Storable::StringToMap(aValue.in(),aMap);
363 QString aMethodName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist);
365 if( aMethodName == "ImportTables" ){
366 aComment.sprintf("myComment=%s;mySourceId=TableFile",GetComment());
372 string anEntry = CreateAttributes( GetStudyDocument(),
373 SO->GetID(),//SComponent->GetID(),
378 aComment.toLatin1().data(),
380 // create SObject referenced to real table object
381 mySObj = SALOMEDS::SObject::_duplicate(GetStudyDocument()->FindObjectID( anEntry.c_str() ));
383 bool isCutSegment = dynamic_cast<CutSegment_i*>(pCutLines);
384 pCutLines->BuildTableOfReal(mySObj, isCutSegment);
386 // mpv (PAL5357): reference attributes are unnecessary now
387 //SALOMEDS::SObject_var refSO = Builder->NewObject( mySObj );
388 //Builder->Addreference( refSO, SO );
396 Restores table object from stream
398 VISU::Storable* VISU::Table_i::Restore( const Storable::TRestoringMap& theMap, SALOMEDS::SObject_ptr SO)
400 if(MYDEBUG) MESSAGE(GetComment());
401 SetName(VISU::Storable::FindValue(theMap,"myName").toLatin1().data(), false);
402 myTitle = VISU::Storable::FindValue(theMap,"myTitle").toLatin1().data();
403 myOrientation = ( VISU::Table::Orientation )( VISU::Storable::FindValue(theMap,"myOrientation").toInt() );
404 mySObj = SALOMEDS::SObject::_duplicate(SO);
405 return Build( true );
408 Flushes table data into stream
410 void VISU::Table_i::ToStream( std::ostringstream& theStr )
412 Storable::DataToStream( theStr, "myName", GetName().c_str() );
413 Storable::DataToStream( theStr, "myTitle", myTitle.c_str() );
414 Storable::DataToStream( theStr, "myOrientation", myOrientation );
417 Called from engine to restore table from the file
419 VISU::Storable* VISU::Table_i::StorableEngine(SALOMEDS::SObject_ptr theSObject,
420 const Storable::TRestoringMap& theMap,
421 const std::string& thePrefix,
422 CORBA::Boolean theIsMultiFile)
424 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
425 VISU::Table_i* pResent = new VISU::Table_i( aStudy, "" );
426 return pResent->Restore( theMap, theSObject);
429 Gets title for the original table object
431 QString VISU::Table_i::GetTableTitle()
433 SALOMEDS::SObject_var SO = mySObj;
434 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
435 SALOMEDS::GenericAttribute_var anAttr;
436 SALOMEDS::AttributeTableOfInteger_var anInt;
437 SALOMEDS::AttributeTableOfReal_var aReal;
438 if ( !SO->_is_nil() ) {
439 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
440 anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
441 CORBA::String_var aString = anInt->GetTitle();
444 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
445 aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
446 CORBA::String_var aString = aReal->GetTitle();
453 //---------------------------------------------------------------
454 void VISU::Table_i::RemoveFromStudy()
456 struct TRemoveFromStudy: public SALOME_Event
458 VISU::Table_i* myRemovable;
459 TRemoveFromStudy(VISU::Table_i* theRemovable):
460 myRemovable(theRemovable)
467 VISU::RemoveFromStudy(myRemovable->GetSObject(),false);
471 // Remove the table with all curves
472 ProcessVoidEvent(new TRemoveFromStudy(this));
475 //----------------------------------------------------------------
477 //----------------------------------------------------------------
479 Restores table object from the stream [ static ]
481 static VISU::Table_i* GetTable( SALOMEDS::Study_ptr theStudy, SALOMEDS::SObject_ptr theSO ) {
482 CORBA::Object_var anObject = VISU::SObjectToObject( theSO );
483 if( !CORBA::is_nil( anObject ) ) {
484 CORBA::Object_ptr aTable = VISU::Table::_narrow( anObject );
485 if( !CORBA::is_nil( aTable ) )
486 return dynamic_cast<VISU::Table_i*>(VISU::GetServant(aTable).in());
491 int VISU::Curve_i::myNbPresent = 0;
492 const string VISU::Curve_i::myComment = "CURVE";
496 QString VISU::Curve_i::GenerateName()
498 return VISU::GenerateName( "Curve", ++myNbPresent ).toLatin1().data();
503 const char* VISU::Curve_i::GetComment() const
505 return myComment.c_str();
509 NB : theHRow, theVRow are the indexes of rows in the Table object and numbered from the 1 to GetNbRows()
511 VISU::Curve_i::Curve_i( SALOMEDS::Study_ptr theStudy, Table_i* theTable,
512 CORBA::Long theHRow, CORBA::Long theVRow,
513 CORBA::Long theZRow, CORBA::Boolean theIsV2 )
514 : PrsObject_i(theStudy), myTable( theTable ), myHRow( theHRow ),
515 myVRow( theVRow ), myZRow( theZRow ), myIsV2( theIsV2 )
518 myLine = VISU::Curve::SOLIDLINE;
520 myMarker = VISU::Curve::CIRCLE;
521 myColor.R = 0.0; myColor.G = 0.0; myColor.B = 0.0;
526 VISU::Curve_i::~Curve_i()
528 MESSAGE("Curve_i::~Curve_i");
531 //----------------------------------------------------------------------------
534 ::SetTitle( const char* theTitle )
536 SetName( theTitle, true );
539 //----------------------------------------------------------------------------
544 return CORBA::string_dup( GetName().c_str() );
547 //----------------------------------------------------------------------------
550 ::SetColor( const SALOMEDS::Color& theColor )
556 //----------------------------------------------------------------------------
564 //----------------------------------------------------------------------------
567 ::SetMarker( VISU::Curve::MarkerType theType )
573 //----------------------------------------------------------------------------
574 VISU::Curve::MarkerType
581 //----------------------------------------------------------------------------
584 ::SetLine( VISU::Curve::LineType theType, CORBA::Long theWidth )
587 myLineWidth = theWidth;
591 //----------------------------------------------------------------------------
592 VISU::Curve::LineType
599 //----------------------------------------------------------------------------
607 //----------------------------------------------------------------------------
611 VISU::Storable* VISU::Curve_i::Create()
614 SetName(GetVerTitle(), false);
615 if ( GetName() == "" )
616 SetName(GenerateName().toLatin1().data(), false);
617 // ... and build the object
618 return Build( false );
621 Builds presentation of curve
623 VISU::Storable* VISU::Curve_i::Build(int theRestoring )
625 if ( myTable != NULL ) {
626 // getting table SObject by it's entry
627 int nbRows = myTable->GetNbRows();
628 if ( myHRow > 0 && myHRow <= nbRows && myVRow > 0 && myVRow <= nbRows ) {
629 if ( !theRestoring ) {
630 // look for component
631 SALOMEDS::SComponent_var SComponent = VISU::FindOrCreateVisuComponent( GetStudyDocument() );
632 // create SObject and set attributes
634 aComment.sprintf("myComment=%s",GetComment());
635 string anEntry = CreateAttributes( GetStudyDocument(),
636 myTable->GetObjectEntry(),
641 aComment.toLatin1().data(),
643 // create SObject referenced to real table object
644 mySObj = SALOMEDS::SObject::_duplicate(GetStudyDocument()->FindObjectID(anEntry.c_str()));
647 SALOMEDS::StudyBuilder_var aStudyBuilder = GetStudyDocument()->NewBuilder();
648 SALOMEDS::GenericAttribute_var anAttr;
649 SALOMEDS::AttributePixMap_var aPixmap;
650 anAttr = aStudyBuilder->FindOrCreateAttribute( mySObj, "AttributePixMap" );
651 aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
652 aPixmap ->SetPixMap("ICON_TREE_CURVE");
661 Returns CORBA::True if curve refers to valid table data
663 CORBA::Boolean VISU::Curve_i::IsValid()
665 // getting table SObject by it's entry
666 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID(myTable->GetObjectEntry().c_str());
667 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
668 SALOMEDS::GenericAttribute_var anAttr;
669 SALOMEDS::AttributeTableOfInteger_var anInt;
670 SALOMEDS::AttributeTableOfReal_var aReal;
671 if ( !SO->_is_nil() ) {
672 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
673 anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
674 if ( myHRow > 0 && myHRow <= anInt->GetNbRows() && myVRow > 0 && myVRow <= anInt->GetNbRows() ) {
678 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
679 aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
680 if ( myHRow > 0 && myHRow <= aReal->GetNbRows() && myVRow > 0 && myVRow <= aReal->GetNbRows() ) {
688 Returns hor.axis title
690 string VISU::Curve_i::GetHorTitle()
693 // getting table SObject by it's entry
694 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID(myTable->GetObjectEntry().c_str());
695 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
696 SALOMEDS::GenericAttribute_var anAttr;
697 SALOMEDS::AttributeTableOfInteger_var anInt;
698 SALOMEDS::AttributeTableOfReal_var aReal;
699 if ( !SO->_is_nil() ) {
700 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
701 anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
702 SALOMEDS::StringSeq_var rowTitles = anInt->GetRowTitles();
703 if ( rowTitles->length() > 0 && myHRow > 0 && myHRow <= anInt->GetNbRows() ) {
704 title = rowTitles[ myHRow-1 ];
707 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
708 aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
709 SALOMEDS::StringSeq_var rowTitles = aReal->GetRowTitles();
710 if ( rowTitles->length() > 0 && myHRow > 0 && myHRow <= aReal->GetNbRows() ) {
711 title = rowTitles[ myHRow-1 ];
718 Returns ver.axis title
720 string VISU::Curve_i::GetVerTitle()
723 // getting table SObject by it's entry
724 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID(myTable->GetObjectEntry().c_str());
725 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
726 SALOMEDS::GenericAttribute_var anAttr;
727 SALOMEDS::AttributeTableOfInteger_var anInt;
728 SALOMEDS::AttributeTableOfReal_var aReal;
729 if ( !SO->_is_nil() ) {
730 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
731 anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
732 SALOMEDS::StringSeq_var rowTitles = anInt->GetRowTitles();
733 if ( rowTitles->length() > 0 && myVRow > 0 && myVRow <= anInt->GetNbRows() )
734 title = rowTitles[ myVRow-1 ];
736 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
737 aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
738 SALOMEDS::StringSeq_var rowTitles = aReal->GetRowTitles();
739 if ( rowTitles->length() > 0 && myVRow > 0 && myVRow <= aReal->GetNbRows() )
740 title = rowTitles[ myVRow-1 ];
746 Returns hor.axis units
748 string VISU::Curve_i::GetHorUnits()
751 // getting table SObject by it's entry
752 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID(myTable->GetObjectEntry().c_str());
753 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
754 SALOMEDS::GenericAttribute_var anAttr;
755 SALOMEDS::AttributeTableOfInteger_var anInt;
756 SALOMEDS::AttributeTableOfReal_var aReal;
757 if ( !SO->_is_nil() ) {
758 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
759 anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
760 SALOMEDS::StringSeq_var rowUnits = anInt->GetRowUnits();
761 if ( rowUnits->length() > 0 && myHRow > 0 && myHRow <= anInt->GetNbRows() )
762 units = rowUnits[ myHRow-1 ];
764 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
765 aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
766 SALOMEDS::StringSeq_var rowUnits = aReal->GetRowUnits();
767 if ( rowUnits->length() > 0 && myHRow > 0 && myHRow <= aReal->GetNbRows() )
768 units = rowUnits[ myHRow-1 ];
774 Returns ver.axis units
776 string VISU::Curve_i::GetVerUnits()
779 // getting table SObject by it's entry
780 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID(myTable->GetObjectEntry().c_str());
781 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
782 SALOMEDS::GenericAttribute_var anAttr;
783 SALOMEDS::AttributeTableOfInteger_var anInt;
784 SALOMEDS::AttributeTableOfReal_var aReal;
785 if ( !SO->_is_nil() ) {
786 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
787 anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
788 SALOMEDS::StringSeq_var rowUnits = anInt->GetRowUnits();
789 if ( rowUnits->length() > 0 && myVRow > 0 && myVRow <= anInt->GetNbRows() )
790 units = rowUnits[ myVRow-1];
792 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
793 aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
794 SALOMEDS::StringSeq_var rowUnits = aReal->GetRowUnits();
795 if ( rowUnits->length() > 0 && myVRow > 0 && myVRow <= aReal->GetNbRows() )
796 units = rowUnits[ myVRow-1 ];
804 int VISU::Curve_i::GetData( double*& theHorList, double*& theVerList, QStringList& zList )
806 theHorList = 0; theVerList = 0;
807 // getting table SObject by it's entry
808 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID(myTable->GetObjectEntry().c_str());
809 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
810 SALOMEDS::GenericAttribute_var anAttr;
811 SALOMEDS::AttributeTableOfInteger_var anInt;
812 SALOMEDS::AttributeTableOfReal_var aReal;
814 QString tip = "%1: %2", z_data;
816 if ( !SO->_is_nil() ) {
817 if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) {
818 anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr );
819 int nbCols = anInt->GetNbColumns(), nbRows = anInt->GetNbRows();
820 if ( nbCols > 0 && myHRow > 0 && myHRow <= anInt->GetNbRows() && myVRow > 0 && myVRow <= anInt->GetNbRows() ) {
822 for ( int j = 1; j <= nbCols; j++ ) {
823 if ( anInt->HasValue( myHRow, j ) && anInt->HasValue( myVRow, j ) )
826 if ( nbPoints > 0 ) {
827 theHorList = new double[ nbPoints ];
828 theVerList = new double[ nbPoints ];
831 SALOMEDS::StringSeq_var rowTitles = anInt->GetRowTitles();
833 for ( int j = 1; j <= nbCols; j++ ) {
834 if ( anInt->HasValue( myHRow, j ) && anInt->HasValue( myVRow, j ) ) {
835 theHorList[k] = anInt->GetValue( myHRow, j );
836 theVerList[k] = anInt->GetValue( myVRow, j );
838 z_data = tip.arg( GetHorTitle().c_str() ).arg( theHorList[k] ) + "\n";
839 z_data += tip.arg( GetVerTitle().c_str() ).arg( theVerList[k] );
841 if( myZRow>0 && myZRow<=nbRows && anInt->HasValue( myZRow, j ) )
844 title = rowTitles[ myZRow-1 ];
845 z_data += "\n" + tip.arg( title.c_str() ).arg( anInt->GetValue( myZRow, j ) );
847 zList.append( z_data );
855 else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) {
856 aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr );
857 int nbCols = aReal->GetNbColumns(), nbRows = aReal->GetNbRows();
858 if ( nbCols > 0 && myHRow > 0 && myHRow <= aReal->GetNbRows() && myVRow > 0 && myVRow <= aReal->GetNbRows() ) {
860 for ( int j = 1; j <= nbCols; j++ ) {
861 if ( aReal->HasValue( myHRow, j ) && aReal->HasValue( myVRow, j ) )
864 if ( nbPoints > 0 ) {
865 theHorList = new double[ nbPoints ];
866 theVerList = new double[ nbPoints ];
869 SALOMEDS::StringSeq_var rowTitles = aReal->GetRowTitles();
871 for ( int j = 1; j <= nbCols; j++ ) {
872 if ( aReal->HasValue( myHRow, j ) && aReal->HasValue( myVRow, j ) ) {
873 theHorList[k] = aReal->GetValue( myHRow, j );
874 theVerList[k] = aReal->GetValue( myVRow, j );
876 z_data = tip.arg( GetHorTitle().c_str() ).arg( theHorList[k] ) + "\n";
877 z_data += tip.arg( GetVerTitle().c_str() ).arg( theVerList[k] );
879 if( myZRow>0 && myZRow<=nbRows && aReal->HasValue( myZRow, j ) )
882 title = rowTitles[ myZRow-1 ];
883 z_data += "\n" + tip.arg( title.c_str() ).arg( aReal->GetValue( myZRow, j ) );
885 zList.append( z_data );
897 Creates curve Plot2d presentation object
899 SPlot2d_Curve* VISU::Curve_i::CreatePresentation()
901 SPlot2d_Curve* crv = new SPlot2d_Curve();
902 crv->setYAxis( myIsV2 ? QwtPlot::yRight : QwtPlot::yLeft );
903 crv->setHorTitle( GetHorTitle().c_str() );
904 string tlt = GetTitle();
905 if ( tlt.length() <= 0 )
907 //crv->setVerTitle( strdup( GetVerTitle().c_str() ) );
908 //crv->setVerTitle( strdup( GetName() ) );
909 crv->setVerTitle( tlt.c_str() );
910 crv->setHorUnits( GetHorUnits().c_str() );
911 crv->setVerUnits( GetVerUnits().c_str() );
915 int nbPoints = GetData( xList, yList, zList );
916 if ( nbPoints > 0 && xList && yList ) {
917 crv->setData( xList, yList, nbPoints, zList );
919 //cout << "********** Number of points: " << nbPoints <<endl;
920 //for ( int i =0 ; i < nbPoints; i++ ) {
921 // cout << i<<"\t"<<xList[i] << "\t"<< yList[i] << endl;
923 crv->setLine( (Plot2d::LineType)GetLine(), GetLineWidth() );
924 crv->setMarker( (Plot2d::MarkerType)GetMarker() );
925 SALOMEDS::Color color = GetColor();
926 crv->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
927 crv->setAutoAssign( IsAuto() );
928 CORBA::String_var aString = mySObj->GetID();
929 crv->setIO(new SALOME_InteractiveObject(aString.in(), "VISU", GetName().c_str()));
931 crv->setTableIO(new SALOME_InteractiveObject(myTable->GetObjectEntry().c_str(), "VISU", myTable->GetName().c_str()));
935 Restores curve object from stream
937 VISU::Storable* VISU::Curve_i::Restore( const Storable::TRestoringMap& theMap, SALOMEDS::SObject_ptr theSO)
939 if(MYDEBUG) MESSAGE(GetComment());
940 mySObj = SALOMEDS::SObject::_duplicate(theSO);
941 SetName(VISU::Storable::FindValue(theMap,"myName").toLatin1().data(), false);
942 myHRow = VISU::Storable::FindValue(theMap,"myHRow").toInt();
943 myVRow = VISU::Storable::FindValue(theMap,"myVRow").toInt();
945 QString z_str = VISU::Storable::FindValue(theMap,"myZRow", &ok);
946 myZRow = ok ? z_str.toInt() : 0;
948 QString v2_str = VISU::Storable::FindValue(theMap,"myIsV2", &ok);
949 myIsV2 = ok ? v2_str.toInt() : false;
951 myColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble();
952 myColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble();
953 myColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble();
954 myMarker = ( VISU::Curve::MarkerType )( VISU::Storable::FindValue(theMap,"myMarker").toInt() );
955 myLine = ( VISU::Curve::LineType )( VISU::Storable::FindValue(theMap,"myLine").toInt() );
956 myLineWidth = VISU::Storable::FindValue(theMap,"myLineWidth").toInt();
957 myAuto = VISU::Storable::FindValue(theMap,"myAuto").toInt();
958 return Build( true );
961 Flushes curve data into stream
963 void VISU::Curve_i::ToStream( std::ostringstream& theStr )
965 Storable::DataToStream( theStr, "myName", GetName().c_str() );
966 Storable::DataToStream( theStr, "myHRow", myHRow );
967 Storable::DataToStream( theStr, "myVRow", myVRow );
968 Storable::DataToStream( theStr, "myZRow", myZRow );
969 Storable::DataToStream( theStr, "myIsV2", myIsV2 );
970 Storable::DataToStream( theStr, "myColor.R", myColor.R );
971 Storable::DataToStream( theStr, "myColor.G", myColor.G );
972 Storable::DataToStream( theStr, "myColor.B", myColor.B );
973 Storable::DataToStream( theStr, "myMarker", myMarker );
974 Storable::DataToStream( theStr, "myLine", myLine );
975 Storable::DataToStream( theStr, "myLineWidth", myLineWidth );
976 Storable::DataToStream( theStr, "myAuto", myAuto );
979 Gets reference table's entry
981 std::string VISU::Curve_i::GetTableID() {
982 return myTable->GetObjectEntry();
985 Called from engine to restore curve from the file
987 VISU::Storable* VISU::Curve_i::StorableEngine(SALOMEDS::SObject_ptr theSObject,
988 const Storable::TRestoringMap& theMap,
989 const std::string& thePrefix,
990 CORBA::Boolean theIsMultiFile)
992 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
993 VISU::Table_i* pTable = GetTable(aStudy, theSObject->GetFather());
994 if( pTable != NULL ) {
995 VISU::Curve_i* pResent = new VISU::Curve_i( aStudy, pTable, 0, 0, 0, false );
996 return pResent->Restore( theMap, theSObject);
1001 void VISU::Curve_i::RemoveFromStudy()
1003 struct TRemoveFromStudy: public SALOME_Event
1005 VISU::Curve_i* myRemovable;
1006 TRemoveFromStudy(VISU::Curve_i* theRemovable):
1007 myRemovable(theRemovable)
1014 VISU::DeleteActors(myRemovable);
1015 VISU::RemoveFromStudy(myRemovable->GetSObject(),false);
1019 ProcessVoidEvent(new TRemoveFromStudy(this));
1022 SALOMEDS::SObject_var VISU::Curve_i::GetSObject()
1027 //----------------------------------------------------------------
1029 //----------------------------------------------------------------
1030 int VISU::Container_i::myNbPresent = 0;
1031 const string VISU::Container_i::myComment = "CONTAINER";
1033 Generate unique name
1035 QString VISU::Container_i::GenerateName()
1037 return VISU::GenerateName( "Plot2DView", ++myNbPresent ).toLatin1().data();
1042 const char* VISU::Container_i::GetComment() const
1044 return myComment.c_str();
1049 VISU::Container_i::Container_i( SALOMEDS::Study_ptr theStudy )
1050 : PrsObject_i( theStudy )
1056 VISU::Container_i::~Container_i()
1058 MESSAGE("Container_i::~Container_i");
1062 Inserts curve into the container
1064 void VISU::Container_i::AddCurve( Curve_ptr theCurve )
1066 if ( GetStudyDocument()->_is_nil() )
1068 SALOMEDS::SObject_var mySO = GetStudyDocument()->FindObjectID( GetEntry().c_str() );
1069 if ( mySO->_is_nil() )
1071 PortableServer::POA_ptr aPOA = GetPOA();
1072 Curve_i* pCurve = dynamic_cast<Curve_i*>( aPOA->reference_to_servant( theCurve ) );
1074 QString entry( pCurve->GetEntry().c_str() );
1075 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID( entry.toLatin1().data() );
1076 if ( !SO->_is_nil() && myCurves.indexOf( entry ) == -1 ) {
1077 myCurves.append( entry );
1078 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
1079 SALOMEDS::SObject_var newSO = Builder->NewObject( mySO );
1080 Builder->Addreference( newSO, SO );
1085 Removes curve from the container
1087 void VISU::Container_i::RemoveCurve( Curve_ptr theCurve )
1089 if ( GetStudyDocument()->_is_nil() )
1091 SALOMEDS::SObject_var mySO = GetStudyDocument()->FindObjectID( GetEntry().c_str() );
1092 if ( mySO->_is_nil() )
1094 PortableServer::POA_ptr aPOA = GetPOA();
1095 Curve_i* pCurve = dynamic_cast<Curve_i*>( aPOA->reference_to_servant( theCurve ) );
1097 QString entry( pCurve->GetEntry().c_str() );
1098 if ( myCurves.indexOf( entry ) != -1 ) {
1100 myCurves.removeAll( entry );
1101 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
1102 SALOMEDS::ChildIterator_var CI = GetStudyDocument()->NewChildIterator( mySO );
1103 for ( ; CI->More(); CI->Next() ) {
1104 SALOMEDS::SObject_var childSO = CI->Value();
1105 SALOMEDS::SObject_var refSO;
1106 if ( childSO->ReferencedObject( refSO ) && !refSO->_is_nil() && entry == QString( refSO->GetID() ) ) {
1107 Builder->RemoveObject( childSO );
1114 Gets number of curves in the container
1116 CORBA::Long VISU::Container_i::GetNbCurves()
1119 return myCurves.count();
1124 void VISU::Container_i::Clear()
1126 if ( GetStudyDocument()->_is_nil() )
1128 SALOMEDS::SObject_var mySO = GetStudyDocument()->FindObjectID( GetEntry().c_str() );
1129 if ( mySO->_is_nil() )
1131 QStringList toDelete;
1132 SALOMEDS::ChildIterator_var CI = GetStudyDocument()->NewChildIterator( mySO );
1133 for ( ; CI->More(); CI->Next() ) {
1134 toDelete.append( CI->Value()->GetID() );
1136 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
1137 for ( int i = 0; i < toDelete.count(); i++ ) {
1138 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID( toDelete[i].toLatin1().data() );
1139 Builder->RemoveObject( SO );
1144 Creates container object
1146 VISU::Storable* VISU::Container_i::Create()
1148 // generate name ...
1149 SetName(GenerateName().toLatin1().data(), false);
1150 // ... and build the object
1151 return Build( false );
1154 Builds presentation of container
1156 VISU::Storable* VISU::Container_i::Build( int theRestoring )
1158 if ( !theRestoring ) {
1159 // looking for component
1160 SALOMEDS::SComponent_var SComponent = VISU::FindOrCreateVisuComponent( GetStudyDocument() );
1161 // create SObject and set attributes
1163 aComment.sprintf("myComment=%s",GetComment());
1164 string anEntry = CreateAttributes( GetStudyDocument(),
1165 SComponent->GetID(),
1170 aComment.toLatin1().data(),
1172 mySObj = SALOMEDS::SObject::_duplicate(GetStudyDocument()->FindObjectID(anEntry.c_str()));
1175 SALOMEDS::StudyBuilder_var aStudyBuilder = GetStudyDocument()->NewBuilder();
1176 SALOMEDS::GenericAttribute_var anAttr;
1177 SALOMEDS::AttributePixMap_var aPixmap;
1178 anAttr = aStudyBuilder->FindOrCreateAttribute( mySObj, "AttributePixMap" );
1179 aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
1180 aPixmap ->SetPixMap("ICON_TREE_CONTAINER");
1185 Updates presentation of container
1187 void VISU::Container_i::Update()
1189 if ( GetStudyDocument()->_is_nil() )
1191 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
1192 SALOMEDS::SObject_var mySO = GetStudyDocument()->FindObjectID( GetEntry().c_str() );
1193 SALOMEDS::GenericAttribute_var anAttr;
1194 if ( !mySO->_is_nil() ) {
1195 QStringList toDelete;
1197 for ( i = 0; i < myCurves.count(); i++ ) {
1198 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID( myCurves[i].toLatin1().data() );
1199 if ( !SO->_is_nil() && Builder->FindAttribute( SO, anAttr, "AttributeIOR" ) ) {
1200 // if real Curve Object still exists
1201 SALOMEDS::ChildIterator_var CI = GetStudyDocument()->NewChildIterator( mySO );
1202 bool bFound = false;
1203 for ( ; CI->More(); CI->Next() ) {
1204 SALOMEDS::SObject_var childSO = CI->Value();
1205 SALOMEDS::SObject_var refSO;
1206 if ( childSO->ReferencedObject( refSO ) && !refSO->_is_nil() && myCurves[i] == QString( refSO->GetID() ) ) {
1207 bFound = true; break;
1211 // create SObject referenced to real curve object if is not yet added
1212 SALOMEDS::SObject_var newSO = Builder->NewObject( mySO );
1213 Builder->Addreference( newSO, SO );
1217 // real Curve Object doesn't exist (might be removed)
1218 toDelete.append( myCurves[i] );
1221 for ( i = 0; i < toDelete.count(); i++ ) {
1222 myCurves.removeAll( toDelete[i] );
1225 SALOMEDS::ChildIterator_var CI = GetStudyDocument()->NewChildIterator( mySO );
1226 for ( ; CI->More(); CI->Next() ) {
1227 SALOMEDS::SObject_var childSO = CI->Value();
1228 SALOMEDS::SObject_var refSO;
1229 if ( childSO->ReferencedObject( refSO ) && ( refSO->_is_nil() || !Builder->FindAttribute( refSO, anAttr, "AttributeIOR" ) ||
1230 myCurves.indexOf( refSO->GetID() ) == -1 ) ) {
1231 toDelete.append( childSO->GetID() );
1234 for ( i = 0; i < toDelete.count(); i++ ) {
1235 SALOMEDS::ChildIterator_var CI = GetStudyDocument()->NewChildIterator( mySO );
1236 for ( ; CI->More(); CI->Next() ) {
1237 SALOMEDS::SObject_var childSO = CI->Value();
1238 if ( toDelete[i] == CI->Value()->GetID() ) {
1239 Builder->RemoveObject( childSO );
1246 Gets curve from container by index
1247 NB : curves are numbered from 1
1249 VISU::Curve_i* VISU::Container_i::GetCurve( CORBA::Long theIndex )
1251 if ( theIndex > 0 && theIndex <= myCurves.count() ) {
1252 SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder();
1253 SALOMEDS::GenericAttribute_var anAttr;
1254 SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID(myCurves[ theIndex-1 ].toLatin1().data() );
1255 CORBA::Object_var anObject = VISU::SObjectToObject( SO );
1256 if( !CORBA::is_nil( anObject ) ) {
1257 // if real Curve Object exists
1258 CORBA::Object_ptr aCurve = VISU::Curve::_narrow( anObject );
1259 if( !CORBA::is_nil( aCurve ) )
1260 return dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in());
1266 Restores container data from the stream
1268 VISU::Storable* VISU::Container_i::Restore( const Storable::TRestoringMap& theMap, SALOMEDS::SObject_ptr SO )
1270 if(MYDEBUG) MESSAGE(GetComment());
1271 mySObj = SALOMEDS::SObject::_duplicate(SO);
1272 SetName(VISU::Storable::FindValue( theMap, "myName" ).toLatin1().data(), false);
1273 QString val = VISU::Storable::FindValue( theMap, "myCurves" );
1274 myCurves = val.split( "*", QString::SkipEmptyParts );
1275 return Build( true );
1278 Flushes container data into the stream
1280 void VISU::Container_i::ToStream( std::ostringstream& theStr )
1282 Storable::DataToStream( theStr, "myName", GetName().c_str() );
1283 Storable::DataToStream( theStr, "myCurves", myCurves.join( QString( "*" ) ) );
1284 // theStr<<" myName "<<myName;
1285 // theStr<<" myCurves "<<myCurves.join( QString( "*" ) ).latin1()<<"* ";
1288 Called from engine to restore container from the file
1290 VISU::Storable* VISU::Container_i::StorableEngine(SALOMEDS::SObject_ptr theSObject,
1291 const Storable::TRestoringMap& theMap,
1292 const std::string& thePrefix,
1293 CORBA::Boolean theIsMultiFile)
1295 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
1296 VISU::Container_i* pResent = new VISU::Container_i( aStudy );
1297 return pResent->Restore( theMap, theSObject );
1300 void VISU::Container_i::RemoveFromStudy()
1302 struct TRemoveFromStudy: public SALOME_Event
1304 VISU::Container_i* myRemovable;
1305 TRemoveFromStudy(VISU::Container_i* theRemovable):
1306 myRemovable(theRemovable)
1313 VISU::RemoveFromStudy(myRemovable->GetSObject(),false);
1317 ProcessVoidEvent(new TRemoveFromStudy(this));
1320 SALOMEDS::SObject_var VISU::Container_i::GetSObject()
1325 SALOMEDS::SObject_var
1326 VISU::ImportTables(const char* theFileName, SALOMEDS::Study_ptr theStudy,
1327 bool theFirstStrAsTitle)
1329 // Set "C" numeric locale to import numbers correctly
1330 Kernel_Utils::Localizer loc;
1332 TTableContainer aContainer;
1333 ImportTables( theFileName, aContainer, theFirstStrAsTitle );
1334 if ( aContainer.empty() )
1335 return SALOMEDS::SObject::_nil();
1337 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1338 SALOMEDS::SComponent_var theSComponent = VISU::FindOrCreateVisuComponent(theStudy);
1339 SALOMEDS::SObject_var aFileObject = aStudyBuilder->NewObject(theSComponent);
1340 SALOMEDS::GenericAttribute_var anAttr =
1341 aStudyBuilder->FindOrCreateAttribute(aFileObject, "AttributeName");
1342 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
1343 QFileInfo aFileInfo(theFileName);
1344 aName->SetValue( aFileInfo.fileName().toLatin1().data());
1345 anAttr = aStudyBuilder->FindOrCreateAttribute(aFileObject, "AttributeString");
1346 SALOMEDS::AttributeString_var aComment = SALOMEDS::AttributeString::_narrow(anAttr);
1348 aString.sprintf("myComment=ImportTables;myFileName=%s;myFirstStrAsTitle=%d",
1349 aFileInfo.absoluteFilePath().toLatin1().data(),theFirstStrAsTitle);
1350 aComment->SetValue(aString.toLatin1().data());
1351 for(int i = 0, iEnd = aContainer.size(); i < iEnd; i++) {
1352 PTableIDMapper aTableIDMapper = aContainer[i];
1353 const TTable2D& aTable2D = *aTableIDMapper;
1354 SALOMEDS::SObject_var aRealObject = aStudyBuilder->NewObject(aFileObject);
1355 anAttr = aStudyBuilder->FindOrCreateAttribute(aRealObject, "AttributeName");
1356 aName = SALOMEDS::AttributeName::_narrow(anAttr);
1357 if(MYDEBUG) MESSAGE("aTable2D.myTitle = "<<aTable2D.myTitle);
1358 if ( aTable2D.myTitle != "" ) {
1359 aName->SetValue(aTable2D.myTitle.c_str());
1363 aNewName.sprintf("Table:%d",i);
1364 aName->SetValue(aNewName.toLatin1().data());
1367 anAttr = aStudyBuilder->FindOrCreateAttribute(aRealObject, "AttributeTableOfReal");
1368 SALOMEDS::AttributeTableOfReal_var aTableOfReal = SALOMEDS::AttributeTableOfReal::_narrow(anAttr);
1369 aTableOfReal->SetTitle(aTable2D.myTitle.c_str());
1370 TTable2D aNewTable2D;
1371 aTable2D.getColumns(aNewTable2D);
1372 int kEnd = aNewTable2D.myRows[0].myValues.size();
1373 // check empty columns
1374 TColStd_MapOfInteger EmptyColumns;
1375 for(int j = 0, jEnd = aNewTable2D.myRows.size(); j < jEnd; j++) {
1376 bool hasVal = false;
1377 for(int k = 0; k < kEnd; k++) {
1378 QString aVal = aNewTable2D.myRows[j].myValues[k].c_str();
1379 bool anIsOk = false;
1380 double aValue = aVal.toDouble(&anIsOk);
1387 EmptyColumns.Add(j);
1390 // create table of real
1391 aTableOfReal->SetNbColumns( kEnd - EmptyColumns.Extent() );
1393 for(int j = 0, jEnd = aNewTable2D.myRows.size(); j < jEnd; j++) {
1394 if( EmptyColumns.Contains(j) ) continue;
1396 if(MYDEBUG) MESSAGE("j = "<<j<<"; kEnd = "<<kEnd);
1397 for(int k = 0; k < kEnd; k++) {
1398 QString aVal = aNewTable2D.myRows[j].myValues[k].c_str();
1399 bool anIsOk = false;
1400 double aValue = aVal.toDouble(&anIsOk);
1401 if( anIsOk && !aVal.contains("NAN",Qt::CaseInsensitive) &&
1402 !aVal.contains("INF",Qt::CaseInsensitive) ) {
1403 aTableOfReal->PutValue(aValue,currNum+1,k+1);
1406 aTableOfReal->SetRowTitle(currNum+1,aNewTable2D.myRows[j].myTitle.c_str());
1407 aTableOfReal->SetRowUnit(currNum+1,aNewTable2D.myRows[j].myUnit.c_str());
1409 for(int k = 0; k < kEnd; k++)
1410 aTableOfReal->SetColumnTitle(k+1,aNewTable2D.myColumnTitles[k].c_str());
1416 //=======================================================================
1417 //function : updateStrForCSV
1418 //purpose : auxilary for ExportTableToFile
1419 //=======================================================================
1420 void updateStrForCSV(QString& aStr, const char aSep)
1422 int index = aStr.indexOf('"');
1424 aStr.insert(index,'"');
1425 if( index+2 >= aStr.size() ) break;
1426 index = aStr.indexOf('"',index+2);
1428 index = aStr.indexOf(aSep);
1430 // current string contains separator => need to use "..."
1432 aStr.push_back('"');
1437 //=======================================================================
1438 //function : ExportTableToFile
1440 //=======================================================================
1441 template<class TTableAttr> bool ExportTableToFile(const TTableAttr& aTabAttr,
1442 const char* theFileName)
1444 if (CORBA::is_nil(aTabAttr))
1447 // Set "C" numeric locale to save numbers correctly
1448 Kernel_Utils::Localizer loc;
1450 QFile aFile(theFileName);
1451 aFile.open(QIODevice::WriteOnly);
1453 /* extract the table info and write it into file */
1455 QString aTitle(aTabAttr->GetTitle()); /*Table title*/
1456 int aRowsNb = aTabAttr->GetNbRows();
1457 int aColNb = aTabAttr->GetNbColumns();
1459 SALOMEDS::StringSeq_var aRowTitles = aTabAttr->GetRowTitles();
1460 SALOMEDS::StringSeq_var aRowUnits = aTabAttr->GetRowUnits();
1461 SALOMEDS::StringSeq_var aColumnTitles = aTabAttr->GetColumnTitles();
1463 //--------------------------------------------------
1464 // write as *.csv file if it is needed
1465 //--------------------------------------------------
1466 QString tmp(theFileName);
1467 tmp = tmp.trimmed();
1468 tmp = tmp.right(3).trimmed();
1469 if( tmp == QString("csv") ) {
1470 const char aSep = ',';
1471 // write column titles
1472 QString aLine(aRowTitles[0]);
1473 updateStrForCSV(aLine,aSep);
1474 for(int i=1; i<aRowsNb; i++) {
1476 QString aTmp(aRowTitles[i]);
1477 updateStrForCSV(aTmp,aSep);
1481 aFile.write(aLine.toLatin1() );
1484 for (int j = 1; j <= aColNb; j++) {
1486 if(aTabAttr->HasValue(j,1)) {
1487 aLine = aValue.sprintf("%.16g",(double)aTabAttr->GetValue(1,j));
1489 for (int i = 2; i <= aRowsNb; i++) {
1490 if(aTabAttr->HasValue(i,j)) {
1491 aLine += aSep + aValue.sprintf("%.16g",(double)aTabAttr->GetValue(i,j));
1496 aFile.write(aLine.toLatin1() );
1502 //--------------------------------------------------
1503 // end of writing as *.csv file
1504 //--------------------------------------------------
1506 /* The given table is rare (some cells is empty) or not? */
1507 bool isRareTable = false;
1508 for (int i = 1; i <= aRowsNb; i++)
1509 for (int j = 1; j <= aColNb && !isRareTable; j++)
1510 isRareTable = !aTabAttr->HasValue(i,j);
1514 /* Separate the given table to 2D tables and write these ones to the file */
1515 QString anAbscissTitle(aRowTitles[0]); /*Absciss row title (X coord)*/
1516 anAbscissTitle.trimmed();
1517 QString anAbscissUnit(aRowUnits[0]);
1518 anAbscissUnit.trimmed();
1519 if (aRowsNb > 2 && aTitle.length() ) aTitle = aTitle + " - ";
1521 for (int i = 2; i <= aRowsNb; i++ )
1524 QString anOrdinate(aRowTitles[i-1]), aTail;
1525 anOrdinate.trimmed();
1527 aLine = "#TITLE: " + aTitle +
1528 ((anOrdinate.length())? anOrdinate :
1529 (aRowsNb>2)? aTail.sprintf("%d",i-1) : aTail.sprintf("") ) + "\n";
1530 aFile.write(aLine.toLatin1() );
1533 if ( anAbscissTitle.length() || anOrdinate.length() ) {
1534 aLine = "#COLUMN_TITLES: " + anAbscissTitle + " | " + anOrdinate;
1535 int tmpind = aLine.indexOf("\n");
1537 aLine.remove(tmpind,1);
1538 tmpind = aLine.indexOf("\n");
1541 aFile.write(aLine.toLatin1() );
1545 aLine = anAbscissUnit + " " +aRowUnits[i-1];
1546 if (!aLine.trimmed().isEmpty()) {
1547 aLine = "#COLUMN_UNITS: " + aLine + "\n";
1548 aFile.write(aLine.toLatin1() );
1551 /* CURVE COORDINATES */
1552 for (int j = 1; j <= aColNb; j++)
1554 if ( aTabAttr -> HasValue(i,j) && aTabAttr -> HasValue(1, j)) {
1555 aLine = aLine.sprintf("%.16g %.16g",
1556 (double)(aTabAttr->GetValue(1,j)),
1557 (double)(aTabAttr->GetValue(i,j))); /* aTabAttr->GetValue(1,j) - X coord */
1558 if ( !aLine.trimmed().isEmpty() ) {
1559 QString aColTitle(aColumnTitles[j-1]);
1560 if ( !aColTitle.trimmed().isEmpty() )
1561 aLine = aLine + " #TITLE: " + aColTitle ;
1562 aFile.write(QString(aLine + "\n").toLatin1() );
1566 aFile.write("\n", 1);
1568 }//end of if (isRareTable)
1570 /* Write the table in the file without separating */
1572 aLine = "#TITLE: " + aTitle + "\n";
1573 aFile.write(aLine.toLatin1());
1575 /* COLUMN_TITLES and COLUMN_UNITS */
1576 QString aTitlesSep = "";
1577 QString aUnitsSep = "";
1578 QString aTitlesStr = "#COLUMN_TITLES: ";
1579 QString aUnitsStr = "#COLUMN_UNITS: ";
1580 for (int i = 1; i <= aRowsNb; i++) {
1581 if (!QString(aRowTitles[i-1]).trimmed().isEmpty()) {
1582 aTitlesStr += (aTitlesSep + aRowTitles[i-1]);
1583 if (aTitlesSep.isEmpty()) aTitlesSep = " | ";
1585 if (!QString(aRowUnits[i-1]).trimmed().isEmpty()) {
1586 aUnitsStr += (aUnitsSep + aRowUnits[i-1]);
1587 if (aUnitsSep.isEmpty()) aUnitsSep = " ";
1590 int tmpind = aTitlesStr.indexOf("\n");
1592 aTitlesStr.remove(tmpind,1);
1593 tmpind = aTitlesStr.indexOf("\n");
1597 aFile.write(aTitlesStr.toLatin1());
1598 aFile.write(aUnitsStr.toLatin1());
1600 /* CURVE COORDINATES */
1601 QString aSep, aValue, aColTitle;
1602 for (int j = 1; j <= aColNb; j++) {
1603 aLine = ""; aSep = "";
1604 for (int i = 1; i <= aRowsNb; i++) {
1605 aLine += (aSep + aValue.sprintf("%.16g", (double)(aTabAttr->GetValue(i,j))));
1606 if (aSep.isEmpty()) aSep = " ";
1608 if (!aLine.trimmed().isEmpty()) {
1609 aColTitle = aColumnTitles[j-1];
1610 if (!aColTitle.trimmed().isEmpty())
1611 aLine = aLine + " #TITLE: " + aColTitle;
1613 aFile.write(aLine.toLatin1());
1622 bool VISU::ExportTableToFile(SALOMEDS::SObject_ptr theTable, const char* theFileName)
1625 SALOMEDS::GenericAttribute_var anAttr ;
1626 if (theTable->FindAttribute(anAttr, "AttributeTableOfReal")) {
1627 SALOMEDS::AttributeTableOfReal_var aTabAttr =
1628 SALOMEDS::AttributeTableOfReal ::_narrow(anAttr);
1629 return ExportTableToFile ( aTabAttr , theFileName);
1631 else if (theTable->FindAttribute(anAttr, "AttributeTableOfInteger")) {
1632 SALOMEDS::AttributeTableOfInteger_var aTabAttr =
1633 SALOMEDS::AttributeTableOfInteger ::_narrow(anAttr);
1634 return ExportTableToFile ( aTabAttr , theFileName);