Salome HOME
Merge master branch into V9_dev.
[modules/geom.git] / src / GEOMGUI / GeometryGUI.cxx
index 4a21919d867a3187506f99aae2d3a4b76507ac7a..d859307d51f403552460633a5a92d95b248a8e62 100755 (executable)
@@ -138,7 +138,7 @@ extern "C" {
   }
 }
 
-GeometryGUI::StudyTextureMap GeometryGUI::myTextureMap;
+GeometryGUI::TextureMap GeometryGUI::myTextureMap;
 
 GEOM::GEOM_Gen_var GeometryGUI::myComponentGeom = GEOM::GEOM_Gen::_nil();
 
@@ -178,17 +178,15 @@ CORBA::Object_var GeometryGUI::ClientSObjectToObject (_PTR(SObject) theSObject)
 }
 
 //=======================================================================
-// function : ClientStudyToStudy
+// function : GetStudy
 // purpose  :
 //=======================================================================
-SALOMEDS::Study_var GeometryGUI::ClientStudyToStudy (_PTR(Study) theStudy)
+SALOMEDS::Study_var GeometryGUI::getStudyServant()
 {
   SALOME_NamingService *aNamingService = SalomeApp_Application::namingService();
-  CORBA::Object_var aSMObject = aNamingService->Resolve("/myStudyManager");
-  SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(aSMObject);
-  int aStudyID = theStudy->StudyId();
-  SALOMEDS::Study_var aDSStudy = aStudyManager->GetStudyByID(aStudyID);
-  return aDSStudy._retn();
+  CORBA::Object_var aStudyObject = aNamingService->Resolve("/Study");
+  SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(aStudyObject);
+  return aStudy._retn();
 }
 
 void GeometryGUI::Modified (bool theIsUpdateActions)
