]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
- add new Dependency Tree selector
authormpa <mpa@opencascade.com>
Mon, 2 Jun 2014 08:20:08 +0000 (12:20 +0400)
committermpa <mpa@opencascade.com>
Mon, 2 Jun 2014 08:20:08 +0000 (12:20 +0400)
src/DependencyTree/CMakeLists.txt
src/DependencyTree/DependencyTree.cxx
src/DependencyTree/DependencyTree_Selector.cxx [new file with mode: 0644]
src/DependencyTree/DependencyTree_Selector.h [new file with mode: 0644]
src/DependencyTree/DependencyTree_View.cxx
src/DependencyTree/DependencyTree_View.h
src/DependencyTree/DependencyTree_ViewModel.cxx
src/GEOMGUI/GeometryGUI.cxx

index 2ab2bc27154870fde73c50a25eef94539cae23ec..4b5943fcde4425234081912123aa355335c43cc6 100644 (file)
@@ -74,6 +74,7 @@ SET(DependencyTree_HEADERS
   DependencyTree.h
   DependencyTree_Arrow.h
   DependencyTree_Object.h
+  DependencyTree_Selector.h
   )
 
 # header files / to be processed by moc
@@ -92,6 +93,7 @@ SET(DependencyTree_SOURCES
   DependencyTree_View.cxx
   DependencyTree_Object.cxx
   DependencyTree_Arrow.cxx
+  DependencyTree_Selector.cxx
   #arrow.cxx
   DependencyTree_ViewModel.cxx
   ${_moc_SOURCES}
index 583ba43e88cf9a2141f722de7754a34ba43c485a..97b428988866d418f417b29b7f9e150704dc152e 100644 (file)
 #include <QtxActionToolMgr.h>
 
 #include "DependencyTree_View.h"
+#include <DependencyTree_Selector.h>
+
 #include <GraphicsView_Viewer.h>
 #include <GraphicsView_ViewFrame.h>
 #include <GraphicsView_Scene.h>
 
 #include <SUIT_Session.h>
 #include <SUIT_ViewManager.h>
+#include <SUIT_SelectionMgr.h>
 #include <SalomeApp_Application.h>
 
+
 #include <QList>
 #include <QGraphicsView>
 
@@ -58,12 +62,16 @@ DependencyTree::DependencyTree()
          SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
            if ( !app ) return;
 
+           LightApp_SelectionMgr* mySelMgr = app->selectionMgr();
+
            SUIT_ViewManager *svm = app->getViewManager(GraphicsView_Viewer::Type(), false );
 
            if(!svm) {
              myView = new DependencyTree_View();
              DependencyTree_ViewModel* ViewModel = new DependencyTree_ViewModel(GraphicsView_Viewer::Type(), myView);
              SUIT_ViewManager *svm = app->createViewManager( ViewModel );
+             new DependencyTree_Selector( ViewModel,
+                        ( SUIT_SelectionMgr*)mySelMgr );
              SUIT_ViewWindow* svw = svm->getActiveView();
              GraphicsView_ViewFrame* aViewFrame = 0;
              if (!svw) svw = svm->createViewWindow();
diff --git a/src/DependencyTree/DependencyTree_Selector.cxx b/src/DependencyTree/DependencyTree_Selector.cxx
new file mode 100644 (file)
index 0000000..5c1c9a7
--- /dev/null
@@ -0,0 +1,101 @@
+// Copyright (C) 2014  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// 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, or (at your option) any later version.
+//
+// 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
+//
+
+#include "DependencyTree_Selector.h"
+#include "DependencyTree_View.h"
+#include "DependencyTree_ViewModel.h"
+#include "DependencyTree_Object.h"
+
+// GUI includes
+#include <LightApp_DataOwner.h>
+
+//GEOM includes
+#include <GEOMBase.h>
+
+#include <iostream>
+
+DependencyTree_Selector::DependencyTree_Selector( DependencyTree_ViewModel* theModel, SUIT_SelectionMgr* theSelMgr )
+:LightApp_GVSelector( (GraphicsView_Viewer*)theModel, theSelMgr )
+{
+  myView = dynamic_cast<DependencyTree_View*>( theModel->getActiveViewPort() );
+}
+
+DependencyTree_Selector::~DependencyTree_Selector()
+{
+}
+
+//=================================================================================
+// function : getSelection()
+// purpose  : get list of selected Data Owner objects.
+//=================================================================================
+void DependencyTree_Selector::getSelection( SUIT_DataOwnerPtrList& theList ) const
+{
+  for( myView->initSelected(); myView->moreSelected(); myView->nextSelected() )
+    if( DependencyTree_Object* treeObject = dynamic_cast<DependencyTree_Object*>( myView->selectedObject() ) ) {
+      const char* entry;
+      const char* name;
+      QString studyEntry = treeObject->getGeomObject()->GetStudyEntry();
+      if( studyEntry.isEmpty() ) {
+        entry = treeObject->getEntry().c_str();
+        name = "TEMP_IO_UNPUBLISHED";
+      }
+      else {
+        entry = studyEntry.toStdString().c_str();
+        name = "TEMP_IO";
+      }
+      Handle(SALOME_InteractiveObject) tmpIO =
+        new SALOME_InteractiveObject( entry, "GEOM", name);
+
+      theList.append( new LightApp_DataOwner( tmpIO ) );
+  }
+}
+
+//=================================================================================
+// function : setSelection()
+// purpose  : set to selected list of Data Owner objects.
+//=================================================================================
+void DependencyTree_Selector::setSelection( const SUIT_DataOwnerPtrList& theList )
+{
+  myView->clearSelected();
+
+  for ( SUIT_DataOwnerPtrList::const_iterator it = theList.begin(); it != theList.end(); ++it ) {
+    const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*it).operator->() );
+    if ( owner )
+      if( !owner->IO().IsNull() ) {
+        const char* name = owner->IO()->getName();
+        const char* entry;
+        if( strcmp( owner->IO()->getComponentDataType(), "GEOM" ) != 0 )
+          return;
+
+        if( strcmp( name, "TEMP_IO_UNPUBLISHED" ) == 0 )
+          entry = owner->IO()->getEntry();
+       else {
+          GEOM::GEOM_Object_var geomObject = GEOMBase::ConvertIOinGEOMObject( owner->IO() );
+          if( geomObject->_is_nil() )
+            return;
+          entry = geomObject->GetEntry();
+       }
+        DependencyTree_Object* object = myView->getObjectByEntry( QString( entry ) );
+        if( object ) {
+           myView->setSelected( object );
+           object->select( object->pos().x(), object->pos().y(), object->getRect() );
+        }
+      }
+  }
+}
diff --git a/src/DependencyTree/DependencyTree_Selector.h b/src/DependencyTree/DependencyTree_Selector.h
new file mode 100644 (file)
index 0000000..9ff9c9e
--- /dev/null
@@ -0,0 +1,44 @@
+// Copyright (C) 2014  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// 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, or (at your option) any later version.
+//
+// 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
+//
+
+#ifndef DEPENDENCYTREE_SELECTOR_H
+#define DEPENDENCYTREE_SELECTOR_H
+
+#include <LightApp_GVSelector.h>
+
+class DependencyTree_ViewModel;
+class DependencyTree_View;
+
+class DependencyTree_Selector: public LightApp_GVSelector
+{
+
+public:
+  DependencyTree_Selector( DependencyTree_ViewModel*, SUIT_SelectionMgr* );
+  ~DependencyTree_Selector();
+
+protected:
+  virtual void getSelection( SUIT_DataOwnerPtrList& ) const;
+  virtual void setSelection( const SUIT_DataOwnerPtrList& );
+
+private:
+  DependencyTree_View* myView;
+
+};
+
+#endif
index 8841b047470c48e76c45d23e78d976c5725a8298..e17a506e2cc3d185463c0b46e1653796f954b0ba 100644 (file)
@@ -21,8 +21,6 @@
 #include "DependencyTree_Object.h"
 #include "DependencyTree_Arrow.h"
 
