From: mpa Date: Tue, 16 Dec 2014 15:13:39 +0000 (+0300) Subject: 0022768: [EDF] Model inspector X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1a61b19c1e7bbf08e2c93ea67356208732da23a3;p=modules%2Fgeom.git 0022768: [EDF] Model inspector --- diff --git a/src/GEOMGUI/GEOM_images.ts b/src/GEOMGUI/GEOM_images.ts index 14cf841bc..bd00e6be9 100644 --- a/src/GEOMGUI/GEOM_images.ts +++ b/src/GEOMGUI/GEOM_images.ts @@ -235,6 +235,10 @@ ICON_DLG_UNION_FACES union_faces.png + + ICON_DLG_INSPECT_OBJECT + inspect_object.png + ICON_DLG_CHECKSHAPE check.png diff --git a/src/GEOMGUI/GEOM_msg_en.ts b/src/GEOMGUI/GEOM_msg_en.ts index 1630caf5a..0909447d0 100644 --- a/src/GEOMGUI/GEOM_msg_en.ts +++ b/src/GEOMGUI/GEOM_msg_en.ts @@ -4748,6 +4748,18 @@ Please, select face, shell or solid and try again STB_UNION_FACES Union faces + + TOP_INSPECT_OBJECT + Inspect Object + + + MEN_INSPECT_OBJECT + Inspect Object + + + STB_INSPECT_OBJECT + Inspect Object + TOP_NORMALE Normal to a face @@ -6981,6 +6993,45 @@ Do you want to create new material? UnionFaces + + RepairGUI_InspectObjectDlg + + GEOM_INSPECT_OBJECT_TITLE + Inspect object + + + GEOM_INSPECT_OBJECT_MAIN_SHAPE + Main shape + + + GEOM_INSPECT_OBJECT_SHOW + Show Selected + + + GEOM_INSPECT_OBJECT_SHOW_ONLY + Show Only Selected + + + GEOM_INSPECT_OBJECT_HIDE + Hide Selected + + + GEOM_INSPECT_OBJECT_PUBLISH + Publish Selected + + + GEOM_INSPECT_OBJECT_NAME + Name + + + RENAME_COMPONENT + Change component name + + + COMPONENT_NAME + Name: + + GEOMGUI_CreationInfoWdg diff --git a/src/GEOMGUI/GEOM_msg_fr.ts b/src/GEOMGUI/GEOM_msg_fr.ts index 037d015c5..024c2dd32 100644 --- a/src/GEOMGUI/GEOM_msg_fr.ts +++ b/src/GEOMGUI/GEOM_msg_fr.ts @@ -4684,6 +4684,18 @@ Choisissez une face, une coque ou un solide et essayez de nouveau STB_UNION_FACES Unir les faces + + TOP_INSPECT_OBJECT + Inspect Object + + + MEN_INSPECT_OBJECT + Inspect Object + + + STB_INSPECT_OBJECT + Inspect Object + TOP_NORMALE Vecteur normal à une face @@ -6945,6 +6957,45 @@ Voulez-vous en créer un nouveau ? UnirFaces + + RepairGUI_InspectObjectDlg + + GEOM_INSPECT_OBJECT_TITLE + Inspect object + + + GEOM_INSPECT_OBJECT_MAIN_SHAPE + Main shape + + + GEOM_INSPECT_OBJECT_SHOW + Show Selected + + + GEOM_INSPECT_OBJECT_SHOW_ONLY + Show Only Selected + + + GEOM_INSPECT_OBJECT_HIDE + Hide Selected + + + GEOM_INSPECT_OBJECT_PUBLISH + Publish Selected + + + GEOM_INSPECT_OBJECT_NAME + Name + + + RENAME_COMPONENT + Changer le nom de la composante + + + COMPONENT_NAME + Nom: + + GEOMGUI_CreationInfoWdg diff --git a/src/GEOMGUI/GEOM_msg_ja.ts b/src/GEOMGUI/GEOM_msg_ja.ts index 65c9fcd45..13c65de93 100644 --- a/src/GEOMGUI/GEOM_msg_ja.ts +++ b/src/GEOMGUI/GEOM_msg_ja.ts @@ -4675,6 +4675,18 @@ STB_UNION_FACES 連合に直面しています。 + + TOP_INSPECT_OBJECT + Inspect Object + + + MEN_INSPECT_OBJECT + Inspect Object + + + STB_INSPECT_OBJECT + Inspect Object + TOP_NORMALE フェースに垂直 @@ -6922,6 +6934,45 @@ UnionFaces + + RepairGUI_InspectObjectDlg + + GEOM_INSPECT_OBJECT_TITLE + Inspect object + + + GEOM_INSPECT_OBJECT_MAIN_SHAPE + Main shape + + + GEOM_INSPECT_OBJECT_SHOW + Show Selected + + + GEOM_INSPECT_OBJECT_SHOW_ONLY + Show Only Selected + + + GEOM_INSPECT_OBJECT_HIDE + Hide Selected + + + GEOM_INSPECT_OBJECT_PUBLISH + Publish Selected + + + GEOM_INSPECT_OBJECT_NAME + Name + + + RENAME_COMPONENT + コンポーネントの名前変更 + + + COMPONENT_NAME + コンポーネント名 + + GEOMGUI_CreationInfoWdg diff --git a/src/GEOMGUI/GeometryGUI.cxx b/src/GEOMGUI/GeometryGUI.cxx index be77999a9..27c7b8aad 100644 --- a/src/GEOMGUI/GeometryGUI.cxx +++ b/src/GEOMGUI/GeometryGUI.cxx @@ -621,6 +621,7 @@ void GeometryGUI::OnGUIEvent( int id, const QVariant& theParam ) case GEOMOp::OpRemoveExtraEdges: // MENU REPAIR - REMOVE EXTRA EDGES case GEOMOp::OpFuseEdges: // MENU REPAIR - FUSE COLLINEAR EDGES case GEOMOp::OpUnionFaces: // MENU REPAIR - UNION FACES + case GEOMOp::OpInspectObj: // MENU REPAIR - INSPECT OBJECT libName = "RepairGUI"; break; case GEOMOp::OpProperties: // MENU MEASURE - PROPERTIES @@ -997,6 +998,7 @@ void GeometryGUI::initialize( CAM_Application* app ) createGeomAction( GEOMOp::OpRemoveExtraEdges, "REMOVE_EXTRA_EDGES" ); createGeomAction( GEOMOp::OpFuseEdges, "FUSE_EDGES" ); createGeomAction( GEOMOp::OpUnionFaces, "UNION_FACES" ); + createGeomAction( GEOMOp::OpInspectObj, "INSPECT_OBJECT" ); createGeomAction( GEOMOp::OpPointCoordinates, "POINT_COORDS" ); createGeomAction( GEOMOp::OpProperties, "BASIC_PROPS" ); @@ -1243,6 +1245,7 @@ void GeometryGUI::initialize( CAM_Application* app ) createMenu( GEOMOp::OpRemoveExtraEdges, repairId, -1 ); createMenu( GEOMOp::OpFuseEdges, repairId, -1 ); createMenu( GEOMOp::OpUnionFaces, repairId, -1 ); + createMenu( GEOMOp::OpInspectObj, repairId, -1 ); int measurId = createMenu( tr( "MEN_MEASURES" ), -1, -1, 10 ); createMenu( GEOMOp::OpPointCoordinates, measurId, -1 ); diff --git a/src/GEOMGUI/GeometryGUI_Operations.h b/src/GEOMGUI/GeometryGUI_Operations.h index 9a1e4fd40..5dbfe8fa3 100644 --- a/src/GEOMGUI/GeometryGUI_Operations.h +++ b/src/GEOMGUI/GeometryGUI_Operations.h @@ -175,6 +175,7 @@ namespace GEOMOp { OpFuseEdges = 4014, // MENU REPAIR - FUSE COLLINEAR EDGES OpUnionFaces = 4015, // MENU REPAIR - UNION FACES OpRemoveWebs = 4016, // MENU REPAIR - REMOVE INTERNAL FACES + OpInspectObj = 4017, // MENU REPAIR - INSPECT OBJECT // MeasureGUI ------------------//-------------------------------- OpProperties = 5000, // MENU MEASURES - PROPERTIES OpCenterMass = 5001, // MENU MEASURES - CENTRE OF MASS diff --git a/src/RepairGUI/CMakeLists.txt b/src/RepairGUI/CMakeLists.txt index 9cc1ac419..9d26ede7b 100755 --- a/src/RepairGUI/CMakeLists.txt +++ b/src/RepairGUI/CMakeLists.txt @@ -83,6 +83,7 @@ SET(RepairGUI_HEADERS RepairGUI_RemoveExtraEdgesDlg.h RepairGUI_UnionFacesDlg.h RepairGUI_FuseEdgesDlg.h + RepairGUI_InspectObjectDlg.h ) # header files / to be processed by moc @@ -103,6 +104,7 @@ SET(_moc_HEADERS RepairGUI_RemoveExtraEdgesDlg.h RepairGUI_UnionFacesDlg.h RepairGUI_FuseEdgesDlg.h + RepairGUI_InspectObjectDlg.h ) # header files / uic wrappings @@ -131,6 +133,7 @@ SET(RepairGUI_SOURCES RepairGUI_RemoveExtraEdgesDlg.cxx RepairGUI_UnionFacesDlg.cxx RepairGUI_FuseEdgesDlg.cxx + RepairGUI_InspectObjectDlg.cxx ${_moc_SOURCES} ${_uic_files} ) diff --git a/src/RepairGUI/RepairGUI.cxx b/src/RepairGUI/RepairGUI.cxx index cb0608260..44d0e434f 100644 --- a/src/RepairGUI/RepairGUI.cxx +++ b/src/RepairGUI/RepairGUI.cxx @@ -47,6 +47,7 @@ #include "RepairGUI_RemoveExtraEdgesDlg.h" // Method REMOVE EXTRA EDGES #include "RepairGUI_FuseEdgesDlg.h" // Method FUSE COLLINEAR EDGES #include "RepairGUI_UnionFacesDlg.h" // Method UNION FACES +#include "RepairGUI_InspectObjectDlg.h" // Method INSPECT OBJECT //======================================================================= // function : RepairGUI() @@ -96,6 +97,7 @@ bool RepairGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent ) case GEOMOp::OpRemoveExtraEdges: aDlg = new RepairGUI_RemoveExtraEdgesDlg (getGeometryGUI(), parent); break; case GEOMOp::OpFuseEdges: aDlg = new RepairGUI_FuseEdgesDlg (getGeometryGUI(), parent); break; case GEOMOp::OpUnionFaces: aDlg = new RepairGUI_UnionFacesDlg (getGeometryGUI(), parent); break; + case GEOMOp::OpInspectObj: aDlg = new RepairGUI_InspectObjectDlg (parent); break; default: app->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID)); break; diff --git a/src/RepairGUI/RepairGUI_InspectObjectDlg.cxx b/src/RepairGUI/RepairGUI_InspectObjectDlg.cxx new file mode 100644 index 000000000..77b3588bb --- /dev/null +++ b/src/RepairGUI/RepairGUI_InspectObjectDlg.cxx @@ -0,0 +1,628 @@ +// 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 +// + +// internal includes +#include "RepairGUI_InspectObjectDlg.h" + +// GEOM includes +#include +#include + +// GUI includes +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include +#include + +// OCCT includes +#include + +// Qt includes +#include +#include +#include +#include + +//================================================================================= +// class : RepairGUI_InspectObjectDlg +// purpose : class for "Inspect Object" tree item creation +//================================================================================= +class RepairGUI_InspectObjectDlg::TreeWidgetItem : public QTreeWidgetItem +{ +public: + TreeWidgetItem( QTreeWidget*, const QStringList&, const TopoDS_Shape&, const Handle(SALOME_InteractiveObject)&, int = Type ); + TreeWidgetItem( QTreeWidgetItem*, const QStringList&, const TopoDS_Shape&, const QString&, int = Type ); + ~TreeWidgetItem(); + + bool isVisible(); + void setVisible( bool, QIcon& ); + + TopoDS_Shape getShape() const; + Handle(SALOME_InteractiveObject) getIO() const; + +private: + bool myIsVisible; + TopoDS_Shape myShape; + Handle(SALOME_InteractiveObject) myIO; + +}; + +RepairGUI_InspectObjectDlg::TreeWidgetItem::TreeWidgetItem( QTreeWidget* view, const QStringList &strings, const TopoDS_Shape& shape, + const Handle(SALOME_InteractiveObject)& io, int type ) +: QTreeWidgetItem( view, strings, type ), + myIsVisible( false ), + myShape( shape ), + myIO( io ) +{ +} + +RepairGUI_InspectObjectDlg::TreeWidgetItem::TreeWidgetItem( QTreeWidgetItem* parent, const QStringList &strings, + const TopoDS_Shape& shape, const QString& entry, int type ) +: QTreeWidgetItem( parent, strings, type ), + myIsVisible( false ), + myShape( shape ) +{ + myIO = new SALOME_InteractiveObject( entry.toAscii(), "GEOM", "TEMP_IO" ); +} + +RepairGUI_InspectObjectDlg::TreeWidgetItem::~TreeWidgetItem() +{ +} + +bool RepairGUI_InspectObjectDlg::TreeWidgetItem::isVisible() +{ + return myIsVisible; +} + +void RepairGUI_InspectObjectDlg::TreeWidgetItem::setVisible( bool isVisible, QIcon& icon ) +{ + myIsVisible = isVisible; + setIcon( 1, icon ); +} + +TopoDS_Shape RepairGUI_InspectObjectDlg::TreeWidgetItem::getShape() const +{ + return myShape; +} + +Handle(SALOME_InteractiveObject) RepairGUI_InspectObjectDlg::TreeWidgetItem::getIO() const +{ + return myIO; +} + +//================================================================================= +// class : RepairGUI_InspectObjectDlg() +// purpose : Constructs a RepairGUI_InspectObjectDlg which is a child of 'parent'. +//================================================================================= +RepairGUI_InspectObjectDlg::RepairGUI_InspectObjectDlg( SUIT_Desktop* parent ) +: GEOMBase_Helper( parent ), + QDialog( parent ), + myTransparency( 0.0 ), + myIsSelectAll( false ) +{ + QIcon iconSelect( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) ); + myVisible = QIcon( SUIT_Session::session()->resourceMgr()->loadPixmap( "SUIT", tr( "ICON_DATAOBJ_VISIBLE" ) ) ); + myInvisible = QIcon( SUIT_Session::session()->resourceMgr()->loadPixmap( "SUIT", tr( "ICON_DATAOBJ_INVISIBLE" ) ) ); + + setWindowTitle( tr( "GEOM_INSPECT_OBJECT_TITLE" ) ); + setAttribute( Qt::WA_DeleteOnClose ); + + myApp = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() ); + if ( !myApp ) return; + + SUIT_ViewWindow* aViewWindow = 0; + SUIT_Study* activeStudy = myApp->activeStudy(); + if (activeStudy) + aViewWindow = myApp->desktop()->activeWindow(); + if (aViewWindow == 0) return; + SalomeApp_Study* aStudy = dynamic_cast( myApp->activeStudy() ); + SUIT_ViewManager* aViewManager = aViewWindow->getViewManager(); + if( aViewManager->getType() != OCCViewer_Viewer::Type() && + aViewManager->getType() != SVTK_Viewer::Type()) + return; + + myGlobalId = aViewManager->getGlobalId(); + + QGridLayout* topLayout = new QGridLayout( this ); + topLayout->setMargin( 11 ); topLayout->setSpacing( 6 ); + + /********************** Inspected Object **********************/ + + QHBoxLayout* mainShapeLayout = new QHBoxLayout(); + + QLabel* label = new QLabel( tr( "GEOM_INSPECT_OBJECT_MAIN_SHAPE" ) ); + QPushButton* selBtn = new QPushButton(); + selBtn->setIcon( iconSelect ); + myEditMainShape = new QLineEdit(); + myEditMainShape->setReadOnly(true); + + mainShapeLayout->addWidget( label ); + mainShapeLayout->addWidget( selBtn ); + mainShapeLayout->addWidget( myEditMainShape ); + + /********************** Sub-objects tree **********************/ + + myTreeObjects = new QTreeWidget(); + myTreeObjects->setColumnCount( 2 ); + QStringList columnNames; + columnNames.append( tr( "GEOM_INSPECT_OBJECT_NAME" ) ); + columnNames.append(""); + myTreeObjects->setHeaderLabels( columnNames ); + QTreeWidgetItem* headerItem = new QTreeWidgetItem( columnNames ); + myTreeObjects->setHeaderItem( headerItem ); + myTreeObjects->header()->moveSection( 1, 0 ); + myTreeObjects->header()->setClickable( true ); + myTreeObjects->header()->setMovable( false ); + myTreeObjects->header()->setResizeMode( 1, QHeaderView::ResizeToContents ); + myTreeObjects->setSelectionMode( QAbstractItemView::ExtendedSelection ); + + /********************** Buttons **********************/ + + QVBoxLayout* buttonsLayout1 = new QVBoxLayout(); + + QPushButton* buttonShow = new QPushButton( tr( "GEOM_INSPECT_OBJECT_SHOW" ) ); + QPushButton* buttonShowOnly = new QPushButton( tr( "GEOM_INSPECT_OBJECT_SHOW_ONLY" ) ); + QPushButton* buttonHide = new QPushButton( tr( "GEOM_INSPECT_OBJECT_HIDE" ) ); + QPushButton* buttonPublish = new QPushButton( tr( "GEOM_INSPECT_OBJECT_PUBLISH" ) ); + + buttonsLayout1->addWidget( buttonShow ); + buttonsLayout1->addWidget( buttonShowOnly ); + buttonsLayout1->addWidget( buttonHide ); + buttonsLayout1->addStretch(); + buttonsLayout1->addWidget( buttonPublish ); + buttonsLayout1->addStretch(); + + QHBoxLayout* buttonsLayout2 = new QHBoxLayout(); + + QPushButton* buttonClose = new QPushButton( tr( "GEOM_BUT_CLOSE" ) ); + QPushButton* buttonHelp = new QPushButton( tr( "GEOM_BUT_HELP" ) ); + + buttonsLayout2->addWidget( buttonClose ); + buttonsLayout2->addStretch(); + buttonsLayout2->addWidget( buttonHelp ); + + topLayout->addLayout( mainShapeLayout, 0, 0 ); + topLayout->addWidget( myTreeObjects, 1, 0 ); + topLayout->addLayout( buttonsLayout1, 0, 1, 2, 1 ); + topLayout->addLayout( buttonsLayout2, 2, 0, 1, 2 ); + + // Signals and slots connections + + connect( selBtn, SIGNAL( clicked() ), this, SLOT( onEditMainShape() ) ); + + connect( myTreeObjects, SIGNAL( itemClicked( QTreeWidgetItem*, int ) ), + this, SLOT( onItemClicked( QTreeWidgetItem*, int ) ) ); + connect( myTreeObjects, SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ), + this, SLOT( onItemDoubleClicked( QTreeWidgetItem*, int ) ) ); + connect( myTreeObjects, SIGNAL( itemExpanded ( QTreeWidgetItem* ) ), + this, SLOT( onItemExpanded( QTreeWidgetItem* ) ) ); + connect( myTreeObjects, SIGNAL( itemSelectionChanged() ), + this, SLOT( onItemSelectionChanged() ) ); + + connect( myTreeObjects->header(), SIGNAL( sectionClicked( int ) ), this, SLOT( onHeaderClicked( int ) ) ); + + connect( buttonShow, SIGNAL( clicked() ), this, SLOT( clickOnShow() ) ); + connect( buttonShowOnly, SIGNAL( clicked() ), this, SLOT( clickOnShowOnly() ) ); + connect( buttonHide, SIGNAL( clicked() ), this, SLOT( clickOnHide() ) ); + connect( buttonPublish, SIGNAL( clicked() ), this, SLOT( clickOnPublish() ) ); + + connect( buttonClose, SIGNAL( clicked() ), this, SLOT( reject() ) ); + connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( clickOnHelp() ) ); + + connect( myApp->selectionMgr(), SIGNAL( currentSelectionChanged() ), + this, SLOT( onViewSelectionChanged() ) ); + + init(); +} + +RepairGUI_InspectObjectDlg::~RepairGUI_InspectObjectDlg() +{ + // restore initial parameters for viewer + getDisplayer()->UnsetColor(); + getDisplayer()->UnsetWidth(); + // no need to delete child widgets, Qt does it all for us +} + +//================================================================================= +// function : init() +// purpose : initialize dialog data +//================================================================================= +void RepairGUI_InspectObjectDlg::init() +{ + //get shape from selection + SALOME_ListIO selected; + myApp->selectionMgr()->selectedObjects(selected); + + if( selected.Extent() != 1 ) + return; + + TopoDS_Shape aShape = GEOMBase::GetTopoFromSelection( selected ); + if( aShape.IsNull() ) + return; + + Handle(SALOME_InteractiveObject) anIO = selected.First(); + GEOM::GEOM_Object_var anObject = GEOMBase::ConvertIOinGEOMObject( anIO ); + QString aName = anObject->GetName(); + CORBA::String_var anEntry = anObject->GetStudyEntry(); + + myEditMainShape->setText( aName ); + myEditMainShape->setEnabled( false ); + + // remember initial transparency value + SalomeApp_Study* aStudy = dynamic_cast( myApp->activeStudy() ); + QVariant v = aStudy->getObjectProperty( myGlobalId, QString( anEntry.in() ), + GEOM::propertyName( GEOM::Transparency ), myTransparency ); + if( v.canConvert( QVariant::Double ) ) + myTransparency = v.toDouble(); + aStudy->setObjectProperty( myGlobalId, QString( anEntry.in() ), GEOM::propertyName( GEOM::Transparency ), 0.5 ); + + if ( GEOM_Displayer::GetActiveView()->isVisible( anIO ) ) + getDisplayer()->Redisplay( anIO, true ); + + TreeWidgetItem* anItem = new TreeWidgetItem( myTreeObjects, QStringList() << aName, aShape, anIO ); + if( getDisplayer()->IsDisplayed( anEntry.in() ) ) + anItem->setVisible( true, myVisible ); + else + anItem->setVisible( false, myInvisible ); + + // add sub-objects in the tree + addSubObjects( anItem ); + + // check icon for tree header + checkVisibleIcon(); +} + +//================================================================================= +// function : checkVisibleIcon() +// purpose : set visible or invisible icon in the header of tree +//================================================================================= +void RepairGUI_InspectObjectDlg::checkVisibleIcon() +{ + bool isInvisible = false; + QTreeWidgetItemIterator it( myTreeObjects ); + while(*it) { + TreeWidgetItem* anItem = dynamic_cast(*it); + if( !anItem->isVisible() ) + isInvisible = true; + ++it; + } + + if( isInvisible ) { + myTreeObjects->headerItem()->setIcon( 1, myInvisible ); + myIsSelectAll = false; + } + else { + myTreeObjects->headerItem()->setIcon( 1, myVisible ); + myIsSelectAll = true; + } +} + +//================================================================================= +// function : addSubObjects() +// purpose : add sub-objects to parent object in the tree +//================================================================================= +void RepairGUI_InspectObjectDlg::addSubObjects( TreeWidgetItem* theParentItem ) +{ + TreeWidgetItem* aMainItem = dynamic_cast( myTreeObjects->topLevelItem(0) ); + TopoDS_Iterator it( theParentItem->getShape() ); + for( ; it.More(); it.Next() ) { + TopoDS_Shape aSubShape = it.Value(); + int anIndex = GEOMBase::GetIndex( aSubShape, aMainItem->getShape() ); + QString anEntry = QString( "TEMP_" ) + aMainItem->getIO()->getEntry() + QString("_%1").arg( anIndex ); + TreeWidgetItem* anItem = new TreeWidgetItem( theParentItem, QStringList(), aSubShape, anEntry); + anItem->setVisible( false, myInvisible ); + addSubObjects( anItem ); + } +} + +//================================================================================= +// function : displayItem() +// purpose : display sub-object of inspected object according its tree item +//================================================================================= +void RepairGUI_InspectObjectDlg::displayItem( TreeWidgetItem* theItem ) +{ + GEOM_Displayer* aDisplayer = getDisplayer(); + if( theItem == myTreeObjects->topLevelItem(0) ) { + aDisplayer->UnsetColor(); + aDisplayer->UnsetWidth(); + } + else if( aDisplayer->GetColor() != Quantity_NOC_VIOLET && aDisplayer->GetWidth() != 2.0 ) { + aDisplayer->SetColor( Quantity_NOC_VIOLET ); + aDisplayer->SetWidth( 2.0 ); + } + + SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation( theItem->getShape(), theItem->getIO()->getEntry(), + GEOM_Displayer::GetActiveView() ); + if( aPrs ) + displayPreview( aPrs, true, false ); +} + +//================================================================================= +// function : setItemDisplayStatus() +// purpose : set visible or invisible status for the same items in the tree +//================================================================================= +void RepairGUI_InspectObjectDlg::setItemDisplayStatus( TreeWidgetItem* theItem, bool theIsVisible ) +{ + QTreeWidgetItemIterator it( myTreeObjects ); + while(*it) { + TreeWidgetItem* anItem = dynamic_cast(*it); + if( anItem->getShape().IsSame( theItem->getShape() ) ) + anItem->setVisible( theIsVisible, theIsVisible ? myVisible : myInvisible ); + ++it; + } +} + +//================================================================================= +// function : onEditMainShape() +// purpose : called when selection button was clicked +//================================================================================= +void RepairGUI_InspectObjectDlg::onEditMainShape() +{ + if( myEditMainShape->text().isEmpty() ) + return; + + GEOM_Displayer* aDisplayer = getDisplayer(); + // restore initial parameters for viewer + aDisplayer->UnsetColor(); + aDisplayer->UnsetWidth(); + + // restore transparency of main object + TreeWidgetItem* aMainItem = dynamic_cast( myTreeObjects->topLevelItem(0) ); + SalomeApp_Study* aStudy = dynamic_cast( myApp->activeStudy() ); + aStudy->setObjectProperty( myGlobalId, QString(aMainItem->getIO()->getEntry()) , + GEOM::propertyName( GEOM::Transparency ), myTransparency ); + + if( GEOM_Displayer::GetActiveView()->isVisible( aMainItem->getIO() ) ) + aDisplayer->Redisplay( aMainItem->getIO(), false ); + + // erase sub-shapes + SALOME_ListIO aListOfIO; + QTreeWidgetItemIterator it( myTreeObjects ); + while(*it) { + if( *it != aMainItem ) { + TreeWidgetItem* anItem = dynamic_cast(*it); + aListOfIO.Append( anItem->getIO() ); + } + ++it; + } + aDisplayer->Erase( aListOfIO ); + + // restore initial parameters for dialog box + myEditMainShape->setEnabled( true ); + myEditMainShape->setText(""); + myEditMainShape->setFocus(); + myTreeObjects->clear(); + myTreeObjects->update(); +} + +//================================================================================= +// function : onItemClicked() +// purpose : called when tree item was clicked +//================================================================================= +void RepairGUI_InspectObjectDlg::onItemClicked( QTreeWidgetItem* theItem, int theColumn ) +{ + if( theColumn!= 1 || !( theItem->flags() & Qt::ItemIsSelectable ) ) + return; + + GEOM_Displayer* aDisplayer = getDisplayer(); + + TreeWidgetItem* anItem = dynamic_cast( theItem ); + + if( anItem->isVisible() ) { + aDisplayer->Erase( anItem->getIO(), false, true ); + setItemDisplayStatus( anItem, false ); + } + else { + displayItem( anItem ); + setItemDisplayStatus( anItem, true ); + } + aDisplayer->UpdateViewer(); + checkVisibleIcon(); +} + +//================================================================================= +// function : onItemDoubleClicked() +// purpose : called when tree item was double clicked +//================================================================================= +void RepairGUI_InspectObjectDlg::onItemDoubleClicked( QTreeWidgetItem* theItem, int theColumn ) +{ + if( theColumn!= 0 || !( theItem->flags() & Qt::ItemIsSelectable ) ) + return; + + bool bOk; + QString label = QInputDialog::getText( this, RepairGUI_InspectObjectDlg::tr( "RENAME_COMPONENT" ), + RepairGUI_InspectObjectDlg::tr ( "COMPONENT_NAME" ), QLineEdit::Normal, + theItem->text(0), &bOk ); + if ( bOk && !label.isEmpty() ) + theItem->setText( 0, label ); +} + +//================================================================================= +// function : onItemExpanded() +// purpose : called when tree item was expanded +//================================================================================= +void RepairGUI_InspectObjectDlg::onItemExpanded( QTreeWidgetItem* theItem ) +{ + TreeWidgetItem* aMainItem = dynamic_cast( myTreeObjects->topLevelItem(0) ); + GEOM::GEOM_Object_var aMainObject = GEOMBase::ConvertIOinGEOMObject( aMainItem->getIO() ); + + for( int i = 0; i < theItem->childCount(); i++ ) { + TreeWidgetItem* aSubItem = dynamic_cast( theItem->child(i) ); + int anIndex = GEOMBase::GetIndex( aSubItem->getShape(), aMainItem->getShape() ); + if( aSubItem->text(0).isEmpty() ) { + char* aName = aMainObject->GetSubName( anIndex ); + if( !QString( aName ).isEmpty() ) + aSubItem->setText( 0, QString( aName ) ); + else + aSubItem->setText( 0, GEOMBase::TypeName( aSubItem->getShape().ShapeType() ) + + QString("_%1").arg( anIndex ) ); + } + } +} + +//================================================================================= +// function : onItemSelectionChanged() +// purpose : called when tree item was selected +//================================================================================= +void RepairGUI_InspectObjectDlg::onItemSelectionChanged() +{ + QList listItem = myTreeObjects->selectedItems(); + SALOME_ListIO aSelected; + for( int i = 0; i < listItem.size(); i++ ) { + TreeWidgetItem* anItem = dynamic_cast( listItem.at(i) ); + aSelected.Append( anItem->getIO() ); + } + myApp->selectionMgr()->setSelectedObjects( aSelected ); +} + +//================================================================================= +// function : onHeaderClicked() +// purpose : called when header item of tree was clicked +//================================================================================= +void RepairGUI_InspectObjectDlg::onHeaderClicked( int theColumn ) +{ + if( theColumn != 1 ) + return; + + GEOM_Displayer* aDisplayer = getDisplayer(); + + if( myIsSelectAll ) { + myIsSelectAll = false; + myTreeObjects->headerItem()->setIcon( 1, myInvisible ); + SALOME_ListIO aListOfIO; + QTreeWidgetItemIterator it( myTreeObjects ); + while(*it) { + TreeWidgetItem* anItem = dynamic_cast(*it); + if( ( anItem->flags() & Qt::ItemIsSelectable ) && anItem->isVisible() ) { + aListOfIO.Append( anItem->getIO() ); + anItem->setVisible( false, myInvisible ); + } + ++it; + } + aDisplayer->Erase( aListOfIO ); + } + else { + myIsSelectAll = true; + myTreeObjects->headerItem()->setIcon( 1, myVisible ); + QTreeWidgetItemIterator it( myTreeObjects ); + while(*it) { + TreeWidgetItem* anItem = dynamic_cast(*it); + if( ( anItem->flags() & Qt::ItemIsSelectable ) && !anItem->isVisible() ) { + displayItem( anItem ); + anItem->setVisible( true, myVisible ); + } + ++it; + } + } + + aDisplayer->UpdateViewer(); +} + +//================================================================================= +// function : onViewSelectionChanged() +// purpose : called when selection of object browser was changed +//================================================================================= +void RepairGUI_InspectObjectDlg::onViewSelectionChanged() +{ + if( myEditMainShape->isEnabled() ) + init(); +} + +//================================================================================= +// function : clickOnShow() +// purpose : called when "Show selected" button was clicked +//================================================================================= +void RepairGUI_InspectObjectDlg::clickOnShow() +{ + QList listItem = myTreeObjects->selectedItems(); + for( int i = 0; i < listItem.size(); i++ ) { + TreeWidgetItem* anItem = dynamic_cast( listItem.at(i) ); + if( !anItem->isVisible() ) { + displayItem( anItem ); + setItemDisplayStatus( anItem, true ); + } + } + getDisplayer()->UpdateViewer(); + checkVisibleIcon(); +} + +//================================================================================= +// function : clickOnShowOnly() +// purpose : called when "Show only selected" button was clicked +//================================================================================= +void RepairGUI_InspectObjectDlg::clickOnShowOnly() +{ + SALOME_ListIO aListOfIO; + QTreeWidgetItemIterator it( myTreeObjects ); + while(*it) { + TreeWidgetItem* anItem = dynamic_cast(*it); + if( ( anItem->flags() & Qt::ItemIsSelectable ) && anItem->isVisible() ) { + aListOfIO.Append( anItem->getIO() ); + anItem->setVisible( false, myInvisible ); + } + ++it; + } + getDisplayer()->Erase( aListOfIO ); + + clickOnShow(); +} + +//================================================================================= +// function : clickOnHide() +// purpose : called when "Hide selected" button was clicked +//================================================================================= +void RepairGUI_InspectObjectDlg::clickOnHide() +{ + QList listItem = myTreeObjects->selectedItems(); + for( int i = 0; i < listItem.size(); i++ ) { + TreeWidgetItem* anItem = dynamic_cast( listItem.at(i) ); + if( anItem->isVisible() ) { + getDisplayer()->Erase( anItem->getIO(), false, true ); + setItemDisplayStatus( anItem, false ); + } + } + getDisplayer()->UpdateViewer(); + checkVisibleIcon(); +} + +//================================================================================= +// function : clickOnPublish() +// purpose : called when "Publish selected" button was clicked +//================================================================================= +void RepairGUI_InspectObjectDlg::clickOnPublish() +{ +} + +//================================================================================= +// function : clickOnHelp() +// purpose : called when Help button was clicked to open a help page +//================================================================================= +void RepairGUI_InspectObjectDlg::clickOnHelp() +{ + myApp->onHelpContextModule( "GEOM", "inspect_object_page.html" ); +} diff --git a/src/RepairGUI/RepairGUI_InspectObjectDlg.h b/src/RepairGUI/RepairGUI_InspectObjectDlg.h new file mode 100644 index 000000000..bf5280105 --- /dev/null +++ b/src/RepairGUI/RepairGUI_InspectObjectDlg.h @@ -0,0 +1,79 @@ +// 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 RepairGUI_InspectObjectDlg_H +#define RepairGUI_InspectObjectDlg_H + +// GEOM includes +#include + +// Qt includes +#include +#include +#include + +class RepairGUI_InspectObjectDlg : public QDialog, public GEOMBase_Helper +{ + Q_OBJECT + + class TreeWidgetItem; + +public: + RepairGUI_InspectObjectDlg( SUIT_Desktop* ); + ~RepairGUI_InspectObjectDlg(); + +private slots: + void onEditMainShape(); + + void onItemClicked( QTreeWidgetItem*, int ); + void onItemSelectionChanged(); + void onItemExpanded( QTreeWidgetItem* ); + void onHeaderClicked( int ); + void onItemDoubleClicked( QTreeWidgetItem*, int ); + + void onViewSelectionChanged(); + + void clickOnShow(); + void clickOnShowOnly(); + void clickOnHide(); + void clickOnPublish(); + void clickOnHelp(); + +private: + void init(); + void checkVisibleIcon(); + void addSubObjects( TreeWidgetItem* ); + void displayItem( TreeWidgetItem* ); + void setItemDisplayStatus( TreeWidgetItem* theItem, bool theIsVisible ); + + SalomeApp_Application* myApp; + int myGlobalId; + + QIcon myVisible; + QIcon myInvisible; + + QTreeWidget* myTreeObjects; + QLineEdit* myEditMainShape; + + bool myIsSelectAll; + double myTransparency; + +}; + +#endif