-// VISU OBJECT : interactive object for VISU entities implementation
+// Copyright (C) 2007-2011 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 "VISU_CutLines_i.hh"
+#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 <memory>
-#include <fstream>
-#include <strstream>
+#include "VISU_TableReader.hxx"
+#include "VISU_ConvertorUtils.hxx"
-#include <qfileinfo.h>
-#include <qstring.h>
-#include <qfile.h>
+#include "utilities.h"
+
+#include <Basics_Utils.hxx>
using namespace std;
//----------------------------------------------------------------
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
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 - "<<this);
+ mySObj = theStudy->FindObjectID(theObjectEntry);
myOrientation = VISU::Table::HORIZONTAL;
}
/*!
*/
VISU::Table_i::~Table_i()
{
- MESSAGE("Table_i::~Table_i");
+ MESSAGE("Table_i::~Table_i - "<<this);
+}
+
+//----------------------------------------------------------------------------
+void
+VISU::Table_i
+::SetTitle( const char* theTitle )
+{
+ SetName( theTitle, true );
+}
+
+//----------------------------------------------------------------------------
+char*
+VISU::Table_i
+::GetTitle()
+{
+ return CORBA::string_dup( GetName().c_str() );
+}
+
+//----------------------------------------------------------------------------
+void
+VISU::Table_i
+::SetOrientation( VISU::Table::Orientation theOrientation )
+{
+ myOrientation = theOrientation;
+}
+
+//----------------------------------------------------------------------------
+VISU::Table::Orientation
+VISU::Table_i
+::GetOrientation()
+{
+ return myOrientation;
+}
+
+
+//----------------------------------------------------------------------------
+void
+VISU::Table_i
+::SortRow(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->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<int, int>() );
+ }
+}
+
+//----------------------------------------------------------------------------
+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<int, int>() );
+ }
}
+
+//----------------------------------------------------------------------------
+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<int, int>() );
+ }
+}
+
+//----------------------------------------------------------------------------
+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<int, int> 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<int,int> 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<VISU::Curve_i*>( 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" ) ) {
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" ) ) {
*/
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<CutLines_i*>(GetServant(aCutLines).in());
+ pCutLines = dynamic_cast<CutLinesBase_i*>(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<CutLines_i*>(GetServant(aCutLines).in());
+ pCutLines = dynamic_cast<CutLinesBase_i*>(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;
- if(pCutLines)
- aComment.sprintf("myComment=%s;myType=%d;mySourceId=CutLines",GetComment(),VISU::TTABLE);
- else{
- aComment.sprintf("myComment=%s;myType=%d;mySourceId=TableAttr",GetComment(),VISU::TTABLE);
- SALOMEDS::SObject_var aFatherSObject = SO->GetFather();
- if(aFatherSObject->FindAttribute(anAttr,"AttributeComment")){
- SALOMEDS::AttributeComment_var aCommentAttr =
- SALOMEDS::AttributeComment::_narrow(anAttr);
- CORBA::String_var aValue = aCommentAttr->Value();
- Storable::TRestoringMap aMap;
- Storable::StrToMap(aValue.in(),aMap);
- bool anIsExist;
- QString aMethodName = VISU::Storable::FindValue(aMap,"myComment",&anIsExist);
- if(anIsExist){
- if(strcmp(aMethodName.latin1(),"ImportTables") == 0){
- aComment.sprintf("myComment=%s;myType=%d;mySourceId=TableFile",GetComment(),VISU::TTABLE);
- }
- }
- }
- }
+ 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( 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 );
+ 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<CutSegment_i*>(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;
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 );
*/
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, "" );
/*!
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(){
- VISU::RemoveFromStudy(mySObj,false);
+//---------------------------------------------------------------
+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));
}
//----------------------------------------------------------------
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;
myLineWidth = 0;
myMarker = VISU::Curve::CIRCLE;
myColor.R = 0.0; myColor.G = 0.0; myColor.B = 0.0;
+ myScale = 1.0;
}
/*!
Destructor
{
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;
+}
+
+//----------------------------------------------------------------------------
+void
+VISU::Curve_i
+::SetScale( CORBA::Double theCoef )
+{
+ myScale = theCoef;
+ UpdatePlot2d( this, eUpdateData );
+}
+
+//----------------------------------------------------------------------------
+CORBA::Double
+VISU::Curve_i
+::GetScale()
+{
+ return myScale;
+}
+
+//----------------------------------------------------------------------------
+void
+VISU::Curve_i
+::RemoveScale()
+{
+ SetScale( 1.0 );
+}
+
+//----------------------------------------------------------------------------
/*!
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
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;
}
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() ) {
{
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();
{
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();
{
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();
{
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();
/*!
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++ ) {
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++;
}
}
}
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++ ) {
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++;
}
}
SPlot2d_Curve* VISU::Curve_i::CreatePresentation()
{
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() ) );
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 <<endl;
//for ( int i =0 ; i < nbPoints; i++ ) {
// cout << i<<"\t"<<xList[i] << "\t"<< yList[i] << endl;
//}
- crv->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;
}
/*!
{
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;
+
+ QString scale_str = VISU::Storable::FindValue(theMap,"myScale", &ok);
+ myScale = ok ? scale_str.toDouble() : 1.0;
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();
*/
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, "myScale", myScale );
Storable::DataToStream( theStr, "myColor.R", myColor.R );
Storable::DataToStream( theStr, "myColor.G", myColor.G );
Storable::DataToStream( theStr, "myColor.B", myColor.B );
/*!
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(){
- VISU::RemoveFromStudy(mySObj,false);
+void VISU::Curve_i::RemoveFromStudy()
+{
+
+ //remove curve from containers
+ PortableServer::POA_ptr aPOA = GetPOA();
+ ContainerSet::ConstIterator it = myContainers.begin();
+ for ( ; it != myContainers.end(); it++ ) {
+ SALOMEDS::SObject_var aSObject = GetStudyDocument()->FindObjectID( (*it).toLatin1().data() );
+ if ( aSObject->_is_nil() ) continue;
+
+ CORBA::Object_var anObj = VISU::SObjectToObject( aSObject );
+ if ( CORBA::is_nil( anObj ) ) continue;
+ VISU::Container_i* aContainer = dynamic_cast<VISU::Container_i*>( VISU::GetServant( anObj.in() ).in() );
+ if ( !aContainer ) continue;
+ aContainer->RemoveCurve(VISU::Curve::_narrow(aPOA->servant_to_reference(this)));
+ }
+
+ 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
*/
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<Curve_i*>( 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());
}
}
}
*/
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<Curve_i*>( 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;
Builder->RemoveObject( childSO );
}
}
+ pCurve->removeContainer(GetEntry().c_str());
}
}
}
*/
CORBA::Long VISU::Container_i::GetNbCurves()
{
- Update();
+ // Update();
return myCurves.count();
}
/*!
*/
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();
*/
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(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_CONTAINER");
}
return this;
}
*/
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();
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() ) {
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::Curve_i*>(VISU::GetServant(aCurve).in());
{
if(MYDEBUG) MESSAGE(GetComment());
mySObj = SALOMEDS::SObject::_duplicate(SO);
- myName = VISU::Storable::FindValue( theMap, "myName" ).latin1();
+ 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 );
}
/*!
*/
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 "<<myName;
// theStr<<" myCurves "<<myCurves.join( QString( "*" ) ).latin1()<<"* ";
/*!
Called from engine to restore container from the file
*/
-VISU::Storable* VISU::Container_i::Restore(SALOMEDS::SObject_ptr theSObject,
- const string& thePrefix, const Storable::TRestoringMap& theMap)
+VISU::Storable* VISU::Container_i::StorableEngine(SALOMEDS::SObject_ptr theSObject,
+ const Storable::TRestoringMap& theMap,
+ const std::string& thePrefix,
+ CORBA::Boolean theIsMultiFile)
{
SALOMEDS::Study_var aStudy = theSObject->GetStudy();
VISU::Container_i* pResent = new VISU::Container_i( aStudy );
return pResent->Restore( theMap, theSObject );
}
-void VISU::Container_i::RemoveFromStudy(){
- VISU::RemoveFromStudy(mySObj,false);
-}
-
-//-------------------------------------------------------------
-// Implementation of reading from file
-//-------------------------------------------------------------
-typedef string TValue;
-typedef vector<TValue> TValues;
-
-struct TRow{
- string myTitle;
- string myUnit;
- TValues myValues;
-};
-
-typedef vector<TRow> TRows;
-
-struct TTable2D {
- string myTitle;
- vector<string> myColumnUnits;
- vector<string> 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);
+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);
}
- }
-};
-
-typedef vector<TTable2D> TTableCont;
+ };
-int getLine(ifstream& theStmIn, QString& theString){
- char tmp;
- ostrstream aStrOut;
- while(theStmIn.get(tmp)){
- aStrOut<<tmp;
- if(tmp == '\n') break;
- }
- aStrOut<<ends;
- theString = aStrOut.str();
- return !theStmIn.eof();
+ ProcessVoidEvent(new TRemoveFromStudy(this));
}
-void ImportTables(const char* theFileName, TTableCont& theTableCont){
- ifstream aStmIn;
- QFileInfo aFileInfo( theFileName );
- if( !aFileInfo.isFile() || !aFileInfo.isReadable() || !aFileInfo.size() )
- return;
- aStmIn.open( theFileName );
- QString aTmp;
- do {
- // find beginning of table (tables are separated by empty lines)
- while( getLine( aStmIn, aTmp ) && aTmp.stripWhiteSpace() == "");
- TTable2D aTable2D;
- if(MYDEBUG) cout << "New table is found" << endl;
- while( !aStmIn.eof() && aTmp.stripWhiteSpace() != "" ){
- QString data = aTmp.stripWhiteSpace();
- QString cmt = "";
- QString keyword = "";
- // split string to data and comment (comment starts from '#' symbol)
- int index = aTmp.find( "#" );
- if ( index >= 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());
- anAttr = aStudyBuilder->FindOrCreateAttribute(aFileObject, "AttributeComment");
- SALOMEDS::AttributeComment_var aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
+ 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",
- aFileInfo.absFilePath().latin1());
- aComment->SetValue(aString.latin1());
- for(int i = 0, iEnd = aTableCont.size(); i < iEnd; i++){
- const TTable2D& aTable2D = aTableCont[i];
+ 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 = "<<aTable2D.myTitle<<endl;
- if(aTable2D.myTitle != "")
+ if(MYDEBUG) MESSAGE("aTable2D.myTitle = "<<aTable2D.myTitle);
+ if ( aTable2D.myTitle != "" ) {
aName->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 = "<<j<<"; kEnd = "<<kEnd<<endl;
-
- for(int k = 0; k < kEnd; k++){
+ // check empty columns
+ TColStd_MapOfInteger EmptyColumns;
+ for(int j = 0, jEnd = aNewTable2D.myRows.size(); j < jEnd; j++) {
+ bool hasVal = false;
+ for(int k = 0; k < kEnd; k++) {
QString aVal = aNewTable2D.myRows[j].myValues[k].c_str();
bool anIsOk = false;
double aValue = aVal.toDouble(&anIsOk);
- if(anIsOk && !aVal.contains("NAN",false) && !aVal.contains("INF",false))
- aTableOfReal->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 = "<<j<<"; kEnd = "<<kEnd);
+ for(int k = 0; k < kEnd; k++) {
+ QString aVal = aNewTable2D.myRows[j].myValues[k].c_str();
+ bool anIsOk = false;
+ double aValue = aVal.toDouble(&anIsOk);
+ if( anIsOk && !aVal.contains("NAN",Qt::CaseInsensitive) &&
+ !aVal.contains("INF",Qt::CaseInsensitive) ) {
+ aTableOfReal->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());
return aFileObject;
}
-template<class TTableAttr> 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<class TTableAttr> 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; i<aRowsNb; i++) {
+ aLine += aSep;
+ QString aTmp(aRowTitles[i]);
+ updateStrForCSV(aTmp,aSep);
+ aLine += aTmp;
+ }
+ aLine += "\n";
+ aFile.write(aLine.toLatin1() );
+ // write table data
+ QString aValue;
+ for (int j = 1; j <= aColNb; j++) {
+ QString aLine = "";
+ if(aTabAttr->HasValue(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;
}