-#include <GEOM_InteractiveObject.hxx>
-#include <GeometryGUI.h>
 #include <GEOMBase.h>
 
 // GUI includes
@@ -61,6 +59,8 @@ myComputedCost(0)
   mySelectionMgr = app->selectionMgr();
   if ( !mySelectionMgr ) return;
 
+  myMainEntries = new GEOM::string_array();
+
   getNewTreeModel();
 }
 
@@ -136,7 +136,7 @@ void DependencyTree_View::init( GraphicsView_ViewFrame* theViewFrame )
   connect( myHierarchyDepth, SIGNAL( valueChanged ( int ) ), this, SLOT( onHierarchyType() ) );
   connect( myDisplayAscendants , SIGNAL( toggled( bool ) ), this, SLOT( onHierarchyType() ) );
   connect( myDisplayDescendants, SIGNAL( toggled( bool ) ), this, SLOT( onHierarchyType() ) );
-  connect( updateButton, SIGNAL( clicked() ), this, SLOT( onUpdateModel( false ) ) );
+  connect( updateButton, SIGNAL( clicked() ), this, SLOT( onUpdateModel() ) );
   connect( cancelButton, SIGNAL( clicked() ), this, SLOT( onCancel() ) );
 
   setPrefBackgroundColor( resMgr->colorValue( "Geometry", "dependency_tree_background_color", QColor( 255, 255, 255 ) ) );
