From bec320673b7507612a07e033cb3d576eb5d1607b Mon Sep 17 00:00:00 2001 From: mpa Date: Wed, 21 May 2014 17:42:20 +0400 Subject: [PATCH] Creation of GUI part --- CMakeLists.txt | 2 +- SalomeGEOMConfig.cmake.in | 1 + adm_local/cmake_files/FindGEOM.cmake | 1 + resources/SalomeApp.xml.in | 9 + src/CMakeLists.txt | 2 +- src/DependencyTree/CMakeLists.txt | 114 +++ src/DependencyTree/DependencyTree.cxx | 114 +++ src/DependencyTree/DependencyTree.h | 44 + src/DependencyTree/DependencyTree_Arrow.cxx | 258 ++++++ src/DependencyTree/DependencyTree_Arrow.h | 71 ++ src/DependencyTree/DependencyTree_Object.cxx | 224 +++++ src/DependencyTree/DependencyTree_Object.h | 70 ++ src/DependencyTree/DependencyTree_View.cxx | 782 ++++++++++++++++++ src/DependencyTree/DependencyTree_View.h | 178 ++++ .../DependencyTree_ViewModel.cxx | 88 ++ src/DependencyTree/DependencyTree_ViewModel.h | 39 + .../resources/DependencyTree_msg_en.ts | 35 + .../resources/DependencyTree_msg_fr.ts | 12 + .../resources/DependencyTree_msg_ja.ts | 12 + src/GEOMGUI/CMakeLists.txt | 2 + src/GEOMGUI/GEOM_msg_en.ts | 56 ++ src/GEOMGUI/GeometryGUI.cxx | 103 +++ src/GEOMGUI/GeometryGUI_Operations.h | 1 + src/GEOMToolsGUI/CMakeLists.txt | 2 + src/GEOMToolsGUI/GEOMToolsGUI.cxx | 2 + src/GEOMToolsGUI/GEOMToolsGUI.h | 1 + src/GEOMToolsGUI/GEOMToolsGUI_1.cxx | 7 + 27 files changed, 2228 insertions(+), 2 deletions(-) create mode 100644 src/DependencyTree/CMakeLists.txt create mode 100644 src/DependencyTree/DependencyTree.cxx create mode 100644 src/DependencyTree/DependencyTree.h create mode 100644 src/DependencyTree/DependencyTree_Arrow.cxx create mode 100644 src/DependencyTree/DependencyTree_Arrow.h create mode 100644 src/DependencyTree/DependencyTree_Object.cxx create mode 100644 src/DependencyTree/DependencyTree_Object.h create mode 100644 src/DependencyTree/DependencyTree_View.cxx create mode 100644 src/DependencyTree/DependencyTree_View.h create mode 100644 src/DependencyTree/DependencyTree_ViewModel.cxx create mode 100644 src/DependencyTree/DependencyTree_ViewModel.h create mode 100644 src/DependencyTree/resources/DependencyTree_msg_en.ts create mode 100644 src/DependencyTree/resources/DependencyTree_msg_fr.ts create mode 100644 src/DependencyTree/resources/DependencyTree_msg_ja.ts diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c9446aa6..111061ef8 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -243,7 +243,7 @@ IF(SALOME_BUILD_GUI) LIST(APPEND _${PROJECT_NAME}_exposed_targets AdvancedGUI BasicGUI BlocksGUI BooleanGUI BuildGUI DisplayGUI DlgRef EntityGUI GEOMBase GEOMFiltersSelection GEOM GEOMToolsGUI GenerationGUI GroupGUI Material MeasureGUI GEOMObject - OperationGUI PrimitiveGUI RepairGUI TransformationGUI ImportExportGUI + OperationGUI PrimitiveGUI RepairGUI TransformationGUI ImportExportGUI DependencyTree ) ENDIF(SALOME_BUILD_GUI) diff --git a/SalomeGEOMConfig.cmake.in b/SalomeGEOMConfig.cmake.in index 9e0392028..c72af1a38 100644 --- a/SalomeGEOMConfig.cmake.in +++ b/SalomeGEOMConfig.cmake.in @@ -162,6 +162,7 @@ SET(GEOM_GEOMBase GEOMBase) SET(GEOM_GEOMFiltersSelection GEOMFiltersSelection) SET(GEOM_GEOM GEOM) SET(GEOM_GEOMToolsGUI GEOMToolsGUI) +SET(GEOM_DependencyTree DependencyTree) SET(GEOM_GenerationGUI GenerationGUI) SET(GEOM_GroupGUI GroupGUI) SET(GEOM_Material Material) diff --git a/adm_local/cmake_files/FindGEOM.cmake b/adm_local/cmake_files/FindGEOM.cmake index 1f882bc78..69722aa4e 100644 --- a/adm_local/cmake_files/FindGEOM.cmake +++ b/adm_local/cmake_files/FindGEOM.cmake @@ -54,6 +54,7 @@ FIND_LIBRARY(GEOM_GEOMBase GEOMBase ${GEOM_ROOT_DIR}/lib/salome) FIND_LIBRARY(GEOM_GEOMFiltersSelection GEOMFiltersSelection ${GEOM_ROOT_DIR}/lib/salome) FIND_LIBRARY(GEOM_GEOM GEOM ${GEOM_ROOT_DIR}/lib/salome) FIND_LIBRARY(GEOM_GEOMToolsGUI GEOMToolsGUI ${GEOM_ROOT_DIR}/lib/salome) +FIND_LIBRARY(GEOM_DependencyTree DependencyTree ${GEOM_ROOT_DIR}/lib/salome) FIND_LIBRARY(GEOM_GenerationGUI GenerationGUI ${GEOM_ROOT_DIR}/lib/salome) FIND_LIBRARY(GEOM_GroupGUI GroupGUI ${GEOM_ROOT_DIR}/lib/salome) FIND_LIBRARY(GEOM_Material Material ${GEOM_ROOT_DIR}/lib/salome) diff --git a/resources/SalomeApp.xml.in b/resources/SalomeApp.xml.in index 0cdf1cf72..d8d3253d4 100644 --- a/resources/SalomeApp.xml.in +++ b/resources/SalomeApp.xml.in @@ -67,6 +67,15 @@ + + + + + + + + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a40066e58..624c14bcc 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -50,7 +50,7 @@ ENDIF() ## IF(SALOME_BUILD_GUI) SET(SUBDIRS_GUI - OBJECT DlgRef GEOMFiltersSelection Material GEOMGUI + DependencyTree OBJECT DlgRef GEOMFiltersSelection Material GEOMGUI GEOMBase GEOMToolsGUI DisplayGUI BasicGUI PrimitiveGUI GenerationGUI EntityGUI BuildGUI BooleanGUI TransformationGUI OperationGUI RepairGUI MeasureGUI GroupGUI BlocksGUI AdvancedGUI ImportExportGUI diff --git a/src/DependencyTree/CMakeLists.txt b/src/DependencyTree/CMakeLists.txt new file mode 100644 index 000000000..ac2b89353 --- /dev/null +++ b/src/DependencyTree/CMakeLists.txt @@ -0,0 +1,114 @@ +# Copyright (C) 2012-2014 CEA/DEN, EDF R&D +# +# 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(UseQt4Ext) +INCLUDE(${QT_USE_FILE}) + +# --- options --- + +# additional include directories +INCLUDE_DIRECTORIES( + ${QT_INCLUDES} + ${GUI_INCLUDE_DIRS} + ${CAS_INCLUDE_DIRS} + ${OMNIORB_INCLUDE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + ${PROJECT_SOURCE_DIR}/src/GEOMGUI + ${PROJECT_SOURCE_DIR}/src/GEOMBase + ${PROJECT_SOURCE_DIR}/src/GEOM + + + ${PROJECT_BINARY_DIR}/idl + ${PROJECT_BINARY_DIR} + ${PROJECT_SOURCE_DIR}/src/OBJECT + ${PROJECT_SOURCE_DIR}/src/GEOMClient + ${PROJECT_SOURCE_DIR}/src/GEOMImpl + ${PROJECT_SOURCE_DIR}/src/DlgRef + ${PROJECT_BINARY_DIR}/src/DlgRef + + ) + +# additional preprocessor / compiler flags +ADD_DEFINITIONS( + ${QT_DEFINITIONS} + ${GUI_DEFINITIONS} + ${CAS_DEFINITIONS} + ${OMNIORB_DEFINITIONS} + ) + +# libraries to link to +SET(_link_LIBRARIES + ${QT_LIBRARIES} + ${GUI_SalomeApp} + ${GUI_suit} + ${GUI_qtx} + ${GUI_QxScene} + ${GUI_GraphicsView} + ${GUI_SalomeObject} + GEOMUtils +) + +# --- headers --- + +SET(DependencyTree_HEADERS + DependencyTree.h + DependencyTree_Object.h + DependencyTree_Arrow.h + DependencyTree_ViewModel.h + ) + +# header files / to be processed by moc +SET(_moc_HEADERS + DependencyTree_View.h +) + +# --- sources --- + +# sources / moc wrappings +QT4_WRAP_CPP(_moc_SOURCES ${_moc_HEADERS}) + +SET(DependencyTree_SOURCES + DependencyTree.cxx + DependencyTree_View.cxx + DependencyTree_Object.cxx + DependencyTree_Arrow.cxx + #arrow.cxx + DependencyTree_ViewModel.cxx + ${_moc_SOURCES} +) + +# --- resources --- + +# resource files / to be processed by lrelease +SET(_res_files + resources/DependencyTree_msg_en.ts + resources/DependencyTree_msg_fr.ts + resources/DependencyTree_msg_ja.ts +) +# --- rules --- + +ADD_LIBRARY(DependencyTree ${DependencyTree_SOURCES}) +TARGET_LINK_LIBRARIES(DependencyTree ${_link_LIBRARIES}) +INSTALL(TARGETS DependencyTree EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) + +#INSTALL(FILES ${_res_files} DESTINATION ${SALOME_GEOM_INSTALL_RES_DATA}) +QT4_INSTALL_TS_RESOURCES("${_res_files}" "${SALOME_GEOM_INSTALL_RES_DATA}") + +INSTALL(FILES ${DependencyTree_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS}) diff --git a/src/DependencyTree/DependencyTree.cxx b/src/DependencyTree/DependencyTree.cxx new file mode 100644 index 000000000..c3de20da4 --- /dev/null +++ b/src/DependencyTree/DependencyTree.cxx @@ -0,0 +1,114 @@ +// 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 + +#include "DependencyTree.h" +#include "DependencyTree_ViewModel.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "DependencyTree_View.h" +#include +#include +#include + +#include +#include +#include + +#include +#include + + +#include +DependencyTree::DependencyTree() +{ + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() ); + if ( !app ) return; + + 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 ); + SUIT_ViewWindow* svw = svm->getActiveView(); + GraphicsView_ViewFrame* aViewFrame = 0; + if (!svw) svw = svm->createViewWindow(); + if (svw) aViewFrame = dynamic_cast(svw); + + myView->init( aViewFrame ); + svm->setTitle("DEPENDENCY_TREE"); + } + else { + svm->getActiveView()->setFocus(); + } + + +} + +DependencyTree::~DependencyTree() +{ +} + +//void DependencyTree::setBackgroundColor( const QColor& theColor ) +//{ +// //myView->setBackgroundColor( theColor ); +// myBackgroundColor = theColor; +//} +//void DependencyTree::setNodeColor( const QColor& theColor ) +//{ +// myView->setNodeColor( theColor ); +//} +//void DependencyTree::setMainNodeColor( const QColor& theColor ) +//{ +// myView->setMainNodeColor( theColor ); +//} +//void DependencyTree::setSelectNodeColor( const QColor& theColor ) +//{ +// myView->setSelectNodeColor( theColor ); +//} +//void DependencyTree::setArrowColor( const QColor& theColor ) +//{ +// myView->setArrowColor( theColor ); +//} +//void DependencyTree::setHighlightArrowColor( const QColor& theColor ) +//{ +// myView->setHighlightArrowColor( theColor ); +//} +//void DependencyTree::setSelectArrowColor( const QColor& theColor ) +//{ +// myView->setSelectArrowColor( theColor ); +//} diff --git a/src/DependencyTree/DependencyTree.h b/src/DependencyTree/DependencyTree.h new file mode 100644 index 000000000..4b5d54eae --- /dev/null +++ b/src/DependencyTree/DependencyTree.h @@ -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 +// + +#include + +#include + +#include "DependencyTree_View.h" +class DependencyTree +{ +public: + DependencyTree(); + ~DependencyTree(); + +// static void setBackgroundColor( const QColor& ); +// static void setNodeColor( const QColor& ); +// static void setMainNodeColor( const QColor& ); +// static void setSelectNodeColor( const QColor& ); +// static void setArrowColor( const QColor& ); +// static void setHighlightArrowColor( const QColor& ); +// static void setSelectArrowColor( const QColor& ); + +private: + DependencyTree_View* myView; + + QColor* myBackgroundColor; +}; + diff --git a/src/DependencyTree/DependencyTree_Arrow.cxx b/src/DependencyTree/DependencyTree_Arrow.cxx new file mode 100644 index 000000000..3f6925ad8 --- /dev/null +++ b/src/DependencyTree/DependencyTree_Arrow.cxx @@ -0,0 +1,258 @@ +// 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_Arrow.h" +#include "DependencyTree_Object.h" + +// GUI includes +#include +#include + +// Qt includes +#include + +#include + +const qreal arrowSize = 20; + +DependencyTree_Arrow::DependencyTree_Arrow( DependencyTree_Object* theStartItem, + DependencyTree_Object* theEndItem, + QGraphicsItem* parent, QGraphicsScene* scene ) +:QGraphicsLineItem( parent, scene ), +myIsBiLink( false ), +myStartItem( theStartItem ), +myEndItem( theEndItem ) +{ + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + + myColor = resMgr->colorValue( "Geometry", "dependency_tree_arrow_color", QColor( 0, 0, 130 ) ); + myHighlightColor = resMgr->colorValue( "Geometry", "dependency_tree_highlight_arrow_color", QColor( 0, 0, 255 ) ); + mySelectColor = resMgr->colorValue( "Geometry", "dependency_tree_select_arrow_color", QColor( 255, 0, 0 ) ); + + myStartItem = theStartItem; + myEndItem = theEndItem; + + myArrowHead = createArrowHead( myStartItem->pos(), myEndItem->pos() ); + myReverseArrowHead = createArrowHead( myEndItem->pos(), myStartItem->pos() ); + + mySelfDependencyArrow = QRectF(); + + setPen( QPen( myColor, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) ); + setColor( myColor ); + + setFlag( QGraphicsItem::ItemIsSelectable, true ); + setZValue( -1000.0 ); +} + +DependencyTree_Arrow::~DependencyTree_Arrow() +{ +} + +//================================================================================= +// function : boundingRect() +// purpose : return the outer bounds of the item as a rectangle. +// QGraphicsView uses this to determine whether the item requires redrawing +//================================================================================= +QRectF DependencyTree_Arrow::boundingRect() const +{ + qreal extra; + QRectF boundingRect; + if( myStartItem == myEndItem ) { + extra = arrowSize / 2.0; + boundingRect = mySelfDependencyArrow; + } + else { + extra = ( pen().width() + 20 ) / 2.0; + boundingRect = QRectF( line().p1(), QSizeF( line().p2().x() - line().p1().x(), + line().p2().y() - line().p1().y() ) ); + } + return boundingRect.normalized().adjusted( -extra, -extra, extra, extra ); +} + +//================================================================================= +// function : shape() +// purpose : return the shape of this item to define an area of preselection +//================================================================================= +QPainterPath DependencyTree_Arrow::shape() const +{ + QPainterPath path; + + if( myStartItem == myEndItem ) { + qreal extra = 5; + QPolygonF aPolygonBigger( mySelfDependencyArrow.normalized() + .adjusted( -extra, -extra, extra, extra ) ); + QPolygonF aPolygonSmaller( mySelfDependencyArrow.normalized() + .adjusted( extra, extra, -extra, -extra ) ); + path.addPolygon( aPolygonBigger.subtracted( aPolygonSmaller ) ); + path.addPolygon(myArrowHead); + } + else { + QPolygonF aShapePolygon; + QPolygon anArrowHead = myArrowHead.toPolygon(); + QPolygon anReverseArrowHead = myReverseArrowHead.toPolygon(); + aShapePolygon << anArrowHead.point(1) << anArrowHead.point(0) << anArrowHead.point(2) << + anReverseArrowHead.point(1) << anReverseArrowHead.point(0) << anReverseArrowHead.point(2); + path.addPolygon( aShapePolygon ); + } + return path; + } + +//================================================================================= +// function : setColor() +// purpose : set default color for arrow +//================================================================================= +void DependencyTree_Arrow::setColor( const QColor& theColor ) +{ + myColor = theColor; +} + +//================================================================================= +// function : setHighlightColor() +// purpose : set color for highlighted arrow +//================================================================================= +void DependencyTree_Arrow::setHighlightColor( const QColor& theColor ) +{ + myHighlightColor = theColor; +} + +//================================================================================= +// function : setSelectColor() +// purpose : set color for selected arrow +//================================================================================= +void DependencyTree_Arrow::setSelectColor( const QColor& theColor ) +{ + mySelectColor = theColor; +} + +//================================================================================= +// function : getStartItem() +// purpose : get start item of arrow +//================================================================================= +DependencyTree_Object* DependencyTree_Arrow::getStartItem() const +{ + return myStartItem; +} + +//================================================================================= +// function : getEndItem() +// purpose : get end item of arrow +//================================================================================= +DependencyTree_Object* DependencyTree_Arrow::getEndItem() const +{ + return myEndItem; +} + +//================================================================================= +// function : setIsBiLink() +// purpose : set true if current arrow is bi-directional link, else set false +//================================================================================= +void DependencyTree_Arrow::setIsBiLink( bool theIsBiLink ) +{ + myIsBiLink = theIsBiLink; +} + +//================================================================================= +// function : paint() +// purpose : paint the contents of an item in local coordinates (called by QGraphicsView) +//================================================================================= +void DependencyTree_Arrow::paint( QPainter* painter, const QStyleOptionGraphicsItem*, QWidget* ) +{ + if( isSelected() ) { + painter->setBrush( mySelectColor ); + painter->setPen( QPen( mySelectColor, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) ); + } + else if( isUnderMouse() ) { + painter->setBrush( myHighlightColor ); + painter->setPen( QPen( myHighlightColor, 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) ); + } + else { + painter->setBrush( myColor ); + painter->setPen( QPen( myColor, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) ); + } + + if( myStartItem == myEndItem ) { + int lineSize = 60; + QPointF p1( myStartItem->pos().x() - myStartItem->boundingRect().width()/2, + myStartItem->pos().y() ); + QPointF p2( p1.x() - lineSize + myStartItem->boundingRect().height()/2, p1.y() ); + QPointF p3( p2.x(), p2.y() - lineSize ); + QPointF p4( p3.x() + lineSize, p3.y() ); + QPointF p5( p4.x(), p4.y() + lineSize - myStartItem->boundingRect().height()/2 ); + mySelfDependencyArrow = QRectF( p3.x(), p3.y(), lineSize, lineSize ); + myArrowHead = createArrowHead( p4, p5, false ); + QVector pointVector; + pointVector << p1 << p2 << p2 << p3 << p3 << p4 << p4 << p5; + + painter->drawLines( pointVector); + painter->drawPolygon(myArrowHead); + } + else { + if (myStartItem->collidesWithItem(myEndItem)) + return; + + myArrowHead = createArrowHead( myStartItem->pos(), myEndItem->pos() ); + myReverseArrowHead = createArrowHead( myEndItem->pos(), myStartItem->pos() ); + + painter->drawLine( line() ); + painter->drawPolygon( myArrowHead ); + if( myIsBiLink ) + painter->drawPolygon( myReverseArrowHead ); + } +} + +//================================================================================= +// function : createArrowHead() +// purpose : create a head of arrow from start point to end point +//================================================================================= +QPolygonF DependencyTree_Arrow::createArrowHead( QPointF theStartPoint, QPointF theEndPoint, + bool theIsDynamic ) +{ + if( theIsDynamic ) { + QLineF centerLine( theStartPoint, theEndPoint ); + QPolygonF endPolygon = QPolygonF( myEndItem->boundingRect() ); + QPointF p1 = endPolygon.first() + theEndPoint; + QPointF p2; + QPointF intersectPoint; + QLineF polyLine; + for( int i = 1; i < endPolygon.count(); ++i ) { + p2 = endPolygon.at(i) + theEndPoint; + polyLine = QLineF( p1, p2 ); + QLineF::IntersectType intersectType = polyLine.intersect( centerLine, &intersectPoint ); + if( intersectType == QLineF::BoundedIntersection ) + break; + p1 = p2; + } + setLine( QLineF( intersectPoint, theStartPoint ) ); + } + else + setLine( QLineF( theEndPoint, theStartPoint ) ); + + double angle = acos(line().dx() / line().length()); + if( line().dy() >= 0 ) + angle = ( M_PI * 2 ) - angle; + + QPointF arrowP1 = line().p1() + QPointF( sin( angle + M_PI / 3 ) * arrowSize, + cos( angle + M_PI / 3 ) * arrowSize ); + QPointF arrowP2 = line().p1() + QPointF( sin( angle + M_PI - M_PI / 3 ) * arrowSize, + cos( angle + M_PI - M_PI / 3 ) * arrowSize ); + + QPolygonF anArrowHead; + anArrowHead << line().p1() << arrowP1 << arrowP2; + return anArrowHead; +} diff --git a/src/DependencyTree/DependencyTree_Arrow.h b/src/DependencyTree/DependencyTree_Arrow.h new file mode 100644 index 000000000..abf227540 --- /dev/null +++ b/src/DependencyTree/DependencyTree_Arrow.h @@ -0,0 +1,71 @@ +// 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_ARROW_H +#define DEPENDENCYTREE_ARROW_H + +#include + +class DependencyTree_Object; + +class DependencyTree_Arrow : public QGraphicsLineItem +{ +public: + + DependencyTree_Arrow( DependencyTree_Object* startItem, DependencyTree_Object* endItem, + QGraphicsItem* parent = 0, QGraphicsScene* scene = 0 ); + ~DependencyTree_Arrow(); + + virtual QRectF boundingRect() const; + virtual QPainterPath shape() const; + + void setColor(const QColor& ); + void setHighlightColor(const QColor& ); + void setSelectColor(const QColor& ); + + DependencyTree_Object* getStartItem() const; + DependencyTree_Object* getEndItem() const; + + void setIsBiLink( bool ); + +protected: + + void paint( QPainter*, const QStyleOptionGraphicsItem*, QWidget* = 0 ); + +private: + + QPolygonF createArrowHead( QPointF , QPointF, bool = true ); + + DependencyTree_Object* myStartItem; + DependencyTree_Object* myEndItem; + + QColor myColor; + QColor mySelectColor; + QColor myHighlightColor; + + QPolygonF myArrowHead; + QPolygonF myReverseArrowHead; + + bool myIsBiLink; + + QRectF mySelfDependencyArrow; + +}; + +#endif diff --git a/src/DependencyTree/DependencyTree_Object.cxx b/src/DependencyTree/DependencyTree_Object.cxx new file mode 100644 index 000000000..ab0c2c1fa --- /dev/null +++ b/src/DependencyTree/DependencyTree_Object.cxx @@ -0,0 +1,224 @@ +// 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_Object.h" + +// GUI includes +#include +#include + +// Qt includes +#include + +const int itemH = 20; +const int itemW = 90; + +DependencyTree_Object::DependencyTree_Object( const QString& theEntry, QGraphicsItem* theParent ) +:GraphicsView_Object( theParent ), +myIsMainObject( false ), +myIsLongName( false ) +{ + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + + myColor = resMgr->colorValue( "Geometry", "dependency_tree_node_color", QColor( 62, 180, 238 ) ); + mySelectColor = resMgr->colorValue( "Geometry", "dependency_tree_select_node_color", QColor( 237, 243, 58 ) ); + myMainObjectColor = resMgr->colorValue( "Geometry", "dependency_tree_main_node_color", QColor( 238, 90, 125 ) ); + + myPolygonItem = new QGraphicsPolygonItem(); + QPolygonF myPolygon; + myPolygon << QPointF( -itemW, -itemH ) << QPointF( itemW, -itemH ) << QPointF( itemW, itemH ) + << QPointF( -itemW, itemH ) << QPointF( -itemW, -itemH ); + + myPolygonItem->setPolygon( myPolygon ); + myPolygonItem->setBrush( myColor ); + myPolygonItem->setPen( getPen( myColor ) ); + + myTextItem = new QGraphicsSimpleTextItem(); + QFont textFont; + textFont.setPointSize( itemH ); + myTextItem->setFont( textFont ); + + myEntry = theEntry; + updateName(); + + addToGroup( myPolygonItem ); + addToGroup( myTextItem ); +} + +DependencyTree_Object::~DependencyTree_Object() +{ +} + +//================================================================================= +// function : highlight() +// purpose : highlight current item +//================================================================================= +bool DependencyTree_Object::highlight( double theX, double theY ) +{ + if( !isHighlighted() ) { + QColor color = myPolygonItem->brush().color(); + int saturation = ( color.saturation() - 100 ) > 10 ? color.saturation() - 100 : 10; + color.setHsv( color.hsvHue(), saturation, color.value() ); + + myPolygonItem->setBrush( color ); + myPolygonItem->setPen( getPen( color ) ); + + if( myIsLongName ) + myPolygonItem->setToolTip( getName() ); + } + return GraphicsView_Object::highlight( theX, theY ); +} + +//================================================================================= +// function : unhighlight() +// purpose : set properties for unhighlighted item +//================================================================================= +void DependencyTree_Object::unhighlight() +{ + if( isSelected() ) + myPolygonItem->setBrush( mySelectColor ); + else if( myIsMainObject ) + myPolygonItem->setBrush( myMainObjectColor ); + else + myPolygonItem->setBrush( myColor ); + + myPolygonItem->setPen( getPen( myPolygonItem->brush().color() ) ); + + GraphicsView_Object::unhighlight(); +} + +//================================================================================= +// function : select() +// purpose : select current item +//================================================================================= +bool DependencyTree_Object::select( double theX, double theY, const QRectF& theRect ) +{ + myPolygonItem->setBrush( mySelectColor ); + myPolygonItem->setPen( getPen( mySelectColor ) ); + + return GraphicsView_Object::select( theX, theY, theRect ); +} + +//================================================================================= +// function : unselect() +// purpose : set properties for unselected item +//================================================================================= +void DependencyTree_Object::unselect() +{ + if( myIsMainObject ) + myPolygonItem->setBrush( myMainObjectColor ); + else + myPolygonItem->setBrush( myColor ); + + myPolygonItem->setPen( getPen( myPolygonItem->brush().color() ) ); + + GraphicsView_Object::unselect(); +} + +//================================================================================= +// function : getEntry() +// purpose : get entry of current item +//================================================================================= +QString DependencyTree_Object::getEntry() const +{ + return myEntry; +} + +//================================================================================= +// function : updateName() +// purpose : update name of current item using its entry +//================================================================================= +void DependencyTree_Object::updateName() +{ + QString name = myEntry; + + setName( myEntry ); + + myTextItem->setText( name ); + double textWidth = myTextItem->sceneBoundingRect().width(); + double textHeight = myTextItem->sceneBoundingRect().height(); + + double polygonWidth = myPolygonItem->sceneBoundingRect().width(); + double polygonHeight = myPolygonItem->sceneBoundingRect().height(); + + if( ( textWidth - 4 ) > polygonWidth ) { + myIsLongName = true; + int numberSymbol = int( polygonWidth * name.length() / textWidth ); + QString newName = name.left( numberSymbol - 3 ) + "..."; + myTextItem->setText( newName ); + textWidth = myTextItem->sceneBoundingRect().width(); + } + myTextItem->setPos( ( polygonWidth - textWidth ) / 2 - itemW, + ( polygonHeight - textHeight ) / 2 - itemH ); +} + +//================================================================================= +// function : setColor() +// purpose : set default color of current item +//================================================================================= +void DependencyTree_Object::setColor( const QColor& theColor ) +{ + myColor = theColor; +} + +//================================================================================= +// function : setSelectColor() +// purpose : set color of selected item +//================================================================================= +void DependencyTree_Object::setSelectColor( const QColor& theColor ) +{ + mySelectColor = theColor; +} + +//================================================================================= +// function : setMainObjectColor() +// purpose : set color if current item is main object of dependency tree +//================================================================================= +void DependencyTree_Object::setMainObjectColor( const QColor& theColor ) +{ + myMainObjectColor = theColor; +} + +//================================================================================= +// function : setIsMainObject() +// purpose : set true if current item is main object of dependency tree +//================================================================================= +void DependencyTree_Object::setIsMainObject( bool theIsMainObject ) +{ + myIsMainObject = theIsMainObject; + + if( myIsMainObject ) + myPolygonItem->setBrush( myMainObjectColor ); + else + myPolygonItem->setBrush( myColor ); + + myPolygonItem->setPen( getPen( myPolygonItem->brush().color() ) ); +} + +//================================================================================= +// function : getPen() +// purpose : get pen which is dependent of current color +//================================================================================= +QPen DependencyTree_Object::getPen( const QColor& theColor ) +{ + int value = ( theColor.value() - 100 ) > 10 ? theColor.value() - 100 : 10; + QColor penColor; + penColor.setHsv( theColor.hsvHue(), theColor.saturation(), value ); + return QPen( QBrush( penColor ), 4 ); +} diff --git a/src/DependencyTree/DependencyTree_Object.h b/src/DependencyTree/DependencyTree_Object.h new file mode 100644 index 000000000..4f4eaf147 --- /dev/null +++ b/src/DependencyTree/DependencyTree_Object.h @@ -0,0 +1,70 @@ +// 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_OBJECT_H +#define DEPENDENCYTREE_OBJECT_H + +#include + +#include + +class DependencyTree_Object: public GraphicsView_Object +{ + +public: + DependencyTree_Object( const QString&, QGraphicsItem* = 0 ); + ~DependencyTree_Object(); + + virtual void compute() {}; + + virtual bool highlight( double, double ); + virtual void unhighlight(); + + virtual bool select( double, double, const QRectF& ); + virtual void unselect(); + + QString getEntry() const; + + void updateName(); + + void setColor(const QColor& ); + void setSelectColor(const QColor& ); + void setMainObjectColor(const QColor& ); + + void setIsMainObject( bool ); + +private: + + QPen getPen( const QColor& ); + + QColor myColor; + QColor mySelectColor; + QColor myMainObjectColor; + + QGraphicsPolygonItem* myPolygonItem; + QGraphicsSimpleTextItem* myTextItem; + + QString myEntry; + + bool myIsMainObject; + bool myIsLongName; + +}; + +#endif diff --git a/src/DependencyTree/DependencyTree_View.cxx b/src/DependencyTree/DependencyTree_View.cxx new file mode 100644 index 000000000..7c6270f56 --- /dev/null +++ b/src/DependencyTree/DependencyTree_View.cxx @@ -0,0 +1,782 @@ +// 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 +#include +#include + + +#include "DependencyTree_View.h" +#include "DependencyTree_Object.h" +#include "DependencyTree_Arrow.h" + + +#include +#include +#include + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include + +// GUI includes +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + + + + +int iter = 0; + +DependencyTree_View::DependencyTree_View( QWidget* theParent ) +:GraphicsView_ViewPort(theParent), +myMaxDownwardLevelsNumber(0), +myMaxUpwardLevelsNumber(0), +myLevelsNumber(0), +myIsCompute(true), +myIsUpdate( true ) +{ + SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() ); + if ( !app ) return; + + SalomeApp_Study* study = dynamic_cast(app->activeStudy()); + + _PTR(Study) aStudy = study->studyDS(); + if ( !aStudy ) + return; + + SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy(aStudy); + + LightApp_SelectionMgr* aSelMgr = app->selectionMgr(); + if ( !aSelMgr ) return; + + SALOME_ListIO aSelList; + aSelMgr->selectedObjects(aSelList); + + GEOM::string_array_var ObjectIORs = new GEOM::string_array(); + ObjectIORs->length( aSelList.Extent()); + int aaa=0; + + for ( SALOME_ListIteratorOfListIO It( aSelList ); It.More(); It.Next() ) { + Handle( SALOME_InteractiveObject ) io = It.Value(); +// if ( io->IsKind(STANDARD_TYPE(GEOM_InteractiveObject))) { +// Handle(GEOM_InteractiveObject) objectGEOM = Handle(GEOM_InteractiveObject)::DownCast( io ); + +// const char* ior = objectGEOM->getIOR(); +// objectGEOM.getEntry(); +// objectGEOM.getName(); +// std::cout << "\n\n\n !!!!! IOR = " << ior << std::endl; +// } + + GEOM::GEOM_Object_var myObject = GEOM::GEOM_Object::_nil(); + myObject = GEOMBase::ConvertIOinGEOMObject( io ); + QString ior = GEOMBase::GetIORFromObject(myObject); + ObjectIORs[aaa] = ior.toLatin1().constData(); + aaa++; + + std::cout << "\n\n IOR = " << ior.toStdString() << std::endl; +// if ( !CORBA::is_nil( myObject ) ) +// myGrp->LineEdit1->setText( GEOMBase::GetName( myObject ) ); + } +// +// SALOME_ListIO selected; +// aSelMgr->selectedObjects( selected ); +// if ( selected.IsEmpty() ) return; +// +// GEOM::string_array ObjectIORs; +// ObjectIORs.lenght( selected.Extent()) +// for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) { +// Handle( SALOME_InteractiveObject ) io = It.Value(); +// const char* entry = io->getEntry(); +// ObjectIORs.push_back( entry ); +// //CORBA::String_var IOR = app->orb()->object_to_string( io ); +// //if ( strcmp(IOR.in(), "") != 0 ) +// //{ +//// QString objIOR = GEOMBase::GetIORFromObject( io ); +// //char* GetStringFromIOR(GEOM::GEOM_Object_ptr theObject) +// +// } + + SALOMEDS::TMPFile_var SeqFile = + GeometryGUI::GetGeomGen()->GetDependencyTree( aStudyDS, ObjectIORs ); + char* buf; + buf = (char*) &SeqFile[0]; + + std::cout << "\n\n\n\n\n TREE = " << buf << std::endl; +} + +DependencyTree_View::~DependencyTree_View() +{ + +} + +void DependencyTree_View::drawArrows() +{ + QMap >::iterator i; + for (i = myTreeModel.begin(); i != myTreeModel.end(); i++ ) { + DependencyTree_Object* Main_object = myTreeMap[i.key()]; + LevelInfo Levelup = i.value().first.at(0); + if( myDisplayAscendants ->isChecked() ) { + QMap::iterator node; + for (node = Levelup.begin(); node != Levelup.end(); node++ ) { + DependencyTree_Object* object = myTreeMap[node.key()]; + addArrow(Main_object, object); + } + } + if( myDisplayAscendants ->isChecked() ) + drawWardArrows( i.value().first ); + if( myDisplayDescendants->isChecked() ) + drawWardArrows( i.value().second ); + + } +} + +void DependencyTree_View::drawWardArrows( LevelsList theWard ) +{ + for(int j = 0; j < theWard.size(); j++ ) { + if( j >= myLevelsNumber ) + break; + LevelInfo Level = theWard.at(j); + QMap::iterator node; + for (node = Level.begin(); node != Level.end(); node++ ) { + DependencyTree_Object* object = myTreeMap[node.key()]; + QList Links = node.value(); + for( int link = 0; link < Links.size(); link++ ) { + DependencyTree_Object* LinkObject = myTreeMap[Links[link]]; + if( isItemAdded( object ) && isItemAdded( LinkObject ) ) { + addArrow(object, LinkObject); + } + } + } + } +} + + +void DependencyTree_View::parseData( QString& theData ) +{ + int cursor = 0; + + while( theData.indexOf('-',cursor) != -1 ) //find next selected object + { + int objectIndex = theData.indexOf( '-', cursor ); + QString objectEntry = theData.mid( cursor, objectIndex - cursor ); + addNode( objectEntry ); + std::cout<<"\n\nMainObject = " << objectEntry.toStdString() < myMaxUpwardLevelsNumber ) + myMaxUpwardLevelsNumber = upwardList.size(); + std::cout<<" Downward:" << std::endl; + LevelsList downwardList = parseWard( theData, cursor ); + if( downwardList.size() > myMaxDownwardLevelsNumber ) + myMaxDownwardLevelsNumber = downwardList.size(); + + myTreeModel[objectEntry] = QPair( upwardList, downwardList ); + } +} + +void DependencyTree_View::addNode( const QString& theEntry ) +{ + if( !myTreeMap[theEntry] ) + myTreeMap[theEntry] = new DependencyTree_Object( theEntry ); +} + +void DependencyTree_View::addArrow( DependencyTree_Object *startItem, DependencyTree_Object *endItem ) +{ + bool isFind = false; + + std::cout << " " << startItem->getEntry().toStdString() << " " << endItem->getEntry().toStdString() << std::endl; + for( int i = 0; i < Arrows.size(); i++ ) { + DependencyTree_Arrow* arrow = Arrows.at(i); + if( arrow->getStartItem() == startItem && arrow->getEndItem() == endItem ) { + isFind = true; + std::cout<<" theSame " << std::endl; + } + else if( arrow->getStartItem() == endItem && arrow->getEndItem() == startItem ) { + arrow->setIsBiLink( true ); + std::cout<<" Bilink " << std::endl; + isFind = true; + } + } + + if( !isFind ) { + DependencyTree_Arrow *arrow = new DependencyTree_Arrow(startItem, endItem); + Arrows.append( arrow ); + addItem(arrow); + std::cout<<" addArrow " << std::endl; + } +} + +DependencyTree_View::LevelsList DependencyTree_View::parseWard( const QString& theData, int& theCursor ) +{ + int indexStart = theData.indexOf( "{", theCursor ) + 1; + int indexEnd = theData.indexOf( "}", indexStart ); + + QString ward = theData.mid( indexStart, indexEnd - indexStart ); + QStringList levelsListStr = ward.split( ';' ); + LevelsList levelsListData; + for( int level = 0; level < levelsListStr.size(); level++ ) { + std::cout<<" Level" << level + 1 << ":" << std::endl; + QStringList namesListStr = levelsListStr[level].split( ',' ); + LevelInfo levelInfoData; + for( int node = 0; node < namesListStr.size(); node++ ) { + QStringList linksListStr = namesListStr[node].split( '_' ); + QString nodeItem = linksListStr[0]; + if( !nodeItem.isEmpty() ) { + addNode( nodeItem ); + NodeLinks linksListData; + std::cout<<" " << nodeItem.toStdString() << " - "; + for( int link = 1; link < linksListStr.size(); link++ ) { + QString linkItem = linksListStr[link]; + addNode( linkItem ); + linksListData.append( linkItem ); + std::cout << linkItem.toStdString() << ", "; + }// Links + levelInfoData[nodeItem] = linksListData; + std::cout << std::endl; + } + }// Level's objects + levelsListData.append(levelInfoData); + }// Levels + + theCursor = indexEnd + 1; + + return levelsListData; +} + +void DependencyTree_View::drawTree() +{ + + int horDistance, verDistance; + myCurrentLevel = 0; + std::cout<<"\n\n\n\n MY TREE MODEL SIZE = " << myTreeModel.size() << std::endl; + std::cout<<"\n\n\n\n MY TREE MAP SIZE = " << myTreeMap.size() << std::endl; + for( int j = 0; j < myTreeModel.keys().size(); j++ ) + std::cout<< " STRING = " << myTreeModel.keys().at(j).toStdString() << std::endl; + QMap >::iterator i; + for (i = myTreeModel.begin(); i != myTreeModel.end(); i++ ) { + myCurrentLevel = 0; + QString objectEntry = i.key(); + std::cout<< " NAME = " << objectEntry.toStdString() << std::endl; + DependencyTree_Object* objectItem = myTreeMap[ objectEntry ]; + objectItem->setEnabled(true); + if( objectItem->isEnabled() ) + std::cout<<"OK!!! "<< std::endl; + horDistance = 100 + int( objectItem->boundingRect().width() ); + verDistance = 3 * int( objectItem->boundingRect().height() ); + if( isItemAdded( objectItem ) ) { + myCurrentLevel = myLevelMap[ objectEntry ]; + } + else { + addItem( objectItem ); + std::cout<<"\nLevel = " << myCurrentLevel << " Object = " << objectEntry.toStdString() << std::endl; + myLevelMap[ objectEntry ] = myCurrentLevel; + myLevelsObject[ myCurrentLevel ].append( objectEntry ); + } + objectItem->setIsMainObject( true ); + + int levelposition = myCurrentLevel; + if( myDisplayAscendants ->isChecked() ){ + drawWard( i.value().first, -1 ); + myCurrentLevel = levelposition; + } + if( myDisplayDescendants->isChecked() ) + drawWard( i.value().second, 1 ); + + //centerOn( objectItem ); + } + + QMap< int, QList >::iterator j; + for (j = myLevelsObject.begin(); j != myLevelsObject.end(); j++ ) { + int step = -horDistance*( j.value().size() - 1 )/2; + std::cout<<"\n\n LEVEL = " << j.key() << std::endl; + for( int object = 0; object < j.value().size(); object++ ) { + if( myIsCompute ) { + std::cout << j.value().at( object ).toStdString() << ", "; + DependencyTree_Object* anObject = myTreeMap[ j.value().at( object ) ]; + anObject->setPos( step, verDistance*j.key() ); + step += horDistance; + //sleep(1); + } + } + } + +} + +void DependencyTree_View::drawWard( const DependencyTree_View::LevelsList theWard, const int theLevelStep ) +{ + int levelsNumber = theWard.size(); + for( int level = 0; level < levelsNumber; level++ ) { + if( level >= myLevelsNumber ) + return; + myCurrentLevel += theLevelStep; + LevelInfo levelInfo = theWard.at( level ); + QMap::iterator node; + for (node = levelInfo.begin(); node != levelInfo.end(); node++ ) { + DependencyTree_Object* object = myTreeMap[ node.key() ]; + if( !isItemAdded( object ) ) { + addItem( object ); + myLevelMap[ node.key() ] = myCurrentLevel; + myLevelsObject[ myCurrentLevel ].append( node.key() ); + } + } + } +} + +void DependencyTree_View::onUpdateTree() +{ + myLevelMap.clear(); + myLevelsObject.clear(); + + + QMap::iterator i; + for (i = myTreeMap.begin(); i != myTreeMap.end(); i++ ) { + DependencyTree_Object* object = myTreeMap[ i.key() ]; + if( isItemAdded( object ) && object ) + removeItem( object ); + + } + + + std::cout<<"\n\n\n\n ARROWS = " << Arrows.size() << std::endl; + + for(int j = 0; jisChecked() && myDisplayDescendants->isChecked() ) + return myMaxUpwardLevelsNumber>myMaxDownwardLevelsNumber?myMaxUpwardLevelsNumber:myMaxDownwardLevelsNumber; + else if( myDisplayAscendants ->isChecked() ) + return myMaxUpwardLevelsNumber; + else if( myDisplayDescendants->isChecked() ) + return myMaxDownwardLevelsNumber; +} + + +void DependencyTree_View::init( GraphicsView_ViewFrame* theViewFrame ) +{ + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + QString Data = "MainObject1-upward{up11_up21_up22,up12_up23,up13_up24;up21_up11,up22_up21_up12,up23_up23,up24}" + "downward{down11_MainObject1,down12_MainObject1;down21_down11,down22_down12,down23_down12,down24_down24_down11,down25_down12;down31_down11_down23,down32_down25}" + "down23-upward{down12_MainObject1;MainObject1_up11_up12_up13;up11_up21_up22,up12_up23,up13_up24;up21,up22_up21_up12,up23,up24}" + "downward{down31_down11_down23}" + "MainObject2-upward{up21,newup11_newup31,newup12_newup21;newup21_newup31LongName;newup31LongName}downward{newdown11_MainObject2,newdown12_MainObject2,newdown13_MainObject2;newdown21_newdown13,down21;newdown31_newdown11}"; + + parseData( Data ); + + + myNodesMovable = new QCheckBox( tr( "MOVE_NODES" ) ); + QWidgetAction* moveNodesAction = new QWidgetAction( theViewFrame ); + moveNodesAction->setDefaultWidget( myNodesMovable ); + + myDisplayAscendants = new QCheckBox( tr( "DISPLAY_ASCENDANTS" )); + myDisplayAscendants ->setChecked( true ); + QWidgetAction* ShowParentsAction = new QWidgetAction(theViewFrame); + ShowParentsAction->setDefaultWidget( myDisplayAscendants ); + + myDisplayDescendants = new QCheckBox(tr("DISPLAY_DESCENDANTS")); + QWidgetAction* ShowChildrenAction = new QWidgetAction(theViewFrame); + ShowChildrenAction->setDefaultWidget( myDisplayDescendants ); + + myLevelsNumber = checkMaxLevelsNumber(); + myHierarchyDepth = new QSpinBox(); + myHierarchyDepth->setRange( 0, checkMaxLevelsNumber() ); + myHierarchyDepth->setValue( 0 ); + myHierarchyDepth->setSpecialValueText( "All" ); + QWidgetAction* LevelsAction = new QWidgetAction(theViewFrame); + LevelsAction->setDefaultWidget( myHierarchyDepth ); + + QLabel* LevelsLabel = new QLabel( tr("HIERARCHY_DEPTH") ); + QWidgetAction* LevelsLebelAction = new QWidgetAction(theViewFrame); + LevelsLebelAction->setDefaultWidget( LevelsLabel ); + + + QPushButton* UpdateButton = new QPushButton(tr("Update")); + QWidgetAction* UpdateAction = new QWidgetAction(theViewFrame); + UpdateAction->setDefaultWidget( UpdateButton ); + + cancelButton = new QPushButton(tr("CANCEL")); + cancelButton->setCheckable(true); + cancelButton->setVisible( false ); + cancelAction = new QWidgetAction(theViewFrame); + cancelAction->setDefaultWidget( cancelButton ); + cancelAction->setVisible(false); + + progressBar = new QProgressBar(this); + progressBar->setMinimum( 0 ); + progressBar->setMaximum( 1000 ); + progressBar->setFixedWidth(100); + progressAction = new QWidgetAction(theViewFrame); + progressAction->setDefaultWidget( progressBar ); + progressAction->setVisible(false); + + QAction* separator = theViewFrame->toolMgr()->separator(false); + theViewFrame->toolMgr()->append( separator, theViewFrame->getToolBarId() ); + theViewFrame->toolMgr()->append( moveNodesAction, theViewFrame->getToolBarId() ); + theViewFrame->toolMgr()->append( LevelsLebelAction, theViewFrame->getToolBarId() ); + theViewFrame->toolMgr()->append( LevelsAction, theViewFrame->getToolBarId() ); + theViewFrame->toolMgr()->append( ShowParentsAction, theViewFrame->getToolBarId() ); + theViewFrame->toolMgr()->append( ShowChildrenAction, theViewFrame->getToolBarId() ); + QAction* separator2 = theViewFrame->toolMgr()->separator(false); + theViewFrame->toolMgr()->append( separator2, theViewFrame->getToolBarId() ); + theViewFrame->toolMgr()->append( UpdateAction, theViewFrame->getToolBarId() ); + std::cout<<"\n\n\n\n ToolBarId = " << theViewFrame->getToolBarId() << std::endl; + theViewFrame->toolMgr()->append( progressAction, theViewFrame->getToolBarId() ); + theViewFrame->toolMgr()->append( cancelAction, theViewFrame->getToolBarId() ); + + connect(cancelButton, SIGNAL(clicked()), this, SLOT(onCancel())); + + 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( updateView() ) ); + connect( myNodesMovable, SIGNAL( toggled(bool) ), this, SLOT( onMoveNodes( bool ) ) ); + + 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 ) ); + +} + +void DependencyTree_View::onMoveNodes( bool theIsMoveNodes ) +{ + QMap::iterator i; + for (i = myTreeMap.begin(); i != myTreeMap.end(); i++ ) { + DependencyTree_Object* object = myTreeMap[ i.key() ]; + object->setMovable( theIsMoveNodes ); + } +} + +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(); +} +void DependencyTree_View::updateView() +{ + + if( !myIsUpdate ) + return; + + myLevelMap.clear(); + myLevelsObject.clear(); + + + QMap::iterator i; + for (i = myTreeMap.begin(); i != myTreeMap.end(); i++ ) { + DependencyTree_Object* object = myTreeMap[ i.key() ]; + if( isItemAdded( object ) && object ) + removeItem( object ); + + } + + + std::cout<<"\n\n\n\n ARROWS = " << Arrows.size() << std::endl; + + for(int j = 0; j(this) ); + cancelAction->setVisible( true ); + progressAction->setVisible(true); + startTimer(100); // millisecs + qthread->start(); +} + +void DependencyTree_View::onRedrawTree() +{ + drawTree(); + drawArrows(); +} +void DependencyTree_View::onCancel() +{ + qthread->cancel(); + cancelButton->setText( tr("CANCELING")); + cancelButton->setEnabled(false); +} + +void DependencyTree_View::timerEvent(QTimerEvent *event) +{ + if ( !cancelButton->isChecked() ) // not yet cancelled + // progressBar->setValue( progressBar->maximum() * qthread.getMesh()->GetComputeProgress() ); + progressBar->setValue( iter++ ); + + if(!myIsCompute || qthread->isFinished()) + { + cancelAction->setVisible( false ); + progressAction->setVisible(false); + cancelButton->setText( tr("CANCEL")); + cancelButton->setEnabled(true); + } + + event->accept(); +} + +void DependencyTree_View::closeEvent(QCloseEvent *event) +{ + if(qthread->isRunning()) + { + event->ignore(); + return; + } + event->accept(); +} + +void DependencyTree_View::setIsCompute( bool theIsCompute ) +{ + myIsCompute = theIsCompute; +} + +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; + onHierarchyType(); +} + +void DependencyTree_View::setNodesMovable( const bool theIsMovable ) +{ + myNodesMovable->setChecked( theIsMovable ); +} + +void DependencyTree_View::setPrefBackgroundColor( const QColor& theColor ) +{ + if( isForegroundEnabled() ) + { + setForegroundColor( theColor ); + updateForeground(); + } + else + setBackgroundColor( theColor ); +} + +void DependencyTree_View::setNodeColor( const QColor& theColor ) +{ + QMap::iterator i; + for (i = myTreeMap.begin(); i != myTreeMap.end(); i++ ) { + DependencyTree_Object* object = myTreeMap[ i.key() ]; + object->setColor( theColor ); + } +} + +void DependencyTree_View::setMainNodeColor( const QColor& theColor ) +{ + QMap::iterator i; + for (i = myTreeMap.begin(); i != myTreeMap.end(); i++ ) { + DependencyTree_Object* object = myTreeMap[ i.key() ]; + object->setMainObjectColor( theColor ); + } +} + +void DependencyTree_View::setSelectNodeColor( const QColor& theColor ) +{ + QMap::iterator i; + for (i = myTreeMap.begin(); i != myTreeMap.end(); i++ ) { + DependencyTree_Object* object = myTreeMap[ i.key() ]; + object->setSelectColor( theColor ); + } +} + +void DependencyTree_View::setArrowColor( const QColor& theColor ) +{ + for( int i = 0; i < Arrows.size(); i++ ) { + DependencyTree_Arrow* arrow = Arrows[i]; + arrow->setColor( theColor ); + } +} + +void DependencyTree_View::setHighlightArrowColor( const QColor& theColor ) +{ + for( int i = 0; i < Arrows.size(); i++ ) { + DependencyTree_Arrow* arrow = Arrows[i]; + arrow->setHighlightColor( theColor ); + } +} + +void DependencyTree_View::setSelectArrowColor( const QColor& theColor ) +{ + for( int i = 0; i < Arrows.size(); i++ ) { + DependencyTree_Arrow* arrow = Arrows[i]; + arrow->setSelectColor( theColor ); + } +} + +//================================================================================ +//================================================================================ + +DependencyTree_ComputeDlg_QThread::DependencyTree_ComputeDlg_QThread(DependencyTree_View* theView) +{ + myView = theView; +} + +void DependencyTree_ComputeDlg_QThread::run() +{ + myView->setIsCompute( true ); + myView->onRedrawTree(); +} + +bool DependencyTree_ComputeDlg_QThread::result() +{ + +} + +void DependencyTree_ComputeDlg_QThread::cancel() +{ + myView->setIsCompute( false ); +} + +////================================================================================ +////================================================================================ +// +//DependencyTree_ComputeDlg_QThreadQDialog::DependencyTree_ComputeDlg_QThreadQDialog(QWidget* parent, +// DependencyTree_View* theView) +// : QDialog(parent, +// Qt::WindowSystemMenuHint | +// Qt::WindowCloseButtonHint | +// Qt::Dialog | +// Qt::WindowMaximizeButtonHint), +// qthread( theView ) +//{ +// // -- +// setWindowTitle(tr("TITLE")); +// setMinimumWidth( 200 ); +// +// cancelButton = new QPushButton(tr("CANCEL")); +// cancelButton->setDefault(true); +// cancelButton->setCheckable(true); +// +// progressBar = new QProgressBar(this); +// progressBar->setMinimum( 0 ); +// progressBar->setMaximum( 1000 ); +// +// QGridLayout* layout = new QGridLayout(this); +// layout->setMargin( 11 ); +// layout->setSpacing( 6 ); +// int row = 0; +// layout->addWidget(progressBar, row++, 0, 1, 2); +// layout->addWidget(cancelButton, row++, 0, 1, 2); +// adjustSize(); +// update(); +// +// connect(cancelButton, SIGNAL(clicked()), this, SLOT(onCancel())); +// // -- +// startTimer(300); // millisecs +// qthread.start(); +//} +// +//bool DependencyTree_ComputeDlg_QThreadQDialog::result() +//{ +// return qthread.result(); +//} +// +//void DependencyTree_ComputeDlg_QThreadQDialog::onCancel() +//{ +// qthread.cancel(); +// cancelButton->setText( tr("CANCELING")); +// cancelButton->setEnabled(false); +//} +// +//void DependencyTree_ComputeDlg_QThreadQDialog::timerEvent(QTimerEvent *event) +//{ +// if ( !cancelButton->isChecked() ) // not yet cancelled +// // progressBar->setValue( progressBar->maximum() * qthread.getMesh()->GetComputeProgress() ); +// progressBar->setValue( 10 ); +// +// if(qthread.isFinished()) +// { +// close(); +// } +// +// event->accept(); +//} +// +//void DependencyTree_ComputeDlg_QThreadQDialog::closeEvent(QCloseEvent *event) +//{ +// if(qthread.isRunning()) +// { +// event->ignore(); +// return; +// } +// event->accept(); +//} +// + + diff --git a/src/DependencyTree/DependencyTree_View.h b/src/DependencyTree/DependencyTree_View.h new file mode 100644 index 000000000..02d0e322e --- /dev/null +++ b/src/DependencyTree/DependencyTree_View.h @@ -0,0 +1,178 @@ +// 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_VIEW_H +#define DEPENDENCYTREE_VIEW_H + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "DependencyTree_Arrow.h" + +class DependencyTree_Object; +class DependencyTree_View; + + +class DependencyTree_ComputeDlg_QThread : public QThread +{ + Q_OBJECT + +public: + DependencyTree_ComputeDlg_QThread(DependencyTree_View*); + bool result(); + void cancel(); + + DependencyTree_View* getView() { return myView; }; + +protected: + void run(); + +private: + DependencyTree_View* myView; +}; + +class DependencyTree_View: public GraphicsView_ViewPort +{ + Q_OBJECT +public: + + + DependencyTree_View( QWidget* theParent=0 ); + ~DependencyTree_View(); + + void setHierarchyType( const int ); + void setNodesMovable( const bool ); + void setPrefBackgroundColor( const QColor& ); + void setNodeColor( const QColor& ); + void setMainNodeColor( const QColor& ); + void setSelectNodeColor( const QColor& ); + void setArrowColor( const QColor& ); + void setHighlightArrowColor( const QColor& ); + void setSelectArrowColor( const QColor& ); + + typedef QList NodeLinks; + typedef QMap LevelInfo; + typedef QList LevelsList; + typedef QMap > TreeModel; + + TreeModel myTreeModel; + QMap myTreeMap; + QList Arrows; + + QMap myLevelMap; + + QMap< int, QList > myLevelsObject; + int myCurrentLevel; + + void init( GraphicsView_ViewFrame* ); + + void onRedrawTree(); + + void setIsCompute( bool theIsCompute ); + bool getIsCompute() { return myIsCompute; }; +private slots: + void onUpdateTree(); + void updateView(); + void onMoveNodes( bool ); + void onHierarchyType(); + +protected: + void timerEvent(QTimerEvent *timer); + void closeEvent(QCloseEvent *event); + +private slots: + void onCancel(); + +private: + void parseData( QString& data ); + void addNode( const QString& entry ); + void addArrow( DependencyTree_Object *startItem, DependencyTree_Object *endItem ); + void findArrow( DependencyTree_Object *startItem, DependencyTree_Object *endItem ); + DependencyTree_View::LevelsList parseWard( const QString& data, int& cursor ); + void drawTree(); + void drawWard( DependencyTree_View::LevelsList ward, const int levelStep ); + void drawArrows(); + void drawWardArrows( LevelsList ); + + int checkMaxLevelsNumber(); + int myLevelsNumber; + int myMaxDownwardLevelsNumber; + int myMaxUpwardLevelsNumber; + + QCheckBox* myNodesMovable; + QSpinBox* myHierarchyDepth; + QCheckBox* myDisplayAscendants; + QCheckBox* myDisplayDescendants; + + QString myData; + + bool myIsUpdate; + + GraphicsView_ViewFrame* myViewFrame; + + bool myIsCompute; + DependencyTree_ComputeDlg_QThread* qthread; + QPushButton * cancelButton; + QProgressBar* progressBar; + QWidgetAction* cancelAction; + QWidgetAction* progressAction; + +}; + + + +///*! +// * \brief Dialog to display Cancel button +// */ +// +//class DependencyTree_ComputeDlg_QThreadQDialog : public QDialog +//{ +// Q_OBJECT +// +//public: +// DependencyTree_ComputeDlg_QThreadQDialog(QWidget* parent, DependencyTree_View*); +// bool result(); +// +//protected: +// void timerEvent(QTimerEvent *timer); +// void closeEvent(QCloseEvent *event); +// +//private slots: +// void onCancel(); +// +//private: +// +// DependencyTree_ComputeDlg_QThread qthread; +// QPushButton * cancelButton; +// QProgressBar* progressBar; +//}; + +#endif diff --git a/src/DependencyTree/DependencyTree_ViewModel.cxx b/src/DependencyTree/DependencyTree_ViewModel.cxx new file mode 100644 index 000000000..deb504074 --- /dev/null +++ b/src/DependencyTree/DependencyTree_ViewModel.cxx @@ -0,0 +1,88 @@ +// 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 + +#include "DependencyTree_ViewModel.h" +#include "DependencyTree_View.h" + +#include + +#include +#include + +DependencyTree_ViewModel::DependencyTree_ViewModel( const QString& title ) +: GraphicsView_Viewer( title ) +{ +} + +DependencyTree_ViewModel::DependencyTree_ViewModel( const QString& title, QWidget* w ) +: GraphicsView_Viewer( title, w ) +{ + +} + +DependencyTree_ViewModel::~DependencyTree_ViewModel() +{ +} + +void DependencyTree_ViewModel::contextMenuPopup( QMenu* theMenu ) +{ + GraphicsView_Viewer::contextMenuPopup( theMenu ); + std::cout<<"\n\n\n\n *****contextMenuPopup " << std::endl; + + if( DependencyTree_View* aViewPort = dynamic_cast(getActiveViewPort()) ) + { + int aNbSelected = aViewPort->nbSelected(); + std::cout<<"\n aNbSelected " << aNbSelected << std::endl; + } + + +} + + +//SUIT_ViewWindow* DependencyTree_ViewModel::createView( SUIT_Desktop* theDesktop ) +//{ +// DependencyTree_ViewWindow* aViewFrame; +//if( myWidget ) +// aViewFrame = new DependencyTree_ViewWindow( theDesktop, this, myWidget ); +//else +// aViewFrame = new DependencyTree_ViewWindow( theDesktop, this ); +// +//connect( aViewFrame, SIGNAL( keyPressed( QKeyEvent* ) ), +// this, SLOT( onKeyEvent( QKeyEvent* ) ) ); +// +//connect( aViewFrame, SIGNAL( keyReleased( QKeyEvent* ) ), +// this, SLOT( onKeyEvent( QKeyEvent* ) ) ); +// +//connect( aViewFrame, SIGNAL( mousePressed( QGraphicsSceneMouseEvent* ) ), +// this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) ); +// +//connect( aViewFrame, SIGNAL( mouseMoving( QGraphicsSceneMouseEvent* ) ), +// this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) ); +// +//connect( aViewFrame, SIGNAL( mouseReleased( QGraphicsSceneMouseEvent* ) ), +// this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) ); +// +//connect( aViewFrame, SIGNAL( wheeling( QGraphicsSceneWheelEvent* ) ), +// this, SLOT( onWheelEvent( QGraphicsSceneWheelEvent* ) ) ); +// +//return aViewFrame; +//} + diff --git a/src/DependencyTree/DependencyTree_ViewModel.h b/src/DependencyTree/DependencyTree_ViewModel.h new file mode 100644 index 000000000..3223a00dc --- /dev/null +++ b/src/DependencyTree/DependencyTree_ViewModel.h @@ -0,0 +1,39 @@ +// 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 +#include + +class DependencyTree_ViewModel: public GraphicsView_Viewer +{ + +public: + + DependencyTree_ViewModel( const QString& title ); + DependencyTree_ViewModel( const QString& title, QWidget* w ); + ~DependencyTree_ViewModel(); + +public: + virtual void contextMenuPopup( QMenu* ); +// virtual SUIT_ViewWindow* createView( SUIT_Desktop* ); + +// static QString Type() { return "DependencyTree"; } + + +}; diff --git a/src/DependencyTree/resources/DependencyTree_msg_en.ts b/src/DependencyTree/resources/DependencyTree_msg_en.ts new file mode 100644 index 000000000..c62ab0de1 --- /dev/null +++ b/src/DependencyTree/resources/DependencyTree_msg_en.ts @@ -0,0 +1,35 @@ + + + + + DependencyTree_View + + DEPENDENCY_TREE + Dependency Tree + + + MOVE_NODES + Move nodes + + + HIERARCHY_DEPTH + Hierarchy depth + + + DISPLAY_ASCENDANTS + Display ascendants + + + DISPLAY_DESCENDANTS + Display descendants + + + CANCEL + Cancel + + + CANCELING + Canceling... + + + diff --git a/src/DependencyTree/resources/DependencyTree_msg_fr.ts b/src/DependencyTree/resources/DependencyTree_msg_fr.ts new file mode 100644 index 000000000..b4eae6fca --- /dev/null +++ b/src/DependencyTree/resources/DependencyTree_msg_fr.ts @@ -0,0 +1,12 @@ + + + + + @default + + MEN_TEXTURE + Texture + + + + diff --git a/src/DependencyTree/resources/DependencyTree_msg_ja.ts b/src/DependencyTree/resources/DependencyTree_msg_ja.ts new file mode 100644 index 000000000..26250801e --- /dev/null +++ b/src/DependencyTree/resources/DependencyTree_msg_ja.ts @@ -0,0 +1,12 @@ + + + + + @default + + MEN_TEXTURE + Texture + + + + diff --git a/src/GEOMGUI/CMakeLists.txt b/src/GEOMGUI/CMakeLists.txt index c5dc25f8a..9ac751273 100755 --- a/src/GEOMGUI/CMakeLists.txt +++ b/src/GEOMGUI/CMakeLists.txt @@ -39,6 +39,7 @@ INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/GEOMClient ${PROJECT_SOURCE_DIR}/src/GEOMImpl ${PROJECT_SOURCE_DIR}/src/GEOMUtils + ${PROJECT_SOURCE_DIR}/src/DependencyTree ${CMAKE_CURRENT_SOURCE_DIR} ) @@ -58,6 +59,7 @@ SET(_link_LIBRARIES Material GEOMImpl GEOMUtils + DependencyTree ${KERNEL_SALOMELocalTrace} ${KERNEL_SalomeDS} ${KERNEL_SalomeDSClient} diff --git a/src/GEOMGUI/GEOM_msg_en.ts b/src/GEOMGUI/GEOM_msg_en.ts index 30942dd61..39e2393f5 100644 --- a/src/GEOMGUI/GEOM_msg_en.ts +++ b/src/GEOMGUI/GEOM_msg_en.ts @@ -5024,6 +5024,62 @@ Please, select face, shell or solid and try again GEOM_PREVIEW Preview + + PREF_TAB_DEPENDENCY_VIEW + Dependency Tree + + + PREF_HIERARCHY_TYPE + Hierarchy type + + + MEN_ONLY_ASCENDANTS + Display only ascendants tree + + + MEN_ONLY_DESCENDANTS + Display only descendants tree + + + MEN_BOTH_ASCENDANTS_DESCENDANTS + Display both ascendants and descendants trees + + + GEOM_MOVE_POSSIBILITY + Possibility to move nodes + + + PREF_GROUP_DEPENDENCY_VIEW_COLOR + Color + + + PREF_DEPENDENCY_VIEW_BACKGROUND_COLOR + Background color + + + PREF_DEPENDENCY_VIEW_NODE_COLOR + Default node color + + + PREF_DEPENDENCY_VIEW_MAIN_NODE_COLOR + Main node color + + + PREF_DEPENDENCY_VIEW_SELECT_NODE_COLOR + Selected node color + + + PREF_DEPENDENCY_VIEW_ARROW_COLOR + Arrow color + + + PREF_DEPENDENCY_VIEW_HIGHLIGHT_ARROW_COLOR + Highlighted arrow color + + + PREF_DEPENDENCY_VIEW_SELECT_ARROW_COLOR + Selected arrow color + GEOM_ALL_IMPORT_FILES All supported formats ( %1 ) diff --git a/src/GEOMGUI/GeometryGUI.cxx b/src/GEOMGUI/GeometryGUI.cxx index f10e4a026..3e9a1c2c8 100644 --- a/src/GEOMGUI/GeometryGUI.cxx +++ b/src/GEOMGUI/GeometryGUI.cxx @@ -75,6 +75,10 @@ #include #include +#include +#include +#include + #include // #include #include @@ -502,6 +506,7 @@ void GeometryGUI::OnGUIEvent( int id, const QVariant& theParam ) case GEOMOp::OpClsBringToFront: // case GEOMOp::OpCreateFolder: // POPUP MENU - CREATE FOLDER case GEOMOp::OpSortChildren: // POPUP MENU - SORT CHILD ITEMS + case GEOMOp::OpShowDependencyTree: // POPUP MENU - SHOW DEPENDENCY TREE libName = "GEOMToolsGUI"; break; case GEOMOp::OpDMWireframe: // MENU VIEW - WIREFRAME @@ -1077,6 +1082,7 @@ void GeometryGUI::initialize( CAM_Application* app ) createGeomAction( GEOMOp::OpPredefMaterCustom, "POP_PREDEF_MATER_CUSTOM" ); createGeomAction( GEOMOp::OpCreateFolder, "POP_CREATE_FOLDER" ); createGeomAction( GEOMOp::OpSortChildren, "POP_SORT_CHILD_ITEMS" ); + createGeomAction( GEOMOp::OpShowDependencyTree, "POP_SHOW_DEPENDENCY_TREE" ); createGeomAction( GEOMOp::OpShowAllDimensions, "POP_SHOW_ALL_DIMENSIONS" ); createGeomAction( GEOMOp::OpHideAllDimensions, "POP_HIDE_ALL_DIMENSIONS" ); @@ -1622,6 +1628,10 @@ void GeometryGUI::initialize( CAM_Application* app ) mgr->insert( action( GEOMOp::OpSortChildren ), -1, -1 ); // Sort child items mgr->setRule( action( GEOMOp::OpSortChildren ), QString("client='ObjectBrowser' and $component={'GEOM'} and nbChildren>1"), QtxPopupMgr::VisibleRule ); + 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->hide( mgr->actionId( action( myEraseAll ) ) ); SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); @@ -2617,6 +2627,50 @@ void GeometryGUI::createPreferences() addPreference( tr( "GEOM_PREVIEW" ), operationsGroup, LightApp_Preferences::Bool, "Geometry", "geom_preview" ); + + int DependencyViewId = addPreference( tr( "PREF_TAB_DEPENDENCY_VIEW" ) ); + + int hierarchy_type = addPreference( tr( "PREF_HIERARCHY_TYPE" ), DependencyViewId, + LightApp_Preferences::Selector, "Geometry", "dependency_tree_hierarchy_type" ); + + QStringList aHierarchyTypeList; + aHierarchyTypeList.append( tr("MEN_BOTH_ASCENDANTS_DESCENDANTS") ); + aHierarchyTypeList.append( tr("MEN_ONLY_ASCENDANTS") ); + aHierarchyTypeList.append( tr("MEN_ONLY_DESCENDANTS") ); + + QList aHierarchyTypeIndexesList; + aHierarchyTypeIndexesList.append(0); + aHierarchyTypeIndexesList.append(1); + aHierarchyTypeIndexesList.append(2); + + setPreferenceProperty( hierarchy_type, "strings", aHierarchyTypeList ); + setPreferenceProperty( hierarchy_type, "indexes", aHierarchyTypeIndexesList ); + + addPreference( tr( "GEOM_MOVE_POSSIBILITY" ), DependencyViewId, + LightApp_Preferences::Bool, "Geometry", "dependency_tree_move_nodes" ); + + int treeColorGroup = addPreference( tr( "PREF_GROUP_DEPENDENCY_VIEW_COLOR" ), DependencyViewId ); + + addPreference( tr( "PREF_DEPENDENCY_VIEW_BACKGROUND_COLOR"), treeColorGroup, + LightApp_Preferences::Color, "Geometry", "dependency_tree_background_color" ); + + addPreference( tr( "PREF_DEPENDENCY_VIEW_NODE_COLOR"), treeColorGroup, + LightApp_Preferences::Color, "Geometry", "dependency_tree_node_color" ); + addPreference( tr( "PREF_DEPENDENCY_VIEW_MAIN_NODE_COLOR"), treeColorGroup, + LightApp_Preferences::Color, "Geometry", "dependency_tree_main_node_color" ); + addPreference( tr( "PREF_DEPENDENCY_VIEW_SELECT_NODE_COLOR"), treeColorGroup, + LightApp_Preferences::Color, "Geometry", "dependency_tree_select_node_color" ); + + addPreference( tr( "PREF_DEPENDENCY_VIEW_ARROW_COLOR"), treeColorGroup, + LightApp_Preferences::Color, "Geometry", "dependency_tree_arrow_color" ); + addPreference( tr( "PREF_DEPENDENCY_VIEW_HIGHLIGHT_ARROW_COLOR"), treeColorGroup, + LightApp_Preferences::Color, "Geometry", "dependency_tree_highlight_arrow_color" ); + addPreference( tr( "PREF_DEPENDENCY_VIEW_SELECT_ARROW_COLOR"), treeColorGroup, + LightApp_Preferences::Color, "Geometry", "dependency_tree_select_arrow_color" ); + + + + } void GeometryGUI::preferencesChanged( const QString& section, const QString& param ) @@ -2687,6 +2741,55 @@ void GeometryGUI::preferencesChanged( const QString& section, const QString& par aDisplayer.UpdateViewer(); } + else if ( param.startsWith( "dependency_tree") ) + { + SalomeApp_Application* app = getApp(); + if ( !app ) return; + + SUIT_ViewManager *svm = app->getViewManager( GraphicsView_Viewer::Type(), false ); + if( !svm ) return; + + if( DependencyTree_ViewModel* viewModel = dynamic_cast( svm->getViewModel() ) ) + if( DependencyTree_View* view = dynamic_cast( viewModel->getActiveViewPort() ) ) { + if( param == QString("dependency_tree_hierarchy_type") ) { + int hierarchyType = aResourceMgr->integerValue( section, param, 0); + view->setHierarchyType( hierarchyType ); + } + else if( param == QString("dependency_tree_move_nodes") ) { + bool isNodesMovable = aResourceMgr->booleanValue( section, param, true); + view->setNodesMovable( isNodesMovable ); + } + else if( param == QString("dependency_tree_background_color") ) { + QColor c = aResourceMgr->colorValue( section, param, QColor( 255, 255, 255 ) ); + view->setPrefBackgroundColor( c ); + } + else if( param == QString("dependency_tree_node_color") ) { + QColor c = aResourceMgr->colorValue( section, param, QColor( 62, 180, 238 ) ); + view->setNodeColor( c ); + } + else if( param == QString("dependency_tree_main_node_color") ) { + QColor c = aResourceMgr->colorValue( section, param, QColor( 238, 90, 125 ) ); + view->setMainNodeColor( c ); + } + else if( param == QString("dependency_tree_select_node_color") ) { + QColor c = aResourceMgr->colorValue( section, param, QColor( 237, 243, 58 ) ); + view->setSelectNodeColor( c ); + } + else if( param == QString("dependency_tree_arrow_color") ) { + QColor c = aResourceMgr->colorValue( section, param, QColor( 0, 0, 130 ) ); + view->setArrowColor( c ); + } + else if( param == QString("dependency_tree_highlight_arrow_color") ) { + QColor c = aResourceMgr->colorValue( section, param, QColor( 0, 0, 255 ) ); + view->setHighlightArrowColor( c ); + } + else if( param == QString("dependency_tree_select_arrow_color") ) { + QColor c = aResourceMgr->colorValue( section, param, QColor( 255, 0, 0 ) ); + view->setSelectArrowColor( c ); + } + + } + } } } diff --git a/src/GEOMGUI/GeometryGUI_Operations.h b/src/GEOMGUI/GeometryGUI_Operations.h index 1f2dc8186..3f7f51d4d 100644 --- a/src/GEOMGUI/GeometryGUI_Operations.h +++ b/src/GEOMGUI/GeometryGUI_Operations.h @@ -61,6 +61,7 @@ namespace GEOMOp { OpIsosWidth = 1261, // POPUP MENU - LINE WIDTH - ISOS WIDTH OpCreateFolder = 1262, // POPUP MENU - CREATE FOLDER OpSortChildren = 1263, // POPUP MENU - SORT CHILD ITEMS + OpShowDependencyTree = 1264, // POPUP MENU - SHOW DEPENDENCY TREE // DisplayGUI ------------------//-------------------------------- OpSwitchVectors = 2001, // MENU VIEW - DISPLAY MODE - SHOW/HIDE EDGE DIRECTION OpShowAll = 2002, // MENU VIEW - SHOW ALL diff --git a/src/GEOMToolsGUI/CMakeLists.txt b/src/GEOMToolsGUI/CMakeLists.txt index 143d07826..8d6a756de 100755 --- a/src/GEOMToolsGUI/CMakeLists.txt +++ b/src/GEOMToolsGUI/CMakeLists.txt @@ -38,6 +38,7 @@ INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/GEOMGUI ${PROJECT_SOURCE_DIR}/src/GEOMBase ${PROJECT_SOURCE_DIR}/src/Material + ${PROJECT_SOURCE_DIR}/src/DependencyTree ${CMAKE_CURRENT_SOURCE_DIR} ) @@ -56,6 +57,7 @@ SET(_link_LIBRARIES GEOM GEOMBase Material + DependencyTree ) # --- headers --- diff --git a/src/GEOMToolsGUI/GEOMToolsGUI.cxx b/src/GEOMToolsGUI/GEOMToolsGUI.cxx index daf888e2d..62f145411 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI.cxx +++ b/src/GEOMToolsGUI/GEOMToolsGUI.cxx @@ -422,6 +422,8 @@ bool GEOMToolsGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent) break; case GEOMOp::OpSortChildren: OnSortChildren(); + case GEOMOp::OpShowDependencyTree: + OnShowDependencyTree(); break; default: SUIT_Session::session()->activeApplication()->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID)); diff --git a/src/GEOMToolsGUI/GEOMToolsGUI.h b/src/GEOMToolsGUI/GEOMToolsGUI.h index 683fffc7c..a0e1049f7 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI.h +++ b/src/GEOMToolsGUI/GEOMToolsGUI.h @@ -90,6 +90,7 @@ private: void OnClsBringToFront(); void OnCreateFolder(); void OnSortChildren(); + void OnShowDependencyTree(); // Shortcut commands void OnChangeTransparency( bool ); diff --git a/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx b/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx index ea5f7b1c9..fd817c14a 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx +++ b/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx @@ -46,6 +46,8 @@ #include #include +#include + #include #include @@ -862,3 +864,8 @@ void GEOMToolsGUI::OnSortChildren() app->updateObjectBrowser( true ); } + +void GEOMToolsGUI::OnShowDependencyTree() +{ + DependencyTree(); +} -- 2.30.2