Salome HOME
Implementation of the "16219: EDF PAL 469: "RemoveFromStudy" Function" issue.
authorrnv <rnv@opencascade.com>
Thu, 31 Mar 2011 11:16:45 +0000 (11:16 +0000)
committerrnv <rnv@opencascade.com>
Thu, 31 Mar 2011 11:16:45 +0000 (11:16 +0000)
14 files changed:
doc/salome/gui/GEOM/images/ob_popup_menu.png
doc/salome/gui/GEOM/images/publish_dlg.png [new file with mode: 0755]
doc/salome/gui/GEOM/input/viewing_geom_obj.doc
src/GEOMGUI/GEOM_Displayer.cxx
src/GEOMGUI/GEOM_Displayer.h
src/GEOMGUI/GEOM_msg_en.ts
src/GEOMGUI/GeometryGUI.cxx
src/GEOMGUI/GeometryGUI_Operations.h
src/GEOMToolsGUI/GEOMToolsGUI.cxx
src/GEOMToolsGUI/GEOMToolsGUI.h
src/GEOMToolsGUI/GEOMToolsGUI_1.cxx
src/GEOMToolsGUI/GEOMToolsGUI_PublishDlg.cxx [new file with mode: 0644]
src/GEOMToolsGUI/GEOMToolsGUI_PublishDlg.h [new file with mode: 0644]
src/GEOMToolsGUI/Makefile.am

index 1adb3bebb466d779ba76026474801b47d533b439..51ae305d72372e5db3a74aad35957f109464b0e4 100644 (file)
Binary files a/doc/salome/gui/GEOM/images/ob_popup_menu.png and b/doc/salome/gui/GEOM/images/ob_popup_menu.png differ
diff --git a/doc/salome/gui/GEOM/images/publish_dlg.png b/doc/salome/gui/GEOM/images/publish_dlg.png
new file mode 100755 (executable)
index 0000000..4656813
Binary files /dev/null and b/doc/salome/gui/GEOM/images/publish_dlg.png differ
index 39a4f9035892e3308ebb1c994a2e7487c4d4fae5..ba06d2397d146f62bd2eb5530966201ccbb17e3a 100644 (file)
@@ -74,9 +74,17 @@ under certain conditions:
 <ul>
 <li>\subpage work_with_groups_page "Create Group" - allows creating groups of geometrical objects.</li>
 <li><b>Hide Children</b> / <b>Show Children</b> - hides / shows child
-sub-objects in the Object Browser, if the selected geometr object has
+sub-objects in the Object Browser, if the selected geometric object has
 child objects. When some child objects are hidden, the name of the
 parent object is hilghlighted with bold font.</li>
+
+<li><b>Unpublish</b> - unpublish the selected geometric object from the Object Browser 
+and erase it from all viewers. To publish unpublished geometric objects select in the 
+context menu of the <b>Geometry</b> root object <b>Publish...</b> item. 
+The following dialog box will appear</li>
 </ul>
 
+\image html publish_dlg.png <br>
+
+Switch the checkbox near the appropriate object and click <b>Publish</b> or <b>Publish And Close</b> button.
 */
index aff2f8320d88910ef4f1572297fcd6a47bbffac9..1f3a7e09a93421187ee93166890cbe0de4a285d3 100644 (file)
 #include <SUIT_ViewManager.h>
 #include <SUIT_ResourceMgr.h>
 
+
 #include <SalomeApp_Study.h>
 #include <SalomeApp_Application.h>
 #include <LightApp_SelectionMgr.h>
+#include <LightApp_DataObject.h>
 #include <SalomeApp_TypeFilter.h>
 #include <SalomeApp_Tools.h>
 
@@ -1816,3 +1818,56 @@ SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bo
   }
   return aSColor;
 }