@@ -144,15 +144,10 @@ void DependencyTree_View::init( GraphicsView_ViewFrame* theViewFrame )
   setHierarchyType( resMgr->integerValue( "Geometry", "dependency_tree_hierarchy_type", 0 ) );
 }
 
-void DependencyTree_View::updateModel( bool getSelectedObjects )
+void DependencyTree_View::updateModel( bool theUseSelectedObject, bool theUseOB )
 {
-  getNewTreeModel( getSelectedObjects );
-
-  SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
-
-  setPrefBackgroundColor( resMgr->colorValue( "Geometry", "dependency_tree_background_color", QColor( 255, 255, 255 ) ) );
-  setNodesMovable( resMgr->booleanValue( "Geometry", "dependency_tree_move_nodes", true ) );
-  setHierarchyType( resMgr->integerValue( "Geometry", "dependency_tree_hierarchy_type", 0 ) );
+  getNewTreeModel( theUseSelectedObject, theUseOB );
+  onHierarchyType();
 }
 
 void DependencyTree_View::drawTree()
@@ -235,25 +230,6 @@ void DependencyTree_View::drawTree()
 
 }
 
-int DependencyTree_View::select( const QRectF& theRect, bool theIsAppend )
-{
-  GraphicsView_ViewPort::select( theRect, theIsAppend );
-
-  mySelectionMgr->clearSelected();
-
-  // get selection
-  SALOME_ListIO listIO;
-  int StudyId = myStudy->StudyId();
-  for( initSelected(); moreSelected(); nextSelected() )
-    if( DependencyTree_Object* treeObject = dynamic_cast<DependencyTree_Object*>( selectedObject() ) ) {
-      CORBA::String_var studyEntry = treeObject->getGeomObject()->GetStudyEntry();
-      Handle(SALOME_InteractiveObject) tmpIO =
-        new SALOME_InteractiveObject( studyEntry.in(), "GEOM", "TEMP_IO");
-      listIO.Append( tmpIO );
-    }
-  mySelectionMgr->setSelectedObjects( listIO, true );
-}
-
 void DependencyTree_View::customEvent( QEvent * event )
 {
   if( event->type() == DRAW_EVENT ) {
@@ -295,6 +271,11 @@ void DependencyTree_View::mouseMoveEvent(QMouseEvent *event)
   }
 }
 
+DependencyTree_Object* DependencyTree_View::getObjectByEntry( QString theEntry )
+{
+  return myTreeMap[theEntry.toStdString()];
+}
+
 void DependencyTree_View::setHierarchyType( const int theType )
 {
   myIsUpdate = false;
@@ -427,9 +408,14 @@ void DependencyTree_View::closeEvent( QCloseEvent* event )
   event->accept();
 }
 
-void DependencyTree_View::onUpdateModel( bool getSelectedObjects )
+void DependencyTree_View::onUpdateModel()
+{
+  updateModel( false );
+}
+
+void DependencyTree_View::onRebuildModel()
 {
-  updateModel( getSelectedObjects );
+  updateModel( true, false );
 }
 
 void DependencyTree_View::updateView()
@@ -614,32 +600,46 @@ void DependencyTree_View::drawWardArrows( GEOMUtils::LevelsList theWard )
   }
 }
 