@@ -926,9 +924,8 @@ void GeometryGUI::createOriginAndBaseVectors()
     return;
   }
   if ( appStudy ) {
-    _PTR(Study) studyDS = appStudy->studyDS();
-    if ( studyDS && !CORBA::is_nil( GetGeomGen() ) ) {
-      GEOM::GEOM_IBasicOperations_var aBasicOperations = GetGeomGen()->GetIBasicOperations( studyDS->StudyId() );
+    if ( !CORBA::is_nil( GetGeomGen() ) ) {
+      GEOM::GEOM_IBasicOperations_var aBasicOperations = GetGeomGen()->GetIBasicOperations();
       if ( !aBasicOperations->_is_nil() ) {
         SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
         double aLength = aResourceMgr->doubleValue( "Geometry", "base_vectors_length", 1.0 );
@@ -937,11 +934,10 @@ void GeometryGUI::createOriginAndBaseVectors()
         GEOM::GEOM_Object_var anOY = aBasicOperations->MakeVectorDXDYDZ( 0.0, aLength, 0.0 );
         GEOM::GEOM_Object_var anOZ = aBasicOperations->MakeVectorDXDYDZ( 0.0, 0.0, aLength );
 
-        SALOMEDS::Study_var aDSStudy = ClientStudyToStudy( studyDS );
-        GetGeomGen()->PublishInStudy( aDSStudy, SALOMEDS::SObject::_nil(), anOrigin, "O" );
-        GetGeomGen()->PublishInStudy( aDSStudy, SALOMEDS::SObject::_nil(), anOX, "OX" );
-        GetGeomGen()->PublishInStudy( aDSStudy, SALOMEDS::SObject::_nil(), anOY, "OY" );
-        GetGeomGen()->PublishInStudy( aDSStudy, SALOMEDS::SObject::_nil(), anOZ, "OZ" );
+        GetGeomGen()->PublishInStudy( SALOMEDS::SObject::_nil(), anOrigin, "O" );
+        GetGeomGen()->PublishInStudy( SALOMEDS::SObject::_nil(), anOX, "OX" );
+        GetGeomGen()->PublishInStudy( SALOMEDS::SObject::_nil(), anOY, "OY" );
+        GetGeomGen()->PublishInStudy( SALOMEDS::SObject::_nil(), anOZ, "OZ" );
         anOrigin->UnRegister();
         anOX->UnRegister();
         anOY->UnRegister();
@@ -2167,7 +2163,7 @@ void GeometryGUI::onAutoBringToFront()
   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( getApp()->activeStudy() );
   if (!appStudy) return;
 
-  GEOM_Displayer displayer( appStudy );
+  GEOM_Displayer displayer;
   
   SALOME_View* window = displayer.GetActiveView();
   if ( !window ) return;
@@ -2210,10 +2206,8 @@ void GeometryGUI::onAutoBringToFront()
 
 void GeometryGUI::updateFieldColorScale()
 {
-  if( SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) )
-  {
-    GEOM_Displayer( aStudy ).UpdateColorScale();
-  }
+  GEOM_Displayer aDisplayer;
+  aDisplayer.UpdateColorScale();
 }
 
 QString GeometryGUI::engineIOR() const
@@ -2223,31 +2217,27 @@ QString GeometryGUI::engineIOR() const
   return "";
 }
 
-Handle(TColStd_HArray1OfByte) GeometryGUI::getTexture
-      (SalomeApp_Study* theStudy, int theId, int& theWidth, int& theHeight)
+Handle(TColStd_HArray1OfByte) GeometryGUI::getTexture (int theId, int& theWidth, int& theHeight)
 {
   theWidth = theHeight = 0;
 
   Handle(TColStd_HArray1OfByte) aTexture;
 
-  if (theStudy) {
-    TextureMap aTextureMap = myTextureMap[ theStudy->studyDS()->StudyId() ];
-    aTexture = aTextureMap[ theId ];
-    if ( aTexture.IsNull() ) {
-      GEOM::GEOM_IInsertOperations_var aInsOp = GeometryGUI::GetGeomGen()->GetIInsertOperations( theStudy->studyDS()->StudyId() );
-      if ( !aInsOp->_is_nil() ) {
-        CORBA::Long aWidth, aHeight;
-        SALOMEDS::TMPFile_var aStream = aInsOp->GetTexture( theId, aWidth, aHeight );
-        if ( aWidth > 0 && aHeight > 0 && aStream->length() > 0 ) {
-          theWidth  = aWidth;
-          theHeight = aHeight;
-
-          aTexture  = new TColStd_HArray1OfByte (1, aStream->length());
-
-          for ( CORBA::ULong i = 0; i < aStream->length(); i++)
-            aTexture->SetValue( i+1, (Standard_Byte)aStream[i] );
-          aTextureMap[ theId ] = aTexture;
-        }
+  aTexture = myTextureMap[ theId ];
+  if ( aTexture.IsNull() ) {
+    GEOM::GEOM_IInsertOperations_var aInsOp = GeometryGUI::GetGeomGen()->GetIInsertOperations();
+    if ( !aInsOp->_is_nil() ) {
+      CORBA::Long aWidth, aHeight;
+      SALOMEDS::TMPFile_var aStream = aInsOp->GetTexture( theId, aWidth, aHeight );
+      if ( aWidth > 0 && aHeight > 0 && aStream->length() > 0 ) {
+        theWidth  = aWidth;
+        theHeight = aHeight;
+
+        aTexture  = new TColStd_HArray1OfByte (1, aStream->length());
+
+        for ( CORBA::ULong i = 0; i < aStream->length(); i++)
+          aTexture->SetValue( i+1, (Standard_Byte)aStream[i] );
+        myTextureMap[ theId ] = aTexture;
       }
     }
   }
@@ -2815,10 +2805,7 @@ void GeometryGUI::preferencesChanged( const QString& section, const QString& par
              param == QString("scalar_bar_height") ||
              param == QString("scalar_bar_text_height") ||
              param == QString("scalar_bar_nb_intervals")) {
-      if( /*SalomeApp_Study* aStudy = */dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) )
-      {
-        updateFieldColorScale();
-      }
+      updateFieldColorScale();
     }
     else if ( param == QString("dimensions_color")            ||
               param == QString("dimensions_line_width")       ||
@@ -2843,13 +2830,7 @@ void GeometryGUI::preferencesChanged( const QString& section, const QString& par
         return;
       }
 
-      SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
-      if ( !aStudy )
-      {
-        return;
-      }
-
-      GEOM_Displayer aDisplayer( aStudy );
+      GEOM_Displayer aDisplayer;
 
       ViewManagerList aVMs;
       anApp->viewManagers( OCCViewer_Viewer::Type(), aVMs );
@@ -2906,7 +2887,7 @@ void GeometryGUI::preferencesChanged( const QString& section, const QString& par
 LightApp_Displayer* GeometryGUI::displayer()
 {
   if ( !myDisplayer )
-    myDisplayer = new GEOM_Displayer( dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) );
+    myDisplayer = new GEOM_Displayer();
   return myDisplayer;
 }
 
@@ -3109,7 +3090,7 @@ void GeometryGUI::storeVisualParameters (int savePoint)
     std::string aStoreEntry = ip->encodeEntry( aStudyEntry, componentName );
 
     // store dimension parameters
-    GEOMGUI_DimensionProperty aDimensions( appStudy, aStudyEntry );
+    GEOMGUI_DimensionProperty aDimensions( aStudyEntry );
     if ( aDimensions.GetNumber() != 0 ) {
       ip->setParameter( aStoreEntry, aDimensionParam.toStdString(), ((QString)aDimensions).toLatin1().data() );
     }
@@ -3199,7 +3180,7 @@ void GeometryGUI::restoreVisualParameters (int savePoint)
         if ( aParamNameStr == GEOM::propertyName( GEOM::Dimensions ) )
         {
           GEOMGUI_DimensionProperty aDimensionProp( aValuesStr );
-          aDimensionProp.SaveToAttribute( appStudy, entry.toLatin1().data() );
+          aDimensionProp.SaveToAttribute( entry.toLatin1().data() );
         }
         else if ( aParamNameStr == GEOM::propertyName( GEOM::ShapeAnnotations ) )
         {
@@ -3323,7 +3304,7 @@ void UpdateNameMode( SalomeApp_Application* app )
   bool isMode = false;
   SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
   SUIT_ViewWindow* viewWindow = app->desktop()->activeWindow();
-  GEOM_Displayer displayer( aStudy );
+  GEOM_Displayer displayer;
   int aMgrId = viewWindow->getViewManager()->getGlobalId();
 
   SALOME_View* window = displayer.GetActiveView();
@@ -3426,12 +3407,14 @@ void GeometryGUI::ClearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
   TCollection_AsciiString asciiIOR( (char *)IOR.in() );
   GEOM_Client::get_client().RemoveShapeFromBuffer( asciiIOR );
 
-  SALOMEDSClient_StudyManager *aManager = SalomeApp_Application::studyMgr();
+  SalomeApp_Application* app =
+    dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication());
+  SalomeApp_Study* appStudy = app ? dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) : 0;
 
-  if (!aManager)
+  if (!appStudy)
     return;
 
-  _PTR(Study) aStudy = aManager->GetStudyByID(theObj->GetStudyID());
+  _PTR(Study) aStudy = appStudy->studyDS();
 
   if ( !aStudy )
     return;
@@ -3598,7 +3581,7 @@ bool GeometryGUI::isDraggable( const SUIT_DataObject* what ) const
       _PTR(SObject) aSO = dataObj->object();
       if ( aSO ) {
         _PTR(GenericAttribute) anAttr;
-        _PTR(SObject) aFatherSO = aSO->GetStudy()->GetUseCaseBuilder()->GetFather( aSO );
+        _PTR(SObject) aFatherSO = SalomeApp_Application::getStudy()->GetUseCaseBuilder()->GetFather( aSO );
         if ( aFatherSO && aFatherSO->FindAttribute(anAttr, "AttributeLocalID") ) {
           _PTR(AttributeLocalID) aLocalID( anAttr );
           anObjectInFolder = aLocalID->Value() == 999;
@@ -3675,7 +3658,7 @@ void GeometryGUI::dropObjects( const DataObjectList& what, SUIT_DataObject* wher
   _PTR(SObject) parentObj = dataObj->object();
 
   // Find the current Study and StudyBuilder
-  _PTR(Study) aStudy = parentObj->GetStudy();
+  _PTR(Study) aStudy = SalomeApp_Application::getStudy();
   _PTR(UseCaseBuilder) aUseCaseBuilder = aStudy->GetUseCaseBuilder();
   // collect all parents of the target node
   QStringList parentIDs;