2014-05-21 19:42:20 +06:00
|
|
|
// 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
|
|
|
|
//
|
|
|
|
|
2014-06-03 12:14:22 +06:00
|
|
|
// Internal includes
|
2014-05-21 19:42:20 +06:00
|
|
|
#include "DependencyTree_View.h"
|
|
|
|
#include "DependencyTree_Object.h"
|
|
|
|
#include "DependencyTree_Arrow.h"
|
|
|
|
|
|
|
|
// GUI includes
|
|
|
|
#include <SUIT_Session.h>
|
|
|
|
#include <SUIT_ResourceMgr.h>
|
|
|
|
#include <SalomeApp_Study.h>
|
2014-05-23 14:09:19 +06:00
|
|
|
#include <QtxActionToolMgr.h>
|
2014-05-21 19:42:20 +06:00
|
|
|
#include <LightApp_SelectionMgr.h>
|
|
|
|
#include <SALOME_ListIteratorOfListIO.hxx>
|
|
|
|
|
2014-06-03 12:14:22 +06:00
|
|
|
// GEOM includes
|
|
|
|
#include <GEOMBase.h>
|
|
|
|
|
2014-05-23 14:09:19 +06:00
|
|
|
// Qt includes
|
2014-05-28 17:07:18 +06:00
|
|
|
#include <QApplication>
|
2014-06-04 15:01:12 +06:00
|
|
|
#include <QWidgetAction>
|
2014-05-21 19:42:20 +06:00
|
|
|
|
|
|
|
DependencyTree_View::DependencyTree_View( QWidget* theParent )
|
2014-06-03 12:14:22 +06:00
|
|
|
:GraphicsView_ViewPort( theParent ),
|
2014-06-04 15:01:12 +06:00
|
|
|
myLevelsNumber(0),
|
2014-05-21 19:42:20 +06:00
|
|
|
myMaxDownwardLevelsNumber(0),
|
|
|
|
myMaxUpwardLevelsNumber(0),
|
2014-06-04 15:01:12 +06:00
|
|
|
myIsUpdate( true )
|
2014-05-21 19:42:20 +06:00
|
|
|
{
|
|
|
|
SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
|
|
|
|
if ( !app ) return;
|
|
|
|
|
2014-05-28 17:06:55 +06:00
|
|
|
SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
|
|
|
|
myStudy = GeometryGUI::ClientStudyToStudy( study->studyDS());
|
2014-05-21 19:42:20 +06:00
|
|
|
|
2014-05-28 17:06:55 +06:00
|
|
|
mySelectionMgr = app->selectionMgr();
|
|
|
|
if ( !mySelectionMgr ) return;
|
2014-05-23 14:09:19 +06:00
|
|
|
|
2014-06-02 14:20:08 +06:00
|
|
|
myMainEntries = new GEOM::string_array();
|
|
|
|
|
2014-05-28 17:06:55 +06:00
|
|
|
getNewTreeModel();
|
2014-05-21 19:42:20 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
DependencyTree_View::~DependencyTree_View()
|
|
|
|
{
|
2014-06-04 15:01:12 +06:00
|
|
|
clearView( true );
|
2014-05-21 19:42:20 +06:00
|
|
|
}
|
|
|
|
|
2014-06-04 15:01:12 +06:00
|
|
|
//=================================================================================
|
|
|
|
// function : init()
|
|
|
|
// purpose : this method is obligatory for initialize view frame actions
|
|
|
|
//=================================================================================
|
2014-05-21 19:42:20 +06:00
|
|
|
void DependencyTree_View::init( GraphicsView_ViewFrame* theViewFrame )
|
|
|
|
{
|
|
|
|
myNodesMovable = new QCheckBox( tr( "MOVE_NODES" ) );
|
2014-05-28 17:06:55 +06:00
|
|
|
QWidgetAction* nodesMovableAction = new QWidgetAction( theViewFrame );
|
|
|
|
nodesMovableAction->setDefaultWidget( myNodesMovable );
|
2014-05-21 19:42:20 +06:00
|
|
|
|
2014-05-28 17:06:55 +06:00
|
|
|
myDisplayAscendants = new QCheckBox( tr( "DISPLAY_ASCENDANTS" ) );
|
2014-06-04 15:01:12 +06:00
|
|
|
QWidgetAction* displayAscendantsAction = new QWidgetAction( theViewFrame );
|
|
|
|
displayAscendantsAction->setDefaultWidget( myDisplayAscendants );
|
2014-05-21 19:42:20 +06:00
|
|
|
|
|
|
|
myDisplayDescendants = new QCheckBox(tr("DISPLAY_DESCENDANTS"));
|
2014-06-04 15:01:12 +06:00
|
|
|
QWidgetAction* displayDescendantsAction = new QWidgetAction( theViewFrame );
|
|
|
|
displayDescendantsAction->setDefaultWidget( myDisplayDescendants );
|
2014-05-21 19:42:20 +06:00
|
|
|
|
2014-05-28 17:06:55 +06:00
|
|
|
QLabel* hierarchyDepthLabel = new QLabel( tr( "HIERARCHY_DEPTH" ) );
|
2014-06-04 15:01:12 +06:00
|
|
|
QWidgetAction* hierarchyDepthLabelAction = new QWidgetAction( theViewFrame );
|
2014-05-28 17:06:55 +06:00
|
|
|
hierarchyDepthLabelAction->setDefaultWidget( hierarchyDepthLabel );
|
|
|
|
|
2014-05-21 19:42:20 +06:00
|
|
|
myLevelsNumber = checkMaxLevelsNumber();
|
2014-05-28 17:06:55 +06:00
|
|
|
|
2014-05-21 19:42:20 +06:00
|
|
|
myHierarchyDepth = new QSpinBox();
|
|
|
|
myHierarchyDepth->setRange( 0, checkMaxLevelsNumber() );
|
2014-05-28 17:06:55 +06:00
|
|
|
myHierarchyDepth->setSpecialValueText( tr( "SHOW_ALL" ) );
|
2014-05-21 19:42:20 +06:00
|
|
|
myHierarchyDepth->setValue( 0 );
|
2014-05-28 17:06:55 +06:00
|
|
|
QWidgetAction* hierarchyDepthAction = new QWidgetAction( theViewFrame );
|
|
|
|
hierarchyDepthAction->setDefaultWidget( myHierarchyDepth );
|
2014-05-21 19:42:20 +06:00
|
|
|
|
2014-05-28 17:07:18 +06:00
|
|
|
updateButton = new QPushButton( tr( "UPDATE" ) );
|
2014-05-28 17:06:55 +06:00
|
|
|
QWidgetAction* updateAction = new QWidgetAction( theViewFrame );
|
|
|
|
updateAction->setDefaultWidget( updateButton );
|
2014-05-21 19:42:20 +06:00
|
|
|
|
2014-05-28 17:06:55 +06:00
|
|
|
QAction* separator1 = theViewFrame->toolMgr()->separator( false );
|
|
|
|
QAction* separator2 = theViewFrame->toolMgr()->separator( false );
|
2014-05-21 19:42:20 +06:00
|
|
|
|
2014-05-28 17:06:55 +06:00
|
|
|
theViewFrame->toolMgr()->append( separator1, theViewFrame->getToolBarId() );
|
|
|
|
theViewFrame->toolMgr()->append( hierarchyDepthLabelAction, theViewFrame->getToolBarId() );
|
|
|
|
theViewFrame->toolMgr()->append( hierarchyDepthAction, theViewFrame->getToolBarId() );
|
2014-06-04 15:01:12 +06:00
|
|
|
theViewFrame->toolMgr()->append( displayAscendantsAction, theViewFrame->getToolBarId() );
|
|
|
|
theViewFrame->toolMgr()->append( displayDescendantsAction, theViewFrame->getToolBarId() );
|
2014-06-03 12:14:22 +06:00
|
|
|
theViewFrame->toolMgr()->append( nodesMovableAction, theViewFrame->getToolBarId() );
|
2014-05-28 17:06:55 +06:00
|
|
|
|
2014-05-21 19:42:20 +06:00
|
|
|
theViewFrame->toolMgr()->append( separator2, theViewFrame->getToolBarId() );
|
2014-05-28 17:06:55 +06:00
|
|
|
theViewFrame->toolMgr()->append( updateAction, theViewFrame->getToolBarId() );
|
2014-05-21 19:42:20 +06:00
|
|
|
|
2014-05-28 17:06:55 +06:00
|
|
|
connect( myNodesMovable, SIGNAL( toggled( bool ) ), this, SLOT( onMoveNodes( bool ) ) );
|
2014-05-21 19:42:20 +06:00
|
|
|
connect( myHierarchyDepth, SIGNAL( valueChanged ( int ) ), this, SLOT( onHierarchyType() ) );
|
2014-05-28 17:06:55 +06:00
|
|
|
connect( myDisplayAscendants , SIGNAL( toggled( bool ) ), this, SLOT( onHierarchyType() ) );
|
|
|
|
connect( myDisplayDescendants, SIGNAL( toggled( bool ) ), this, SLOT( onHierarchyType() ) );
|
2014-06-02 14:20:08 +06:00
|
|
|
connect( updateButton, SIGNAL( clicked() ), this, SLOT( onUpdateModel() ) );
|
2014-06-04 15:01:12 +06:00
|
|
|
|
|
|
|
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
|
2014-05-21 19:42:20 +06:00
|
|
|
|
|
|
|
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 ) );
|
|
|
|
}
|
|
|
|
|
2014-06-04 15:01:12 +06:00
|
|
|
//=================================================================================
|
|
|
|
// function : updateModel()
|
|
|
|
// purpose : run all stage of dependency tree creation
|
|
|
|
//=================================================================================
|
2014-06-02 14:20:08 +06:00
|
|
|
void DependencyTree_View::updateModel( bool theUseSelectedObject, bool theUseOB )
|
2014-05-21 19:42:20 +06:00
|
|
|
{
|
2014-06-02 14:20:08 +06:00
|
|
|
getNewTreeModel( theUseSelectedObject, theUseOB );
|
|
|
|
onHierarchyType();
|
2014-05-21 19:42:20 +06:00
|
|
|
}
|
|
|
|
|
2014-06-04 15:01:12 +06:00
|
|
|
//=================================================================================
|
|
|
|
// function : mouseMoveEvent()
|
|
|
|
// purpose : make some actions when mouse was moved
|
|
|
|
//=================================================================================
|
|
|
|
void DependencyTree_View::mouseMoveEvent( QMouseEvent *event )
|
2014-05-28 17:06:55 +06:00
|
|
|
{
|
2014-06-04 15:01:12 +06:00
|
|
|
QGraphicsView::mouseMoveEvent( event );
|
|
|
|
ArrowsInfo::const_iterator i;
|
|
|
|
for( i = myArrows.begin(); i != myArrows.end(); i++ ) {
|
|
|
|
DependencyTree_Arrow* arrow = myArrows[ i->first ];
|
|
|
|
arrow->update();
|
2014-05-28 17:06:55 +06:00
|
|
|
}
|
2014-05-21 19:42:20 +06:00
|
|
|
}
|
|
|
|
|
2014-06-04 15:01:12 +06:00
|
|
|
//=================================================================================
|
|
|
|
// function : getViewName()
|
|
|
|
// purpose : return the name of current view
|
|
|
|
//=================================================================================
|
|
|
|
QString DependencyTree_View::getViewName() const
|
2014-05-28 17:07:18 +06:00
|
|
|
{
|
2014-06-04 15:01:12 +06:00
|
|
|
return tr( "DEPENDENCY_TREE" );
|
2014-05-28 17:07:18 +06:00
|
|
|
}
|
|
|
|
|
2014-06-04 15:01:12 +06:00
|
|
|
//=================================================================================
|
|
|
|
// function : getStudyId()
|
|
|
|
// purpose : return Id of current study
|
|
|
|
//=================================================================================
|
|
|
|
int DependencyTree_View::getStudyId() const
|
2014-05-28 17:07:18 +06:00
|
|
|
{
|
2014-06-04 15:01:12 +06:00
|
|
|
return myStudy->StudyId();
|
2014-05-28 17:07:18 +06:00
|
|
|
}
|
|
|
|
|
2014-06-04 15:01:12 +06:00
|
|
|
//=================================================================================
|
|
|
|
// function : getObjectByEntry()
|
|
|
|
// purpose : return DependencyTree_Object by entry
|
|
|
|
//=================================================================================
|
|
|
|
DependencyTree_Object* DependencyTree_View::getObjectByEntry( const std::string& theEntry )
|
2014-05-21 19:42:20 +06:00
|
|
|
{
|
2014-06-04 15:01:12 +06:00
|
|
|
return myTreeMap[ theEntry ];
|
2014-05-21 19:42:20 +06:00
|
|
|
}
|
|
|
|
|
2014-06-04 15:01:12 +06:00
|
|
|
//=================================================================================
|
|
|
|
// function : updateObjectName()
|
|
|
|
// purpose : update object name, having edited it in Object Browser
|
|
|
|
//=================================================================================
|
|
|
|
bool DependencyTree_View::updateObjectName( const std::string& theEntry )
|
2014-06-02 14:20:08 +06:00
|
|
|
{
|
2014-06-04 15:01:12 +06:00
|
|
|
bool res = false;
|
|
|
|
for( initSelected(); moreSelected(); nextSelected() ) {
|
|
|
|
if( DependencyTree_Object* aDepObject = dynamic_cast<DependencyTree_Object*>( selectedObject() ) ) {
|
|
|
|
aDepObject->updateName();
|
|
|
|
res = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
2014-06-02 14:20:08 +06:00
|
|
|
}
|
|
|
|
|
2014-06-04 15:01:12 +06:00
|
|
|
//=================================================================================
|
|
|
|
// function : setHierarchyType()
|
|
|
|
// purpose : set hierarchy type of dependency tree
|
|
|
|
//=================================================================================
|
2014-05-21 19:42:20 +06:00
|
|
|
void DependencyTree_View::setHierarchyType( const int theType )
|
|
|
|
{
|
|
|
|
myIsUpdate = false;
|
|
|
|
switch( theType ) {
|
|
|
|
case 0:
|
|
|
|
myDisplayAscendants->setChecked( true );
|
|
|
|
myDisplayDescendants->setChecked( true );
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
myDisplayAscendants->setChecked( true );
|
|
|
|
myDisplayDescendants->setChecked( false );
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
myDisplayAscendants->setChecked( false );
|
|
|
|
myDisplayDescendants->setChecked( true );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
myIsUpdate = true;
|
2014-05-28 17:06:55 +06:00
|
|
|
myLevelsNumber = checkMaxLevelsNumber();
|
2014-05-21 19:42:20 +06:00
|
|
|
onHierarchyType();
|
|
|
|
}
|
|
|
|
|
2014-06-04 15:01:12 +06:00
|
|
|
//=================================================================================
|
|
|
|
// function : setNodesMovable()
|
|
|
|
// purpose : set possibility to move nodes or not
|
|
|
|
//=================================================================================
|
2014-05-21 19:42:20 +06:00
|
|
|
void DependencyTree_View::setNodesMovable( const bool theIsMovable )
|
|
|
|
{
|
|
|
|
myNodesMovable->setChecked( theIsMovable );
|
|
|
|
}
|
|
|
|
|
2014-06-04 15:01:12 +06:00
|
|
|
//=================================================================================
|
|
|
|
// function : setPrefBackgroundColor()
|
|
|
|
// purpose : set background color from preferences
|
|
|
|
//=================================================================================
|
2014-05-21 19:42:20 +06:00
|
|
|
void DependencyTree_View::setPrefBackgroundColor( const QColor& theColor )
|
|
|
|
{
|
|
|
|
if( isForegroundEnabled() )
|
|
|
|
{
|
|
|
|
setForegroundColor( theColor );
|
|
|
|
updateForeground();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
setBackgroundColor( theColor );
|
|
|
|
}
|
|
|
|
|
2014-06-04 15:01:12 +06:00
|
|
|
//=================================================================================
|
|
|
|
// function : setNodeColor()
|
|
|
|
// purpose : set node color from preferences
|
|
|
|
//=================================================================================
|
2014-05-21 19:42:20 +06:00
|
|
|
void DependencyTree_View::setNodeColor( const QColor& theColor )
|
|
|
|
{
|
2014-05-28 17:06:55 +06:00
|
|
|
EntryObjectMap::const_iterator i;
|
2014-06-04 15:01:12 +06:00
|
|
|
for( i = myTreeMap.begin(); i != myTreeMap.end(); i++ ) {
|
2014-05-23 14:09:19 +06:00
|
|
|
DependencyTree_Object* object = myTreeMap[ i->first ];
|
2014-05-21 19:42:20 +06:00
|
|
|
object->setColor( theColor );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-04 15:01:12 +06:00
|
|
|
//=================================================================================
|
|
|
|
// function : setMainNodeColor()
|
|
|
|
// purpose : set main node color from preferences
|
|
|
|
//=================================================================================
|
2014-05-21 19:42:20 +06:00
|
|
|
void DependencyTree_View::setMainNodeColor( const QColor& theColor )
|
|
|
|
{
|
2014-05-28 17:06:55 +06:00
|
|
|
EntryObjectMap::const_iterator i;
|
2014-06-04 15:01:12 +06:00
|
|
|
for( i = myTreeMap.begin(); i != myTreeMap.end(); i++ ) {
|
2014-05-23 14:09:19 +06:00
|
|
|
DependencyTree_Object* object = myTreeMap[ i->first ];
|
2014-05-21 19:42:20 +06:00
|
|
|
object->setMainObjectColor( theColor );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-04 15:01:12 +06:00
|
|
|
//=================================================================================
|
|
|
|
// function : setSelectNodeColor()
|
|
|
|
// purpose : set selected node color from preferences
|
|
|
|
//=================================================================================
|
2014-05-21 19:42:20 +06:00
|
|
|
void DependencyTree_View::setSelectNodeColor( const QColor& theColor )
|
|
|
|
{
|
2014-05-28 17:06:55 +06:00
|
|
|
EntryObjectMap::const_iterator i;
|
2014-06-04 15:01:12 +06:00
|
|
|
for( i = myTreeMap.begin(); i != myTreeMap.end(); i++ ) {
|
2014-05-23 14:09:19 +06:00
|
|
|
DependencyTree_Object* object = myTreeMap[ i->first ];
|
2014-05-21 19:42:20 +06:00
|
|
|
object->setSelectColor( theColor );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-04 15:01:12 +06:00
|
|
|
//=================================================================================
|
|
|
|
// function : setArrowColor()
|
|
|
|
// purpose : set arrow color from preferences
|
|
|
|
//=================================================================================
|
2014-05-21 19:42:20 +06:00
|
|
|
void DependencyTree_View::setArrowColor( const QColor& theColor )
|
|
|
|
{
|
2014-06-04 15:01:12 +06:00
|
|
|
ArrowsInfo::const_iterator i;
|
|
|
|
for( i = myArrows.begin(); i != myArrows.end(); i++ ) {
|
|
|
|
DependencyTree_Arrow* arrow = myArrows[ i->first ];
|
2014-05-21 19:42:20 +06:00
|
|
|
arrow->setColor( theColor );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-04 15:01:12 +06:00
|
|
|
//=================================================================================
|
|
|
|
// function : setHighlightArrowColor()
|
|
|
|
// purpose : set highlighted arrow color from preferences
|
|
|
|
//=================================================================================
|
2014-05-21 19:42:20 +06:00
|
|
|
void DependencyTree_View::setHighlightArrowColor( const QColor& theColor )
|
|
|
|
{
|
2014-06-04 15:01:12 +06:00
|
|
|
ArrowsInfo::const_iterator i;
|
|
|
|
for( i = myArrows.begin(); i != myArrows.end(); i++ ) {
|
|
|
|
DependencyTree_Arrow* arrow = myArrows[ i->first ];
|
2014-05-21 19:42:20 +06:00
|
|
|
arrow->setHighlightColor( theColor );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-04 15:01:12 +06:00
|
|
|
//=================================================================================
|
|
|
|
// function : setSelectArrowColor()
|
|
|
|
// purpose : set selected arrow color from preferences
|
|
|
|
//=================================================================================
|
2014-05-21 19:42:20 +06:00
|
|
|
void DependencyTree_View::setSelectArrowColor( const QColor& theColor )
|
|
|
|
{
|
2014-06-04 15:01:12 +06:00
|
|
|
ArrowsInfo::const_iterator i;
|
|
|
|
for( i = myArrows.begin(); i != myArrows.end(); i++ ) {
|
|
|
|
DependencyTree_Arrow* arrow = myArrows[ i->first ];
|
2014-05-21 19:42:20 +06:00
|
|
|
arrow->setSelectColor( theColor );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-04 15:01:12 +06:00
|
|
|
//=================================================================================
|
|
|
|
// function : onRebuildModel()
|
|
|
|
// purpose : slot for updating tree model using selected objects in viewer
|
|
|
|
//=================================================================================
|
2014-06-02 14:20:08 +06:00
|
|
|
void DependencyTree_View::onRebuildModel()
|
2014-05-29 17:18:22 +06:00
|
|
|
{
|
2014-06-02 14:20:08 +06:00
|
|
|
updateModel( true, false );
|
2014-05-29 17:18:22 +06:00
|
|
|
}
|
|
|
|
|
2014-06-04 15:01:12 +06:00
|
|
|
//=================================================================================
|
|
|
|
// function : onUpdateModel()
|
|
|
|
// purpose : slot for updating tree model for main objects in viewer
|
|
|
|
//=================================================================================
|
|
|
|
void DependencyTree_View::onUpdateModel()
|
2014-05-28 17:06:55 +06:00
|
|
|
{
|
2014-06-04 15:01:12 +06:00
|
|
|
updateModel( false );
|
2014-05-28 17:06:55 +06:00
|
|
|
}
|
|
|
|
|
2014-06-04 15:01:12 +06:00
|
|
|
//=================================================================================
|
|
|
|
// function : onMoveNodes()
|
|
|
|
// purpose : slot for setting the possibility to move nodes in viewer
|
|
|
|
//=================================================================================
|
2014-05-28 17:06:55 +06:00
|
|
|
void DependencyTree_View::onMoveNodes( bool theIsMoveNodes )
|
|
|
|
{
|
|
|
|
EntryObjectMap::const_iterator i;
|
2014-06-04 15:01:12 +06:00
|
|
|
for( i = myTreeMap.begin(); i != myTreeMap.end(); i++ ) {
|
2014-05-28 17:06:55 +06:00
|
|
|
DependencyTree_Object* object = myTreeMap[ i->first ];
|
|
|
|
if( object )
|
|
|
|
object->setMovable( theIsMoveNodes );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-04 15:01:12 +06:00
|
|
|
//=================================================================================
|
|
|
|
// function : onHierarchyType()
|
|
|
|
// purpose : slot for setting the hierarchy type of tree
|
|
|
|
//=================================================================================
|
2014-05-28 17:06:55 +06:00
|
|
|
void DependencyTree_View::onHierarchyType()
|
|
|
|
{
|
|
|
|
myHierarchyDepth->setRange( 0, checkMaxLevelsNumber() );
|
|
|
|
if( myHierarchyDepth->value() > checkMaxLevelsNumber() )
|
|
|
|
myHierarchyDepth->setValue( checkMaxLevelsNumber() );
|
|
|
|
|
|
|
|
if( myHierarchyDepth->value() == 0 )
|
|
|
|
myLevelsNumber = myHierarchyDepth->maximum();
|
|
|
|
else
|
|
|
|
myLevelsNumber = myHierarchyDepth->value();
|
|
|
|
|
|
|
|
updateView();
|
|
|
|
}
|
|
|
|
|
2014-06-04 15:01:12 +06:00
|
|
|
//=================================================================================
|
|
|
|
// function : parseTree()
|
|
|
|
// purpose : parse created model to initialize all nodes and arrows
|
|
|
|
//=================================================================================
|
2014-05-28 17:06:55 +06:00
|
|
|
void DependencyTree_View::parseTree()
|
|
|
|
{
|
|
|
|
GEOMUtils::TreeModel::const_iterator i;
|
2014-06-04 15:01:12 +06:00
|
|
|
for( i = myTreeModel.begin(); i != myTreeModel.end(); i++ ) {
|
2014-05-28 17:06:55 +06:00
|
|
|
std::string objectEntry = i->first;
|
|
|
|
addNode( objectEntry );
|
|
|
|
parseTreeWard( i->second.first );
|
|
|
|
if( i->second.first.size() > myMaxUpwardLevelsNumber )
|
|
|
|
myMaxUpwardLevelsNumber = i->second.first.size();
|
|
|
|
parseTreeWard( i->second.second );
|
|
|
|
if( i->second.second.size() > myMaxDownwardLevelsNumber )
|
|
|
|
myMaxDownwardLevelsNumber = i->second.second.size();
|
|
|
|
}
|
|
|
|
|
2014-06-04 15:01:12 +06:00
|
|
|
for( i = myTreeModel.begin(); i != myTreeModel.end(); i++ ) {
|
|
|
|
DependencyTree_Object* Main_object = myTreeMap[ i->first ];
|
2014-05-28 17:06:55 +06:00
|
|
|
if( i->second.first.size() > 0 ) {
|
|
|
|
GEOMUtils::LevelInfo Levelup = i->second.first.at(0);
|
|
|
|
GEOMUtils::LevelInfo::const_iterator node;
|
2014-06-04 15:01:12 +06:00
|
|
|
for( node = Levelup.begin(); node != Levelup.end(); node++ ) {
|
|
|
|
DependencyTree_Object* object = myTreeMap[ node->first ];
|
2014-05-28 17:06:55 +06:00
|
|
|
addArrow( Main_object, object );
|
2014-05-23 19:04:32 +06:00
|
|
|
}
|
2014-05-28 17:06:55 +06:00
|
|
|
}
|
|
|
|
parseTreeWardArrow( i->second.first );
|
|
|
|
parseTreeWardArrow( i->second.second );
|
|
|
|
}
|
|
|
|
}
|
2014-06-04 15:01:12 +06:00
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : parseTreeWard()
|
|
|
|
// purpose : parse tree ward to initialize all nodes of current ward
|
|
|
|
//=================================================================================
|
|
|
|
void DependencyTree_View::parseTreeWard( const GEOMUtils::LevelsList& theWard )
|
2014-05-28 17:06:55 +06:00
|
|
|
{
|
|
|
|
int levelsNumber = theWard.size();
|
|
|
|
for( int level = 0; level < levelsNumber; level++ ) {
|
|
|
|
GEOMUtils::LevelInfo levelInfo = theWard[ level ];
|
|
|
|
GEOMUtils::LevelInfo::const_iterator node;
|
2014-06-04 15:01:12 +06:00
|
|
|
for( node = levelInfo.begin(); node != levelInfo.end(); node++ )
|
2014-05-28 17:06:55 +06:00
|
|
|
addNode( node->first );
|
|
|
|
}
|
|
|
|
}
|
2014-06-04 15:01:12 +06:00
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : parseTreeWardArrow()
|
|
|
|
// purpose : parse tree ward to initialize all arrows of current ward
|
|
|
|
//=================================================================================
|
|
|
|
void DependencyTree_View::parseTreeWardArrow( const GEOMUtils::LevelsList& theWard)
|
2014-05-28 17:06:55 +06:00
|
|
|
{
|
2014-06-04 15:01:12 +06:00
|
|
|
for( int j = 0; j < theWard.size(); j++ ) {
|
|
|
|
GEOMUtils::LevelInfo Level = theWard.at(j);
|
|
|
|
GEOMUtils::LevelInfo::const_iterator node;
|
|
|
|
for( node = Level.begin(); node != Level.end(); node++ ) {
|
|
|
|
DependencyTree_Object* object = myTreeMap[ node->first ];
|
2014-05-28 17:06:55 +06:00
|
|
|
std::vector<std::string> Links = node->second;
|
|
|
|
for( int link = 0; link < Links.size(); link++ ) {
|
2014-06-04 15:01:12 +06:00
|
|
|
DependencyTree_Object* LinkObject = myTreeMap[ Links[ link ] ];
|
2014-05-28 17:06:55 +06:00
|
|
|
if( object && LinkObject )
|
|
|
|
addArrow( object, LinkObject );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-04 15:01:12 +06:00
|
|
|
//=================================================================================
|
|
|
|
// function : addNode()
|
|
|
|
// purpose : add node to viewer
|
|
|
|
//=================================================================================
|
|
|
|
void DependencyTree_View::addNode( const std::string& theEntry )
|
|
|
|
{
|
|
|
|
if( !myTreeMap[theEntry] )
|
|
|
|
myTreeMap[theEntry] = new DependencyTree_Object( theEntry );
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : addArrow()
|
|
|
|
// purpose : add arrow to viewer
|
|
|
|
//=================================================================================
|
|
|
|
void DependencyTree_View::addArrow( DependencyTree_Object* startItem, DependencyTree_Object* endItem )
|
|
|
|
{
|
|
|
|
bool isFind = false;
|
|
|
|
|
|
|
|
ArrowsInfo::const_iterator i;
|
|
|
|
for( i = myArrows.begin(); i != myArrows.end(); i++ ) {
|
|
|
|
DependencyTree_Arrow* arrow = i->second;
|
|
|
|
if( arrow->getStartItem() == startItem && arrow->getEndItem() == endItem )
|
|
|
|
isFind = true;
|
|
|
|
else if( arrow->getStartItem() == endItem && arrow->getEndItem() == startItem ) {
|
|
|
|
arrow->setIsBiLink( true );
|
|
|
|
isFind = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( !isFind ) {
|
|
|
|
DependencyTree_Arrow *arrow = new DependencyTree_Arrow( startItem, endItem );
|
|
|
|
myArrows[ std::pair<DependencyTree_Object*,DependencyTree_Object*>( startItem, endItem ) ] = arrow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : drawTree()
|
|
|
|
// purpose : redraw dependency tree using existing model
|
|
|
|
//=================================================================================
|
|
|
|
void DependencyTree_View::drawTree()
|
|
|
|
{
|
|
|
|
clearView( false );
|
|
|
|
clearSelected();
|
|
|
|
|
|
|
|
// draw nodes on scene
|
|
|
|
std::map< std::string, int > entryLevelMap;
|
|
|
|
std::map< int, std::vector< std::string > > levelObjects;
|
|
|
|
int currentLevel;
|
|
|
|
int horDistance, verDistance;
|
|
|
|
GEOMUtils::TreeModel::const_reverse_iterator i;
|
|
|
|
for( i = myTreeModel.rbegin(); i != myTreeModel.rend(); i++ ) {
|
|
|
|
currentLevel = 0;
|
|
|
|
std::string objectEntry = i->first;
|
|
|
|
DependencyTree_Object* objectItem = myTreeMap[ objectEntry ];
|
|
|
|
horDistance = 100 + int( objectItem->boundingRect().width() );
|
|
|
|
verDistance = 3 * int( objectItem->boundingRect().height() );
|
|
|
|
if( isItemAdded( objectItem ) )
|
|
|
|
currentLevel = entryLevelMap[ objectEntry ];
|
|
|
|
else {
|
|
|
|
addItem( objectItem );
|
|
|
|
objectItem->unselect();
|
|
|
|
entryLevelMap[ objectEntry ] = currentLevel;
|
|
|
|
levelObjects[ currentLevel ].push_back( objectEntry );
|
|
|
|
}
|
|
|
|
objectItem->setIsMainObject( true );
|
|
|
|
|
|
|
|
if( myDisplayAscendants->isChecked() )
|
|
|
|
drawWard( i->second.first, entryLevelMap, levelObjects, currentLevel, -1 );
|
|
|
|
if( myDisplayDescendants->isChecked() )
|
|
|
|
drawWard( i->second.second, entryLevelMap, levelObjects, currentLevel, 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
std::map< int, std::vector< std::string > >::const_iterator level;
|
|
|
|
for( level = levelObjects.begin(); level != levelObjects.end(); level++ ) {
|
|
|
|
int step = -horDistance * ( level->second.size() - 1 ) / 2;
|
|
|
|
for( int objIter = 0; objIter < level->second.size(); objIter++ ) {
|
|
|
|
DependencyTree_Object* anObject = myTreeMap[ level->second.at( objIter ) ];
|
|
|
|
anObject->setPos( step, verDistance * level->first );
|
|
|
|
step += horDistance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// draw arrows on scene
|
|
|
|
GEOMUtils::TreeModel::const_iterator j;
|
|
|
|
for( j = myTreeModel.begin(); j != myTreeModel.end(); j++ ) {
|
|
|
|
DependencyTree_Object* Main_object = myTreeMap[ j->first ];
|
|
|
|
if( j->second.first.size() > 0 ) {
|
|
|
|
GEOMUtils::LevelInfo Levelup = j->second.first.at(0);
|
|
|
|
if( myDisplayAscendants ->isChecked() ) {
|
|
|
|
GEOMUtils::LevelInfo::const_iterator node;
|
|
|
|
for( node = Levelup.begin(); node != Levelup.end(); node++ ) {
|
|
|
|
DependencyTree_Object* object = myTreeMap[ node->first ];
|
|
|
|
DependencyTree_Arrow* arrow =
|
|
|
|
myArrows[ std::pair<DependencyTree_Object*,DependencyTree_Object*>( Main_object, object )];
|
|
|
|
if( arrow && !isItemAdded( arrow ) )
|
|
|
|
addItem( arrow );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( myDisplayAscendants->isChecked() )
|
|
|
|
drawWardArrows( j->second.first );
|
|
|
|
if( myDisplayDescendants->isChecked() )
|
|
|
|
drawWardArrows( j->second.second );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : drawWard()
|
|
|
|
// purpose : draw nodes of dependency tree ward (ascendant or descendant)
|
|
|
|
//=================================================================================
|
2014-05-28 17:06:55 +06:00
|
|
|
void DependencyTree_View::drawWard( const GEOMUtils::LevelsList& theWard,
|
|
|
|
std::map< std::string, int >& theEntryLevelMap,
|
|
|
|
std::map< int, std::vector< std::string > >& theLevelObjects,
|
|
|
|
int theCurrentLevel, const int theLevelStep )
|
|
|
|
{
|
|
|
|
for( int level = 0; level < theWard.size(); level++ ) {
|
2014-06-04 15:01:12 +06:00
|
|
|
if( level >= myLevelsNumber )
|
2014-05-28 17:06:55 +06:00
|
|
|
return;
|
|
|
|
theCurrentLevel += theLevelStep;
|
|
|
|
GEOMUtils::LevelInfo levelInfo = theWard.at( level );
|
|
|
|
GEOMUtils::LevelInfo::const_iterator node;
|
2014-06-04 15:01:12 +06:00
|
|
|
for( node = levelInfo.begin(); node != levelInfo.end(); node++ ) {
|
2014-05-28 17:06:55 +06:00
|
|
|
DependencyTree_Object* object = myTreeMap[ node->first ];
|
2014-06-04 15:01:12 +06:00
|
|
|
if( object && !isItemAdded( object ) ) {
|
|
|
|
addItem( object );
|
2014-05-28 17:06:55 +06:00
|
|
|
object->unselect();
|
|
|
|
theEntryLevelMap[ node->first ] = theCurrentLevel;
|
|
|
|
theLevelObjects[ theCurrentLevel ].push_back( node->first );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-04 15:01:12 +06:00
|
|
|
//=================================================================================
|
|
|
|
// function : drawWardArrows()
|
|
|
|
// purpose : draw arrows of dependency tree ward (ascendant or descendant)
|
|
|
|
//=================================================================================
|
|
|
|
void DependencyTree_View::drawWardArrows( const GEOMUtils::LevelsList& theWard )
|
2014-05-28 17:06:55 +06:00
|
|
|
{
|
2014-06-04 15:01:12 +06:00
|
|
|
for( int j = 0; j < theWard.size(); j++ ) {
|
|
|
|
if( j >= myLevelsNumber )
|
2014-05-28 17:06:55 +06:00
|
|
|
break;
|
|
|
|
GEOMUtils::LevelInfo Level = theWard.at(j);
|
|
|
|
GEOMUtils::LevelInfo::const_iterator node;
|
2014-06-04 15:01:12 +06:00
|
|
|
for( node = Level.begin(); node != Level.end(); node++ ) {
|
|
|
|
DependencyTree_Object* object = myTreeMap[ node->first ];
|
2014-05-28 17:06:55 +06:00
|
|
|
GEOMUtils::NodeLinks Links = node->second;
|
|
|
|
for( int link = 0; link < Links.size(); link++ ) {
|
2014-06-04 15:01:12 +06:00
|
|
|
DependencyTree_Object* LinkObject = myTreeMap[ Links[ link ] ];
|
2014-05-28 17:06:55 +06:00
|
|
|
if( isItemAdded( object ) && isItemAdded( LinkObject ) ) {
|
2014-06-04 15:01:12 +06:00
|
|
|
DependencyTree_Arrow* arrow = myArrows[ std::pair<DependencyTree_Object*,DependencyTree_Object*>( object, LinkObject ) ];
|
|
|
|
if( arrow && !isItemAdded( arrow ) )
|
|
|
|
addItem( arrow );
|
2014-05-28 17:06:55 +06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-04 15:01:12 +06:00
|
|
|
//=================================================================================
|
|
|
|
// function : updateView()
|
|
|
|
// purpose : update viewer using created dependency tree model
|
|
|
|
//=================================================================================
|
|
|
|
void DependencyTree_View::updateView()
|
|
|
|
{
|
|
|
|
if( !myIsUpdate )
|
|
|
|
return;
|
|
|
|
|
|
|
|
drawTree();
|
|
|
|
fitAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : clearView()
|
|
|
|
// purpose : clear viewer and initialize all variables
|
|
|
|
//=================================================================================
|
|
|
|
void DependencyTree_View::clearView( bool isClearModel )
|
2014-05-28 17:06:55 +06:00
|
|
|
{
|
2014-06-04 15:01:12 +06:00
|
|
|
EntryObjectMap::const_iterator objectIter;
|
|
|
|
for( objectIter = myTreeMap.begin(); objectIter != myTreeMap.end(); objectIter++ ) {
|
|
|
|
DependencyTree_Object* object = objectIter->second;
|
|
|
|
if( object )
|
|
|
|
if( isItemAdded( object ) )
|
|
|
|
removeItem( object );
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrowsInfo::const_iterator arrowIter;
|
|
|
|
for( arrowIter = myArrows.begin(); arrowIter != myArrows.end(); arrowIter++ ) {
|
|
|
|
DependencyTree_Arrow* object = arrowIter->second;
|
|
|
|
if( object )
|
|
|
|
if( isItemAdded( object ) )
|
|
|
|
removeItem( object );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( isClearModel ) {
|
|
|
|
myTreeMap.clear();
|
|
|
|
myArrows.clear();
|
|
|
|
myTreeModel.clear();
|
|
|
|
myLevelsNumber = 0;
|
|
|
|
myMaxDownwardLevelsNumber = 0;
|
|
|
|
myMaxUpwardLevelsNumber = 0;
|
|
|
|
myIsUpdate = true;
|
|
|
|
}
|
|
|
|
}
|
2014-05-28 17:06:55 +06:00
|
|
|
|
2014-06-04 15:01:12 +06:00
|
|
|
//=================================================================================
|
|
|
|
// function : getNewTreeModel()
|
|
|
|
// purpose : get dependency tree model from engine
|
|
|
|
//=================================================================================
|
|
|
|
void DependencyTree_View::getNewTreeModel( bool theUseSelectedObject, bool theUseOB )
|
|
|
|
{
|
2014-05-28 17:06:55 +06:00
|
|
|
GEOM::string_array_var objectsEntry = new GEOM::string_array();
|
|
|
|
int iter = 0;
|
2014-06-02 14:20:08 +06:00
|
|
|
|
|
|
|
if( theUseSelectedObject ) {
|
|
|
|
if( theUseOB ) {
|
|
|
|
SALOME_ListIO mainObjects;
|
|
|
|
mySelectionMgr->selectedObjects( mainObjects );
|
|
|
|
// create a list of selected object entry
|
2014-06-04 15:01:12 +06:00
|
|
|
objectsEntry->length( mainObjects.Extent() );
|
2014-06-02 14:20:08 +06:00
|
|
|
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++ )
|
2014-06-04 15:01:12 +06:00
|
|
|
if( DependencyTree_Object* treeObject = dynamic_cast<DependencyTree_Object*>( selectedObject() ) )
|
2014-06-02 14:20:08 +06:00
|
|
|
objectsEntry[ iter ] = treeObject->getEntry().c_str();
|
|
|
|
}
|
|
|
|
myMainEntries = objectsEntry;
|
2014-05-28 17:06:55 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
// get string which describes dependency tree structure
|
|
|
|
SALOMEDS::TMPFile_var SeqFile =
|
2014-06-02 14:20:08 +06:00
|
|
|
GeometryGUI::GetGeomGen()->GetDependencyTree( myStudy, myMainEntries );
|
2014-06-04 15:01:12 +06:00
|
|
|
char* buf = (char*)&SeqFile[0];
|
2014-05-28 17:06:55 +06:00
|
|
|
|
2014-06-02 14:20:08 +06:00
|
|
|
clearView( true );
|
2014-06-04 15:01:12 +06:00
|
|
|
mySelectionMgr->clearSelected();
|
|
|
|
|
2014-05-28 17:06:55 +06:00
|
|
|
// get dependency tree structure
|
|
|
|
GEOMUtils::ConvertStringToTree( buf, myTreeModel );
|
|
|
|
|
|
|
|
parseTree();
|
|
|
|
}
|
2014-05-21 19:42:20 +06:00
|
|
|
|
2014-06-04 15:01:12 +06:00
|
|
|
//=================================================================================
|
|
|
|
// function : checkMaxLevelsNumber()
|
|
|
|
// purpose : calculate max levels number
|
|
|
|
//=================================================================================
|
2014-05-28 17:06:55 +06:00
|
|
|
int DependencyTree_View::checkMaxLevelsNumber()
|
|
|
|
{
|
|
|
|
if( myDisplayAscendants->isChecked() && myDisplayDescendants->isChecked() )
|
2014-06-04 15:01:12 +06:00
|
|
|
return myMaxUpwardLevelsNumber > myMaxDownwardLevelsNumber ?
|
|
|
|
myMaxUpwardLevelsNumber : myMaxDownwardLevelsNumber;
|
2014-05-28 17:06:55 +06:00
|
|
|
else if( myDisplayAscendants ->isChecked() )
|
|
|
|
return myMaxUpwardLevelsNumber;
|
|
|
|
else if( myDisplayDescendants->isChecked() )
|
|
|
|
return myMaxDownwardLevelsNumber;
|
|
|
|
}
|