From b95033d8f2b3010dcaf82ad5af5d4343f7688665 Mon Sep 17 00:00:00 2001 From: san Date: Thu, 9 Jun 2005 14:06:15 +0000 Subject: [PATCH] Curve plot added --- src/VISUGUI/VisuGUI.cxx | 176 ++++++++++++++++++++++++++++++---- src/VISUGUI/VisuGUI_Tools.cxx | 17 +++- src/VISUGUI/VisuGUI_Tools.h | 4 +- 3 files changed, 172 insertions(+), 25 deletions(-) diff --git a/src/VISUGUI/VisuGUI.cxx b/src/VISUGUI/VisuGUI.cxx index b529eeb8..476ff568 100644 --- a/src/VISUGUI/VisuGUI.cxx +++ b/src/VISUGUI/VisuGUI.cxx @@ -49,10 +49,12 @@ #include "SVTK_RenderWindow.h" #include "SVTK_ViewWindow.h" - #include "SVTK_ViewModel.h" #include "SVTK_Functor.h" +#include "SPlot2d_ViewModel.h" +#include "SPlot2d_SetupPlot2dDlg.h" + #include "OB_Browser.h" #include "SALOME_ListIO.hxx" @@ -136,7 +138,7 @@ VisuGUI:: OnImportFromFile() { if(MYDEBUG) MESSAGE("VisuGUI::OnImportFromFile()"); - CheckLock(GetDSStudy(GetCStudy(GetAppStudy(this))),this); + CheckLock(GetCStudy(GetAppStudy(this))); SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr(); QStringList aFilter; @@ -191,7 +193,7 @@ OnExploreMEDFile() { if(MYDEBUG) MESSAGE("VisuGUI::OnExploreMEDFile()"); _PTR(Study) aStudy = GetCStudy(GetAppStudy(this)); - CheckLock(GetDSStudy(aStudy),this); + CheckLock(aStudy); SALOME_MED::MED_Gen_var aGen = GetMEDEngine(); @@ -220,7 +222,7 @@ VisuGUI:: OnImportTableFromFile() { if(MYDEBUG) MESSAGE("VisuGUI::OnImportTableFromFile()"); - CheckLock(GetDSStudy(GetCStudy(GetAppStudy(this))),this); + CheckLock(GetCStudy(GetAppStudy(this))); QStringList aFilter; aFilter.append( tr("FLT_TABLE_FILES") ); @@ -332,7 +334,7 @@ template void CreatePrs3d(SalomeApp_Module* theModule) { - if(CheckLock(GetDSStudy(GetCStudy(GetAppStudy(theModule))),theModule)) + if(CheckLock(GetCStudy(GetAppStudy(theModule)))) return; SALOMEDS::SObject_var aTimeStampSObj; @@ -354,8 +356,8 @@ void VisuGUI:: OnCreateMesh() { - SALOMEDS::Study_var aStudy = GetDSStudy(GetCStudy(GetAppStudy(this))); - if (CheckLock(aStudy, this)) + _PTR(Study) aStudy = GetCStudy(GetAppStudy(this)); + if (CheckLock(aStudy)) return; // Get selected SObject @@ -365,7 +367,7 @@ OnCreateMesh() if (anIO.IsNull() || !anIO->hasEntry()) return; - aResultSObj = aStudy->FindObjectID(anIO->getEntry()); + aResultSObj = GetDSStudy(aStudy)->FindObjectID(anIO->getEntry()); // Get VISU::Result VISU::Result_var aResult; @@ -501,7 +503,7 @@ void VisuGUI:: OnCreatePlot2dView() { - CheckLock(GetDSStudy(GetCStudy(GetAppStudy(this))),this); + CheckLock(GetCStudy(GetAppStudy(this))); GetVisuGen( this )->CreateContainer(); updateObjBrowser(); } @@ -716,9 +718,10 @@ void VisuGUI:: OnDeleteObject() { - SALOMEDS::Study_var aStudy = GetDSStudy(GetCStudy(GetAppStudy(this))); - if (CheckLock(aStudy, this)) + _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this)); + if (CheckLock(aCStudy)) return; + SALOMEDS::Study_var aStudy = GetDSStudy(aCStudy); Handle(SALOME_InteractiveObject) anIO; CORBA::Object_var anObject = GetSelectedObj(this, &anIO); @@ -784,6 +787,143 @@ void VisuGUI:: OnPlotData() { + Handle(SALOME_InteractiveObject) anIO; + CORBA::Object_var anObject = GetSelectedObj( this, &anIO ); + _PTR(SObject) SO; + _PTR(GenericAttribute) anAttr; + _PTR(AttributeName) aName; + QString SOName; + _PTR(Study) aStudy = GetCStudy( GetAppStudy( this ) ); + + if ( !CORBA::is_nil( anObject ) ) { + VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject); + if (!CORBA::is_nil(aVisuObj) && aVisuObj->GetType() == VISU::TTABLE) { + // Table (VISU object) is selected + CORBA::Object_ptr aTbl = VISU::Table::_narrow( anObject ); + if( !CORBA::is_nil( aTbl ) ) { + VISU::Table_i* table = dynamic_cast(VISU::GetServant(aTbl).in()); + if ( table ) { + _PTR(SObject) SO = aStudy->FindObjectID( table->GetObjectEntry() ); + if ( IsSObjectTable(SO) ) { + // get name of SObject + if ( SO->FindAttribute( anAttr, "AttributeName" ) ) { + aName = anAttr; + SOName = aName->Value(); + } + SPlot2d_SetupPlot2dDlg* dlg = new SPlot2d_SetupPlot2dDlg( SO, GetDesktop( this ) ); + if ( dlg->exec() == QDialog::Accepted ) { + if ( !IsStudyLocked( aStudy ) ) { + // if study is not locked - create new container, create curves + // and insert them into container, then plot container if current viewer is of VIEW_PLOT2D type + int horIndex; + QValueList verIndices; + dlg->getCurvesSource( horIndex, verIndices ); + if ( horIndex >= 0 && verIndices.count() > 0 ) { + CORBA::Object_var aContainer = GetVisuGen(this)->CreateContainer(); + if( !CORBA::is_nil( aContainer ) ) { + VISU::Container_i* pContainer = dynamic_cast(VISU::GetServant(aContainer).in()); + if ( pContainer ) { + for ( int i = 0; i < verIndices.count(); i++ ) { + CORBA::Object_var aNewCurve = GetVisuGen(this)->CreateCurve( table->_this(), horIndex+1, verIndices[i]+1 ); + if( !CORBA::is_nil( aNewCurve ) ) { + VISU::Curve_i* pCrv = dynamic_cast(VISU::GetServant(aNewCurve).in()); + if ( pCrv ) { + bool isAuto; + int marker, line, lineWidth; + QColor color; + if ( dlg->getCurveAttributes( verIndices[i], isAuto, marker, line, lineWidth, color ) && !isAuto ) { + SALOMEDS::Color c; c.R = color.red()/255.; c.G = color.green()/255.; c.B = color.blue()/255.; + pCrv->SetColor( c ); + pCrv->SetMarker( ( VISU::Curve::MarkerType )marker ); + pCrv->SetLine( ( VISU::Curve::LineType )line, lineWidth ); + } + pContainer->AddCurve( pCrv->_this() ); + } + } + } + updateObjBrowser(); + PlotContainer( this, pContainer, VISU::eDisplay ); + } + } + } + } + else { + // if study is locked just get curves info and plot them if current viewer is of VIEW_PLOT2D type + QPtrList container; + dlg->getCurves( container ); + if ( !container.isEmpty() ) { + GetPlot2dViewer( this )->getActiveViewFrame()->displayCurves( container, true ); + GetPlot2dViewer( this )->getActiveViewFrame()->setTitle( SOName ); + } + } + } + delete dlg; + } + } + } + } + } + else if ( !anIO.IsNull() ) { + // check if Table SObject is selected + SO = aStudy->FindObjectID( anIO->getEntry() ); + if ( IsSObjectTable(SO) ) { + // get name of SObject + if ( SO->FindAttribute( anAttr, "AttributeName" ) ) { + aName = anAttr; + SOName = aName->Value(); + } + SPlot2d_SetupPlot2dDlg* dlg = new SPlot2d_SetupPlot2dDlg( SO, GetDesktop( this ) ); + if ( dlg->exec() == QDialog::Accepted ) { + if ( !IsStudyLocked( aStudy ) ) { + // if study is not locked - create new table and container objects, create curves + // and insert them into container, then plot container if current viewer is of VIEW_PLOT2D type + int horIndex; + QValueList verIndices; + dlg->getCurvesSource( horIndex, verIndices ); + if ( horIndex >= 0 && verIndices.count() > 0 ) { + CORBA::Object_var aTable = GetVisuGen(this)->CreateTable( SO->GetID().c_str() ); + CORBA::Object_var aContainer = GetVisuGen(this)->CreateContainer(); + if ( !CORBA::is_nil( aTable ) && !CORBA::is_nil( aContainer ) ) { + VISU::Table_i* pTable = dynamic_cast(VISU::GetServant(aTable).in()); + VISU::Container_i* pContainer = dynamic_cast(VISU::GetServant(aContainer).in()); + + if ( pContainer && pTable ) { + for ( int i = 0; i < verIndices.count(); i++ ) { + CORBA::Object_var aNewCurve = GetVisuGen(this)->CreateCurve( pTable->_this(), horIndex+1, verIndices[i]+1 ); + if( !CORBA::is_nil( aNewCurve ) ) { + VISU::Curve_i* pCrv = dynamic_cast(VISU::GetServant(aNewCurve).in()); + if ( pCrv ) { + bool isAuto; + int marker, line, lineWidth; + QColor color; + if ( dlg->getCurveAttributes( verIndices[i], isAuto, marker, line, lineWidth, color ) && !isAuto ) { + SALOMEDS::Color c; c.R = color.red()/255.; c.G = color.green()/255.; c.B = color.blue()/255.; + pCrv->SetColor( c ); + pCrv->SetMarker( ( VISU::Curve::MarkerType )marker ); + pCrv->SetLine( ( VISU::Curve::LineType )line, lineWidth ); + } + pContainer->AddCurve( pCrv->_this() ); + } + } + } + updateObjBrowser(); + PlotContainer( this, pContainer, VISU::eDisplay ); + } + } + } + } else { + // if study is locked just get curves info and plot them + QPtrList container; + dlg->getCurves( container ); + if ( !container.isEmpty() ) { + GetPlot2dViewer( this )->getActiveViewFrame()->displayCurves( container, true ); + GetPlot2dViewer( this )->getActiveViewFrame()->setTitle( SOName ); + } + } + } + delete dlg; + } + } } void @@ -796,10 +936,10 @@ void VisuGUI:: OnClearContainer() { - SALOMEDS::Study_var aStudy = GetDSStudy(GetCStudy(GetAppStudy(this))); - if (CheckLock(aStudy, this)) + _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this)); + if (CheckLock(aCStudy)) return; - + SALOMEDS::Study_var aStudy = GetDSStudy(aCStudy); Handle(SALOME_InteractiveObject) anIO; CORBA::Object_var anObject = GetSelectedObj(this, &anIO); if (anIO.IsNull() || CORBA::is_nil(anObject)) @@ -846,9 +986,9 @@ VisuGUI:: OnSaveViewParams() { _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this)); - SALOMEDS::Study_var aStudy = GetDSStudy(aCStudy); - if (CheckLock(aStudy, this)) + if (CheckLock(aCStudy)) return; + SALOMEDS::Study_var aStudy = GetDSStudy(aCStudy); SUIT_ViewManager* aViewMgr = getApp()->activeViewManager(); if (aViewMgr->getType() != SVTK_Viewer::Type()) @@ -895,9 +1035,9 @@ VisuGUI:: OnDeleteViewParams() { _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this)); - SALOMEDS::Study_var aStudy = GetDSStudy(aCStudy); - if (CheckLock(aStudy, this)) + if (CheckLock(aCStudy)) return; + SALOMEDS::Study_var aStudy = GetDSStudy(aCStudy); Handle(SALOME_InteractiveObject) anIO; CORBA::Object_var anObject = GetSelectedObj(this, &anIO); diff --git a/src/VISUGUI/VisuGUI_Tools.cxx b/src/VISUGUI/VisuGUI_Tools.cxx index cf2f9706..1b80eb97 100644 --- a/src/VISUGUI/VisuGUI_Tools.cxx +++ b/src/VISUGUI/VisuGUI_Tools.cxx @@ -100,16 +100,15 @@ namespace VISU } bool - IsStudyLocked(const SALOMEDS::Study_var& theStudy) + IsStudyLocked( _PTR(Study) theStudy ) { - if(!CORBA::is_nil(theStudy)) + if( theStudy ) return theStudy->GetProperties()->IsLocked(); return true; } bool - CheckLock(const SALOMEDS::Study_var& theStudy, - const CAM_Module* theModule) + CheckLock( _PTR(Study) theStudy ) { if(IsStudyLocked(theStudy)) throw std::runtime_error(QObject::tr("WRN_STUDY_LOCKED").latin1()); @@ -474,7 +473,7 @@ namespace VISU { if(!thePrs) return; - if(CheckLock(GetDSStudy(GetCStudy(GetAppStudy(theModule))),theModule)) + if(CheckLock(GetCStudy(GetAppStudy(theModule)))) return; SALOMEDS::SObject_var aSObject = thePrs->GetSObject(); CORBA::String_var anEntry = aSObject->GetID(); @@ -574,6 +573,8 @@ namespace VISU if ( !aView ) return; Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame(); + if ( !aPlot ) + return; if ( theDisplaying == VISU::eDisplayOnly ) aPlot->EraseAll(); @@ -620,6 +621,9 @@ namespace VISU if ( !aView ) return; Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame(); + if ( !aPlot ) + return; + // if ( theDisplaying == VISU::eDisplayOnly ) // aPlot->EraseAll(); QList clist; @@ -650,6 +654,9 @@ namespace VISU if ( !aView ) return; Plot2d_ViewFrame* aPlot = aView->getActiveViewFrame(); + if ( !aPlot ) + return; + if ( theDisplaying == VISU::eDisplayOnly ) aPlot->EraseAll(); QList clist; diff --git a/src/VISUGUI/VisuGUI_Tools.h b/src/VISUGUI/VisuGUI_Tools.h index d06b7a2e..296596fc 100644 --- a/src/VISUGUI/VisuGUI_Tools.h +++ b/src/VISUGUI/VisuGUI_Tools.h @@ -61,8 +61,8 @@ namespace VISU{ SalomeApp_SelectionMgr* GetSelectionMgr(const SalomeApp_Module* theModule); SalomeApp_Study* GetAppStudy(const CAM_Module* theModule); _PTR(Study) GetCStudy(const SalomeApp_Study* theStudy); - bool IsStudyLocked(const SALOMEDS::Study_var& theStudy); - bool CheckLock(const SALOMEDS::Study_var& theStudy, const CAM_Module* theModule); + bool IsStudyLocked( _PTR(Study) theStudy ); + bool CheckLock( _PTR(Study) theStudy ); VISU::Storable::TRestoringMap getMapOfValue(SALOMEDS::SObject_var theSObject); VISU::Storable::TRestoringMap getMapOfValue(_PTR(SObject) theSObject); QString getValue(SALOMEDS::SObject_var theSObject, QString theKey); -- 2.39.2