+
+
+void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
+                                      const bool eraseOnlyChildren) {
+  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;
+
+  LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
+  
+  if( !parent)
+    return;
+
+  // Erase from all views
+  QList<SALOME_View*> views;
+  SALOME_View* view;
+  ViewManagerList vmans = app->viewManagers();
+  SUIT_ViewManager* vman;
+  foreach ( vman, vmans ) {
+    SUIT_ViewModel* vmod = vman->getViewModel();
+    view = dynamic_cast<SALOME_View*> ( vmod );
+    if ( view ) 
+      views.append( view );
+  }
+  
+  if( views.count() == 0 )
+    return;
+  
+  //Erase childrens w/o update views
+  DataObjectList listObj = parent->children( true );
+  SUIT_DataObject* obj;
+  foreach( obj, listObj ) {
+    LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
+    if(l_obj)
+      foreach ( view, views ) {
+      Handle(SALOME_InteractiveObject) anIO = 
+       new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
+      Erase(anIO, false, false, view);
+    }
+  }
+  
+  //Erase parent with view update or repaint views
+  foreach ( view, views ) {
+    if(!eraseOnlyChildren)
+      Erase(theIO, false, true, view);
+    else
+      view->Repaint();
+  }
+}
index 7b5977046db81452545281af16c2b7188ba1924c..56676d37504f83dc63503d09fd4dac736049671d 100644 (file)
@@ -98,6 +98,9 @@ public:
                             const bool forced = false,
                             const bool updateViewer = true );
 