-void DependencyTree_View::getNewTreeModel( bool getSelectedObjects )
+void DependencyTree_View::getNewTreeModel( bool theUseSelectedObject, bool theUseOB )
 {
-  clearView( true );
 
-  if( getSelectedObjects )
-    mySelectionMgr->selectedObjects( myMainObjects );
-
-  // create a list of selected object entry
   GEOM::string_array_var objectsEntry = new GEOM::string_array();
-  objectsEntry->length( myMainObjects.Extent());
   int iter = 0;
-  for ( SALOME_ListIteratorOfListIO It( myMainObjects ); It.More(); It.Next(), iter++ ) {
-    Handle( SALOME_InteractiveObject ) io = It.Value();
-    GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_nil();
-    geomObject = GEOMBase::ConvertIOinGEOMObject( io );
-    QString entry = geomObject->GetEntry();
-    objectsEntry[ iter ] = entry.toLatin1().constData();
+
+  if( theUseSelectedObject ) {
+    if( theUseOB ) {
+      SALOME_ListIO mainObjects;
+      mySelectionMgr->selectedObjects( mainObjects );
+      // create a list of selected object entry
+      objectsEntry->length( mainObjects.Extent());
+      for ( SALOME_ListIteratorOfListIO It( mainObjects ); It.More(); It.Next(), iter++ ) {
+        Handle( SALOME_InteractiveObject ) io = It.Value();
+        GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_nil();
+        geomObject = GEOMBase::ConvertIOinGEOMObject( io );
+        QString entry = geomObject->GetEntry();
+        objectsEntry[ iter ] = entry.toLatin1().constData();
+      }
+    }
+    else {
+      objectsEntry->length( nbSelected() );
+      for( initSelected(); moreSelected(); nextSelected(), iter++ )
+        if( DependencyTree_Object* treeObject = dynamic_cast<DependencyTree_Object*>( selectedObject() ) ) {
+          objectsEntry[ iter ] = treeObject->getEntry().c_str();
+          std::cout << "\n\n\n ----------- entry = " << treeObject->getEntry() << std::endl;
+        }
+    }
+
+    myMainEntries = objectsEntry;
   }
 
   // get string which describes dependency tree structure
   SALOMEDS::TMPFile_var SeqFile =
-    GeometryGUI::GetGeomGen()->GetDependencyTree( myStudy, objectsEntry );
+    GeometryGUI::GetGeomGen()->GetDependencyTree( myStudy, myMainEntries );
   char* buf = (char*) &SeqFile[0];
 
   std::cout << "\n\n\n\n\n TREE = " << buf << std::endl;
 
+  clearView( true );
   // get dependency tree structure
   GEOMUtils::ConvertStringToTree( buf, myTreeModel );
 
index accc5e62408e9b64ed3ce16c72e87ff594b024af..4c1b86e8d6d26c60c425e629ca56755a9d58603b 100644 (file)
@@ -29,6 +29,9 @@
 #include <SALOME_ListIO.hxx>
 
 #include <GEOMUtils.hxx>
+#include <GEOM_InteractiveObject.hxx>
+#include <GeometryGUI.h>
+
 
 #include <QWidgetAction>
 #include <QPushButton>
@@ -74,13 +77,14 @@ public:
   ~DependencyTree_View();
 
   void init( GraphicsView_ViewFrame* );
-  void updateModel( bool = true );
+  void updateModel( bool = true, bool = true );
   void drawTree();
 
-  virtual int select( const QRectF&, bool );
   virtual void customEvent ( QEvent* );
   void mouseMoveEvent(QMouseEvent *event);
 
+  DependencyTree_Object* getObjectByEntry( QString );
+
   void setHierarchyType( const int );
   void setNodesMovable( const bool );
   void setPrefBackgroundColor( const QColor& );
@@ -99,7 +103,8 @@ public:
   QMutex myMutex;
 
 public slots:
-  void onUpdateModel( bool = true );
+  void onUpdateModel();
+  void onRebuildModel();
 
 protected:
   void closeEvent( QCloseEvent* );
@@ -126,7 +131,7 @@ private:
                  std::map< int, std::vector< std::string > >&, int, const int );
   void drawWardArrows( GEOMUtils::LevelsList );
 
-  void getNewTreeModel( bool = true );
+  void getNewTreeModel( bool = true, bool = true );
   void clearView( bool );
 
   int checkMaxLevelsNumber();
@@ -163,7 +168,7 @@ private:
 
   DependencyTree_ComputeDlg_QThread* qthread;
 
-  SALOME_ListIO myMainObjects;
+  GEOM::string_array_var myMainEntries;
 
   SALOMEDS::Study_var myStudy;
   LightApp_SelectionMgr* mySelectionMgr;
index 813e94c728200cfb5f83604bb30c9a904f3a592b..afeda3d6151642a33461e978e00be6194bd90f5d 100644 (file)
@@ -128,7 +128,7 @@ void DependencyTree_ViewModel::contextMenuPopup( QMenu* theMenu )
       theMenu->clear();
       theMenu->addAction( tr( "MEN_DISPLAY" ), this, SLOT( onShowSelected() ) );
       theMenu->addAction( tr( "MEN_DISPLAY_ONLY" ), this, SLOT( onShowOnlySelected() ) );
-      theMenu->addAction( tr( "REBUILD_THE_TREE"), aViewPort, SLOT( onUpdateModel() ) );
+      theMenu->addAction( tr( "REBUILD_THE_TREE"), aViewPort, SLOT( onRebuildModel() ) );
     }
   }
 
index c93a2824118e0eb76ab6af92bfd377d9d19150bd..8fed3dfef05e952ba0a84b39e0e021ffbb7b5962 100644 (file)
@@ -1630,7 +1630,7 @@ void GeometryGUI::initialize( CAM_Application* app )
 
   mgr->insert( separator(), -1, -1 );     // -----------
   mgr->insert( action(  GEOMOp::OpShowDependencyTree ), -1, -1 ); // Show dependency tree
-  mgr->setRule( action( GEOMOp::OpShowDependencyTree ), clientOCCorVTKorOB + " and selcount>0" + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
+  mgr->setRule( action( GEOMOp::OpShowDependencyTree ), clientOCCorVTKorOB + " and selcount>0 and ($component={'GEOM'}) and type='Shape'", QtxPopupMgr::VisibleRule );
 
   mgr->hide( mgr->actionId( action( myEraseAll ) ) );