]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
Curve plot added
authorsan <san@opencascade.com>
Thu, 9 Jun 2005 14:06:15 +0000 (14:06 +0000)
committersan <san@opencascade.com>
Thu, 9 Jun 2005 14:06:15 +0000 (14:06 +0000)
src/VISUGUI/VisuGUI.cxx
src/VISUGUI/VisuGUI_Tools.cxx
src/VISUGUI/VisuGUI_Tools.h

index b529eeb8048c8e0eb938cbe6239fc7f391f25a9b..476ff5688abd24bf4855e4fafcd9ef453025fc8c 100644 (file)
 
 #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<class TPrs3d_i, class TDlg, int IsDlgModal>
 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::Table_i*>(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<int> 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::Container_i*>(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::Curve_i*>(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<Plot2d_Curve> 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<int> 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::Table_i*>(VISU::GetServant(aTable).in());
+             VISU::Container_i* pContainer = dynamic_cast<VISU::Container_i*>(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::Curve_i*>(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<Plot2d_Curve> 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);
index cf2f970664e3e8ce6811b1f70a94a4111405e0a1..1b80eb979b5b6d417b76943734c6baeaa7d9f6e0 100644 (file)
@@ -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<Plot2d_Curve> 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<Plot2d_Curve> clist;
index d06b7a2eb70a19515b981ae01c0a2c736f456546..296596fc0b18c6c4a63ba0be61bfaba9efd2699e 100644 (file)
@@ -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);