X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FVISU_I%2FVISU_Table_i.cc;h=9dc035e9586d8fbfb6b62401a8a085c726abe5d8;hb=1f9d5836e71aac9c59192e955e63465940ef7a6f;hp=1607524ce31c374d90be9189c629b34f436e4fc8;hpb=55d716c5e69656916a6070607a89fb446144fea8;p=modules%2Fvisu.git diff --git a/src/VISU_I/VISU_Table_i.cc b/src/VISU_I/VISU_Table_i.cc index 1607524c..9dc035e9 100644 --- a/src/VISU_I/VISU_Table_i.cc +++ b/src/VISU_I/VISU_Table_i.cc @@ -1,44 +1,47 @@ -// VISU OBJECT : interactive object for VISU entities implementation +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. // -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. // +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// VISU OBJECT : interactive object for VISU entities implementation // File : VISU_Table_i.cc // Author : Vadim SANDLER // Module : VISU - +// #include "VISU_Table_i.hh" -#include "QAD_Application.h" -#include "QAD_Desktop.h" -#include "QAD_Study.h" +#include "VISU_Tools.h" +#include "VISU_CutLinesBase_i.hh" +#include "VISU_CutSegment_i.hh" +#include "VISU_Result_i.hh" +#include "VISU_ViewManager_i.hh" + +#include "SALOME_Event.h" +#include "SPlot2d_Curve.h" -#include "VISU_CutLines_i.hh" +#include "VISU_TableReader.hxx" +#include "VISU_ConvertorUtils.hxx" -#include -#include -#include +#include "utilities.h" -#include -#include -#include +#include using namespace std; @@ -52,19 +55,19 @@ static int MYDEBUG = 0; //---------------------------------------------------------------- int VISU::Table_i::myNbPresent = 0; const string VISU::Table_i::myComment = "TABLE"; -/*! +/*! Generate unique name */ -const char* VISU::Table_i::GenerateName() -{ - return VISU::GenerateName( "Table", ++myNbPresent ); +QString VISU::Table_i::GenerateName() +{ + return VISU::GenerateName( "Table", ++myNbPresent ); } /*! Gets comment string */ -const char* VISU::Table_i::GetComment() const -{ - return myComment.c_str(); +const char* VISU::Table_i::GetComment() const +{ + return myComment.c_str(); } /*! Constructor @@ -72,7 +75,8 @@ const char* VISU::Table_i::GetComment() const VISU::Table_i::Table_i( SALOMEDS::Study_ptr theStudy, const char* theObjectEntry ) : PrsObject_i(theStudy) { - mySObj = SALOMEDS::SObject::_duplicate((theStudy->FindObjectID(theObjectEntry))); + MESSAGE("Table_i::Table_i - "<FindObjectID(theObjectEntry); myOrientation = VISU::Table::HORIZONTAL; } /*! @@ -80,15 +84,187 @@ VISU::Table_i::Table_i( SALOMEDS::Study_ptr theStudy, const char* theObjectEntry */ VISU::Table_i::~Table_i() { - MESSAGE("Table_i::~Table_i"); + MESSAGE("Table_i::~Table_i - "<NewBuilder(); + if ( !SO->_is_nil() ) { + SALOMEDS::GenericAttribute_var anAttr; + if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) { + SALOMEDS::AttributeTableOfInteger_var anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr ); + anInt->SortRow( theRow, (SALOMEDS::AttributeTable::SortOrder)theSortOrder, + (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy ); + } + else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) { + SALOMEDS::AttributeTableOfReal_var aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr ); + aReal->SortRow( theRow, (SALOMEDS::AttributeTable::SortOrder)theSortOrder, + (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy ); + } + UpdateCurves( std::map() ); + } +} + +//---------------------------------------------------------------------------- +void +VISU::Table_i +::SortColumn(CORBA::Long theColumn, VISU::SortOrder theSortOrder, VISU::SortPolicy theSortPolicy) +{ + SALOMEDS::SObject_var SO = mySObj; + SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder(); + if ( !SO->_is_nil() ) { + SALOMEDS::GenericAttribute_var anAttr; + if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) { + SALOMEDS::AttributeTableOfInteger_var anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr ); + anInt->SortColumn( theColumn, (SALOMEDS::AttributeTable::SortOrder)theSortOrder, + (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy ); + } + else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) { + SALOMEDS::AttributeTableOfReal_var aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr ); + aReal->SortColumn( theColumn, (SALOMEDS::AttributeTable::SortOrder)theSortOrder, + (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy ); + } + UpdateCurves( std::map() ); + } +} + +//---------------------------------------------------------------------------- +void +VISU::Table_i +::SortByRow(CORBA::Long theRow, VISU::SortOrder theSortOrder, VISU::SortPolicy theSortPolicy) +{ + SALOMEDS::SObject_var SO = mySObj; + SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder(); + if ( !SO->_is_nil() ) { + SALOMEDS::GenericAttribute_var anAttr; + if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) { + SALOMEDS::AttributeTableOfInteger_var anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr ); + anInt->SortByRow( theRow, (SALOMEDS::AttributeTable::SortOrder)theSortOrder, + (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy ); + } + else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) { + SALOMEDS::AttributeTableOfReal_var aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr ); + aReal->SortByRow( theRow, (SALOMEDS::AttributeTable::SortOrder)theSortOrder, + (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy ); + } + UpdateCurves( std::map() ); + } +} + +//---------------------------------------------------------------------------- +void +VISU::Table_i +::SortByColumn(CORBA::Long theColumn, VISU::SortOrder theSortOrder, VISU::SortPolicy theSortPolicy) +{ + SALOMEDS::SObject_var SO = mySObj; + SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder(); + if ( !SO->_is_nil() ) { + SALOMEDS::LongSeq_var aRowIndices; + SALOMEDS::GenericAttribute_var anAttr; + if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) { + SALOMEDS::AttributeTableOfInteger_var anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr ); + aRowIndices = anInt->SortByColumn( theColumn, (SALOMEDS::AttributeTable::SortOrder)theSortOrder, + (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy ); + } + else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) { + SALOMEDS::AttributeTableOfReal_var aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr ); + aRowIndices = aReal->SortByColumn( theColumn, (SALOMEDS::AttributeTable::SortOrder)theSortOrder, + (SALOMEDS::AttributeTable::SortPolicy)theSortPolicy ); + } + std::map aMixData; + for ( int i = 0, n = aRowIndices->length(); i < n; i++ ) + aMixData[ aRowIndices[i] ] = i+1; + UpdateCurves( aMixData ); + } +} + +//---------------------------------------------------------------------------- +void +VISU::Table_i +::UpdateCurves(std::map theMixData) +{ + SALOMEDS::SObject_var SO = mySObj; + SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder(); + SALOMEDS::ChildIterator_var CI = GetStudyDocument()->NewChildIterator( SO ); + for ( CI->InitEx( true ); CI->More(); CI->Next() ) { + CORBA::Object_var anObj = SObjectToObject( CI->Value() ); + VISU::Curve_var aCurve = VISU::Curve::_narrow( anObj ); + if ( !aCurve->_is_nil() ) { + if ( VISU::Curve_i* pCurve = dynamic_cast( GetServant( aCurve ).in() ) ) { + int aHRow = pCurve->GetHRow(), aVRow = pCurve->GetVRow(); + if ( theMixData.find( aHRow ) != theMixData.end() ) + pCurve->SetHRow( theMixData[ aHRow ] ); + if ( theMixData.find( aVRow ) != theMixData.end() ) + pCurve->SetVRow( theMixData[ aVRow ] ); + UpdatePlot2d( pCurve, eUpdateData ); + } + } + } +} + +//---------------------------------------------------------------------------- +SALOMEDS::SObject_var +VISU::Table_i +::GetSObject() const +{ + return mySObj; } + +//---------------------------------------------------------------------------- +std::string +VISU::Table_i +::GetObjectEntry() +{ + CORBA::String_var anEntry = mySObj->GetID(); + return anEntry.in(); +} + +//---------------------------------------------------------------------------- /*! Gets number of rows in table */ CORBA::Long VISU::Table_i::GetNbRows() { SALOMEDS::SObject_var SO = mySObj; - SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder(); + SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder(); if ( !SO->_is_nil() ) { SALOMEDS::GenericAttribute_var anAttr; if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) { @@ -108,7 +284,7 @@ CORBA::Long VISU::Table_i::GetNbRows() CORBA::Long VISU::Table_i::GetNbColumns() { SALOMEDS::SObject_var SO = mySObj; - SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder(); + SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder(); if ( !SO->_is_nil() ) { SALOMEDS::GenericAttribute_var anAttr; if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) { @@ -127,70 +303,92 @@ CORBA::Long VISU::Table_i::GetNbColumns() */ VISU::Storable* VISU::Table_i::Create() { - // generate name ... - myName = GetTableTitle(); + // generate name ... + SetName(GetTableTitle().toLatin1().data(), false); // mpv (PAL 5357): if name attribute already exist at this label, use it as name of table - if ( myName == "" ) + if ( GetName() == "" ) if ( !mySObj->_is_nil() ) { - CutLines_i* pCutLines = NULL; + CutLinesBase_i* pCutLines = NULL; CORBA::Object_var anObj = SObjectToObject(mySObj); if(!CORBA::is_nil(anObj)){ - VISU::CutLines_var aCutLines = VISU::CutLines::_narrow(anObj); + VISU::CutLinesBase_var aCutLines = VISU::CutLinesBase::_narrow(anObj); if(!aCutLines->_is_nil()) - pCutLines = dynamic_cast(GetServant(aCutLines).in()); + pCutLines = dynamic_cast(GetServant(aCutLines).in()); } if (!pCutLines) - if (mySObj->GetName()) myName = mySObj->GetName(); + if (mySObj->GetName()) SetName(mySObj->GetName(), false); } - if ( myName == "" ) - myName = GenerateName(); + if ( GetName() == "" ) + SetName(GenerateName().toLatin1().data(), false); // ... and build the object return Build( false ); } /*! Builds presentation of table */ -VISU::Storable* VISU::Table_i::Build( int theRestoring ) +VISU::Storable* VISU::Table_i::Build( int theRestoring ) { - + // look for reference SObject with table attribute SALOMEDS::SObject_var SO = mySObj; if ( !SO->_is_nil() ) { - CutLines_i* pCutLines = NULL; + CutLinesBase_i* pCutLines = NULL; CORBA::Object_var anObj = SObjectToObject(SO); if(!CORBA::is_nil(anObj)){ - VISU::CutLines_var aCutLines = VISU::CutLines::_narrow(anObj); + VISU::CutLinesBase_var aCutLines = VISU::CutLinesBase::_narrow(anObj); if(!aCutLines->_is_nil()) - pCutLines = dynamic_cast(GetServant(aCutLines).in()); + pCutLines = dynamic_cast(GetServant(aCutLines).in()); } - SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder(); + SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder(); SALOMEDS::GenericAttribute_var anAttr; // look for component if ( !theRestoring ) { - SALOMEDS::SComponent_var SComponent = VISU::FindOrCreateVisuComponent( myStudy ); - // create SObject and set attributes - QString aComment; - aComment.sprintf("myComment=%s;myType=%d",GetComment(),VISU::TTABLE); - string anEntry = CreateAttributes( myStudy, - SO->GetID(),//SComponent->GetID(), - "", - GetID(), - GetName(), - "", - aComment.latin1(), - pCutLines ); - // create SObject referenced to real table object - mySObj = SALOMEDS::SObject::_duplicate(myStudy->FindObjectID( anEntry.c_str() )); - if(pCutLines) { - pCutLines->BuildTableOfReal(mySObj); - } - // mpv (PAL5357): reference attributes are unnecessary now - //SALOMEDS::SObject_var refSO = Builder->NewObject( mySObj ); - //Builder->Addreference( refSO, SO ); + SALOMEDS::SComponent_var SComponent = VISU::FindOrCreateVisuComponent( GetStudyDocument() ); + // create SObject and set attributes + QString aComment; + if(pCutLines) + aComment.sprintf("myComment=%s;mySourceId=CutLines",GetComment()); + else{ + aComment.sprintf("myComment=%s;mySourceId=TableAttr",GetComment()); + SALOMEDS::SObject_var aFatherSObject = SO->GetFather(); + if(aFatherSObject->FindAttribute(anAttr,"AttributeString")){ + SALOMEDS::AttributeString_var aCommentAttr = + SALOMEDS::AttributeString::_narrow(anAttr); + CORBA::String_var aValue = aCommentAttr->Value(); + Storable::TRestoringMap aMap; + Storable::StringToMap(aValue.in(),aMap); + bool anIsExist; + QString aMethodName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist); + if(anIsExist){ + if( aMethodName == "ImportTables" ){ + aComment.sprintf("myComment=%s;mySourceId=TableFile",GetComment()); + } + } + } } + + string anEntry = CreateAttributes( GetStudyDocument(), + SO->GetID(),//SComponent->GetID(), + "ICON_TREE_TABLE", + GetID(), + GetName(), + "", + aComment.toLatin1().data(), + pCutLines ); + // create SObject referenced to real table object + mySObj = SALOMEDS::SObject::_duplicate(GetStudyDocument()->FindObjectID( anEntry.c_str() )); + if(pCutLines) { + bool isCutSegment = dynamic_cast(pCutLines); + pCutLines->BuildTableOfReal(mySObj, isCutSegment); + } + // mpv (PAL5357): reference attributes are unnecessary now + //SALOMEDS::SObject_var refSO = Builder->NewObject( mySObj ); + //Builder->Addreference( refSO, SO ); + } + return this; } return NULL; @@ -201,8 +399,8 @@ VISU::Storable* VISU::Table_i::Build( int theRestoring ) VISU::Storable* VISU::Table_i::Restore( const Storable::TRestoringMap& theMap, SALOMEDS::SObject_ptr SO) { if(MYDEBUG) MESSAGE(GetComment()); - myName = (const char*)(VISU::Storable::FindValue(theMap,"myName")); - myTitle = (const char*)(VISU::Storable::FindValue(theMap,"myTitle")); + SetName(VISU::Storable::FindValue(theMap,"myName").toLatin1().data(), false); + myTitle = VISU::Storable::FindValue(theMap,"myTitle").toLatin1().data(); myOrientation = ( VISU::Table::Orientation )( VISU::Storable::FindValue(theMap,"myOrientation").toInt() ); mySObj = SALOMEDS::SObject::_duplicate(SO); return Build( true ); @@ -212,15 +410,17 @@ VISU::Storable* VISU::Table_i::Restore( const Storable::TRestoringMap& theMap, S */ void VISU::Table_i::ToStream( std::ostringstream& theStr ) { - Storable::DataToStream( theStr, "myName", myName.c_str() ); + Storable::DataToStream( theStr, "myName", GetName().c_str() ); Storable::DataToStream( theStr, "myTitle", myTitle.c_str() ); Storable::DataToStream( theStr, "myOrientation", myOrientation ); } /*! Called from engine to restore table from the file */ -VISU::Storable* VISU::Table_i::Restore(SALOMEDS::SObject_ptr theSObject, - const string& thePrefix, const Storable::TRestoringMap& theMap) +VISU::Storable* VISU::Table_i::StorableEngine(SALOMEDS::SObject_ptr theSObject, + const Storable::TRestoringMap& theMap, + const std::string& thePrefix, + CORBA::Boolean theIsMultiFile) { SALOMEDS::Study_var aStudy = theSObject->GetStudy(); VISU::Table_i* pResent = new VISU::Table_i( aStudy, "" ); @@ -229,24 +429,48 @@ VISU::Storable* VISU::Table_i::Restore(SALOMEDS::SObject_ptr theSObject, /*! Gets title for the original table object */ -const char* VISU::Table_i::GetTableTitle() +QString VISU::Table_i::GetTableTitle() { SALOMEDS::SObject_var SO = mySObj; - SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder(); + SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder(); SALOMEDS::GenericAttribute_var anAttr; SALOMEDS::AttributeTableOfInteger_var anInt; SALOMEDS::AttributeTableOfReal_var aReal; - if ( !SO->_is_nil() ) { + if ( !SO->_is_nil() ) { if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) { anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr ); - return anInt->GetTitle(); + CORBA::String_var aString = anInt->GetTitle(); + return aString.in(); } else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) { aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr ); - return aReal->GetTitle(); + CORBA::String_var aString = aReal->GetTitle(); + return aString.in(); } } - return ""; + return ""; +} + +//--------------------------------------------------------------- +void VISU::Table_i::RemoveFromStudy() +{ + struct TRemoveFromStudy: public SALOME_Event + { + VISU::Table_i* myRemovable; + TRemoveFromStudy(VISU::Table_i* theRemovable): + myRemovable(theRemovable) + {} + + virtual + void + Execute() + { + VISU::RemoveFromStudy(myRemovable->GetSObject(),false); + } + }; + + // Remove the table with all curves + ProcessVoidEvent(new TRemoveFromStudy(this)); } //---------------------------------------------------------------- @@ -267,26 +491,29 @@ static VISU::Table_i* GetTable( SALOMEDS::Study_ptr theStudy, SALOMEDS::SObject_ int VISU::Curve_i::myNbPresent = 0; const string VISU::Curve_i::myComment = "CURVE"; -/*! +/*! Generate unique name */ -const char* VISU::Curve_i::GenerateName() -{ - return VISU::GenerateName( "Curve", ++myNbPresent ); +QString VISU::Curve_i::GenerateName() +{ + return VISU::GenerateName( "Curve", ++myNbPresent ).toLatin1().data(); } /*! Gets comment string */ -const char* VISU::Curve_i::GetComment() const -{ - return myComment.c_str(); +const char* VISU::Curve_i::GetComment() const +{ + return myComment.c_str(); } /*! Constructor NB : theHRow, theVRow are the indexes of rows in the Table object and numbered from the 1 to GetNbRows() */ -VISU::Curve_i::Curve_i(SALOMEDS::Study_ptr theStudy, Table_i* theTable, CORBA::Long theHRow, CORBA::Long theVRow ) - : PrsObject_i(theStudy), myTable( theTable ), myHRow( theHRow ), myVRow( theVRow ) +VISU::Curve_i::Curve_i( SALOMEDS::Study_ptr theStudy, Table_i* theTable, + CORBA::Long theHRow, CORBA::Long theVRow, + CORBA::Long theZRow, CORBA::Boolean theIsV2 ) +: PrsObject_i(theStudy), myTable( theTable ), myHRow( theHRow ), + myVRow( theVRow ), myZRow( theZRow ), myIsV2( theIsV2 ) { myAuto = true; myLine = VISU::Curve::SOLIDLINE; @@ -301,22 +528,100 @@ VISU::Curve_i::~Curve_i() { MESSAGE("Curve_i::~Curve_i"); } + +//---------------------------------------------------------------------------- +void +VISU::Curve_i +::SetTitle( const char* theTitle ) +{ + SetName( theTitle, true ); +} + +//---------------------------------------------------------------------------- +char* +VISU::Curve_i +::GetTitle() +{ + return CORBA::string_dup( GetName().c_str() ); +} + +//---------------------------------------------------------------------------- +void +VISU::Curve_i +::SetColor( const SALOMEDS::Color& theColor ) +{ + myColor = theColor; + myAuto = false; +} + +//---------------------------------------------------------------------------- +SALOMEDS::Color +VISU::Curve_i +::GetColor() +{ + return myColor; +} + +//---------------------------------------------------------------------------- +void +VISU::Curve_i +::SetMarker( VISU::Curve::MarkerType theType ) +{ + myMarker = theType; + myAuto = false; +} + +//---------------------------------------------------------------------------- +VISU::Curve::MarkerType +VISU::Curve_i +::GetMarker() +{ + return myMarker; +} + +//---------------------------------------------------------------------------- +void +VISU::Curve_i +::SetLine( VISU::Curve::LineType theType, CORBA::Long theWidth ) +{ + myLine = theType; + myLineWidth = theWidth; + myAuto = false; +} + +//---------------------------------------------------------------------------- +VISU::Curve::LineType +VISU::Curve_i +::GetLine() +{ + return myLine; +} + +//---------------------------------------------------------------------------- +CORBA::Long +VISU::Curve_i +::GetLineWidth() +{ + return myLineWidth; +} + +//---------------------------------------------------------------------------- /*! Creates curve object */ VISU::Storable* VISU::Curve_i::Create() { - // generate name ... - myName = GetVerTitle(); - if ( myName == "" ) - myName = GenerateName(); + // generate name ... + SetName(GetVerTitle(), false); + if ( GetName() == "" ) + SetName(GenerateName().toLatin1().data(), false); // ... and build the object return Build( false ); } /*! Builds presentation of curve */ -VISU::Storable* VISU::Curve_i::Build(int theRestoring ) +VISU::Storable* VISU::Curve_i::Build(int theRestoring ) { if ( myTable != NULL ) { // getting table SObject by it's entry @@ -324,20 +629,28 @@ VISU::Storable* VISU::Curve_i::Build(int theRestoring ) if ( myHRow > 0 && myHRow <= nbRows && myVRow > 0 && myVRow <= nbRows ) { if ( !theRestoring ) { // look for component - SALOMEDS::SComponent_var SComponent = VISU::FindOrCreateVisuComponent( myStudy ); + SALOMEDS::SComponent_var SComponent = VISU::FindOrCreateVisuComponent( GetStudyDocument() ); // create SObject and set attributes QString aComment; - aComment.sprintf("myComment=%s;myType=%d",GetComment(),VISU::TCURVE); - string anEntry = CreateAttributes( myStudy, + aComment.sprintf("myComment=%s",GetComment()); + string anEntry = CreateAttributes( GetStudyDocument(), myTable->GetObjectEntry(), "", GetID(), GetName(), "", - aComment.latin1(), + aComment.toLatin1().data(), true ); // create SObject referenced to real table object - mySObj = SALOMEDS::SObject::_duplicate(myStudy->FindObjectID(anEntry.c_str())); + mySObj = SALOMEDS::SObject::_duplicate(GetStudyDocument()->FindObjectID(anEntry.c_str())); + + // Set icon + SALOMEDS::StudyBuilder_var aStudyBuilder = GetStudyDocument()->NewBuilder(); + SALOMEDS::GenericAttribute_var anAttr; + SALOMEDS::AttributePixMap_var aPixmap; + anAttr = aStudyBuilder->FindOrCreateAttribute( mySObj, "AttributePixMap" ); + aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr ); + aPixmap ->SetPixMap("ICON_TREE_CURVE"); } return this; } @@ -351,12 +664,12 @@ VISU::Storable* VISU::Curve_i::Build(int theRestoring ) CORBA::Boolean VISU::Curve_i::IsValid() { // getting table SObject by it's entry - SALOMEDS::SObject_var SO = myStudy->FindObjectID(myTable->GetObjectEntry()); - SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder(); + SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID(myTable->GetObjectEntry().c_str()); + SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder(); SALOMEDS::GenericAttribute_var anAttr; SALOMEDS::AttributeTableOfInteger_var anInt; SALOMEDS::AttributeTableOfReal_var aReal; - if ( !SO->_is_nil() ) { + if ( !SO->_is_nil() ) { if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) { anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr ); if ( myHRow > 0 && myHRow <= anInt->GetNbRows() && myVRow > 0 && myVRow <= anInt->GetNbRows() ) { @@ -379,12 +692,12 @@ string VISU::Curve_i::GetHorTitle() { string title; // getting table SObject by it's entry - SALOMEDS::SObject_var SO = myStudy->FindObjectID(myTable->GetObjectEntry()); - SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder(); + SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID(myTable->GetObjectEntry().c_str()); + SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder(); SALOMEDS::GenericAttribute_var anAttr; SALOMEDS::AttributeTableOfInteger_var anInt; SALOMEDS::AttributeTableOfReal_var aReal; - if ( !SO->_is_nil() ) { + if ( !SO->_is_nil() ) { if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) { anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr ); SALOMEDS::StringSeq_var rowTitles = anInt->GetRowTitles(); @@ -409,12 +722,12 @@ string VISU::Curve_i::GetVerTitle() { string title; // getting table SObject by it's entry - SALOMEDS::SObject_var SO = myStudy->FindObjectID(myTable->GetObjectEntry()); - SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder(); + SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID(myTable->GetObjectEntry().c_str()); + SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder(); SALOMEDS::GenericAttribute_var anAttr; SALOMEDS::AttributeTableOfInteger_var anInt; SALOMEDS::AttributeTableOfReal_var aReal; - if ( !SO->_is_nil() ) { + if ( !SO->_is_nil() ) { if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) { anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr ); SALOMEDS::StringSeq_var rowTitles = anInt->GetRowTitles(); @@ -437,12 +750,12 @@ string VISU::Curve_i::GetHorUnits() { string units; // getting table SObject by it's entry - SALOMEDS::SObject_var SO = myStudy->FindObjectID(myTable->GetObjectEntry()); - SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder(); + SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID(myTable->GetObjectEntry().c_str()); + SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder(); SALOMEDS::GenericAttribute_var anAttr; SALOMEDS::AttributeTableOfInteger_var anInt; SALOMEDS::AttributeTableOfReal_var aReal; - if ( !SO->_is_nil() ) { + if ( !SO->_is_nil() ) { if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) { anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr ); SALOMEDS::StringSeq_var rowUnits = anInt->GetRowUnits(); @@ -465,12 +778,12 @@ string VISU::Curve_i::GetVerUnits() { string units; // getting table SObject by it's entry - SALOMEDS::SObject_var SO = myStudy->FindObjectID(myTable->GetObjectEntry()); - SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder(); + SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID(myTable->GetObjectEntry().c_str()); + SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder(); SALOMEDS::GenericAttribute_var anAttr; SALOMEDS::AttributeTableOfInteger_var anInt; SALOMEDS::AttributeTableOfReal_var aReal; - if ( !SO->_is_nil() ) { + if ( !SO->_is_nil() ) { if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) { anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr ); SALOMEDS::StringSeq_var rowUnits = anInt->GetRowUnits(); @@ -489,19 +802,22 @@ string VISU::Curve_i::GetVerUnits() /*! Gets curve data */ -int VISU::Curve_i::GetData( double*& theHorList, double*& theVerList ) +int VISU::Curve_i::GetData( double*& theHorList, double*& theVerList, QStringList& zList ) { theHorList = 0; theVerList = 0; // getting table SObject by it's entry - SALOMEDS::SObject_var SO = myStudy->FindObjectID(myTable->GetObjectEntry()); - SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder(); + SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID(myTable->GetObjectEntry().c_str()); + SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder(); SALOMEDS::GenericAttribute_var anAttr; SALOMEDS::AttributeTableOfInteger_var anInt; SALOMEDS::AttributeTableOfReal_var aReal; - if ( !SO->_is_nil() ) { + + QString tip = "%1: %2", z_data; + + if ( !SO->_is_nil() ) { if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfInteger" ) ) { anInt = SALOMEDS::AttributeTableOfInteger::_narrow( anAttr ); - int nbCols = anInt->GetNbColumns() ; + int nbCols = anInt->GetNbColumns(), nbRows = anInt->GetNbRows(); if ( nbCols > 0 && myHRow > 0 && myHRow <= anInt->GetNbRows() && myVRow > 0 && myVRow <= anInt->GetNbRows() ) { int nbPoints = 0; for ( int j = 1; j <= nbCols; j++ ) { @@ -512,10 +828,24 @@ int VISU::Curve_i::GetData( double*& theHorList, double*& theVerList ) theHorList = new double[ nbPoints ]; theVerList = new double[ nbPoints ]; int k = 0; + + SALOMEDS::StringSeq_var rowTitles = anInt->GetRowTitles(); + for ( int j = 1; j <= nbCols; j++ ) { if ( anInt->HasValue( myHRow, j ) && anInt->HasValue( myVRow, j ) ) { theHorList[k] = anInt->GetValue( myHRow, j ); theVerList[k] = anInt->GetValue( myVRow, j ); + + z_data = tip.arg( GetHorTitle().c_str() ).arg( theHorList[k] ) + "\n"; + z_data += tip.arg( GetVerTitle().c_str() ).arg( theVerList[k] ); + + if( myZRow>0 && myZRow<=nbRows && anInt->HasValue( myZRow, j ) ) + { + string title; + title = rowTitles[ myZRow-1 ]; + z_data += "\n" + tip.arg( title.c_str() ).arg( anInt->GetValue( myZRow, j ) ); + } + zList.append( z_data ); k++; } } @@ -525,7 +855,7 @@ int VISU::Curve_i::GetData( double*& theHorList, double*& theVerList ) } else if ( Builder->FindAttribute( SO, anAttr, "AttributeTableOfReal" ) ) { aReal = SALOMEDS::AttributeTableOfReal::_narrow( anAttr ); - int nbCols = aReal->GetNbColumns() ; + int nbCols = aReal->GetNbColumns(), nbRows = aReal->GetNbRows(); if ( nbCols > 0 && myHRow > 0 && myHRow <= aReal->GetNbRows() && myVRow > 0 && myVRow <= aReal->GetNbRows() ) { int nbPoints = 0; for ( int j = 1; j <= nbCols; j++ ) { @@ -536,10 +866,24 @@ int VISU::Curve_i::GetData( double*& theHorList, double*& theVerList ) theHorList = new double[ nbPoints ]; theVerList = new double[ nbPoints ]; int k = 0; + + SALOMEDS::StringSeq_var rowTitles = aReal->GetRowTitles(); + for ( int j = 1; j <= nbCols; j++ ) { if ( aReal->HasValue( myHRow, j ) && aReal->HasValue( myVRow, j ) ) { theHorList[k] = aReal->GetValue( myHRow, j ); theVerList[k] = aReal->GetValue( myVRow, j ); + + z_data = tip.arg( GetHorTitle().c_str() ).arg( theHorList[k] ) + "\n"; + z_data += tip.arg( GetVerTitle().c_str() ).arg( theVerList[k] ); + + if( myZRow>0 && myZRow<=nbRows && aReal->HasValue( myZRow, j ) ) + { + string title; + title = rowTitles[ myZRow-1 ]; + z_data += "\n" + tip.arg( title.c_str() ).arg( aReal->GetValue( myZRow, j ) ); + } + zList.append( z_data ); k++; } } @@ -553,11 +897,12 @@ int VISU::Curve_i::GetData( double*& theHorList, double*& theVerList ) /*! Creates curve Plot2d presentation object */ -Plot2d_Curve* VISU::Curve_i::CreatePresentation() +SPlot2d_Curve* VISU::Curve_i::CreatePresentation() { - Plot2d_Curve* crv = new Plot2d_Curve(); + SPlot2d_Curve* crv = new SPlot2d_Curve(); + crv->setYAxis( myIsV2 ? QwtPlot::yRight : QwtPlot::yLeft ); crv->setHorTitle( GetHorTitle().c_str() ); - string tlt = GetTitle(); + string tlt = GetTitle(); if ( tlt.length() <= 0 ) tlt = GetVerTitle(); //crv->setVerTitle( strdup( GetVerTitle().c_str() ) ); @@ -567,22 +912,27 @@ Plot2d_Curve* VISU::Curve_i::CreatePresentation() crv->setVerUnits( GetVerUnits().c_str() ); double* xList = 0; double* yList = 0; - int nbPoints = GetData( xList, yList ); + QStringList zList; + int nbPoints = GetData( xList, yList, zList ); if ( nbPoints > 0 && xList && yList ) { - crv->setData( xList, yList, nbPoints ); + crv->setData( xList, yList, nbPoints, zList ); } //cout << "********** Number of points: " << nbPoints <setLine( (Plot2d_Curve::LineType)GetLine(), GetLineWidth() ); - crv->setMarker( (Plot2d_Curve::MarkerType)GetMarker() ); + crv->setLine( (Plot2d::LineType)GetLine(), GetLineWidth() ); + crv->setMarker( (Plot2d::MarkerType)GetMarker() ); SALOMEDS::Color color = GetColor(); crv->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) ); crv->setAutoAssign( IsAuto() ); - crv->setIO(new SALOME_InteractiveObject(mySObj->GetID(),"VISU",GetName())); + CORBA::String_var aString = mySObj->GetID(); + crv->setIO(new SALOME_InteractiveObject(aString.in(), "VISU", GetName().c_str())); if ( myTable ) - crv->setTableIO(new SALOME_InteractiveObject(myTable->GetObjectEntry(),"VISU",myTable->GetName())); + crv->setTableIO(new SALOME_InteractiveObject(myTable->GetObjectEntry().c_str(), "VISU", myTable->GetName().c_str())); + + if(!myContainers.isEmpty()) + crv->addOwners(myContainers); return crv; } /*! @@ -592,9 +942,16 @@ VISU::Storable* VISU::Curve_i::Restore( const Storable::TRestoringMap& theMap, S { if(MYDEBUG) MESSAGE(GetComment()); mySObj = SALOMEDS::SObject::_duplicate(theSO); - myName = VISU::Storable::FindValue(theMap,"myName").latin1(); + SetName(VISU::Storable::FindValue(theMap,"myName").toLatin1().data(), false); myHRow = VISU::Storable::FindValue(theMap,"myHRow").toInt(); myVRow = VISU::Storable::FindValue(theMap,"myVRow").toInt(); + bool ok = false; + QString z_str = VISU::Storable::FindValue(theMap,"myZRow", &ok); + myZRow = ok ? z_str.toInt() : 0; + ok = false; + QString v2_str = VISU::Storable::FindValue(theMap,"myIsV2", &ok); + myIsV2 = ok ? v2_str.toInt() : false; + myColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble(); myColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble(); myColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble(); @@ -609,9 +966,11 @@ VISU::Storable* VISU::Curve_i::Restore( const Storable::TRestoringMap& theMap, S */ void VISU::Curve_i::ToStream( std::ostringstream& theStr ) { - Storable::DataToStream( theStr, "myName", myName.c_str() ); + Storable::DataToStream( theStr, "myName", GetName().c_str() ); Storable::DataToStream( theStr, "myHRow", myHRow ); Storable::DataToStream( theStr, "myVRow", myVRow ); + Storable::DataToStream( theStr, "myZRow", myZRow ); + Storable::DataToStream( theStr, "myIsV2", myIsV2 ); Storable::DataToStream( theStr, "myColor.R", myColor.R ); Storable::DataToStream( theStr, "myColor.G", myColor.G ); Storable::DataToStream( theStr, "myColor.B", myColor.B ); @@ -623,42 +982,96 @@ void VISU::Curve_i::ToStream( std::ostringstream& theStr ) /*! Gets reference table's entry */ -const char* VISU::Curve_i::GetTableID() { +std::string VISU::Curve_i::GetTableID() { return myTable->GetObjectEntry(); } /*! Called from engine to restore curve from the file */ -VISU::Storable* VISU::Curve_i::Restore(SALOMEDS::SObject_ptr theSObject, - const string& thePrefix, const Storable::TRestoringMap& theMap) +VISU::Storable* VISU::Curve_i::StorableEngine(SALOMEDS::SObject_ptr theSObject, + const Storable::TRestoringMap& theMap, + const std::string& thePrefix, + CORBA::Boolean theIsMultiFile) { SALOMEDS::Study_var aStudy = theSObject->GetStudy(); VISU::Table_i* pTable = GetTable(aStudy, theSObject->GetFather()); if( pTable != NULL ) { - VISU::Curve_i* pResent = new VISU::Curve_i( aStudy, pTable, 0, 0 ); + VISU::Curve_i* pResent = new VISU::Curve_i( aStudy, pTable, 0, 0, 0, false ); return pResent->Restore( theMap, theSObject); } return NULL; } +void VISU::Curve_i::RemoveFromStudy() +{ + struct TRemoveFromStudy: public SALOME_Event + { + VISU::Curve_i* myRemovable; + TRemoveFromStudy(VISU::Curve_i* theRemovable): + myRemovable(theRemovable) + {} + + virtual + void + Execute() + { + VISU::DeleteActors(myRemovable); + VISU::RemoveFromStudy(myRemovable->GetSObject(),false); + } + }; + + ProcessVoidEvent(new TRemoveFromStudy(this)); +} + +SALOMEDS::SObject_var VISU::Curve_i::GetSObject() +{ + return mySObj; +} + + +/*! + Add container. + id - owner of the curve +*/ +void VISU::Curve_i::addContainer(const QString& id) { + myContainers.insert(id); +} + +/*! + Remove Container + id - entry of the container +*/ +void VISU::Curve_i::removeContainer(const QString& id) { + myContainers.insert(id); +} + +/*! + Get all owners of the curve. + \return owners of the curve. +*/ +VISU::ContainerSet VISU::Curve_i::getContainers() const { + return myContainers; +} + + //---------------------------------------------------------------- // Container Object //---------------------------------------------------------------- int VISU::Container_i::myNbPresent = 0; const string VISU::Container_i::myComment = "CONTAINER"; -/*! +/*! Generate unique name */ -const char* VISU::Container_i::GenerateName() -{ - return VISU::GenerateName( "Plot2DView", ++myNbPresent ); +QString VISU::Container_i::GenerateName() +{ + return VISU::GenerateName( "Plot2DView", ++myNbPresent ).toLatin1().data(); } /*! Gets comment string */ -const char* VISU::Container_i::GetComment() const -{ - return myComment.c_str(); +const char* VISU::Container_i::GetComment() const +{ + return myComment.c_str(); } /*! Constructor @@ -680,21 +1093,22 @@ VISU::Container_i::~Container_i() */ void VISU::Container_i::AddCurve( Curve_ptr theCurve ) { - if ( myStudy->_is_nil() ) + if ( GetStudyDocument()->_is_nil() ) return; - SALOMEDS::SObject_var mySO = myStudy->FindObjectID( GetEntry() ); + SALOMEDS::SObject_var mySO = GetStudyDocument()->FindObjectID( GetEntry().c_str() ); if ( mySO->_is_nil() ) return; PortableServer::POA_ptr aPOA = GetPOA(); Curve_i* pCurve = dynamic_cast( aPOA->reference_to_servant( theCurve ) ); if( pCurve ) { - QString entry = pCurve->GetEntry(); - SALOMEDS::SObject_var SO = myStudy->FindObjectID( entry.latin1() ); - if ( !SO->_is_nil() && myCurves.find( entry ) == myCurves.end() ) { + QString entry( pCurve->GetEntry().c_str() ); + SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID( entry.toLatin1().data() ); + if ( !SO->_is_nil() && myCurves.indexOf( entry ) == -1 ) { myCurves.append( entry ); - SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder(); + SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder(); SALOMEDS::SObject_var newSO = Builder->NewObject( mySO ); Builder->Addreference( newSO, SO ); + pCurve->addContainer(GetEntry().c_str()); } } } @@ -703,20 +1117,20 @@ void VISU::Container_i::AddCurve( Curve_ptr theCurve ) */ void VISU::Container_i::RemoveCurve( Curve_ptr theCurve ) { - if ( myStudy->_is_nil() ) + if ( GetStudyDocument()->_is_nil() ) return; - SALOMEDS::SObject_var mySO = myStudy->FindObjectID( GetEntry() ); + SALOMEDS::SObject_var mySO = GetStudyDocument()->FindObjectID( GetEntry().c_str() ); if ( mySO->_is_nil() ) return; PortableServer::POA_ptr aPOA = GetPOA(); Curve_i* pCurve = dynamic_cast( aPOA->reference_to_servant( theCurve ) ); if( pCurve ) { - QString entry = pCurve->GetEntry(); - if ( myCurves.find( entry ) != myCurves.end() ) { + QString entry( pCurve->GetEntry().c_str() ); + if ( myCurves.indexOf( entry ) != -1 ) { // found !!! - myCurves.remove( entry ); - SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder(); - SALOMEDS::ChildIterator_var CI = myStudy->NewChildIterator( mySO ); + myCurves.removeAll( entry ); + SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder(); + SALOMEDS::ChildIterator_var CI = GetStudyDocument()->NewChildIterator( mySO ); for ( ; CI->More(); CI->Next() ) { SALOMEDS::SObject_var childSO = CI->Value(); SALOMEDS::SObject_var refSO; @@ -724,6 +1138,7 @@ void VISU::Container_i::RemoveCurve( Curve_ptr theCurve ) Builder->RemoveObject( childSO ); } } + pCurve->removeContainer(GetEntry().c_str()); } } } @@ -740,19 +1155,19 @@ CORBA::Long VISU::Container_i::GetNbCurves() */ void VISU::Container_i::Clear() { - if ( myStudy->_is_nil() ) + if ( GetStudyDocument()->_is_nil() ) return; - SALOMEDS::SObject_var mySO = myStudy->FindObjectID( GetEntry() ); + SALOMEDS::SObject_var mySO = GetStudyDocument()->FindObjectID( GetEntry().c_str() ); if ( mySO->_is_nil() ) return; QStringList toDelete; - SALOMEDS::ChildIterator_var CI = myStudy->NewChildIterator( mySO ); + SALOMEDS::ChildIterator_var CI = GetStudyDocument()->NewChildIterator( mySO ); for ( ; CI->More(); CI->Next() ) { toDelete.append( CI->Value()->GetID() ); } - SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder(); + SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder(); for ( int i = 0; i < toDelete.count(); i++ ) { - SALOMEDS::SObject_var SO = myStudy->FindObjectID( toDelete[i].latin1() ); + SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID( toDelete[i].toLatin1().data() ); Builder->RemoveObject( SO ); } myCurves.clear(); @@ -762,30 +1177,39 @@ void VISU::Container_i::Clear() */ VISU::Storable* VISU::Container_i::Create() { - // generate name ... - myName = GenerateName(); + // generate name ... + SetName(GenerateName().toLatin1().data(), false); // ... and build the object return Build( false ); } /*! Builds presentation of container */ -VISU::Storable* VISU::Container_i::Build( int theRestoring ) +VISU::Storable* VISU::Container_i::Build( int theRestoring ) { if ( !theRestoring ) { // looking for component - SALOMEDS::SComponent_var SComponent = VISU::FindOrCreateVisuComponent( myStudy ); + SALOMEDS::SComponent_var SComponent = VISU::FindOrCreateVisuComponent( GetStudyDocument() ); // create SObject and set attributes QString aComment; - aComment.sprintf("myComment=%s;myType=%d",GetComment(),VISU::TCONTAINER); - string anEntry = CreateAttributes( myStudy, + aComment.sprintf("myComment=%s",GetComment()); + string anEntry = CreateAttributes( GetStudyDocument(), SComponent->GetID(), "", GetID(), GetName(), "", - aComment.latin1(), + aComment.toLatin1().data(), true ); + mySObj = SALOMEDS::SObject::_duplicate(GetStudyDocument()->FindObjectID(anEntry.c_str())); + + // Set icon + SALOMEDS::StudyBuilder_var aStudyBuilder = GetStudyDocument()->NewBuilder(); + SALOMEDS::GenericAttribute_var anAttr; + SALOMEDS::AttributePixMap_var aPixmap; + anAttr = aStudyBuilder->FindOrCreateAttribute( mySObj, "AttributePixMap" ); + aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr ); + aPixmap ->SetPixMap("ICON_TREE_CONTAINER"); } return this; } @@ -794,19 +1218,19 @@ VISU::Storable* VISU::Container_i::Build( int theRestoring ) */ void VISU::Container_i::Update() { - if ( myStudy->_is_nil() ) + if ( GetStudyDocument()->_is_nil() ) return; - SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder(); - SALOMEDS::SObject_var mySO = myStudy->FindObjectID( GetEntry() ); + SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder(); + SALOMEDS::SObject_var mySO = GetStudyDocument()->FindObjectID( GetEntry().c_str() ); SALOMEDS::GenericAttribute_var anAttr; if ( !mySO->_is_nil() ) { QStringList toDelete; int i; for ( i = 0; i < myCurves.count(); i++ ) { - SALOMEDS::SObject_var SO = myStudy->FindObjectID( myCurves[i].latin1() ); + SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID( myCurves[i].toLatin1().data() ); if ( !SO->_is_nil() && Builder->FindAttribute( SO, anAttr, "AttributeIOR" ) ) { - // if real Curve Object still exists - SALOMEDS::ChildIterator_var CI = myStudy->NewChildIterator( mySO ); + // if real Curve Object still exists + SALOMEDS::ChildIterator_var CI = GetStudyDocument()->NewChildIterator( mySO ); bool bFound = false; for ( ; CI->More(); CI->Next() ) { SALOMEDS::SObject_var childSO = CI->Value(); @@ -826,21 +1250,21 @@ void VISU::Container_i::Update() toDelete.append( myCurves[i] ); } } - for ( i = 0; i < toDelete.count(); i++ ) { - myCurves.remove( toDelete[i] ); + for ( i = 0; i < toDelete.count(); i++ ) { + myCurves.removeAll( toDelete[i] ); } toDelete.clear(); - SALOMEDS::ChildIterator_var CI = myStudy->NewChildIterator( mySO ); + SALOMEDS::ChildIterator_var CI = GetStudyDocument()->NewChildIterator( mySO ); for ( ; CI->More(); CI->Next() ) { SALOMEDS::SObject_var childSO = CI->Value(); SALOMEDS::SObject_var refSO; if ( childSO->ReferencedObject( refSO ) && ( refSO->_is_nil() || !Builder->FindAttribute( refSO, anAttr, "AttributeIOR" ) || - myCurves.find( refSO->GetID() ) == myCurves.end() ) ) { + myCurves.indexOf( refSO->GetID() ) == -1 ) ) { toDelete.append( childSO->GetID() ); } } - for ( i = 0; i < toDelete.count(); i++ ) { - SALOMEDS::ChildIterator_var CI = myStudy->NewChildIterator( mySO ); + for ( i = 0; i < toDelete.count(); i++ ) { + SALOMEDS::ChildIterator_var CI = GetStudyDocument()->NewChildIterator( mySO ); for ( ; CI->More(); CI->Next() ) { SALOMEDS::SObject_var childSO = CI->Value(); if ( toDelete[i] == CI->Value()->GetID() ) { @@ -857,12 +1281,12 @@ void VISU::Container_i::Update() VISU::Curve_i* VISU::Container_i::GetCurve( CORBA::Long theIndex ) { if ( theIndex > 0 && theIndex <= myCurves.count() ) { - SALOMEDS::StudyBuilder_var Builder = myStudy->NewBuilder(); + SALOMEDS::StudyBuilder_var Builder = GetStudyDocument()->NewBuilder(); SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::SObject_var SO = myStudy->FindObjectID( myCurves[ theIndex-1 ].latin1() ); + SALOMEDS::SObject_var SO = GetStudyDocument()->FindObjectID(myCurves[ theIndex-1 ].toLatin1().data() ); CORBA::Object_var anObject = VISU::SObjectToObject( SO ); if( !CORBA::is_nil( anObject ) ) { - // if real Curve Object exists + // if real Curve Object exists CORBA::Object_ptr aCurve = VISU::Curve::_narrow( anObject ); if( !CORBA::is_nil( aCurve ) ) return dynamic_cast(VISU::GetServant(aCurve).in()); @@ -873,12 +1297,13 @@ VISU::Curve_i* VISU::Container_i::GetCurve( CORBA::Long theIndex ) /*! Restores container data from the stream */ -VISU::Storable* VISU::Container_i::Restore( const Storable::TRestoringMap& theMap ) +VISU::Storable* VISU::Container_i::Restore( const Storable::TRestoringMap& theMap, SALOMEDS::SObject_ptr SO ) { if(MYDEBUG) MESSAGE(GetComment()); - myName = VISU::Storable::FindValue( theMap, "myName" ).latin1(); + mySObj = SALOMEDS::SObject::_duplicate(SO); + SetName(VISU::Storable::FindValue( theMap, "myName" ).toLatin1().data(), false); QString val = VISU::Storable::FindValue( theMap, "myCurves" ); - myCurves = QStringList::split( QString( "*" ), val, false ); + myCurves = val.split( "*", QString::SkipEmptyParts ); return Build( true ); } /*! @@ -886,7 +1311,7 @@ VISU::Storable* VISU::Container_i::Restore( const Storable::TRestoringMap& theMa */ void VISU::Container_i::ToStream( std::ostringstream& theStr ) { - Storable::DataToStream( theStr, "myName", myName.c_str() ); + Storable::DataToStream( theStr, "myName", GetName().c_str() ); Storable::DataToStream( theStr, "myCurves", myCurves.join( QString( "*" ) ) ); // theStr<<" myName "<GetStudy(); VISU::Container_i* pResent = new VISU::Container_i( aStudy ); - return pResent->Restore( theMap ); -} - -//------------------------------------------------------------- -// Implementation of reading from file -//------------------------------------------------------------- -typedef string TValue; -typedef vector TValues; - -struct TRow{ - string myTitle; - string myUnit; - TValues myValues; -}; - -typedef vector TRows; - -struct TTable2D { - string myTitle; - vector myColumnUnits; - vector myColumnTitles; - TRows myRows; - int Check(){ - if(myRows.empty()) return 0; - int iEnd = myRows[0].myValues.size(); - if(iEnd == 0) return 0; - if(myColumnTitles.size() != iEnd) myColumnTitles.resize(iEnd); - if(myColumnUnits.size() != iEnd) myColumnUnits.resize(iEnd); - int jEnd = myRows.size(); - for(int j = 0; j < jEnd; j++) - if(myRows[j].myValues.size() != iEnd) - return 0; - return 1; - } - void getColumns(TTable2D& theTable2D) const { - TRows& aRows = theTable2D.myRows; - aRows.clear(); - if(myRows.empty()) return; - int jEnd = myRows.size(); - //Define Titles & Units - theTable2D.myColumnTitles.resize(jEnd); - theTable2D.myColumnUnits.resize(jEnd); - for(int j = 0; j < jEnd; j++){ - theTable2D.myColumnTitles[j] = myRows[j].myTitle; - theTable2D.myColumnUnits[j] = myRows[j].myUnit; - } - //Define Rows - int iEnd = myRows[0].myValues.size(); - for(int i = 0; i < iEnd; i++){ - TRow aNewRow; - aNewRow.myTitle = myColumnTitles[i]; - aNewRow.myUnit = myColumnUnits[i]; - aNewRow.myValues.resize(jEnd); - for(int j = 0; j < jEnd; j++){ - aNewRow.myValues[j] = myRows[j].myValues[i]; - } - aRows.push_back(aNewRow); - } - } -}; + return pResent->Restore( theMap, theSObject ); +} -typedef vector TTableCont; +void VISU::Container_i::RemoveFromStudy() +{ + struct TRemoveFromStudy: public SALOME_Event + { + VISU::Container_i* myRemovable; + TRemoveFromStudy(VISU::Container_i* theRemovable): + myRemovable(theRemovable) + {} + + virtual + void + Execute() + { + VISU::RemoveFromStudy(myRemovable->GetSObject(),false); + } + }; -int getLine(ifstream& theStmIn, QString& theString){ - char tmp; - ostrstream aStrOut; - while(theStmIn.get(tmp)){ - aStrOut<= 0 ) { - data = aTmp.left( index ).stripWhiteSpace(); - cmt = aTmp.mid( index+1 ).stripWhiteSpace(); - } - // if comment is not empty, try to get keyword from it (separated by ':' symbol) - if ( !cmt.isEmpty() ) { - int index1 = cmt.find( ":" ); - if ( index1 >= 0 ) { - QString tmpstr = cmt.left( index1 ).stripWhiteSpace(); - if ( tmpstr == QString( "TITLE" ) || - tmpstr == QString( "COLUMN_TITLES" ) || - tmpstr == QString( "COLUMN_UNITS" ) || - tmpstr == QString( "COMMENT" ) ) { - keyword = tmpstr; - cmt = cmt.mid( index1+1 ).stripWhiteSpace(); - } - } - } - // if data is empty, process only comment - if ( data.isEmpty() ) { - // if keyword is found, try to process it - // elsewise it is a simple comment, just ignore it - if ( !keyword.isEmpty() ) { - if ( keyword == QString( "TITLE" ) ) { - QString title = cmt; - if ( aTable2D.myTitle != "" ) - title = QString( aTable2D.myTitle.c_str() ) + QString( " " ) + title; - if(MYDEBUG) cout << "...Table TITLE is: " << title.latin1() << endl; - aTable2D.myTitle = title.latin1(); - } - else if ( keyword == QString( "COLUMN_TITLES" ) ) { - // comment may contain column headers - QStringList aStrList = QStringList::split( "|", cmt ); - if(MYDEBUG) cout << "...Column TITLES are: "; - for ( int i = 0; i < aStrList.count(); i++ ) { - QString tmpstr = aStrList[ i ].stripWhiteSpace(); - if(MYDEBUG) cout << tmpstr.latin1() << " "; - aTable2D.myColumnTitles.push_back( tmpstr.latin1() ); - } - if(MYDEBUG) cout << endl; - } - else if ( keyword == QString( "COLUMN_UNITS" ) ) { - // comment may contain column units - QStringList aStrList = QStringList::split( " ", cmt ); - if(MYDEBUG) cout << "...Column UNITS are: "; - for ( int i = 0; i < aStrList.count(); i++ ) { - QString tmpstr = aStrList[ i ].stripWhiteSpace(); - if(MYDEBUG) cout << tmpstr.latin1() << " "; - aTable2D.myColumnUnits.push_back( tmpstr.latin1() ); - } - if(MYDEBUG) cout << endl; - } - else if ( keyword == QString( "COMMENT" ) ) { - // keyword 'COMMENT' processing can be here - // currently it is ignored - if(MYDEBUG) cout << "...COMMENT: " << cmt.latin1() << endl; - } - } - else { - if(MYDEBUG) cout << "...comment: " << cmt.latin1() << endl; - // simple comment processing can be here - // currently it is ignored - } - } - // if data is not empty, try to process it - else { - TRow aRow; - if(MYDEBUG) cout << "...New row is found: " << endl; - if ( !cmt.isEmpty() ) { - aRow.myTitle = cmt.latin1(); - if(MYDEBUG) cout << "......ROW TITLE is: " << cmt.latin1() << endl; - } - QStringList aValList = QStringList::split( " ", data ); - for ( int i = 0; i < aValList.count(); i++ ) { - if ( aValList[i].stripWhiteSpace() != "" ) { - TValue aVal = aValList[i].stripWhiteSpace().latin1(); - aRow.myValues.push_back( aVal ); - } - } - if( aRow.myValues.size() > 0 ) - aTable2D.myRows.push_back( aRow ); - // ************** OLD CODE ****************** - /* - TValue aVal; - istrstream aStream( data ); - aStream.precision( STRPRECISION ); - while( aStream >> aVal ) { - aRow.myValues.push_back( aVal ); - } - if( aRow.myValues.size() > 0 ) - aTable2D.myRows.push_back( aRow ); - */ - // ************** OLD CODE ****************** - } - getLine( aStmIn, aTmp ); - } - if( aTable2D.Check() ) { - if(MYDEBUG) cout << "aTable2D is checked OK " << aTable2D.myTitle << endl; - theTableCont.push_back( aTable2D ); - } - } - while( !aStmIn.eof() ); - aStmIn.close(); - if(MYDEBUG) cout << "After close" << endl; +SALOMEDS::SObject_var VISU::Container_i::GetSObject() +{ + return mySObj; } -SALOMEDS::SObject_var VISU::ImportTables(const char* theFileName, SALOMEDS::Study_ptr theStudy){ - TTableCont aTableCont; - ImportTables(theFileName,aTableCont); - if(aTableCont.empty()) return SALOMEDS::SObject::_nil(); +SALOMEDS::SObject_var +VISU::ImportTables(const char* theFileName, SALOMEDS::Study_ptr theStudy, + bool theFirstStrAsTitle) +{ + // Set "C" numeric locale to import numbers correctly + Kernel_Utils::Localizer loc; + + TTableContainer aContainer; + ImportTables( theFileName, aContainer, theFirstStrAsTitle ); + if ( aContainer.empty() ) + return SALOMEDS::SObject::_nil(); + SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder(); SALOMEDS::SComponent_var theSComponent = VISU::FindOrCreateVisuComponent(theStudy); SALOMEDS::SObject_var aFileObject = aStudyBuilder->NewObject(theSComponent); - SALOMEDS::GenericAttribute_var anAttr = + SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aFileObject, "AttributeName"); SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr); QFileInfo aFileInfo(theFileName); - aName->SetValue(aFileInfo.fileName().latin1()); - int iEnd = aTableCont.size(); - for(int i = 0, iEnd = aTableCont.size(); i < iEnd; i++){ - const TTable2D& aTable2D = aTableCont[i]; + aName->SetValue( aFileInfo.fileName().toLatin1().data()); + anAttr = aStudyBuilder->FindOrCreateAttribute(aFileObject, "AttributeString"); + SALOMEDS::AttributeString_var aComment = SALOMEDS::AttributeString::_narrow(anAttr); + QString aString; + aString.sprintf("myComment=ImportTables;myFileName=%s;myFirstStrAsTitle=%d", + aFileInfo.absoluteFilePath().toLatin1().data(),theFirstStrAsTitle); + aComment->SetValue(aString.toLatin1().data()); + for(int i = 0, iEnd = aContainer.size(); i < iEnd; i++) { + PTableIDMapper aTableIDMapper = aContainer[i]; + const TTable2D& aTable2D = *aTableIDMapper; SALOMEDS::SObject_var aRealObject = aStudyBuilder->NewObject(aFileObject); anAttr = aStudyBuilder->FindOrCreateAttribute(aRealObject, "AttributeName"); aName = SALOMEDS::AttributeName::_narrow(anAttr); - if(MYDEBUG) cout<<"aTable2D.myTitle = "<SetValue(aTable2D.myTitle.c_str()); - else{ + } + else { QString aNewName; aNewName.sprintf("Table:%d",i); - aName->SetValue(aNewName.latin1()); + aName->SetValue(aNewName.toLatin1().data()); } + anAttr = aStudyBuilder->FindOrCreateAttribute(aRealObject, "AttributeTableOfReal"); SALOMEDS::AttributeTableOfReal_var aTableOfReal = SALOMEDS::AttributeTableOfReal::_narrow(anAttr); aTableOfReal->SetTitle(aTable2D.myTitle.c_str()); TTable2D aNewTable2D; aTable2D.getColumns(aNewTable2D); int kEnd = aNewTable2D.myRows[0].myValues.size(); - aTableOfReal->SetNbColumns(kEnd); - for(int j = 0, jEnd = aNewTable2D.myRows.size(); j < jEnd; j++){ - if(MYDEBUG) cout<<"j = "<PutValue(aValue,j+1,k+1); + if(anIsOk) { + hasVal = true; + break; + } + } + if(!hasVal) { + EmptyColumns.Add(j); } - - aTableOfReal->SetRowTitle(j+1,aNewTable2D.myRows[j].myTitle.c_str()); - aTableOfReal->SetRowUnit(j+1,aNewTable2D.myRows[j].myUnit.c_str()); + } + // create table of real + aTableOfReal->SetNbColumns( kEnd - EmptyColumns.Extent() ); + int currNum = -1; + for(int j = 0, jEnd = aNewTable2D.myRows.size(); j < jEnd; j++) { + if( EmptyColumns.Contains(j) ) continue; + currNum++; + if(MYDEBUG) MESSAGE("j = "<PutValue(aValue,currNum+1,k+1); + } + } + aTableOfReal->SetRowTitle(currNum+1,aNewTable2D.myRows[j].myTitle.c_str()); + aTableOfReal->SetRowUnit(currNum+1,aNewTable2D.myRows[j].myUnit.c_str()); } for(int k = 0; k < kEnd; k++) aTableOfReal->SetColumnTitle(k+1,aNewTable2D.myColumnTitles[k].c_str()); @@ -1152,93 +1444,226 @@ SALOMEDS::SObject_var VISU::ImportTables(const char* theFileName, SALOMEDS::Stud return aFileObject; } -template bool ExportTableToFile(const TTableAttr& aTabAttr, + +//======================================================================= +//function : updateStrForCSV +//purpose : auxilary for ExportTableToFile +//======================================================================= +void updateStrForCSV(QString& aStr, const char aSep) +{ + int index = aStr.indexOf('"'); + while(index>=0) { + aStr.insert(index,'"'); + if( index+2 >= aStr.size() ) break; + index = aStr.indexOf('"',index+2); + } + index = aStr.indexOf(aSep); + if(index>=0) { + // current string contains separator => need to use "..." + aStr.insert(0,'"'); + aStr.push_back('"'); + } +} + + +//======================================================================= +//function : ExportTableToFile +//purpose : +//======================================================================= +template bool ExportTableToFile(const TTableAttr& aTabAttr, const char* theFileName) { - if (!CORBA::is_nil(aTabAttr)) { - QFile aFile(theFileName); - aFile.open(IO_WriteOnly); + if (CORBA::is_nil(aTabAttr)) + return false; - /* extract the tabe info and write it into file */ - - QString aTitle(aTabAttr->GetTitle()); /*Table title*/ - int aRowsNb = aTabAttr->GetNbRows(); - int aColNb = aTabAttr->GetNbColumns(); - - SALOMEDS::StringSeq_var aRowTitles = aTabAttr->GetRowTitles(); - QString anAbscissTitle(aRowTitles[0]); /*Absciss row title (X coord)*/ - anAbscissTitle.stripWhiteSpace(); + // Set "C" numeric locale to save numbers correctly + Kernel_Utils::Localizer loc; - SALOMEDS::StringSeq_var aRowUnits = aTabAttr->GetRowUnits(); - QString anAbscissUnit(aRowUnits[0]); - anAbscissUnit.stripWhiteSpace(); - - SALOMEDS::StringSeq_var aColumnTitles = aTabAttr->GetColumnTitles(); + QFile aFile(theFileName); + aFile.open(QIODevice::WriteOnly); + + /* extract the table info and write it into file */ + + QString aTitle(aTabAttr->GetTitle()); /*Table title*/ + int aRowsNb = aTabAttr->GetNbRows(); + int aColNb = aTabAttr->GetNbColumns(); + + SALOMEDS::StringSeq_var aRowTitles = aTabAttr->GetRowTitles(); + SALOMEDS::StringSeq_var aRowUnits = aTabAttr->GetRowUnits(); + SALOMEDS::StringSeq_var aColumnTitles = aTabAttr->GetColumnTitles(); + + //-------------------------------------------------- + // write as *.csv file if it is needed + //-------------------------------------------------- + QString tmp(theFileName); + tmp = tmp.trimmed(); + tmp = tmp.right(3).trimmed(); + if( tmp == QString("csv") ) { + const char aSep = ','; + // write column titles + QString aLine(aRowTitles[0]); + updateStrForCSV(aLine,aSep); + for(int i=1; iHasValue(j,1)) { + aLine = aValue.sprintf("%.16g",(double)aTabAttr->GetValue(1,j)); + } + for (int i = 2; i <= aRowsNb; i++) { + if(aTabAttr->HasValue(i,j)) { + aLine += aSep + aValue.sprintf("%.16g",(double)aTabAttr->GetValue(i,j)); + } + else aLine += aSep; + } + aLine += "\n"; + aFile.write(aLine.toLatin1() ); + } + + aFile.close(); + return true; + } + //-------------------------------------------------- + // end of writing as *.csv file + //-------------------------------------------------- + + /* The given table is rare (some cells is empty) or not? */ + bool isRareTable = false; + for (int i = 1; i <= aRowsNb; i++) + for (int j = 1; j <= aColNb && !isRareTable; j++) + isRareTable = !aTabAttr->HasValue(i,j); + + QString aLine; + if (isRareTable) { + /* Separate the given table to 2D tables and write these ones to the file */ + QString anAbscissTitle(aRowTitles[0]); /*Absciss row title (X coord)*/ + anAbscissTitle.trimmed(); + QString anAbscissUnit(aRowUnits[0]); + anAbscissUnit.trimmed(); if (aRowsNb > 2 && aTitle.length() ) aTitle = aTitle + " - "; - QString aLine; - for (int i = 2; i <= aRowsNb; i++ ) - { - /* TITLE */ - QString anOrdinate(aRowTitles[i-1]), aTail; - anOrdinate.stripWhiteSpace(); - - aLine = "#TITLE: " + aTitle + - ((anOrdinate.length())? anOrdinate : - (aRowsNb>2)? aTail.sprintf("%d",i-1) : aTail.sprintf("") ) + "\n"; - aFile.writeBlock(aLine, aLine.length() ); - - /* COLUMN_TITLES */ - if ( anAbscissTitle.length() || anOrdinate.length() ) { - aLine = "#COLUMN_TITLES: " + anAbscissTitle + " | " + anOrdinate + "\n"; - aFile.writeBlock(aLine, aLine.length() ); - } - - /* COLUMN_UNITS */ - aLine = anAbscissUnit + " " +aRowUnits[i-1]; - if (!aLine.stripWhiteSpace().isEmpty()) { - aLine = "#COLUMN_UNITS: " + aLine + "\n"; - aFile.writeBlock(aLine, aLine.length() ); - } - - /* CURVE COORDINATES */ - for (int j = 1; j <= aColNb; j++) - { - if ( aTabAttr -> HasValue(i,j) && aTabAttr -> HasValue(1, j)) { - aLine = aLine.sprintf("%.16g %.16g", - (double)(aTabAttr->GetValue(1,j)), - (double)(aTabAttr->GetValue(i,j))); /* aTabAttr->GetValue(1,j) - X coord */ - if ( !aLine.stripWhiteSpace().isEmpty() ) { - QString aColTitle(aColumnTitles[j-1]); - if ( !aColTitle.stripWhiteSpace().isEmpty() ) - aLine = aLine + " #TITLE: " + aColTitle ; - aFile.writeBlock(aLine + "\n", aLine.length() + 1); - } - } - } - aFile.writeBlock("\n", 1); - } - aFile.close(); - return true; - } - return false; + for (int i = 2; i <= aRowsNb; i++ ) + { + /* TITLE */ + QString anOrdinate(aRowTitles[i-1]), aTail; + anOrdinate.trimmed(); + + aLine = "#TITLE: " + aTitle + + ((anOrdinate.length())? anOrdinate : + (aRowsNb>2)? aTail.sprintf("%d",i-1) : aTail.sprintf("") ) + "\n"; + aFile.write(aLine.toLatin1() ); + + /* COLUMN_TITLES */ + if ( anAbscissTitle.length() || anOrdinate.length() ) { + aLine = "#COLUMN_TITLES: " + anAbscissTitle + " | " + anOrdinate; + int tmpind = aLine.indexOf("\n"); + while(tmpind>=0) { + aLine.remove(tmpind,1); + tmpind = aLine.indexOf("\n"); + } + aLine += "\n"; + aFile.write(aLine.toLatin1() ); + } + + /* COLUMN_UNITS */ + aLine = anAbscissUnit + " " +aRowUnits[i-1]; + if (!aLine.trimmed().isEmpty()) { + aLine = "#COLUMN_UNITS: " + aLine + "\n"; + aFile.write(aLine.toLatin1() ); + } + + /* CURVE COORDINATES */ + for (int j = 1; j <= aColNb; j++) + { + if ( aTabAttr -> HasValue(i,j) && aTabAttr -> HasValue(1, j)) { + aLine = aLine.sprintf("%.16g %.16g", + (double)(aTabAttr->GetValue(1,j)), + (double)(aTabAttr->GetValue(i,j))); /* aTabAttr->GetValue(1,j) - X coord */ + if ( !aLine.trimmed().isEmpty() ) { + QString aColTitle(aColumnTitles[j-1]); + if ( !aColTitle.trimmed().isEmpty() ) + aLine = aLine + " #TITLE: " + aColTitle ; + aFile.write(QString(aLine + "\n").toLatin1() ); + } + } + } + aFile.write("\n", 1); + } + }//end of if (isRareTable) + else { + /* Write the table in the file without separating */ + /* TITLE */ + aLine = "#TITLE: " + aTitle + "\n"; + aFile.write(aLine.toLatin1()); + + /* COLUMN_TITLES and COLUMN_UNITS */ + QString aTitlesSep = ""; + QString aUnitsSep = ""; + QString aTitlesStr = "#COLUMN_TITLES: "; + QString aUnitsStr = "#COLUMN_UNITS: "; + for (int i = 1; i <= aRowsNb; i++) { + if (!QString(aRowTitles[i-1]).trimmed().isEmpty()) { + aTitlesStr += (aTitlesSep + aRowTitles[i-1]); + if (aTitlesSep.isEmpty()) aTitlesSep = " | "; + } + if (!QString(aRowUnits[i-1]).trimmed().isEmpty()) { + aUnitsStr += (aUnitsSep + aRowUnits[i-1]); + if (aUnitsSep.isEmpty()) aUnitsSep = " "; + } + } + int tmpind = aTitlesStr.indexOf("\n"); + while(tmpind>=0) { + aTitlesStr.remove(tmpind,1); + tmpind = aTitlesStr.indexOf("\n"); + } + aTitlesStr += "\n"; + aUnitsStr += "\n"; + aFile.write(aTitlesStr.toLatin1()); + aFile.write(aUnitsStr.toLatin1()); + + /* CURVE COORDINATES */ + QString aSep, aValue, aColTitle; + for (int j = 1; j <= aColNb; j++) { + aLine = ""; aSep = ""; + for (int i = 1; i <= aRowsNb; i++) { + aLine += (aSep + aValue.sprintf("%.16g", (double)(aTabAttr->GetValue(i,j)))); + if (aSep.isEmpty()) aSep = " "; + } + if (!aLine.trimmed().isEmpty()) { + aColTitle = aColumnTitles[j-1]; + if (!aColTitle.trimmed().isEmpty()) + aLine = aLine + " #TITLE: " + aColTitle; + aLine += "\n"; + aFile.write(aLine.toLatin1()); + } + } + } //end of else + + aFile.close(); + return true; } - + bool VISU::ExportTableToFile(SALOMEDS::SObject_ptr theTable, const char* theFileName) { //Find table SALOMEDS::GenericAttribute_var anAttr ; - if (theTable->FindAttribute(anAttr, "AttributeTableOfReal")) - { - SALOMEDS::AttributeTableOfReal_var aTabAttr = SALOMEDS::AttributeTableOfReal ::_narrow(anAttr); - return ExportTableToFile ( aTabAttr , theFileName); - - } + if (theTable->FindAttribute(anAttr, "AttributeTableOfReal")) { + SALOMEDS::AttributeTableOfReal_var aTabAttr = + SALOMEDS::AttributeTableOfReal ::_narrow(anAttr); + return ExportTableToFile ( aTabAttr , theFileName); + } else if (theTable->FindAttribute(anAttr, "AttributeTableOfInteger")) { - - SALOMEDS::AttributeTableOfInteger_var aTabAttr = SALOMEDS::AttributeTableOfInteger ::_narrow(anAttr); + SALOMEDS::AttributeTableOfInteger_var aTabAttr = + SALOMEDS::AttributeTableOfInteger ::_narrow(anAttr); return ExportTableToFile ( aTabAttr , theFileName); - } return false; }