Salome HOME
Merge from V6_3_BR 06/06/2011
[modules/geom.git] / src / GEOMToolsGUI / GEOMToolsGUI_1.cxx
index a376130709b8c7a3f0e0f92bdefc1e0a6b182bfe..6f92a81e6d03ff65ac10ed896933e41b8aea2628 100644 (file)
@@ -1,23 +1,23 @@
-//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+// 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
+// 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.
+// 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.
+// 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
+// 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
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 //  GEOM GEOMGUI : GUI for Geometry component
@@ -31,6 +31,7 @@
 #include "GEOMToolsGUI_NbIsosDlg.h"
 #include "GEOMToolsGUI_DeflectionDlg.h"
 #include "GEOMToolsGUI_MarkerDlg.h"
+#include "GEOMToolsGUI_PublishDlg.h"
 
 #include <GeometryGUI.h>
 #include <GEOM_Displayer.h>
 // VTK includes
 #include <vtkRenderer.h>
 
-void GEOMToolsGUI::OnRename()
-{
-  SALOME_ListIO selected;
-  SalomeApp_Application* app =
-    dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
-  if ( app ) {
-    LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
-    SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
-    if ( aSelMgr && appStudy ) {
-      aSelMgr->selectedObjects( selected );
-      if ( !selected.IsEmpty() ) {
-        _PTR(Study) aStudy = appStudy->studyDS();
-
-        bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
-        if ( aLocked ) {
-          SUIT_MessageBox::warning ( app->desktop(),
-                                     QObject::tr("WRN_WARNING"),
-                                     QObject::tr("WRN_STUDY_LOCKED") );
-          return;
-        }
-
-        bool isAny = false; // is there any appropriate object selected
-        for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
-          Handle(SALOME_InteractiveObject) IObject = It.Value();
-
-          _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
-          _PTR(GenericAttribute) anAttr;
-          if ( obj ) {
-            if ( obj->FindAttribute(anAttr, "AttributeName") ) {
-              _PTR(AttributeName) aName (anAttr);
-
-              GEOM::GEOM_Object_var anObj =
-                GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(obj));
-              if (!CORBA::is_nil(anObj)) {
-                isAny = true;
-                QString newName = LightApp_NameDlg::getName( app->desktop(), aName->Value().c_str() );
-                if (!newName.isEmpty()) {
-                  aName->SetValue( newName.toLatin1().data() ); // rename the SObject
-                  IObject->setName( newName.toLatin1().data() );// rename the InteractiveObject
-                  anObj->SetName( newName.toLatin1().data() );  // Rename the corresponding GEOM_Object
-                  (dynamic_cast<SalomeApp_Module*>(app->activeModule()))->updateObjBrowser( false );
-                }
-              } // if ( anObj )
-            } // if ( name attribute )
-          } // if ( obj )
-        } // iterator
-
-        if (!isAny) {
-          SUIT_MessageBox::warning( app->desktop(),
-                                    QObject::tr("WRN_WARNING"),
-                                    QObject::tr("GEOM_WRN_NO_APPROPRIATE_SELECTION") );
-          return;
-        }
-      }
-    }
-  }
-
-  app->updateActions(); //SRN: To update a Save button in the toolbar
-}
 
 void GEOMToolsGUI::OnCheckGeometry()
 {
@@ -350,7 +292,8 @@ void GEOMToolsGUI::OnColor()
                   
                   if ( io->IsKind( STANDARD_TYPE(AIS_Shape) ) ) {
                     TopoDS_Shape theShape = Handle(AIS_Shape)::DownCast( io )->Shape();
-                    if (theShape.ShapeType() == TopAbs_VERTEX) {
+                   bool onlyVertex = (theShape.ShapeType() == TopAbs_VERTEX || GEOM_Displayer::isCompoundOfVertices( theShape ));
+                    if (onlyVertex) {
                       // Set color for a point
 
                       Handle(AIS_Drawer) aCurDrawer = io->Attributes();
@@ -795,7 +738,12 @@ void GEOMToolsGUI::OnShowHideChildren( bool show )
   SALOME_ListIO selected;
   SalomeApp_Application* app =
     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
-  if ( app ) {
+  
+  SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
+  
+  GEOM_Displayer* disp  = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
+
+  if ( app && disp ) {
     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
     if ( aSelMgr && appStudy ) {
@@ -820,6 +768,8 @@ void GEOMToolsGUI::OnShowHideChildren( bool show )
           if ( obj ) {
             _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
             aExp->SetExpandable( show );
+           if(!show)
+             disp->EraseWithChildren(IObject,true);
           } // if ( obj )
         } // iterator
       }
@@ -834,3 +784,78 @@ void GEOMToolsGUI::OnPointMarker()
   GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
   dlg.exec();
 }
+
+
+void GEOMToolsGUI::OnUnpublishObject() {
+  SALOME_ListIO selected;
+  SalomeApp_Application* app =
+    dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
+
+  SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
+
+  GEOM_Displayer* disp  = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
+  
+  if ( app && disp ) {
+    LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
+    SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
+    if ( aSelMgr && appStudy ) {
+      aSelMgr->selectedObjects( selected );
+      if ( !selected.IsEmpty() ) {
+        _PTR(Study) aStudy = appStudy->studyDS();
+        _PTR(StudyBuilder) B = aStudy->NewBuilder();
+
+        bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
+        if ( aLocked ) {
+          SUIT_MessageBox::warning( app->desktop(),
+                                    QObject::tr( "WRN_WARNING" ),
+                                    QObject::tr( "WRN_STUDY_LOCKED" ) );
+          return;
+        }
+
+        for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
+          Handle(SALOME_InteractiveObject) IObject = It.Value();
+
+          _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
+          _PTR(GenericAttribute) anAttr;
+          if ( obj ) {
+            _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
+            aDrw->SetDrawable( false );
+           disp->EraseWithChildren(IObject);
+          } // if ( obj )
+        } // iterator
+        aSelMgr->clearSelected();
+      }
+    }
+    app->updateObjectBrowser( false );
+    app->updateActions();
+  }
+}
+
+void GEOMToolsGUI::OnPublishObject() {
+  SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
+  if(!app)
+    return;
+
+  SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
+  if(!appStudy)
+    return;
+  
+  _PTR(Study) aStudy = appStudy->studyDS();
+  
+  if(!aStudy)
+    return;
+
+  //Check lock of the study
+  bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
+  if ( aLocked ) {
+    SUIT_MessageBox::warning( app->desktop(),
+                             QObject::tr( "WRN_WARNING" ),
+                             QObject::tr( "WRN_STUDY_LOCKED" ) );
+    return;
+  } 
+  
+  GEOMToolsGUI_PublishDlg * publishDlg =
+    new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );
+  publishDlg->exec();
+}