+  void          EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
+                                 const bool eraseOnlyChildren = false);
+
   /* Display/Erase list of objects methods */
 
   void          Display   ( const SALOME_ListIO& theIOList,
index 51e009ed297d61eccb998fc5553bb05d720f085b..b4725cbe509c785cf7994175ec267e8b5f6d27dc 100644 (file)
@@ -2473,6 +2473,14 @@ Please, select face, shell or solid and try again</translation>
         <source>MEN_POP_HIDE_CHILDREN</source>
         <translation>Hide Children</translation>
     </message>
+    <message>
+        <source>MEN_POP_UNPUBLISH_OBJ</source>
+        <translation>Unpublish</translation>
+    </message>
+    <message>
+        <source>MEN_POP_PUBLISH_OBJ</source>
+        <translation>Publish...</translation>
+    </message>                                             
     <message>
         <source>MEN_POP_ISOS</source>
         <translation>Isos</translation>
@@ -3109,6 +3117,14 @@ Please, select face, shell or solid and try again</translation>
         <source>STB_POP_SHOW_CHILDREN</source>
         <translation>Show child objects</translation>
     </message>
+    <message>
+        <source>STB_POP_UNPUBLISH_OBJ</source>
+       <translation>Unpublish object</translation>
+   </message>
+    <message>
+        <source>STB_POP_PUBLISH_OBJ</source>
+        <translation>Publish object</translation>
+   </message>                                              
     <message>
         <source>STB_POP_HIDE_CHILDREN</source>
         <translation>Hide child objects</translation>
@@ -3637,6 +3653,14 @@ Please, select face, shell or solid and try again</translation>
         <source>TOP_POP_SHOW_CHILDREN</source>
         <translation>Show Children</translation>
     </message>
+    <message>
+        <source>TOP_POP_UNPUBLISH_OBJ</source>
+        <translation>Unpublish object</translation>
+    </message> 
+    <message>
+        <source>TOP_POP_PUBLISH_OBJ</source>
+       <translation>Publish object</translation>
+   </message>                      
     <message>
         <source>TOP_POP_HIDE_CHILDREN</source>
         <translation>Hide Children</translation>
@@ -4820,4 +4844,35 @@ Would you like to continue?</translation>
         <translation>New L2</translation>
     </message>
 </context>
+<context>
+    <name>GEOMToolsGUI_PublishDlg</name>
+    <message>
+        <source>GEOM_PUBLISH_OBJECTS_TLT</source>
+       <translation>Publish Objects</translation>
+    </message>                             
+    <message>
+       <source>OBJECT_NAME</source>
+       <translation>Name</translation>
+    </message>
+    <message>
+       <source>OBJECT_ENTRY</source>
+       <translation>Entry</translation>
+    </message>    
+    <message>
+        <source>UNSELECT_ALL</source>
+        <translation>U&amp;nselect All</translation>
+    </message>
+    <message>    
+        <source>SELECT_ALL</source>
+       <translation>Select &amp;All</translation>
+    </message>
+    <message>
+        <source>GEOM_PUBLISH_BTN</source>
+       <translation>&amp;Publish</translation>
+    </message>
+    <message>
+        <source>GEOM_PUBLISH_CLOSE_BTN</source>
+       <translation>P&amp;ublish And Close</translation>
+    </message>                         
+</context>
 </TS>
index b7b0bcc28799dc4c462d7fd4aa54dd500e070e26..4ecb5452027d650a8d6be3d31f290c2046ff44a9 100644 (file)
@@ -358,6 +358,8 @@ void GeometryGUI::OnGUIEvent( int id )
                              << GEOMOp::OpShowOnly
                              << GEOMOp::OpShowChildren
                              << GEOMOp::OpHideChildren
+                             << GEOMOp::OpUnpublishObject
+                             << GEOMOp::OpPublishObject
                              << GEOMOp::OpPointMarker;
   if ( !ViewOCC && !ViewVTK && !NotViewerDependentCommands.contains( id ) )
       return;
@@ -398,6 +400,8 @@ void GeometryGUI::OnGUIEvent( int id )
   case GEOMOp::OpNoAutoColor:      // POPUP MENU - DISABLE AUTO COLOR
   case GEOMOp::OpShowChildren:     // POPUP MENU - SHOW CHILDREN
   case GEOMOp::OpHideChildren:     // POPUP MENU - HIDE CHILDREN
+  case GEOMOp::OpUnpublishObject:  // POPUP MENU - UNPUBLISH
+  case GEOMOp::OpPublishObject:    // ROOT GEOM OBJECT - POPUP MENU - PUBLISH
   case GEOMOp::OpPointMarker:      // POPUP MENU - POINT MARKER
   case GEOMOp::OpRename:           // POPUP MENU - RENAME
     libName = "GEOMToolsGUI";
@@ -785,6 +789,8 @@ void GeometryGUI::initialize( CAM_Application* app )
   createGeomAction( GEOMOp::OpGroupCreatePopup, "POP_CREATE_GROUP" );
   createGeomAction( GEOMOp::OpShowChildren,     "POP_SHOW_CHILDREN" );
   createGeomAction( GEOMOp::OpHideChildren,     "POP_HIDE_CHILDREN" );
+  createGeomAction( GEOMOp::OpUnpublishObject,  "POP_UNPUBLISH_OBJ" );
+  createGeomAction( GEOMOp::OpPublishObject,    "POP_PUBLISH_OBJ" );
   createGeomAction( GEOMOp::OpPointMarker,      "POP_POINT_MARKER" );
 
   createGeomAction( GEOMOp::OpPipeTShape, "PIPETSHAPE" );
@@ -975,6 +981,8 @@ void GeometryGUI::initialize( CAM_Application* app )
   createMenu( GEOMOp::OpShowAll, viewId, -1 );
   createMenu( GEOMOp::OpHideAll, viewId, -1 );
   createMenu( separator(),       viewId, -1 );
+  createMenu( GEOMOp::OpPublishObject, viewId, -1 );
+  createMenu( separator(),       viewId, -1 );
 
 /*
   PAL9111:
@@ -1091,6 +1099,7 @@ void GeometryGUI::initialize( CAM_Application* app )
     "(client='ObjectBrowser' or client='OCCViewer') and type='Shape' and selcount=1 and isOCC=true";
 
   QtxPopupMgr* mgr = popupMgr();
+
   mgr->insert( action(  GEOMOp::OpRename ), -1, -1 );  // rename
   mgr->setRule( action( GEOMOp::OpRename ), QString("$type in {'Shape' 'Group'} and selcount=1"), QtxPopupMgr::VisibleRule );
   mgr->insert( action(  GEOMOp::OpDelete ), -1, -1 );  // delete
@@ -1099,6 +1108,7 @@ void GeometryGUI::initialize( CAM_Application* app )
   mgr->setRule( action( GEOMOp::OpGroupCreatePopup ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and isOCC=true"), QtxPopupMgr::VisibleRule );
   mgr->insert( action(  GEOMOp::OpShowChildren ), -1, -1 ); // show children
   mgr->setRule( action( GEOMOp::OpShowChildren ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and hasHiddenChildren=true"), QtxPopupMgr::VisibleRule );
+
   mgr->insert( action(  GEOMOp::OpHideChildren ), -1, -1 ); // hide children
   mgr->setRule( action( GEOMOp::OpHideChildren ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and hasShownChildren=true"), QtxPopupMgr::VisibleRule );
   mgr->insert( action(  GEOMOp::OpGroupEdit ), -1, -1 );  // edit group
@@ -1180,6 +1190,15 @@ void GeometryGUI::initialize( CAM_Application* app )
   mgr->setRule(action(GEOMOp::OpShowOnly ), rule.arg( types ).arg( "true" ), QtxPopupMgr::VisibleRule );
   mgr->insert( separator(), -1, -1 );
 
+  mgr->insert( separator(), -1, -1 );     // -----------
+  mgr->insert( action(  GEOMOp::OpUnpublishObject ), -1, -1 ); // Unpublish object
+  mgr->setRule( action( GEOMOp::OpUnpublishObject ), QString("client='ObjectBrowser' and $type in {'Shape' 'Group'} and selcount>0"), QtxPopupMgr::VisibleRule );
+
+
+  mgr->insert( action(  GEOMOp::OpPublishObject ), -1, -1 ); // Publish object
+  mgr->setRule( action( GEOMOp::OpPublishObject ), QString("client='ObjectBrowser' and isComponent=true"), QtxPopupMgr::VisibleRule );
+
+
   mgr->hide( mgr->actionId( action( myEraseAll ) ) );
 }
 
index ce4f9edbd3ca98adf9784049bb73eca2b3c3946d..4d86e9bdd1f0b3f76e4e513bc91ca80e2b90fcdb 100644 (file)
@@ -51,6 +51,9 @@ namespace GEOMOp {
     OpShowChildren      = 1250,   // POPUP MENU - SHOW CHILDREN
     OpHideChildren      = 1251,   // POPUP MENU - HIDE CHILDREN
     OpRename            = 1252,   // POPUP MENU - RENAME
+    OpUnpublishObject   = 1253,   // POPUP MENU - UNPUBLISH
+    OpPublishObject     = 1254,   // GEOM ROOT OBJECT - POPUP MENU - PUBLISH
+
     // DisplayGUI ----------------//--------------------------------
     OpDisplayMode       = 2000,   // MENU VIEW  - DISPLAY MODE - WIREFRAME/SHADING
     OpSwitchVectors     = 2001,   // MENU VIEW  - DISPLAY MODE - SHOW/HIDE EDGE DIRECTION
index 5f8442776fe9224e244dba174a3f55034203abd2..cbde99ce1d9f6f8d71c2c121e51a966d38bf2759 100644 (file)
@@ -362,6 +362,12 @@ bool GEOMToolsGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
   case GEOMOp::OpPointMarker:    // POPUP - POINT MARKER
     OnPointMarker();
     break;
+  case GEOMOp::OpUnpublishObject:// POPUP - UNPUBLISH
+    OnUnpublishObject();
+    break;
+  case GEOMOp::OpPublishObject:// GEOM ROOT OBJECT - POPUP - PUBLISH
+    OnPublishObject();
+    break;
   default:
     SUIT_Session::session()->activeApplication()->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
     break;
index 09cdbd4e8e9e282aba8365f82f9415027ff625bb..25516496a86f8425a6ac3f0b24c5874043f1212e 100644 (file)
@@ -73,6 +73,8 @@ private:
   void         OnDeflection();
   void         OnSelectOnly(int mode);
   void         OnShowHideChildren( bool );
+  void         OnUnpublishObject();
+  void         OnPublishObject() ;
   void         OnPointMarker();
 
   // Shortcut commands
index a376130709b8c7a3f0e0f92bdefc1e0a6b182bfe..8f434de962ab40c58fdf272d2d96c48847e4f2ec 100644 (file)
@@ -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>
@@ -795,7 +796,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 +826,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 +842,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();
+}
diff --git a/src/GEOMToolsGUI/GEOMToolsGUI_PublishDlg.cxx b/src/GEOMToolsGUI/GEOMToolsGUI_PublishDlg.cxx
new file mode 100644 (file)
index 0000000..7852c05
--- /dev/null
@@ -0,0 +1,389 @@
+//  Copyright (C) 2007-2010  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.
+//
+//  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
+//
+
+// GEOM GEOMGUI : GUI for Geometry component
+// File   : GEOMToolsGUI_PublishDlg.cxx
+// Author : Roman NIKOLAEV, Open CASCADE S.A.S.
+//
+
+#include "GEOMToolsGUI_PublishDlg.h"
+
+//SALOME GUI includes
+#include <SUIT_Session.h>
+#include <SUIT_DataObject.h>
+
+#include <CAM_DataModel.h>
+
+#include <SalomeApp_DataObject.h>
+
+#include <SalomeApp_Application.h>
+#include <SalomeApp_Module.h>
+#include <SalomeApp_Study.h>
+
+
+//QT includes
+#include <QGridLayout>
+#include <QTreeWidget>
+#include <QPushButton>
+
+#define  DEFAULT_MARGIN 11
+#define  DEFAULT_SPACING 6
+
+GEOMToolsGUI_PublishDlg::GEOMToolsGUI_PublishDlg(QWidget* parent):
+  QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
+{
+   setObjectName( "GEOMToolsGUI_PublishDlg" );
+   setModal( true );
+   setWindowTitle( tr( "GEOM_PUBLISH_OBJECTS_TLT" ) );
+
+   setAttribute(Qt::WA_DeleteOnClose);
+   
+   //List of the objects
+   myTreeWidget = new QTreeWidget(this);
+   //myTreeWidget->setRootIsDecorated(false);
+   //myTreeWidget->setUniformRowHeights(true);
+   myTreeWidget->setAllColumnsShowFocus(true);
+   myTreeWidget->setColumnCount(2);
+
+   QStringList columnNames;
+   columnNames.append(tr("OBJECT_NAME"));
+   columnNames.append(tr("OBJECT_ENTRY"));
+   QTreeWidgetItem * headerItem = new QTreeWidgetItem(columnNames);
+   myTreeWidget->setHeaderItem ( headerItem );
+
+   //Select All button
+   QPushButton* selectAllButton = new  QPushButton( tr("SELECT_ALL"),this );
+
+   //Unselect Select All button
+   QPushButton* unselectAllButton = new  QPushButton( tr("UNSELECT_ALL"),this );
+
+   //Publish button
+   QPushButton* publishButton = new QPushButton( tr("GEOM_PUBLISH_BTN"),this );
+
+   //Publish and Close button
+   QPushButton* publishCloseButton = new QPushButton( tr("GEOM_PUBLISH_CLOSE_BTN"), this );
+   
+   //Close button
+   QPushButton* closeButton = new QPushButton( tr("GEOM_BUT_CLOSE"), this );
+   
+   QGridLayout* gridLayout = new QGridLayout(this);
+   gridLayout->setMargin(DEFAULT_MARGIN);
+   gridLayout->setSpacing(DEFAULT_SPACING);
+
+   gridLayout->addWidget(myTreeWidget, 0, 0, 3, 3);
+   gridLayout->addWidget(selectAllButton, 0, 3, 1, 1);
+   gridLayout->addWidget(unselectAllButton, 1, 3, 1, 1);
+   gridLayout->addItem( new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding), 2, 3, 1, 1);
+   gridLayout->addWidget(publishCloseButton, 3, 0, 1, 1); 
+   gridLayout->addWidget(publishButton, 3, 1, 1, 1);
+   gridLayout->addItem( new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum), 3, 2, 1, 1);
+   gridLayout->addWidget(closeButton, 3, 3, 1, 1);
+
+   //Connect signals and slots
+   connect( selectAllButton, SIGNAL(clicked()), this, SLOT(clickOnSelectAll()) );
+   connect( unselectAllButton, SIGNAL(clicked()), this, SLOT(clickOnUnSelectAll()) );
+   
+   connect(publishCloseButton, SIGNAL(clicked()), this, SLOT(clickOnOk()));
+   connect(publishButton, SIGNAL(clicked()), this, SLOT(clickOnApply()));
+   connect(closeButton, SIGNAL(clicked()), this, SLOT(reject()));
+
+   initData();
+}
+
+//=================================================================================
+// function : ~GEOMToolsGUI_PublishDlg()
+// purpose  : Destroys the object and frees any allocated resources
+//=================================================================================
+GEOMToolsGUI_PublishDlg::~GEOMToolsGUI_PublishDlg()
+{
+}
+
+//=================================================================================
+// function : initData()
+// purpose  : Fill dialog after opening
+//=================================================================================
+void GEOMToolsGUI_PublishDlg::initData() {
+  SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
+  if(!app)
+    return;
+  
+  SalomeApp_Module* module = dynamic_cast<SalomeApp_Module*>(app->activeModule());
+  
+  if(!module)
+    return;
+
+  CAM_DataModel* dataModel = module->dataModel();
+  if(!dataModel)
+    return;
+  
+  myGeomRoot = dynamic_cast<SalomeApp_DataObject*>(dataModel->root());
+
+  if(!myGeomRoot)
+    return;
+
+  SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
+  if(!appStudy ) 
+    return;
+
+  _PTR(Study) aStudy = appStudy->studyDS();
+  if(!aStudy)
+    return;
+
+  buildTree(aStudy, myGeomRoot);
+
+
+  myTreeWidget->resizeColumnToContents(0);
+  myTreeWidget->resizeColumnToContents(1);
+}
+
+//=================================================================================
+// function : buildTree()
+// purpose  :
+//=================================================================================
+QTreeWidgetItem* GEOMToolsGUI_PublishDlg::createItem(QTreeWidgetItem* theParent, Pair theAttributes, bool isCheckable) {
+  QStringList aList;
+  aList<<theAttributes.second<<theAttributes.first;
+  QTreeWidgetItem* anItem = new QTreeWidgetItem(aList);
+  
+  if(isCheckable)
+    anItem->setCheckState(0, Qt::Unchecked);
+  else {
+    anItem->setFlags(anItem->flags() & ~Qt::ItemIsUserCheckable);
+  }
+  
+  if(theParent)
+    theParent->addChild(anItem);
+  else 
+    myTreeWidget->addTopLevelItem(anItem);
+
+  myEntryToItem.insert(theAttributes.first, anItem);
+  
+  anItem->setExpanded(true);
+  return anItem;
+}
+
+//=================================================================================
+// function : buildTree()
+// purpose  :
+//=================================================================================
+QTreeWidgetItem* GEOMToolsGUI_PublishDlg::findParentItem(_PTR(Study) theStudy, SalomeApp_DataObject* theObject, BufferedList& theList ) {
+  
+  QTreeWidgetItem* aResult = NULL;
+  SalomeApp_DataObject* aParrent = dynamic_cast<SalomeApp_DataObject*>(theObject->parent());
+  if(aParrent) {
+    QString targetEntry = aParrent->entry();
+    if( !(aResult = myEntryToItem.value(targetEntry)) ) {
+      if( aParrent != myGeomRoot ) {
+       QString aName;
+       _PTR(SObject) aSO ( theStudy->FindObjectID(qPrintable(aParrent->entry())));
+       _PTR(GenericAttribute) anAttr;
+       if ( aSO->FindAttribute(anAttr, "AttributeName") ) {
+         _PTR(AttributeName) anAttrName (anAttr);
+         aName = anAttrName->Value().c_str();
+       }
+       theList.push_front(qMakePair(targetEntry, aName));
+       aResult = findParentItem(theStudy,aParrent,theList);
+      } else {
+       //Publish List
+       for(int i = 0; i < theList.size(); i++ ) {
+         aResult = createItem(aResult, theList[i], false);
+       }
+       theList.clear();
+      }
+    } else {
+      //Publish List
+      for(int i = 0; i < theList.size(); i++ ) {
+       aResult = createItem(aResult, theList[i], false);
+      }
+      theList.clear();
+    }
+  }
+  return aResult;
+}
+
+//=================================================================================
+// function : buildTree()
+// purpose  :
+//=================================================================================
+void GEOMToolsGUI_PublishDlg::buildTree(_PTR(Study) theStudy, SalomeApp_DataObject* theItem) {
+  if(!theItem || theItem->isReference())
+    return;
+  
+  if(theItem != myGeomRoot) {
+
+    //If object hasn't "AttributeDrawable" => it visible
+    bool isDrawable = true;
+    _PTR(SObject) SO ( theStudy->FindObjectID(qPrintable(theItem->entry())));
+    _PTR(GenericAttribute) anAttr;
+    if ( SO && SO->FindAttribute(anAttr, "AttributeDrawable") ) {
+      _PTR(AttributeDrawable) aDrw (anAttr);
+      isDrawable = aDrw->IsDrawable();
+    }
+    
+    if(!isDrawable) {
+      QString aName;
+      if ( SO->FindAttribute(anAttr, "AttributeName") ) {
+       _PTR(AttributeName) aAttrName (anAttr);
+       aName = aAttrName->Value().c_str();
+      }
+      BufferedList aList;
+      QTreeWidgetItem* parentItem = findParentItem(theStudy, theItem, aList);
+      createItem(parentItem,qMakePair(theItem->entry(),aName),true);
+    }
+  }
+  
+  DataObjectList listObj = theItem->children( false );
+  DataObjectList::iterator itr = listObj.begin();
+  while( itr != listObj.end()) {
+    buildTree(theStudy, dynamic_cast<SalomeApp_DataObject*>(*itr));
+    itr++;
+  }
+}
+
+//=================================================================================
+// function : clickOnApply()
+// purpose  : Called then "Publish" button clicked
+//=================================================================================
+void GEOMToolsGUI_PublishDlg::clickOnApply() {
+  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;
+
+
+  QList<QTreeWidgetItem*> toProcess;
+  getDrawableList(myTreeWidget->invisibleRootItem(), toProcess);
+
+  _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
+  for( int i = 0; i < toProcess.count(); i++) {
+    QTreeWidgetItem* item = toProcess[i];
+    if(item) {
+      QString entry = myEntryToItem.key(item);
+      _PTR(SObject) SO ( aStudy->FindObjectID(qPrintable(entry)) );
+      if(!SO) continue;
+      _PTR(AttributeDrawable) aDrw = aBuilder->FindOrCreateAttribute( SO, "AttributeDrawable" );
+      aDrw->SetDrawable( true );
+      //Remove or change item
+      if( item != myTreeWidget->invisibleRootItem() ){
+       if( item->data(0,Qt::UserRole).toBool() ) {
+         delete item;
+       } else {
+         item->setFlags(item->flags() & ~Qt::ItemIsUserCheckable);
+         item->setData(0,Qt::CheckStateRole,QVariant());
+       }
+      }
+    }
+  }
+  toProcess.clear();
+  getTails(myTreeWidget->invisibleRootItem(), toProcess);
+  for( int i = 0; i < toProcess.count(); i++) {
+    if( toProcess[i] != myTreeWidget->invisibleRootItem() )
+      delete toProcess[i];
+  }
+      
+  app->updateObjectBrowser( false );
+  app->updateActions();
+}
+
+//=================================================================================
+// function : clickOnOk()
+// purpose  : Called then "Publish And Close" button clicked
+//=================================================================================
+void GEOMToolsGUI_PublishDlg::clickOnOk() {
+  clickOnApply();
+  accept();
+}
+
+//=================================================================================
+// function : clickOnSelectAll()
+// purpose  : Called then "Select All" button clicked
+//=================================================================================
+void GEOMToolsGUI_PublishDlg::clickOnSelectAll() {
+  processAll(myTreeWidget->invisibleRootItem(),Qt::Checked);
+}
+
+//=================================================================================
+// function : clickOnUnSelectAll()
+// purpose  : Called then "Unselect All" button clicked
+//=================================================================================
+void GEOMToolsGUI_PublishDlg::clickOnUnSelectAll() {
+  processAll(myTreeWidget->invisibleRootItem(),Qt::Unchecked);
+}
+
+//=================================================================================
+// function : processAll()
+// purpose  : 
+//=================================================================================
+void GEOMToolsGUI_PublishDlg::processAll(QTreeWidgetItem* theItem, Qt::CheckState state) {
+  
+    
+  if((theItem->flags() & Qt::ItemIsUserCheckable))
+    theItem->setCheckState(0,state);
+  
+  int i = 0;
+  while(i < theItem->childCount()) {
+    processAll(theItem->child(i), state);
+    i++;
+  }
+}
+
+//=================================================================================
+// function : processAll()
+// purpose  : 
+//=================================================================================
+void GEOMToolsGUI_PublishDlg::getDrawableList(QTreeWidgetItem* theItem, QList<QTreeWidgetItem*>& theList) {
+  
+  theItem->setData(0, Qt::UserRole, true);
+
+  if((theItem->flags() & Qt::ItemIsUserCheckable) ) {
+    theItem->setData(0, Qt::UserRole,theItem->checkState(0) == Qt::Checked);
+  }
+  
+  int i = 0;
+  while(i < theItem->childCount()) {
+    getDrawableList(theItem->child(i), theList);
+    theItem->setData( 0, Qt::UserRole, (theItem->data(0,Qt::UserRole).toBool() && theItem->child(i)->data(0,Qt::UserRole).toBool()) );
+    i++;
+  } 
+
+  if( (theItem->flags() & Qt::ItemIsUserCheckable) && (theItem->checkState(0) == Qt::Checked))
+    theList.push_back(theItem);
+}
+
+
+void GEOMToolsGUI_PublishDlg::getTails(QTreeWidgetItem* theItem, QList<QTreeWidgetItem*>& theList) {
+  int i = 0;
+  while(i < theItem->childCount()) {
+    getTails(theItem->child(i),theList);
+    i++;
+  }
+
+  if(theItem->data(0,Qt::UserRole).toBool())
+    theList.push_back(theItem);
+}
diff --git a/src/GEOMToolsGUI/GEOMToolsGUI_PublishDlg.h b/src/GEOMToolsGUI/GEOMToolsGUI_PublishDlg.h
new file mode 100644 (file)
index 0000000..f78cd92
--- /dev/null
@@ -0,0 +1,83 @@
+//  Copyright (C) 2007-2010  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.
+//
+//  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
+//
+
+// GEOM GEOMGUI : GUI for Geometry component
+// File   : GEOMToolsGUI_PublishDlg.h
+// Author : Roman NIKOLAEV, Open CASCADE S.A.S.
+//
+
+#ifndef GEOMTOOLSGUI_PUBLISHDLG_H
+#define GEOMTOOLSGUI_PUBLISHDLG_H
+
+#include "GEOM_ToolsGUI.hxx"
+
+#include <QMap>
+#include <QList>
+#include <QDialog>
+#include <QTreeWidgetItem>
+
+
+
+
+#include <SALOMEDSClient.hxx>
+
+class QTreeWidget;
+class QTreeWidgetItem;
+
+class SalomeApp_DataObject;
+
+typedef QPair<QString, QString> Pair;
+typedef QList<Pair > BufferedList;
+typedef QMap<QString, QTreeWidgetItem*> Entry2ItemMap;
+
+class GEOMTOOLSGUI_EXPORT GEOMToolsGUI_PublishDlg : public QDialog
+{ 
+  Q_OBJECT
+
+public:
+  GEOMToolsGUI_PublishDlg( QWidget* );
+  ~GEOMToolsGUI_PublishDlg();
+
+protected:
+  void               initData();
+  void               buildTree(_PTR(Study) theStudy, SalomeApp_DataObject* theItem);
+  QTreeWidgetItem*   findParentItem(_PTR(Study) theStudy, SalomeApp_DataObject* theItem, BufferedList& theList);
+  QTreeWidgetItem*   createItem(QTreeWidgetItem* theItem, Pair theAttributes, bool isCheckable);
+  void               getDrawableList(QTreeWidgetItem* theItem, QList<QTreeWidgetItem*>& theList);
+  void               getTails(QTreeWidgetItem* theItem, QList<QTreeWidgetItem*>& theList);
+  
+protected slots:
+  void clickOnOk();
+  void clickOnApply();
+  void clickOnSelectAll();
+  void clickOnUnSelectAll();
+  
+private:  
+  QTreeWidget*           myTreeWidget;
+  SalomeApp_DataObject*  myGeomRoot;
+  Entry2ItemMap          myEntryToItem;
+  void processAll(QTreeWidgetItem* theItem, Qt::CheckState state);
+};
+
+
+
+#endif //GEOMTOOLSGUI_PUBLISHDLG_H
index 8f3ffbbd492cb6fddb8b02518c6ddd97ac0d8bf0..fb214b4483b0088ed3df9a0dcc7a207bcfed32b1 100644 (file)
@@ -34,7 +34,8 @@ salomeinclude_HEADERS =                               \
        GEOMToolsGUI_DeflectionDlg.h            \
        GEOMToolsGUI_TransparencyDlg.h          \
        GEOMToolsGUI_DeleteDlg.h                \
-       GEOMToolsGUI_MarkerDlg.h
+       GEOMToolsGUI_MarkerDlg.h                \
+       GEOMToolsGUI_PublishDlg.h
 
 dist_libGEOMToolsGUI_la_SOURCES =              \
        GEOMToolsGUI.cxx                        \
@@ -43,14 +44,16 @@ dist_libGEOMToolsGUI_la_SOURCES =           \
        GEOMToolsGUI_NbIsosDlg.cxx              \
        GEOMToolsGUI_DeflectionDlg.cxx          \
        GEOMToolsGUI_DeleteDlg.cxx              \
-       GEOMToolsGUI_MarkerDlg.cxx
+       GEOMToolsGUI_MarkerDlg.cxx              \
+       GEOMToolsGUI_PublishDlg.cxx
 
 MOC_FILES =                                    \
        GEOMToolsGUI_TransparencyDlg_moc.cxx    \
        GEOMToolsGUI_NbIsosDlg_moc.cxx          \
        GEOMToolsGUI_DeflectionDlg_moc.cxx      \
        GEOMToolsGUI_DeleteDlg_moc.cxx          \
-       GEOMToolsGUI_MarkerDlg_moc.cxx
+       GEOMToolsGUI_MarkerDlg_moc.cxx          \
+       GEOMToolsGUI_PublishDlg_moc.cxx
 
 nodist_libGEOMToolsGUI_la_SOURCES =            \
        $(MOC_FILES)