From 9c27a6dc8d7d3d6300ded5f94c7d468051da226a Mon Sep 17 00:00:00 2001 From: san Date: Mon, 14 Nov 2011 08:45:02 +0000 Subject: [PATCH] Issue 21378 [CEA 505] Possibility to change data object's color using SalomePyQt API http://salome.mantis.opencascade.com/view.php?id=21378 Issue 21379 [CEA 504] Implement mechanism of references in Object Browser in light SALOME GUI http://salome.mantis.opencascade.com/view.php?id=21379 --- src/LightApp/LightApp_DataObject.cxx | 102 +++++++++++++++++- src/LightApp/LightApp_DataObject.h | 7 +- .../SALOME_PYQT_DataObjectLight.cxx | 49 +++++++++ .../SALOME_PYQT_DataObjectLight.h | 20 ++-- .../SALOME_PYQT_ModuleLight.cxx | 47 ++++++++ .../SALOME_PYQT_ModuleLight.h | 20 ++-- src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx | 89 +++++++++++++++ src/SALOME_PYQT/SalomePyQt/SalomePyQt.h | 7 ++ src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip | 12 ++- src/SalomeApp/SalomeApp_Application.cxx | 30 +++--- src/SalomeApp/SalomeApp_DataObject.cxx | 40 ++++--- src/SalomeApp/SalomeApp_DataObject.h | 9 +- 12 files changed, 376 insertions(+), 56 deletions(-) diff --git a/src/LightApp/LightApp_DataObject.cxx b/src/LightApp/LightApp_DataObject.cxx index 39a932e29..b0162dce5 100644 --- a/src/LightApp/LightApp_DataObject.cxx +++ b/src/LightApp/LightApp_DataObject.cxx @@ -209,6 +209,31 @@ QString LightApp_DataObject::entry() const return QString(); } +/*! + \brief Returns the string identifier of the data objects referenced by this one. + + This method should be reimplemented in the subclasses. + Default implementation returns null string. + + \return ID string of the referenced data object +*/ +QString LightApp_DataObject::refEntry() const +{ + return QString(); +} + +/*! + \brief Tells if this data objects is a reference to some other or not. + + The base implementation retuns true, if refEntry() returns non-empty string. + + \return true if refEntry() is a non-empty string. +*/ +bool LightApp_DataObject::isReference() const +{ + return !refEntry().isEmpty(); +} + /*! \brief Get the data object unique key. \return data object key @@ -222,17 +247,88 @@ SUIT_DataObjectKey* LightApp_DataObject::key() const /*! \brief Get object text data for the specified column. - Column with \a id = 0 (NameId) is supposed to be used + Column with \a id == NameId is supposed to be used to get the object name. - Column with \a id = 1 (EntryId) is supposed to be used + Column with \a id == EntryId is supposed to be used to get the object entry. + Column with \a id == RefEntryId is supposed to be used + to show the entry of the object referenced by this one. \param id column id \return object text data */ QString LightApp_DataObject::text( const int id ) const { - return id == EntryId ? entry() : CAM_DataObject::text( id ); + QString txt; + + switch ( id ) + { + case EntryId: + txt = entry(); + break; + case RefEntryId: + // Issue 21379: reference support at LightApp level + if ( isReference() ) + txt = refEntry(); + break; + default: + // Issue 21379: Note that we cannot return some specially decorated + // name string (like "* ref_obj_name") when isReference() returns true, + // since there is no generic way at LightApp level + // to query the object name using refEntry() up to now. + // TODO: Think how to make reference name generation + // more generic at move it here from SalomeApp level... + txt = CAM_DataObject::text( id ); + break; + } + + return txt; +} + +/*! + \brief Get data object color for the specified column. + \param role color role + \param id column id (not used) + \return object color for the specified column +*/ +QColor LightApp_DataObject::color( const ColorRole role, const int id) const +{ + QColor c; + + // Issue 21379: reference support at LightApp level + // Centralized way for choosing text/background color for references. + // Colors for "normal" objects should be chosen by sub-classes. + switch ( role ) + { + case Text: + case Foreground: + // text color (not selected item) + // TODO: think how to detect invalid references... + if ( isReference() ) + c = QColor( 255, 0, 0 ); // valid reference (red) + break; + + case Highlight: + // background color for the highlighted item + // TODO: think how to detect invalid references... + if ( isReference() ) + c = QColor( 255, 0, 0 ); // valid reference (red) + break; + + case HighlightedText: + // text color for the highlighted item + if ( isReference() ) + c = QColor( 255, 255, 255 ); // white + break; + + default: + break; + } + + if ( !c.isValid() ) + c = CAM_DataObject::color( role, id ); + + return c; } /*! diff --git a/src/LightApp/LightApp_DataObject.h b/src/LightApp/LightApp_DataObject.h index f87d97d63..2e597bfbd 100644 --- a/src/LightApp/LightApp_DataObject.h +++ b/src/LightApp/LightApp_DataObject.h @@ -39,7 +39,8 @@ class LIGHTAPP_EXPORT LightApp_DataObject : public virtual CAM_DataObject public: //! Column id enum { - EntryId = VisibilityId + 1 //!< entry column + EntryId = VisibilityId + 1, //!< entry column + RefEntryId //!< reference entry column }; public: @@ -49,7 +50,11 @@ public: virtual SUIT_DataObjectKey* key() const; virtual QString entry() const; + virtual QString refEntry() const; + virtual bool isReference() const; + virtual QString text( const int = NameId ) const; + virtual QColor color( const ColorRole, const int = NameId ) const; virtual SUIT_DataObject* componentObject() const; virtual QString componentDataType() const; diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_DataObjectLight.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_DataObjectLight.cxx index ecdfce0a7..4db8c6fb6 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_DataObjectLight.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_DataObjectLight.cxx @@ -69,6 +69,24 @@ QString SALOME_PYQT_DataObjectLight::entry() const return myEntry; } +//================================================================================= +// function : SALOME_PYQT_DataObjectLight::refEntry() +// purpose : return entry of the data object referenced by this one (if any) +//================================================================================= +QString SALOME_PYQT_DataObjectLight::refEntry() const +{ + return myRefEntry; +} + +//================================================================================= +// function : SALOME_PYQT_DataObjectLight::setRefEntry() +// purpose : sets entry of the data object referenced by this one +//================================================================================= +void SALOME_PYQT_DataObjectLight::setRefEntry( const QString& refEntry ) +{ + myRefEntry = refEntry; +} + //================================================================================= // function : SALOME_PYQT_DataObjectLight::name() // purpose : return name of object @@ -100,6 +118,32 @@ QString SALOME_PYQT_DataObjectLight::toolTip(const int index) const return myToolTip; } +//================================================================================= +// function : SALOME_PYQT_DataObjectLight::toolTip() +// purpose : return toolTip of object +//================================================================================= +QColor SALOME_PYQT_DataObjectLight::color( const ColorRole role, const int id ) const +{ + QColor c; + + switch ( role ) + { + case Text: + case Foreground: + if ( !isReference() ) + c = myColor; + break; + + default: + break; + } + + // Issue 21379: LightApp_DataObject::color() defines colors for valid references + if ( !c.isValid() ) + c = LightApp_DataObject::color( role, id ); + + return c; +} bool SALOME_PYQT_DataObjectLight::setName(const QString& name) { @@ -126,3 +170,8 @@ void SALOME_PYQT_DataObjectLight::setToolTip(const QString& tooltip) { myToolTip = tooltip; } + +void SALOME_PYQT_DataObjectLight::setColor(const QColor& color) +{ + myColor = color; +} diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_DataObjectLight.h b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_DataObjectLight.h index 80d5a2ae0..08b59fc97 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_DataObjectLight.h +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_DataObjectLight.h @@ -42,20 +42,28 @@ class SALOME_PYQT_LIGHT_EXPORT SALOME_PYQT_DataObjectLight : public virtual Ligh virtual ~SALOME_PYQT_DataObjectLight(); virtual QString entry() const; + + virtual QString refEntry() const; + void setRefEntry( const QString& refEntry ); virtual QString name() const; - QPixmap icon(const int = NameId) const; - QString toolTip(const int = NameId) const; - - bool setName(const QString& name); - void setIcon(const QString& icon); - void setToolTip(const QString& tooltip); + virtual QPixmap icon(const int = NameId) const; + virtual QString toolTip(const int = NameId) const; + + bool setName(const QString& name); + void setIcon(const QString& icon); + void setToolTip(const QString& tooltip); + + virtual QColor color( const ColorRole, const int = NameId ) const; + void setColor(const QColor& color); private: QString myEntry; + QString myRefEntry; QString myName; QString myToolTip; QPixmap myIcon; + QColor myColor; }; #endif // SALOME_PYQT_DATAOBJECTLIGHT_H diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx index 825034ad7..965036feb 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx @@ -2751,6 +2751,53 @@ void SALOME_PYQT_ModuleLight::setToolTip(const QString& obj, const QString& tool } } +/* + * Return color of object + */ +QColor SALOME_PYQT_ModuleLight::getColor(const QString& obj) +{ + SALOME_PYQT_DataObjectLight* dataObj = findObject( obj ); + if( dataObj ) { + return dataObj->color( SUIT_DataObject::Foreground ); + } + return QColor(); +} + +/* + * Set color for object + */ +void SALOME_PYQT_ModuleLight::setColor(const QString& obj, const QColor& color) +{ + SALOME_PYQT_DataObjectLight* dataObj = findObject( obj ); + if( dataObj ) { + dataObj->setColor( color ); + } +} + +/* + * Return entry of the referenced object (if any) + */ +QString SALOME_PYQT_ModuleLight::getReference(const QString& obj) +{ + SALOME_PYQT_DataObjectLight* dataObj = findObject(obj); + if(dataObj) { + return dataObj->refEntry(); + } + return QString::null; +} + + +/* + * Set entry of the referenced object + */ +void SALOME_PYQT_ModuleLight::setReference(const QString& obj, const QString& refEntry) +{ + SALOME_PYQT_DataObjectLight* dataObj = findObject(obj); + if(dataObj) { + dataObj->setRefEntry(refEntry); + } +} + /* * Remove object by entry */ diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.h b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.h index dbc6d21e8..cf07211b3 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.h +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.h @@ -128,19 +128,27 @@ public: void dumpPython(QStringList& theListOfFiles); /*create new SALOME_PYQT_DataObjectLight and return its entry*/ - QString createObject(const QString& parent); - QString createObject(const QString& name, - const QString& iconname, - const QString& tooltip, - const QString& parent); + QString createObject(const QString& parent); + QString createObject(const QString& name, + const QString& iconname, + const QString& tooltip, + const QString& parent); /*Sets Name, Icon and Tool Tip for object*/ void setName(const QString& obj,const QString& iconname); void setIcon(const QString& obj,const QString& name); - void setToolTip(const QString& obj, const QString& name); + void setToolTip(const QString& obj, const QString& tooltip); /*Gets Name and Tool Tip for object*/ QString getName(const QString& obj); QString getToolTip(const QString& obj); + + void setColor(const QString& obj, const QColor& color); + QColor getColor(const QString& obj); + + void setReference( const QString& obj, + const QString& refEntry ); + QString getReference( const QString& obj ); + /*remove object*/ void removeObject(const QString& obj); /*remove child*/ diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx index 3429ec9b8..3385b7245 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx @@ -2975,6 +2975,52 @@ void SalomePyQt::setToolTip(const QString& obj,const QString& tooltip) ProcessVoidEvent(new TSetToolTipEvent(obj,tooltip)); } +/*! + SalomePyQt::setReference(obj,refEntry) + Set entry to referenced object +*/ +class TSetRefEvent: public SALOME_Event +{ +public: + QString myObj; + QString myRefEntry; + TSetRefEvent( const QString& obj, + const QString& refEntry) : myObj(obj), + myRefEntry(refEntry) {} + virtual void Execute() { + SALOME_PYQT_ModuleLight* module = getActiveModule(); + if ( module ) + module->setReference(myObj,myRefEntry); + } +}; +void SalomePyQt::setReference(const QString& obj,const QString& refEntry) +{ + ProcessVoidEvent(new TSetRefEvent(obj,refEntry)); +} + +/*! + SalomePyQt::setColor(obj,color) + Set object color +*/ +class TSetColorEvent: public SALOME_Event +{ +public: + QString myObj; + QColor myColor; + TSetColorEvent( const QString& obj, + const QColor& color) : myObj(obj), + myColor(color) {} + virtual void Execute() { + SALOME_PYQT_ModuleLight* module = getActiveModule(); + if ( module ) + module->setColor(myObj,myColor); + } +}; +void SalomePyQt::setColor(const QString& obj,const QColor& color) +{ + ProcessVoidEvent(new TSetColorEvent(obj,color)); +} + /*! SalomePyQt::getName(obj) Return name of object @@ -3020,6 +3066,49 @@ QString SalomePyQt::getToolTip(const QString& obj) return ProcessEvent(new TGetToolTipEvent(obj)); } +/*! + SalomePyQt::getReference(obj) + Return entry of the referenced object (if any) +*/ +class TGetRefEvent: public SALOME_Event +{ +public: + typedef QString TResult; + TResult myResult; + QString myObj; + TGetRefEvent( const QString& obj ) : myObj(obj) {} + virtual void Execute() { + SALOME_PYQT_ModuleLight* module = getActiveModule(); + if ( module ) + myResult = module->getReference(myObj); + } +}; +QString SalomePyQt::getReference(const QString& obj) +{ + return ProcessEvent(new TGetRefEvent(obj)); +} + +/*! + SalomePyQt::getColor(obj) + Return the color of the object +*/ +class TGetColorEvent: public SALOME_Event +{ +public: + typedef QColor TResult; + TResult myResult; + QString myObj; + TGetColorEvent( const QString& obj ) : myObj(obj) {} + virtual void Execute() { + SALOME_PYQT_ModuleLight* module = getActiveModule(); + if ( module ) + myResult = module->getColor(myObj); + } +}; +QColor SalomePyQt::getColor(const QString& obj) +{ + return ProcessEvent(new TGetColorEvent(obj)); +} /*! SalomePyQt::removeChild(obj) diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h index 5114bb024..52920dee6 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h @@ -152,6 +152,13 @@ public: static QString getName(const QString& obj); static QString getToolTip(const QString& obj); + static void setColor(const QString& obj,const QColor& color); + static QColor getColor(const QString& obj); + + static void setReference( const QString& obj, + const QString& refEntry ); + static QString getReference( const QString& obj ); + static QIcon loadIcon( const QString&, const QString& ); static void helpContext( const QString&, const QString& ); diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip index 9b7c7b1f5..a8f419999 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip @@ -223,9 +223,9 @@ public: static QString createObject( const QString& = QString("") ) /ReleaseGIL/ ; static QString createObject( const QString&, - const QString&, - const QString&, - const QString& = QString("") ) /ReleaseGIL/ ; + const QString&, + const QString&, + const QString& = QString("") ) /ReleaseGIL/ ; static void setName(const QString& ,const QString& ) /ReleaseGIL/ ; static void setIcon(const QString& ,const QString& ) /ReleaseGIL/ ; @@ -233,6 +233,12 @@ public: static QString getName(const QString& ) /ReleaseGIL/ ; static QString getToolTip(const QString& ) /ReleaseGIL/ ; + static void setColor( const QString&, const QColor& ) /ReleaseGIL/ ; + static QColor getColor( const QString& ) /ReleaseGIL/ ; + + static void setReference( const QString& ,const QString& ) /ReleaseGIL/ ; + static QString getReference( const QString& ) /ReleaseGIL/ ; + static void removeObject(const QString& ) /ReleaseGIL/ ; static void removeChild(const QString& = QString("") ) /ReleaseGIL/ ; static QStringList getChildren(const QString&=QString("") , const bool = false) /ReleaseGIL/ ; diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index 3ac65184b..67f7f02d7 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -1389,28 +1389,22 @@ void SalomeApp_Application::onRegDisplay() /*!find original object by double click on item */ void SalomeApp_Application::onDblClick( SUIT_DataObject* theObj ) { - SalomeApp_DataObject* obj = dynamic_cast( theObj ); - SalomeApp_Study* study = dynamic_cast( activeStudy() ); + // Issue 21379: References are supported at LightApp_DataObject level + LightApp_DataObject* obj = dynamic_cast( theObj ); - if( study && obj ) + if( obj && obj->isReference() ) { - QString entry = obj->entry(); - _PTR(SObject) sobj = study->studyDS()->FindObjectID( entry.toStdString() ), ref; - - if( sobj && sobj->ReferencedObject( ref ) ) - { - entry = ref->GetID().c_str(); + QString entry = obj->refEntry(); - SUIT_DataOwnerPtrList aList; - aList.append( new LightApp_DataOwner( entry ) ); - selectionMgr()->setSelected( aList, false ); + SUIT_DataOwnerPtrList aList; + aList.append( new LightApp_DataOwner( entry ) ); + selectionMgr()->setSelected( aList, false ); + + SUIT_DataBrowser* ob = objectBrowser(); - SUIT_DataBrowser* ob = objectBrowser(); - - QModelIndexList aSelectedIndexes = ob->selectedIndexes(); - if ( !aSelectedIndexes.isEmpty() ) - ob->treeView()->scrollTo( aSelectedIndexes.first() ); - } + QModelIndexList aSelectedIndexes = ob->selectedIndexes(); + if ( !aSelectedIndexes.isEmpty() ) + ob->treeView()->scrollTo( aSelectedIndexes.first() ); } } diff --git a/src/SalomeApp/SalomeApp_DataObject.cxx b/src/SalomeApp/SalomeApp_DataObject.cxx index eff0a65c3..6a96b5c46 100644 --- a/src/SalomeApp/SalomeApp_DataObject.cxx +++ b/src/SalomeApp/SalomeApp_DataObject.cxx @@ -125,7 +125,7 @@ QString SalomeApp_DataObject::text( const int id ) const { QString txt; - // add "Value", "IOR", and "Reference Entry" columns + // Text for "Value" and "IOR" columns switch ( id ) { case ValueId: @@ -141,11 +141,9 @@ QString SalomeApp_DataObject::text( const int id ) const case IORId: txt = ior( referencedObject() ); break; - case RefEntryId : - if ( isReference() ) - txt = entry( referencedObject() ); - break; default: + // Issue 21379: LightApp_DataObject::text() treats "Entry" + // and "Reference Entry" columns txt = LightApp_DataObject::text( id ); break; } @@ -202,9 +200,7 @@ QColor SalomeApp_DataObject::color( const ColorRole role, const int id ) const case Foreground: // text color (not selected item) if ( isReference() ) { - if ( !(QString(referencedObject()->GetName().c_str()).isEmpty()) ) - c = QColor( 255, 0, 0 ); // valid reference (red) - else + if ( QString(referencedObject()->GetName().c_str()).isEmpty() ) c = QColor( 200, 200, 200 ); // invalid reference (grayed) } else if ( myObject ) { @@ -216,12 +212,11 @@ QColor SalomeApp_DataObject::color( const ColorRole role, const int id ) const } } break; + case Highlight: // background color for the highlighted item if ( isReference() ) { - if ( !(QString(referencedObject()->GetName().c_str()).isEmpty()) ) - c = QColor( 255, 0, 0 ); // valid reference (red) - else + if ( QString(referencedObject()->GetName().c_str()).isEmpty() ) c = QColor( 200, 200, 200 ); // invalid reference (grayed) } else if ( myObject ) { @@ -235,14 +230,14 @@ QColor SalomeApp_DataObject::color( const ColorRole role, const int id ) const } } break; - case HighlightedText: - // text color for the highlighted item - if ( isReference() ) - c = QColor( 255, 255, 255 ); // white + default: break; } + + // Issue 21379: LightApp_DataObject::color() defines colors for valid references if ( !c.isValid() ) c = LightApp_DataObject::color( role, id ); + return c; } @@ -329,8 +324,23 @@ _PTR(SObject) SalomeApp_DataObject::object() const return myObject; } +/*! + \brief Returns the string identifier of the data objects referenced by this one. + + Re-implemented from LightApp_DataObject using SALOMEDS API. + + \return ID string of the referenced SObject +*/ +QString SalomeApp_DataObject::refEntry() const +{ + return entry( referencedObject() ); +} + /*! \brief Check if the data object is a reference. + + Re-implemented from LightApp_DataObject using SALOMEDS API. + \return \c true if this data object actually refers to another one */ bool SalomeApp_DataObject::isReference() const diff --git a/src/SalomeApp/SalomeApp_DataObject.h b/src/SalomeApp/SalomeApp_DataObject.h index c9e23bc3d..3d41c46f5 100644 --- a/src/SalomeApp/SalomeApp_DataObject.h +++ b/src/SalomeApp/SalomeApp_DataObject.h @@ -38,9 +38,8 @@ class SALOMEAPP_EXPORT SalomeApp_DataObject : public virtual LightApp_DataObject public: //! Column id enum { - ValueId = EntryId + 1, //!< value column - IORId, //!< IOR column - RefEntryId //!< reference entry column + ValueId = RefEntryId + 1, //!< value column + IORId //!< IOR column }; public: @@ -59,8 +58,10 @@ public: virtual _PTR(SObject) object() const; - bool isReference() const; + virtual QString refEntry() const; + virtual bool isReference() const; _PTR(SObject) referencedObject() const; + bool hasChildren() const; bool expandable() const; -- 2.39.2