From: nds Date: Tue, 11 Oct 2016 14:44:18 +0000 (+0300) Subject: Annotation's visualization in tree X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f88158f32925e902abce68700ec3929f7e4e6513;p=modules%2Fgeom.git Annotation's visualization in tree --- diff --git a/src/GEOMGUI/CMakeLists.txt b/src/GEOMGUI/CMakeLists.txt index db3cb4cea..c850545b6 100755 --- a/src/GEOMGUI/CMakeLists.txt +++ b/src/GEOMGUI/CMakeLists.txt @@ -75,6 +75,7 @@ SET(GEOMGUI_HEADERS GEOM_GEOMGUI.hxx GEOMGUI_CreationInfoWdg.h GEOMGUI_TextTreeWdg.h + GEOMGUI_VisualProperties.h GEOMGUI_DimensionProperty.h GEOMGUI_ShapeAnnotations.h ) diff --git a/src/GEOMGUI/GEOMGUI_DimensionProperty.h b/src/GEOMGUI/GEOMGUI_DimensionProperty.h index 3ff770055..4c7d32d93 100644 --- a/src/GEOMGUI/GEOMGUI_DimensionProperty.h +++ b/src/GEOMGUI/GEOMGUI_DimensionProperty.h @@ -28,6 +28,8 @@ #define GEOMGUI_DIMENSIONPROPERTY_H // OCCT includes +#include + #include #include #include @@ -42,6 +44,9 @@ class SalomeApp_Study; +class GEOMGUI_DimensionProperty; +typedef QSharedPointer DimensionPropertyPtr; + /*! * \brief Utility class to unpack/pack dimension presentations as object property of study. * @@ -57,7 +62,7 @@ class SalomeApp_Study; * Diam: (plane)[0-3] (flyout)[4] (text flags)[5-6] (arrow flag)[7] (circle loc, xdir, ydir, rad)[8-17] * Angle: (flyout)[0] (text flags)[1-2] (arrow flag)[3] (p1)[4-6] (p2)[7-9] (center)[10-12] */ -class Standard_EXPORT GEOMGUI_DimensionProperty +class Standard_EXPORT GEOMGUI_DimensionProperty : public GEOMGUI_VisualProperties { public: diff --git a/src/GEOMGUI/GEOMGUI_ShapeAnnotations.cxx b/src/GEOMGUI/GEOMGUI_ShapeAnnotations.cxx index f8fa87d9a..af678d9b9 100755 --- a/src/GEOMGUI/GEOMGUI_ShapeAnnotations.cxx +++ b/src/GEOMGUI/GEOMGUI_ShapeAnnotations.cxx @@ -232,17 +232,6 @@ bool GEOMGUI_ShapeAnnotations::operator == (const GEOMGUI_ShapeAnnotations& theO return true; } -//================================================================================= -// function : Add -// purpose : -//================================================================================= -void GEOMGUI_ShapeAnnotations::Add( const Handle(GEOM_Annotation)& theShapeAnnotation, const gp_Ax3& theLCS ) -{ - Add( ShapeAnnotation() ); - // - FromPresentation( Count() - 1, theShapeAnnotation, theLCS ); -} - //================================================================================= // function : FromPresentation // purpose : @@ -285,6 +274,26 @@ void GEOMGUI_ShapeAnnotations::ToPresentation( const int theIndex, //theShapeAnnotation->SetAttachPoint( aEntry.Attach.Transformed( aToLCS ) ); } +bool GEOMGUI_ShapeAnnotations::IsVisible( const int theIndex ) const +{ + return myAnnotations[theIndex].IsVisible; +} + +void GEOMGUI_ShapeAnnotations::SetVisible( const int theIndex, const bool theIsVisible ) +{ + ShapeAnnotation& aChangeEntry = myAnnotations[theIndex]; + aChangeEntry.IsVisible = theIsVisible; +} + +QString GEOMGUI_ShapeAnnotations::GetName( const int theIndex ) const +{ + return "Name"; +} + +void GEOMGUI_ShapeAnnotations::SetName( const int theIndex, const QString& theName ) +{ +} + //================================================================================= // function : LoadFromAttribute // purpose : diff --git a/src/GEOMGUI/GEOMGUI_ShapeAnnotations.h b/src/GEOMGUI/GEOMGUI_ShapeAnnotations.h index ce18dd5b3..c0a9a592d 100755 --- a/src/GEOMGUI/GEOMGUI_ShapeAnnotations.h +++ b/src/GEOMGUI/GEOMGUI_ShapeAnnotations.h @@ -27,6 +27,8 @@ #ifndef GEOMGUI_SHAPEANNOTATIONS_H #define GEOMGUI_SHAPEANNOTATIONS_H +#include + // OCCT includes #include #include @@ -40,6 +42,9 @@ class SalomeApp_Study; class GEOM_Annotation; +class GEOMGUI_ShapeAnnotations; +typedef QSharedPointer ShapeAnnotationsPtr; + /*! * \brief Algorithms to translate and manitain list of shape annotation properties. * @@ -47,7 +52,7 @@ class GEOM_Annotation; * To ensure that dimension is bound to the equal shape irrespectively of its location * transformation. */ -class Standard_EXPORT GEOMGUI_ShapeAnnotations +class Standard_EXPORT GEOMGUI_ShapeAnnotations : public GEOMGUI_VisualProperties { public: @@ -143,19 +148,13 @@ public: /*! * \brief Adds new shape annotation entry using explicit definition. * \param theShapeAnnotation [in] the explicit definition of the annotation. + * \param theLCS [in] the local coordinate system of parent object. */ void Add( const ShapeAnnotation& theShapeAnnotation ) { myAnnotations.append( theShapeAnnotation ); } - /*! - * \brief Adds new entry using data of the interactive presentation given. - * \param theShapeAnnotation [in] the interactive shape annotation holding properties. - * \param theLCS [in] the local coordinate system of parent object. - */ - void Add( const Handle(GEOM_Annotation)& theShapeAnnotation, const gp_Ax3& theLCS ); - /*! * \brief Update entry data using the explicit definition. * \param theIndex [in] the index of the dimension record. @@ -211,7 +210,37 @@ public: /*! * \brief Returns number of shape annotation records. */ - int Count() const { return myAnnotations.size(); } + virtual int GetNumber() const { return myAnnotations.size(); }; + + /*! + * \brief Returns visibility state of dimension record by its index. + * + * \param theIndex [in] the index of the dimension record. + */ + virtual bool IsVisible( const int theIndex ) const; + + /*! + * \brief Changes visibility state of the dimension record. + * + * \param theIndex [in] the index of the dimension record. + * \param theIsVisible [in] the new visibility state. + */ + virtual void SetVisible( const int theIndex, const bool theIsVisible ); + + /*! + * \brief Returns name of dimension record by its index. + * + * \param theIndex [in] the index of the dimension record. + */ + virtual QString GetName( const int theIndex ) const; + + /*! + * \brief Changes name of dimension record. + * + * \param theIndex [in] the index of the dimension record. + * \param theName [in] the new name. + */ + virtual void SetName( const int theIndex, const QString& theName ); public: @@ -220,14 +249,14 @@ public: * \param theStudy [in] the study. * \param theEntry [in] the entry of GEOM object to operate with. */ - void LoadFromAttribute( SalomeApp_Study* theStudy, const std::string& theEntry ); + virtual void LoadFromAttribute( SalomeApp_Study* theStudy, const std::string& theEntry ); /*! * \brief Saves properties data to attribute. * \param theStudy [in] the study. * \param theEntry [in] the entry of GEOM object to operate with. */ - void SaveToAttribute( SalomeApp_Study* theStudy, const std::string& theEntry ); + virtual void SaveToAttribute( SalomeApp_Study* theStudy, const std::string& theEntry ); private: diff --git a/src/GEOMGUI/GEOMGUI_TextTreeWdg.cxx b/src/GEOMGUI/GEOMGUI_TextTreeWdg.cxx index d7b0c221c..1b0a9ed0b 100644 --- a/src/GEOMGUI/GEOMGUI_TextTreeWdg.cxx +++ b/src/GEOMGUI/GEOMGUI_TextTreeWdg.cxx @@ -22,6 +22,7 @@ #include "GEOMGUI_TextTreeWdg.h" #include "GEOMGUI_DimensionProperty.h" +#include "GEOMGUI_ShapeAnnotations.h" #include "GeometryGUI.h" #include "GeometryGUI_Operations.h" #include @@ -99,15 +100,15 @@ GEOMGUI_TextTreeWdg::GEOMGUI_TextTreeWdg( SalomeApp_Application* app ) createActions(); setContextMenuPolicy( Qt::CustomContextMenu ); connect( this, SIGNAL( customContextMenuRequested(const QPoint&) ), - this, SLOT( showContextMenu(const QPoint&) ) ); + this, SLOT( showContextMenu(const QPoint&) ) ); connect( myStudy, SIGNAL( objVisibilityChanged( QString, Qtx::VisibilityState ) ), - this, SLOT( updateVisibilityColumn( QString, Qtx::VisibilityState ) ) ); + this, SLOT( updateVisibilityColumn( QString, Qtx::VisibilityState ) ) ); connect( app->objectBrowser(), SIGNAL( updated() ), this, SLOT( updateTree() ) ); GeometryGUI* aGeomGUI = dynamic_cast( app->module( "Geometry" ) ); connect( aGeomGUI, SIGNAL( DimensionsUpdated( const QString& ) ), this, SLOT( updateBranch( const QString& ) ) ); connect( this, SIGNAL( itemClicked( QTreeWidgetItem*, int) ), - this, SLOT( onItemClicked( QTreeWidgetItem*, int ) ) ); + this, SLOT( onItemClicked( QTreeWidgetItem*, int ) ) ); } @@ -144,20 +145,25 @@ void GEOMGUI_TextTreeWdg::updateTree() if ( SC ) { _PTR(ChildIterator) anIter ( aDSStudy->NewChildIterator( SC ) ); anIter->InitEx( true ); - QList objEntries = myObjects.keys(); + QList aGeomObjEntries = getObjects( Geometry ).keys(); + QList anAnnotationObjEntries = getObjects( AnnotationShape ).keys(); while( anIter->More() ) { - _PTR(SObject) valSO ( anIter->Value() ); - _PTR(SObject) refSO; - if ( !valSO->ReferencedObject( refSO ) ) { - // update tree of object's dimensions - QString anEntry = valSO->GetID().c_str(); - updateBranch( anEntry ); - objEntries.removeAll( anEntry ); - } - anIter->Next(); + _PTR(SObject) valSO ( anIter->Value() ); + _PTR(SObject) refSO; + if ( !valSO->ReferencedObject( refSO ) ) { + // update tree of object's dimensions + QString anEntry = valSO->GetID().c_str(); + updateBranch( anEntry ); + aGeomObjEntries.removeAll( anEntry ); + anAnnotationObjEntries.removeAll( anEntry ); + } + anIter->Next(); } - foreach (QString entry, objEntries) { - removeBranch( entry, true ); + foreach (QString entry, aGeomObjEntries) { + removeBranch( Geometry, entry, true ); + } + foreach (QString entry, anAnnotationObjEntries) { + removeBranch( AnnotationShape, entry, true ); } } } @@ -168,67 +174,105 @@ void GEOMGUI_TextTreeWdg::updateTree() // purpose : //================================================================================= void GEOMGUI_TextTreeWdg::updateBranch( const QString& theEntry ) +{ + /// dimension property branch + fillBranch( Geometry, theEntry ); + + // annotation property branch + fillBranch(AnnotationShape, theEntry); +} + +void GEOMGUI_TextTreeWdg::fillBranch( const BranchType& theBranchType, const QString& theEntry ) { myStudy = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); - if ( myStudy ) { + + if ( myStudy && !theEntry.isEmpty() ) { + VisualPropertiesPtr aProp = getVisualProperty( theBranchType ); + int aNumber = aProp->GetNumber(); + const std::string anEntry = theEntry.toStdString(); + + aProp->LoadFromAttribute( myStudy, theEntry.toStdString() ); + + if (!aProp) + return; + _PTR(Study) aStudyDS = myStudy->studyDS(); if ( aStudyDS ) { _PTR(SObject) obj( aStudyDS->FindObjectID( theEntry.toStdString() ) ); QString aName = obj->GetName().c_str(); - GEOMGUI_DimensionProperty aProp; - aProp.LoadFromAttribute( myStudy, theEntry.toStdString() ); - int nbProps = aProp.GetNumber(); + int nbProps = aProp->GetNumber(); - QTreeWidgetItem* objectItem = itemFromEntry( theEntry ); + QTreeWidgetItem* objectItem = itemFromEntry( theBranchType, theEntry ); if ( objectItem ) { - removeBranch( theEntry, nbProps > 0 ? false : true ); + removeBranch( theBranchType, theEntry, nbProps > 0 ? false : true ); } QStringList itemName; if ( nbProps > 0 ) { - itemName << aName << ""; - if ( !objectItem ) { - objectItem = new QTreeWidgetItem( myDimensionsItem, itemName ); - objectItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled ); - objectItem->setData( 1, Qt::UserRole, theEntry ); - myDimensionsItem->addChild( objectItem ); - myObjects.insert( theEntry, objectItem ); - if ( myDimensionsItem->childCount() == 1 ) - myDimensionsItem->setExpanded( true ); - } - bool isDisplayed = myDisplayer.IsDisplayed( theEntry ); - // read dimension records from property - for ( int anIt = 0; anIt < aProp.GetNumber(); ++anIt ) - { - QString aName = aProp.GetName( anIt ); - bool isVisible = aProp.IsVisible( anIt ); - - QTreeWidgetItem* anItem = new QTreeWidgetItem; - anItem->setText( 0, aName ); - // if ( isDisplayed ) - anItem->setIcon( 1, isVisible ? myVisibleIcon : myInvisibleIcon ); - anItem->setData( 0, Qt::UserRole, anIt ); - anItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled ); - objectItem->addChild( anItem ); - } + itemName << aName << ""; + if ( !objectItem ) { + QTreeWidgetItem* aPropRootItem = getPropertyRootItem(theBranchType); + + objectItem = new QTreeWidgetItem( aPropRootItem, itemName ); + objectItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled ); + objectItem->setData( 1, Qt::UserRole, theEntry ); + aPropRootItem->addChild( objectItem ); + getObjects( theBranchType ).insert( theEntry, objectItem ); + if ( aPropRootItem->childCount() == 1 ) + aPropRootItem->setExpanded( true ); + } + bool isDisplayed = myDisplayer.IsDisplayed( theEntry ); + // read dimension records from property + for ( int anIt = 0; anIt < aProp->GetNumber(); ++anIt ) { + QString aName = aProp->GetName( anIt ); + bool isVisible = aProp->IsVisible( anIt ); + + QTreeWidgetItem* anItem = new QTreeWidgetItem; + anItem->setText( 0, aName ); + // if ( isDisplayed ) + anItem->setIcon( 1, isVisible ? myVisibleIcon : myInvisibleIcon ); + anItem->setData( 0, Qt::UserRole, anIt ); + anItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled ); + objectItem->addChild( anItem ); + } } } } } +//================================================================================= +// function : getVisualProperty +// purpose : +//================================================================================= +VisualPropertiesPtr GEOMGUI_TextTreeWdg::getVisualProperty( const BranchType& theBranchType ) +{ + VisualPropertiesPtr aProp; + + if ( theBranchType == Geometry ) { + aProp = QSharedPointer( new GEOMGUI_DimensionProperty() ); + } + else { + aProp = QSharedPointer( new GEOMGUI_ShapeAnnotations() ); + } + +return aProp; +} + //================================================================================= // function : removeBranch // purpose : //================================================================================= -void GEOMGUI_TextTreeWdg::removeBranch( const QString& theEntry, bool force ) +void GEOMGUI_TextTreeWdg::removeBranch( const BranchType& theBranchType, const QString& theEntry, + bool force ) { - QTreeWidgetItem* objectItem = itemFromEntry( theEntry ); + QTreeWidgetItem* objectItem = itemFromEntry( theBranchType, theEntry ); if ( !objectItem ) return; qDeleteAll( objectItem->takeChildren() ); if ( force ) { - myDimensionsItem->removeChild( objectItem ); - myObjects.remove( theEntry ); + QTreeWidgetItem* aPropRootItem = getPropertyRootItem( theBranchType ); + aPropRootItem->removeChild( objectItem ); + getObjects( theBranchType ).remove( theEntry ); } } @@ -242,17 +286,21 @@ void GEOMGUI_TextTreeWdg::onItemClicked( QTreeWidgetItem* theItem, int theColumn return; std::string anEntry = entryFromItem( theItem->parent() ).toStdString(); + BranchType aBranchType = branchTypeFromItem( theItem ); + int aDimIndex = idFromItem( theItem ); - GEOMGUI_DimensionProperty aProp; - aProp.LoadFromAttribute( myStudy, anEntry ); - if ( aProp.IsVisible( aDimIndex ) ) { - aProp.SetVisible( aDimIndex, false ); + + VisualPropertiesPtr aProp = getVisualProperty( aBranchType ); + aProp->LoadFromAttribute( myStudy, anEntry ); + if ( aProp->IsVisible( aDimIndex ) ) { + aProp->SetVisible( aDimIndex, false ); theItem->setIcon( 1, myInvisibleIcon ); } else { - aProp.SetVisible( aDimIndex, true ); + aProp->SetVisible( aDimIndex, true ); theItem->setIcon( 1, myVisibleIcon ); } - aProp.SaveToAttribute( myStudy, anEntry ); + aProp->SaveToAttribute( myStudy, anEntry ); + redisplay( anEntry.c_str() ); } @@ -287,33 +335,48 @@ QString GEOMGUI_TextTreeWdg::entryFromItem( QTreeWidgetItem* theShapeItem ) // function : itemFromEntry // purpose : //================================================================================= -QTreeWidgetItem* GEOMGUI_TextTreeWdg::itemFromEntry( QString theEntry ) +QTreeWidgetItem* GEOMGUI_TextTreeWdg::itemFromEntry( const BranchType& theBranchType, QString theEntry ) { if ( theEntry.isEmpty() ) return 0; - return myObjects.value( theEntry, 0 ); + return getObjects(theBranchType).value( theEntry, 0 ); } //================================================================================= // function : updateVisibilityColumn -// purpose : Update icons of dimension items. +// purpose : Update visible state of icons of entry items. //================================================================================= void GEOMGUI_TextTreeWdg::updateVisibilityColumn( QString theEntry, Qtx::VisibilityState theState ) { - QTreeWidgetItem* anItem = itemFromEntry( theEntry ); + //BranchType theBranchType, + updateVisibilityColumn( Geometry, theEntry, theState ); + updateVisibilityColumn( AnnotationShape, theEntry, theState ); +} + +//================================================================================= +// function : updateVisibilityColumn +// purpose : Update icons of dimension items. +//================================================================================= +void GEOMGUI_TextTreeWdg::updateVisibilityColumn( const BranchType& theBranchType, QString theEntry, + Qtx::VisibilityState theState ) +{ + QTreeWidgetItem* anItem = itemFromEntry( theBranchType, theEntry ); if ( !anItem ) return; anItem->setDisabled( theState != Qtx::ShownState ); QTreeWidgetItem* aChildItem; - GEOMGUI_DimensionProperty aProp; + + VisualPropertiesPtr aProp = getVisualProperty( theBranchType ); + for ( int i=0; i < anItem->childCount(); i++ ) { aChildItem = anItem->child( i ); if ( theState == Qtx::ShownState ) { - aProp.LoadFromAttribute( myStudy, theEntry.toStdString() ); - if ( aProp.GetNumber() == 0 ) - continue; - aChildItem->setIcon( 1, aProp.IsVisible( idFromItem( aChildItem ) ) ? myVisibleIcon : myInvisibleIcon ); + aProp->LoadFromAttribute( myStudy, theEntry.toStdString() ); + if ( aProp->GetNumber() == 0 ) + continue; + aChildItem->setIcon( 1, aProp->IsVisible( idFromItem( aChildItem ) ) ? myVisibleIcon + : myInvisibleIcon ); aChildItem->setDisabled( false ); } else { aChildItem->setIcon( 1, QIcon() ); @@ -333,56 +396,65 @@ void GEOMGUI_TextTreeWdg::showContextMenu( const QPoint& pos ) QMenu aMenu; aMenu.addAction( myActions[GEOMOp::OpShow] ); aMenu.addAction( myActions[GEOMOp::OpHide] ); + if ( selectedItems().count() == 1 ) { QTreeWidgetItem* anItem = selectedItems().first(); QString anEntry = entryFromItem( anItem->parent() ); if ( !anEntry.isEmpty() ) { - GEOMGUI_DimensionProperty aProp; - aProp.LoadFromAttribute( myStudy, anEntry.toStdString() ); - if ( aProp.GetNumber() == 0 ) - return; + BranchType aBranchType = branchTypeFromItem( anItem ); + VisualPropertiesPtr aProp = getVisualProperty( aBranchType ); + + aProp->LoadFromAttribute( myStudy, anEntry.toStdString() ); + if ( aProp->GetNumber() == 0 ) + return; aMenu.clear(); - if ( aProp.IsVisible( idFromItem( anItem ) ) ) - aMenu.addAction( myActions[GEOMOp::OpHide] ); + if ( aProp->IsVisible( idFromItem( anItem ) ) ) + aMenu.addAction( myActions[GEOMOp::OpHide] ); else - aMenu.addAction( myActions[GEOMOp::OpShow] ); + aMenu.addAction( myActions[GEOMOp::OpShow] ); } } QAction* selPopupItem = aMenu.exec( viewport()->mapToGlobal(pos) ); - if ( selPopupItem == myActions[GEOMOp::OpShow] ) - setVisibility( true ); - else if ( selPopupItem == myActions[GEOMOp::OpHide] ) - setVisibility( false ); + + if ( selPopupItem == myActions[GEOMOp::OpShow] || + selPopupItem == myActions[GEOMOp::OpHide] ) { + bool isVisible = selPopupItem == myActions[GEOMOp::OpShow]; + foreach ( QTreeWidgetItem* anItem, selectedItems() ) { + setVisibility( anItem, isVisible ); + } + } } //================================================================================= // function : setVisibility -// purpose : +// purpose : set item visible //================================================================================= -void GEOMGUI_TextTreeWdg::setVisibility( bool theVisibility ) +void GEOMGUI_TextTreeWdg::setVisibility( QTreeWidgetItem* theItem, bool theVisibility ) { - if ( myDimensionsItem->isSelected() ) { + BranchType aBranchType = branchTypeFromItem( theItem ); + if ( theItem == myDimensionsItem || + theItem == myAnnotationsItem ) { // set visibility for all dimensions QTreeWidgetItem* anItem; - foreach ( QString entry, myObjects.keys() ) { - anItem = itemFromEntry( entry ); + foreach ( QString entry, getObjects( aBranchType ).keys() ) { + anItem = itemFromEntry( aBranchType, entry ); if ( !anItem->isDisabled() ) - setShapeDimensionsVisibility( entry, theVisibility ); + setShapeDimensionsVisibility( aBranchType, entry, theVisibility ); } return; } - foreach ( QTreeWidgetItem* item, selectedItems() ) { - if ( item->isDisabled() || item->parent()->isSelected() ) - continue; - QString anEntry = entryFromItem( item ); - if ( !anEntry.isEmpty() ) { - // it is a shape item - setShapeDimensionsVisibility( anEntry, theVisibility ); - } else { - // it is a dimension item - anEntry = entryFromItem( item->parent() ); - setDimensionVisibility( anEntry, item, theVisibility ); - } + else { + if ( !theItem->isDisabled() && !theItem->parent()->isSelected() ) { + QString anEntry = entryFromItem( theItem ); + if ( !anEntry.isEmpty() ) { + // it is a shape item + setShapeDimensionsVisibility( aBranchType, anEntry, theVisibility ); + } else { + // it is a dimension item + anEntry = entryFromItem( theItem->parent() ); + setDimensionVisibility( aBranchType, anEntry, theItem, theVisibility ); + } + } } } @@ -390,13 +462,14 @@ void GEOMGUI_TextTreeWdg::setVisibility( bool theVisibility ) // function : setShapeDimensionsVisibility // purpose : //================================================================================= -void GEOMGUI_TextTreeWdg::setShapeDimensionsVisibility( QString theEntry, bool theVisibility ) +void GEOMGUI_TextTreeWdg::setShapeDimensionsVisibility( const BranchType& theBranchType, + QString theEntry, bool theVisibility ) { - QTreeWidgetItem* anItem = itemFromEntry( theEntry ); + QTreeWidgetItem* anItem = itemFromEntry( theBranchType, theEntry ); QTreeWidgetItem* aChildItem; for ( int i=0; i < anItem->childCount(); i++ ) { aChildItem = anItem->child( i ); - setDimensionVisibility( theEntry, aChildItem, theVisibility ); + setDimensionVisibility( theBranchType, theEntry, aChildItem, theVisibility ); } redisplay( theEntry ); } @@ -405,15 +478,17 @@ void GEOMGUI_TextTreeWdg::setShapeDimensionsVisibility( QString theEntry, bool t // function : setDimensionVisibility // purpose : //================================================================================= -void GEOMGUI_TextTreeWdg::setDimensionVisibility( QString theEntry, QTreeWidgetItem* theDimItem, bool theVisibility ) +void GEOMGUI_TextTreeWdg::setDimensionVisibility( const BranchType& theBranchType, QString theEntry, + QTreeWidgetItem* theDimItem, bool theVisibility ) { - GEOMGUI_DimensionProperty aProp; - aProp.LoadFromAttribute( myStudy, theEntry.toStdString() ); + VisualPropertiesPtr aProp = getVisualProperty( theBranchType ); + + aProp->LoadFromAttribute( myStudy, theEntry.toStdString() ); int aDimIndex = idFromItem( theDimItem ); - if ( aProp.GetNumber() == 0 || aProp.IsVisible( aDimIndex ) == theVisibility ) + if ( aProp->GetNumber() == 0 || aProp->IsVisible( aDimIndex ) == theVisibility ) return;; - aProp.SetVisible( aDimIndex, theVisibility ); - aProp.SaveToAttribute( myStudy, theEntry.toStdString() ); + aProp->SetVisible( aDimIndex, theVisibility ); + aProp->SaveToAttribute( myStudy, theEntry.toStdString() ); theDimItem->setIcon( 1, theVisibility ? myVisibleIcon : myInvisibleIcon ); redisplay( theEntry ); @@ -428,3 +503,46 @@ void GEOMGUI_TextTreeWdg::redisplay( QString theEntry ) Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( theEntry.toLatin1().constData(), "GEOM", "TEMP_IO" ); myDisplayer.Redisplay( io ); } + +//================================================================================= +// function : getPropertyRootItem +// purpose : +//================================================================================= +QTreeWidgetItem* GEOMGUI_TextTreeWdg::getPropertyRootItem( const BranchType& theBranchType ) +{ + return theBranchType == Geometry ? myDimensionsItem : myAnnotationsItem; +} + +//================================================================================= +// function : getObjects +// purpose : +//================================================================================= +QHash& GEOMGUI_TextTreeWdg::getObjects( const BranchType& theBranchType ) +{ + return theBranchType == Geometry ? myObjects : myAnnotationObjects; +} + +//================================================================================= +// function : branchTypeFromItem +// purpose : +//================================================================================= +GEOMGUI_TextTreeWdg::BranchType GEOMGUI_TextTreeWdg::branchTypeFromItem( QTreeWidgetItem* theItem ) +{ + BranchType aBranchType = Geometry; + + bool aBranchTypeFound = false; + QTreeWidgetItem* anItem = theItem; + while( !aBranchTypeFound && anItem ) { + if ( anItem == myDimensionsItem || + anItem == myAnnotationsItem) { + aBranchTypeFound = true; + aBranchType = anItem == myDimensionsItem ? Geometry : AnnotationShape; + } + else { + anItem = anItem->parent(); + } + } + + return aBranchType; +} + diff --git a/src/GEOMGUI/GEOMGUI_TextTreeWdg.h b/src/GEOMGUI/GEOMGUI_TextTreeWdg.h index 6efa1609a..94d456ebc 100644 --- a/src/GEOMGUI/GEOMGUI_TextTreeWdg.h +++ b/src/GEOMGUI/GEOMGUI_TextTreeWdg.h @@ -22,6 +22,7 @@ #include "GEOM_GEOMGUI.hxx" #include "GEOM_Displayer.h" +#include "GEOMGUI_VisualProperties.h" #include #include @@ -35,6 +36,7 @@ class QTreeWidgetItem; class SalomeApp_Application; class SalomeApp_Study; + /*! * \brief Tree view contains Dimension and Annotation text items: * - text visibility in OCC viewer @@ -44,41 +46,59 @@ class GEOMGUI_EXPORT GEOMGUI_TextTreeWdg : public QTreeWidget { Q_OBJECT - public: +public: + enum BranchType { Geometry, AnnotationShape }; + + +public: GEOMGUI_TextTreeWdg( SalomeApp_Application* app ); ~GEOMGUI_TextTreeWdg(); int getWinID() { return myWindowID; } - void removeBranch( const QString& theEntry, - bool force = true ); + void removeBranch( const BranchType& theBranchType, const QString& theEntry, + bool force = true ); int idFromItem( QTreeWidgetItem* theItem ); QString entryFromItem( QTreeWidgetItem* theShapeItem ); - QTreeWidgetItem* itemFromEntry( QString theEntry ); - void setShapeDimensionsVisibility( QString theEntry, bool theVisibility ); - void setDimensionVisibility( QString theEntry, QTreeWidgetItem* theDimItem, bool theVisibility ); - + QTreeWidgetItem* itemFromEntry( const BranchType& theBranchType, QString theEntry ); + void setShapeDimensionsVisibility( const BranchType& theBranchType, + QString theEntry, bool theVisibility ); + void setDimensionVisibility( const BranchType& theBranchType, + QString theEntry, QTreeWidgetItem* theDimItem, + bool theVisibility ); protected: void createActions(); void redisplay( QString theEntry ); - public slots: +public slots: void updateTree(); void updateBranch( const QString& theEntry ); private slots: void onItemClicked(QTreeWidgetItem*, int ); void updateVisibilityColumn( QString theEntry, Qtx::VisibilityState theState ); - void setVisibility( bool visibility ); + void setVisibility( QTreeWidgetItem* theItem, bool visibility ); void showContextMenu( const QPoint& pos ); - private: +private: + VisualPropertiesPtr getVisualProperty( const BranchType& theBranchType ); + + void fillBranch( const BranchType& theBranchType, + const QString& theEntry ); + void updateVisibilityColumn( const BranchType& theBranchType, + QString theEntry, + Qtx::VisibilityState theState ); + QTreeWidgetItem* getPropertyRootItem( const BranchType& theBranchType ); + QHash& getObjects( const BranchType& theBranchType ); + BranchType branchTypeFromItem( QTreeWidgetItem* theItem ); +private: int myWindowID; QIcon myVisibleIcon; QIcon myInvisibleIcon; QHash myObjects; + QHash myAnnotationObjects; SalomeApp_Study* myStudy; QTreeWidgetItem* myDimensionsItem; QTreeWidgetItem* myAnnotationsItem; diff --git a/src/GEOMGUI/GEOMGUI_VisualProperties.h b/src/GEOMGUI/GEOMGUI_VisualProperties.h new file mode 100644 index 000000000..6a0c27d45 --- /dev/null +++ b/src/GEOMGUI/GEOMGUI_VisualProperties.h @@ -0,0 +1,122 @@ +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, 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 +// + +// File : GEOMGUI_VisualProperties.h +// Author : Anton POLETAEV, Open CASCADE S.A.S. +// + +#ifndef GEOMGUI_VisualProperties_H +#define GEOMGUI_VisualProperties_H + +// OCCT includes +#include +#include + +class GEOMGUI_VisualProperties; +typedef QSharedPointer VisualPropertiesPtr; + +class SalomeApp_Study; + +/*! + * \brief Utility class to presentations as object property of study. + * + * This is an abstract class with interface to manipulate with a property object + * Methods should be implemented in inherited classes. + */ +class Standard_EXPORT GEOMGUI_VisualProperties +{ +public: + + /*! + * \brief Constructor. Inits empty property. + */ + GEOMGUI_VisualProperties() {} + + /*! + * \brief Destructor. + */ + ~GEOMGUI_VisualProperties() {} + + /*! + * \brief Returns number of dimension records. + */ + virtual int GetNumber() const = 0; + + /*! + * \brief Removes record by its index. + * \param theIndex [in] the index of dimension record. + */ + //virtual void RemoveRecord( const int theIndex ) = 0; + /*! + * \brief Clears property data. + */ + //virtual void Clear() = 0; +public: + + /*! + * \brief Returns visibility state of dimension record by its index. + * + * \param theIndex [in] the index of the dimension record. + */ + virtual bool IsVisible( const int theIndex ) const = 0; + + /*! + * \brief Changes visibility state of the dimension record. + * + * \param theIndex [in] the index of the dimension record. + * \param theIsVisible [in] the new visibility state. + */ + virtual void SetVisible( const int theIndex, const bool theIsVisible ) = 0; + + /*! + * \brief Returns name of dimension record by its index. + * + * \param theIndex [in] the index of the dimension record. + */ + virtual QString GetName( const int theIndex ) const = 0; + + /*! + * \brief Changes name of dimension record. + * + * \param theIndex [in] the index of the dimension record. + * \param theName [in] the new name. + */ + virtual void SetName( const int theIndex, const QString& theName ) = 0; + +public: + + /*! + * \brief Loads properties data from attribute "AttributeTableOfReal". + * \param theStudy [in] the study. + * \param theEntry [in] the entry of GEOM object to operate with. + */ + virtual void LoadFromAttribute( SalomeApp_Study* theStudy, const std::string& theEntry ) = 0; + + /*! + * \brief Saves properties data to attribute "AttributeTableOfReal". + * \param theStudy [in] the study. + * \param theEntry [in] the entry of GEOM object to operate with. + */ + virtual void SaveToAttribute( SalomeApp_Study* theStudy, const std::string& theEntry ) = 0; +}; + +#endif diff --git a/src/GEOMGUI/GEOM_Displayer.cxx b/src/GEOMGUI/GEOM_Displayer.cxx index e66324174..6e494dfe8 100755 --- a/src/GEOMGUI/GEOM_Displayer.cxx +++ b/src/GEOMGUI/GEOM_Displayer.cxx @@ -1422,7 +1422,7 @@ void GEOM_Displayer::updateShapeAnnotations( const Handle(SALOME_InteractiveObje { aAnnotationList = aProperty.value(); - for ( int anI = 0; anI < aAnnotationList.Count(); ++anI ) + for ( int anI = 0; anI < aAnnotationList.GetNumber(); ++anI ) { if ( !aAnnotationList.Get( anI ).IsVisible ) { diff --git a/src/MeasureGUI/MeasureGUI_AnnotationDlg.cxx b/src/MeasureGUI/MeasureGUI_AnnotationDlg.cxx old mode 100755 new mode 100644 index baf3a0efb..d010060ea --- a/src/MeasureGUI/MeasureGUI_AnnotationDlg.cxx +++ b/src/MeasureGUI/MeasureGUI_AnnotationDlg.cxx @@ -93,19 +93,17 @@ //purpose : //======================================================================= -MeasureGUI_AnnotationDlg::MeasureGUI_AnnotationDlg(GeometryGUI* theGeometryGUI, - const bool theIsCreate, QWidget* parent, bool modal, Qt::WindowFlags fl) -: GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl), - myIsCreation(theIsCreate) +MeasureGUI_AnnotationDlg::MeasureGUI_AnnotationDlg(GeometryGUI* theGeometryGUI, const bool theIsCreate, + QWidget* parent, bool modal, Qt::WindowFlags fl ) +: GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl ), + myIsCreation( theIsCreate ) { myEditCurrentArgument = 0; SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); QPixmap iconSelect(resMgr->loadPixmap("GEOM", tr("ICON_SELECT"))); - setWindowTitle(myIsCreation ? - tr("CREATE_ANNOTATION_TITLE") : - tr("EDIT_ANNOTATION_TITLE")); + setWindowTitle( myIsCreation ? tr("CREATE_ANNOTATION_TITLE") : tr("EDIT_ANNOTATION_TITLE")); // Shape type button group mainFrame()->GroupConstructors->hide(); @@ -138,13 +136,13 @@ MeasureGUI_AnnotationDlg::MeasureGUI_AnnotationDlg(GeometryGUI* theGeometryGUI, myTypeCombo = new QComboBox(propGroup); myTypeCombo->insertItem(0, tr("3D")); myTypeCombo->insertItem(1, tr("2D")); - myTypeCombo->setCurrentIndex(0); // double + myTypeCombo->setCurrentIndex(0); // 3D, not fixed propLayout->addWidget(shapeLabel, 1, 0); propLayout->addWidget(myShapeSelBtn, 1, 1); propLayout->addWidget(myShapeName, 1, 2); - propLayout->addWidget(typeLabel, 2, 0, 1, 2); - propLayout->addWidget(myTypeCombo, 2, 2); + propLayout->addWidget(typeLabel, 2, 0, 1, 2); + propLayout->addWidget(myTypeCombo, 2, 2); propLayout->setColumnStretch(2, 5); QLabel* shapeTypeLabel = new QLabel(tr("ANNOTATION_SUB_SHAPE"), propGroup); @@ -154,7 +152,7 @@ MeasureGUI_AnnotationDlg::MeasureGUI_AnnotationDlg(GeometryGUI* theGeometryGUI, mySubShapeTypeCombo->addItem(tr("GEOM_EDGE"), TopAbs_EDGE); mySubShapeTypeCombo->addItem(tr("GEOM_FACE"), TopAbs_FACE); mySubShapeTypeCombo->addItem(tr("GEOM_SOLID"), TopAbs_SOLID); - mySubShapeTypeCombo->setCurrentIndex(0); // VERTEX + mySubShapeTypeCombo->setCurrentIndex(0); // SHAPE propLayout->addWidget(shapeTypeLabel, 3, 0); propLayout->addWidget(mySubShapeTypeCombo, 3, 1, 1, 2); @@ -171,7 +169,8 @@ MeasureGUI_AnnotationDlg::MeasureGUI_AnnotationDlg(GeometryGUI* theGeometryGUI, propLayout->addWidget(mySubShapeName, 4, 2); // Field properties - QGroupBox* styleGroup = new QGroupBox(tr("ANNOTATION_STYLE"), centralWidget()); + QGroupBox* styleGroup = new QGroupBox(tr("ANNOTATION_STYLE"), + centralWidget()); QGridLayout* styleLayout = new QGridLayout(styleGroup); styleLayout->setMargin(9); styleLayout->setSpacing(6); @@ -189,7 +188,7 @@ MeasureGUI_AnnotationDlg::MeasureGUI_AnnotationDlg(GeometryGUI* theGeometryGUI, LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); connect(aSelMgr, SIGNAL(currentSelectionChanged()), this, - SLOT(SelectionIntoArgument())); + SLOT(SelectionIntoArgument())); connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk())); connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply())); @@ -205,8 +204,7 @@ MeasureGUI_AnnotationDlg::MeasureGUI_AnnotationDlg(GeometryGUI* theGeometryGUI, //purpose : //======================================================================= -MeasureGUI_AnnotationDlg::~MeasureGUI_AnnotationDlg() -{ +MeasureGUI_AnnotationDlg::~MeasureGUI_AnnotationDlg() { } //================================================================================= @@ -214,13 +212,10 @@ MeasureGUI_AnnotationDlg::~MeasureGUI_AnnotationDlg() // purpose : fills annotation properties with default values(in create mode) or // the values of modified object //================================================================================= -void MeasureGUI_AnnotationDlg::Init() -{ +void MeasureGUI_AnnotationDlg::Init() { if (myIsCreation) { initName(tr("ANNOTATION_PREFIX")); - myEditCurrentArgument = myShapeName; - // default presentation values myAnnotationProperties.Position = gp_Pnt(250, 250, 250); myAnnotationProperties.Text = tr("ANNOTATION_PREFIX"); @@ -228,23 +223,39 @@ void MeasureGUI_AnnotationDlg::Init() myAnnotationProperties.IsScreenFixed = false; myAnnotationProperties.Attach = gp_Pnt(0, 0, 0); myAnnotationProperties.ShapeIndex = -1; - myAnnotationProperties.ShapeType = (int)TopAbs_SHAPE; + myAnnotationProperties.ShapeType = (int) TopAbs_SHAPE; + + // update internal controls and fields following to default values + activateSelectionArgument(myShapeSelBtn); + myTextEdit->setText(myAnnotationProperties.Text); + myTypeCombo->setCurrentIndex(!myAnnotationProperties.IsScreenFixed); + + int aSubShapeTypeIndex = -1; + int aTypesCount = aTypesCount = mySubShapeTypeCombo->count(); + for (int i = 0; i < aTypesCount && aSubShapeTypeIndex < 0; i++) { + int aType = mySubShapeTypeCombo->itemData(i).toInt(); + if (aType == myAnnotationProperties.ShapeType) + aSubShapeTypeIndex = i; + } + mySubShapeTypeCombo->setCurrentIndex(aSubShapeTypeIndex); + mySelectionMode = (TopAbs_ShapeEnum) myAnnotationProperties.ShapeType; SelectionIntoArgument(); + updateSubShapeEnableState(); - mySelectionMode = TopAbs_SHAPE; + // connect controls + connect(myShapeSelBtn, SIGNAL(clicked()), this, + SLOT(SetEditCurrentArgument())); + connect(mySubShapeSelBtn, SIGNAL(clicked()), this, + SLOT(SetEditCurrentArgument())); - connect(myShapeSelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); - connect(mySubShapeSelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); - - connect(myTextEdit, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChange())); - connect(myTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onTypeChange())); - connect(mySubShapeTypeCombo, SIGNAL(currentIndexChanged(int)), - this, SLOT(onSubShapeTypeChange())); + connect(myTextEdit, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChange())); + connect(myTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onTypeChange())); + connect(mySubShapeTypeCombo, SIGNAL(currentIndexChanged(int)), + this, SLOT(onSubShapeTypeChange())); //SelectionIntoArgument(); - } - else { // edition + } else { // edition } redisplayPreview(); @@ -254,8 +265,7 @@ void MeasureGUI_AnnotationDlg::Init() // function : activateSelection // purpose : Activate local selection //================================================================================= -void MeasureGUI_AnnotationDlg::activateSelection() -{ +void MeasureGUI_AnnotationDlg::activateSelection() { //globalSelection(GEOM_ALLSHAPES); //if (!myShape->_is_nil() && mySelectionMode != TopAbs_SHAPE) { // localSelection(myShape.get(), mySelectionMode); @@ -266,103 +276,104 @@ void MeasureGUI_AnnotationDlg::activateSelection() // function : getShapeType() // purpose : //================================================================================= -TopAbs_ShapeEnum MeasureGUI_AnnotationDlg::getShapeType() const -{ - return (TopAbs_ShapeEnum)mySubShapeTypeCombo->itemData(mySubShapeTypeCombo->currentIndex()).toInt(); +TopAbs_ShapeEnum MeasureGUI_AnnotationDlg::getShapeType() const { + return (TopAbs_ShapeEnum) mySubShapeTypeCombo->itemData( + mySubShapeTypeCombo->currentIndex()).toInt(); } //================================================================================= // function : ClickOnOk() // purpose : //================================================================================= -void MeasureGUI_AnnotationDlg::ClickOnOk() -{ - setIsApplyAndClose(true); - if (ClickOnApply()) - ClickOnCancel(); - setIsApplyAndClose(false); +void MeasureGUI_AnnotationDlg::ClickOnOk() { + setIsApplyAndClose(true); + if (ClickOnApply()) + ClickOnCancel(); + setIsApplyAndClose(false); } //================================================================================= // function : ClickOnApply() // purpose : //================================================================================= -bool MeasureGUI_AnnotationDlg::ClickOnApply() -{ - if(!isApplyAndClose()) { - setIsDisableBrowsing(true); - setIsDisplayResult(false); - } +bool MeasureGUI_AnnotationDlg::ClickOnApply() { + if (!isApplyAndClose()) { + setIsDisableBrowsing(true); + setIsDisplayResult(false); + } - QString msg; - if (!isValid(msg)) { - showError(msg); - return false; - } + QString msg; + if (!isValid(msg)) { + showError(msg); + return false; + } - SUIT_OverrideCursor wc; - SUIT_Session::session()->activeApplication()->putInfo(""); - - try - { - if (openCommand()) - if (!execute (/*isApplyAndClose()*/)) - { - abortCommand(); - showError(); - return false; - } - } - catch(const SALOME::SALOME_Exception& e) { - SalomeApp_Tools::QtCatchCorbaException(e); + SUIT_OverrideCursor wc; + SUIT_Session::session()->activeApplication()->putInfo(""); + + try { + if (openCommand()) + if (!execute(/*isApplyAndClose()*/)) { abortCommand(); + showError(); return false; - } - commitCommand(); + } + } catch (const SALOME::SALOME_Exception& e) { + SalomeApp_Tools::QtCatchCorbaException(e); + abortCommand(); + return false; + } + commitCommand(); - if(!isApplyAndClose()) { - setIsDisableBrowsing(false); - setIsDisplayResult(true); - } + if (!isApplyAndClose()) { + setIsDisableBrowsing(false); + setIsDisplayResult(true); + } - /*if (myIsCreation) - { - myAnnotation = GEOM::GEOM_Field::_nil(); - if (!isApplyAndClose()) - Init(); - }*/ - return true; - } + /*if (myIsCreation) + { + myAnnotation = GEOM::GEOM_Field::_nil(); + if (!isApplyAndClose()) + Init(); + }*/ + return true; +} //================================================================================= // function : SetEditCurrentArgument() // purpose : process click on shape/sub-shape button. It stores as current edit argument // the corresponded line edit, set focus in it and unpress other button if it was pressed //================================================================================= -void MeasureGUI_AnnotationDlg::SetEditCurrentArgument() -{ - QPushButton* aSelectButton = (QPushButton*)sender(); +void MeasureGUI_AnnotationDlg::SetEditCurrentArgument() { + QPushButton* aSelectButton = (QPushButton*) sender(); + + activateSelectionArgument(aSelectButton); + + SelectionIntoArgument(); +} + +//================================================================================= +// function : activateSelectionArgument() +// purpose : it stores as current edit argument the corresponded line edit, +// sets the focus on it and unpresses other button if it was pressed +//================================================================================= +void MeasureGUI_AnnotationDlg::activateSelectionArgument( + QPushButton* theSelectionButton) { QPushButton* anOtherButton = 0; - if (aSelectButton == myShapeSelBtn) { + if (theSelectionButton == myShapeSelBtn) { myEditCurrentArgument = myShapeName; anOtherButton = mySubShapeSelBtn; - } - else if (aSelectButton == mySubShapeSelBtn) { + } else if (theSelectionButton == mySubShapeSelBtn) { myEditCurrentArgument = mySubShapeName; anOtherButton = myShapeSelBtn; - } - else + } else myEditCurrentArgument = 0; if (myEditCurrentArgument) myEditCurrentArgument->setFocus(); - aSelectButton->setDown(true); - - if (aSelectButton->isChecked()) - anOtherButton->setDown(false); - - SelectionIntoArgument(); + theSelectionButton->setDown(true); + anOtherButton->setDown(false); } //================================================================================= @@ -370,40 +381,37 @@ void MeasureGUI_AnnotationDlg::SetEditCurrentArgument() // purpose : Called when selection has changed. Sets the current selection in the // annotation property and redisplays presentation //================================================================================= -void MeasureGUI_AnnotationDlg::SelectionIntoArgument() -{ +void MeasureGUI_AnnotationDlg::SelectionIntoArgument() { if (myIsCreation && myEditCurrentArgument) { - GEOM::GeomObjPtr anObj = getSelected(mySelectionMode); + myEditCurrentArgument->setText(""); - QString aName = GEOMBase::GetName(anObj.get()); + GEOM::GeomObjPtr anObj = getSelected(mySelectionMode); gp_Pnt anAttachPoint(0, 0, 0); int aSubShapeIndex = -1; if (myEditCurrentArgument == myShapeName) { // Selection of a shape is active - if (mySelectionMode == TopAbs_SHAPE) { + if (anObj->_is_nil() || mySelectionMode != TopAbs_SHAPE) { + myShape = GEOM::GEOM_Object::_nil(); + } else { + myShape = anObj; + QString aName = GEOMBase::GetName(anObj.get()); myEditCurrentArgument->setText(aName); + } - if (anObj->_is_nil()) - myShape = GEOM::GEOM_Object::_nil(); - else - myShape = anObj; - - bool aNullShape = myShape->_is_nil(); - mySubShapeTypeCombo->setEnabled(!aNullShape); - mySubShapeSelBtn->setEnabled(!aNullShape); - mySubShapeName->setEnabled(!aNullShape); - activateSelection(); + bool aNullShape = myShape->_is_nil(); + mySubShapeTypeCombo->setEnabled(!aNullShape); + updateSubShapeEnableState(); + activateSelection(); - if (!myShape->_is_nil()) { - TopoDS_Shape aShape; - GEOMBase::GetShape(myShape.get(), aShape); - anAttachPoint = getAttachPoint(aShape); - } + if (!myShape->_is_nil()) { + TopoDS_Shape aShape; + GEOMBase::GetShape(myShape.get(), aShape); + anAttachPoint = getAttachPoint(aShape); } - } - else if (myEditCurrentArgument == mySubShapeName) { + } else if (myEditCurrentArgument == mySubShapeName) { if (!myShape->_is_nil()) { + QString aName = GEOMBase::GetName(anObj.get()); myEditCurrentArgument->setText(aName); TopTools_IndexedMapOfShape aMainMap; @@ -411,7 +419,7 @@ void MeasureGUI_AnnotationDlg::SelectionIntoArgument() GEOMBase::GetShape(myShape.get(), aMainShape); TopExp::MapShapes(aMainShape, aMainMap); - TopExp_Explorer anExp (aMainShape, getShapeType()); + TopExp_Explorer anExp(aMainShape, getShapeType()); bool isShowWarning = true; TopoDS_Shape aSubShape; @@ -424,18 +432,19 @@ void MeasureGUI_AnnotationDlg::SelectionIntoArgument() } } anAttachPoint = getAttachPoint(aSubShape); + myAnnotationProperties.ShapeIndex = aSubShapeIndex; } } myAnnotationProperties.Attach = anAttachPoint; } + redisplayPreview(); } //======================================================================= //function : onTextChange //purpose : change annotation text //======================================================================= -void MeasureGUI_AnnotationDlg::onTextChange() -{ +void MeasureGUI_AnnotationDlg::onTextChange() { myAnnotationProperties.Text = myTextEdit->text(); redisplayPreview(); } @@ -444,8 +453,7 @@ void MeasureGUI_AnnotationDlg::onTextChange() //function : onTypeChange //purpose : change annotation type: 2D or 3D //======================================================================= -void MeasureGUI_AnnotationDlg::onTypeChange() -{ +void MeasureGUI_AnnotationDlg::onTypeChange() { myAnnotationProperties.IsScreenFixed = myTypeCombo->currentIndex() == 1; redisplayPreview(); } @@ -454,12 +462,19 @@ void MeasureGUI_AnnotationDlg::onTypeChange() //function : onSubShapeTypeChange //purpose : //======================================================================= -void MeasureGUI_AnnotationDlg::onSubShapeTypeChange() -{ +void MeasureGUI_AnnotationDlg::onSubShapeTypeChange() { + activateSelectionArgument(mySubShapeSelBtn); + TopAbs_ShapeEnum aShapeType = getShapeType(); myAnnotationProperties.ShapeType = aShapeType; + if (aShapeType != mySelectionMode) { + mySubShapeName->setText(""); + myAnnotationProperties.ShapeIndex = -1; + mySelectionMode = aShapeType; + } + + updateSubShapeEnableState(); - mySelectionMode = getShapeType(); activateSelection(); redisplayPreview(); } @@ -474,25 +489,22 @@ void MeasureGUI_AnnotationDlg::onSubShapeTypeChange() // function : isValid() // purpose : Verify validity of input data //================================================================================= -bool MeasureGUI_AnnotationDlg::isValid(QString& theMessage) -{ +bool MeasureGUI_AnnotationDlg::isValid(QString& theMessage) { SalomeApp_Study* study = getStudy(); RETURN_WITH_MSG(!study, tr("GEOM_NO_STUDY")) RETURN_WITH_MSG(study->studyDS()->GetProperties()->IsLocked(), - tr("GEOM_STUDY_LOCKED")) + tr("GEOM_STUDY_LOCKED")) if (myIsCreation) { RETURN_WITH_MSG(myShape->_is_nil(), tr("NO_SHAPE")) - } - else { + } else { //RETURN_WITH_MSG(CORBA::is_nil(myShape), tr("NO_FIELD")) } if (getShapeType() != TopAbs_SHAPE) { if (myIsCreation) { RETURN_WITH_MSG(myAnnotationProperties.ShapeIndex < 0, tr("NO_SUB_SHAPE")) - } - else { + } else { //RETURN_WITH_MSG(CORBA::is_nil(myShape), tr("NO_FIELD")) } } @@ -510,7 +522,35 @@ bool MeasureGUI_AnnotationDlg::execute() return false; if (myIsCreation) { - + QString aName = getNewObjectName(); + + SalomeApp_Study* aStudy = getStudy(); + GEOMGUI_ShapeAnnotations aProp = + aStudy->getObjectProperty( GEOM::sharedPropertiesId(), + myShape->GetStudyEntry(), + GEOM::propertyName( GEOM::ShapeAnnotations ), + QVariant() ) + .value(); + + // append new dimension record to data + aProp.Add( myAnnotationProperties ); + aProp.SetName( aProp.GetNumber() - 1, aName ); + aProp.SetVisible( aProp.GetNumber() - 1, true ); + + // store modified property data + aStudy->setObjectProperty( GEOM::sharedPropertiesId(), + myShape->GetStudyEntry(), GEOM::propertyName(GEOM::ShapeAnnotations), + aProp); + myGeomGUI->emitDimensionsUpdated( QString( myShape->GetStudyEntry() ) ); + } + else { + /*SalomeApp_Study* aStudy = getStudy(); + myAnnotationProperties = aStudy->getObjectProperty( GEOM::sharedPropertiesId(), + myShape->GetStudyEntry(), + GEOM::propertyName( GEOM::ShapeAnnotations ), + QVariant() ) + .value(); + mySavedPropertyState.SaveToAttribute( aStudy, myEditObject->GetStudyEntry() );*/ } return true; } @@ -519,9 +559,9 @@ bool MeasureGUI_AnnotationDlg::execute() // function : buildPrs // purpose : creates annotation presentation object and corresponded SALOME presentation //================================================================================= -SALOME_Prs* MeasureGUI_AnnotationDlg::buildPrs() -{ - Handle (GEOM_Annotation) aPresentation = new GEOM_Annotation(); +SALOME_Prs* MeasureGUI_AnnotationDlg::buildPrs() { + Handle (GEOM_Annotation) + aPresentation = new GEOM_Annotation(); SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); const QFont aFont = aResMgr->fontValue( "Geometry", "shape_annotation_font", QFont( "Y14.5M-2009", 24 ) ); @@ -550,10 +590,10 @@ SALOME_Prs* MeasureGUI_AnnotationDlg::buildPrs() // add Prs to preview SUIT_ViewWindow* vw = - SUIT_Session::session()->activeApplication()->desktop()->activeWindow(); + SUIT_Session::session()->activeApplication()->desktop()->activeWindow(); SOCC_Prs* aPrs = - dynamic_cast(((SOCC_Viewer*) (vw->getViewManager()->getViewModel()))->CreatePrs( - 0)); + dynamic_cast(((SOCC_Viewer*) (vw->getViewManager()->getViewModel()))->CreatePrs( + 0)); if (aPrs) aPrs->AddObject(aPresentation); @@ -561,13 +601,23 @@ SALOME_Prs* MeasureGUI_AnnotationDlg::buildPrs() return aPrs; } +//================================================================================= +// function : updateSubShapeEnableState +// purpose : creates annotation presentation object and corresponded SALOME presentation +//================================================================================= +void MeasureGUI_AnnotationDlg::updateSubShapeEnableState() +{ + bool isWholeShape = getShapeType() == TopAbs_SHAPE; + bool aNullShape = myShape->_is_nil(); + mySubShapeSelBtn->setEnabled(!aNullShape && !isWholeShape); + mySubShapeName->setEnabled(!aNullShape && !isWholeShape); +} //================================================================================= // function : buildPrs // purpose : creates annotation presentation object and corresponded SALOME presentation //================================================================================= -void MeasureGUI_AnnotationDlg::redisplayPreview() -{ +void MeasureGUI_AnnotationDlg::redisplayPreview() { QString aMess; if (!isValid(aMess)) { erasePreview(true); @@ -583,11 +633,9 @@ void MeasureGUI_AnnotationDlg::redisplayPreview() if (SALOME_Prs* aPrs = buildPrs()) displayPreview(aPrs); - } - catch (const SALOME::SALOME_Exception& e) { + } catch (const SALOME::SALOME_Exception& e) { SalomeApp_Tools::QtCatchCorbaException(e); - } - catch (...) { + } catch (...) { } } @@ -595,8 +643,7 @@ void MeasureGUI_AnnotationDlg::redisplayPreview() // function : getAttachPoint // purpose : finds a point on shape to attach annotation object //================================================================================= -gp_Pnt MeasureGUI_AnnotationDlg::getAttachPoint(const TopoDS_Shape& theShape) -{ +gp_Pnt MeasureGUI_AnnotationDlg::getAttachPoint(const TopoDS_Shape& theShape) { gp_Pnt aPoint = gp_Pnt(0, 0, 0); return aPoint;