-// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
//
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// 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.
+// 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.
+// 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
+// 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
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// File : SalomeApp_DataObject.cxx
// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
-//
+
#include "SalomeApp_DataObject.h"
#include "SalomeApp_Study.h"
#include "SalomeApp_Application.h"
#include <QObject>
#include <QVariant>
+//VSR: uncomment below macro to support unicode text properly in SALOME
+// current commented out due to regressions
+//#define PAL22528_UNICODE
+
+namespace
+{
+ QString fromUtf8( const char* txt )
+ {
+#ifdef PAL22528_UNICODE
+ return QString::fromUtf8( txt );
+#else
+ return QString( txt );
+#endif
+ }
+
+ QString fromUtf8( const std::string& txt )
+ {
+ return fromUtf8( txt.c_str() );
+ }
+}
+
/*!
\class SalomeApp_DataObject
\brief Implementation of the data object for use in CORBA-based
\param parent parent data object
*/
SalomeApp_DataObject::SalomeApp_DataObject( const _PTR(SObject)& sobj,
- SUIT_DataObject* parent )
+ SUIT_DataObject* parent )
: CAM_DataObject( parent ),
LightApp_DataObject( parent )
{
{
QString str;
if ( myObject )
- str = myObject->GetName().c_str();
+ str = fromUtf8( myObject->GetName() );
if ( str.isEmpty() ) {
_PTR(SObject) refObj = referencedObject();
if ( refObj )
- str = refObj->GetName().c_str();
+ str = fromUtf8( refObj->GetName() );
}
if ( isReference() ) {
{
QString txt;
- // add "Value", "IOR", and "Reference Entry" columns
+ // Text for "Value" and "IOR" columns
switch ( id )
{
case ValueId:
-#ifndef WIN32
- if ( componentObject() != this )
-#else
if ( componentObject() != (SUIT_DataObject*)this )
-#endif
txt = value( object() );
- if ( txt.isEmpty() )
- txt = value( referencedObject() );
+ if ( txt.isEmpty() )
+ txt = value( referencedObject() );
break;
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;
}
if ( myObject && myObject->FindAttribute( anAttr, "AttributePixMap" ) ){
_PTR(AttributePixMap) aPixAttr ( anAttr );
if ( aPixAttr->HasPixMap() ) {
- QString componentType = componentDataType();
- QString pixmapID = aPixAttr->GetPixMap().c_str();
- // select a plugin within a component
- QStringList plugin_pixmap = pixmapID.split( "::", QString::KeepEmptyParts );
- if ( plugin_pixmap.size() == 2 ) {
- componentType = plugin_pixmap.front();
- pixmapID = plugin_pixmap.back();
- }
- QString pixmapName = QObject::tr( pixmapID.toLatin1().constData() );
- LightApp_RootObject* aRoot = dynamic_cast<LightApp_RootObject*>( root() );
- if ( aRoot && aRoot->study() ) {
- SUIT_ResourceMgr* mgr = aRoot->study()->application()->resourceMgr();
- return mgr->loadPixmap( componentType, pixmapName, false );
- }
+ QString componentType = componentDataType();
+ QString pixmapID = fromUtf8( aPixAttr->GetPixMap() );
+ // select a plugin within a component
+ QStringList plugin_pixmap = pixmapID.split( "::", QString::KeepEmptyParts );
+ if ( plugin_pixmap.size() == 2 ) {
+ componentType = plugin_pixmap.front();
+ pixmapID = plugin_pixmap.back();
+ }
+ QString pixmapName = QObject::tr( pixmapID.toLatin1().constData() );
+ LightApp_RootObject* aRoot = dynamic_cast<LightApp_RootObject*>( root() );
+ if ( aRoot && aRoot->study() ) {
+ SUIT_ResourceMgr* mgr = aRoot->study()->application()->resourceMgr();
+ return mgr->loadPixmap( componentType, pixmapName, false );
+ }
}
}
}
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
- c = QColor( 200, 200, 200 ); // invalid reference (grayed)
+ if ( QString(referencedObject()->GetName().c_str()).isEmpty() )
+ c = QColor( 200, 200, 200 ); // invalid reference (grayed)
}
else if ( myObject ) {
// get color atrtribute value
_PTR(GenericAttribute) anAttr;
if ( myObject->FindAttribute( anAttr, "AttributeTextColor" ) ) {
- _PTR(AttributeTextColor) aColAttr = anAttr;
- c = QColor( (int)aColAttr->TextColor().R, (int)aColAttr->TextColor().G, (int)aColAttr->TextColor().B );
+ _PTR(AttributeTextColor) aColAttr = anAttr;
+ c = QColor( (int)aColAttr->TextColor().R, (int)aColAttr->TextColor().G, (int)aColAttr->TextColor().B );
}
}
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
- c = QColor( 200, 200, 200 ); // invalid reference (grayed)
+ if ( QString(referencedObject()->GetName().c_str()).isEmpty() )
+ c = QColor( 200, 200, 200 ); // invalid reference (grayed)
}
else if ( myObject ) {
// get color atrtribute value
_PTR(GenericAttribute) anAttr;
if( myObject->FindAttribute ( anAttr, "AttributeTextHighlightColor") ) {
_PTR(AttributeTextHighlightColor) aHighColAttr = anAttr;
- c = QColor( (int)(aHighColAttr->TextHighlightColor().R),
- (int)(aHighColAttr->TextHighlightColor().G),
- (int)(aHighColAttr->TextHighlightColor().B));
+ c = QColor( (int)(aHighColAttr->TextHighlightColor().R),
+ (int)(aHighColAttr->TextHighlightColor().G),
+ (int)(aHighColAttr->TextHighlightColor().B));
}
}
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;
}
// --- try to find (and not load) the component instance, like GEOM instance,
// registered in naming service under Containers/<hostname>/...
// with any container name, on every machine available
- Engines::MachineParameters params;
+ Engines::ContainerParameters params;
app->lcc()->preSet(params); // --- any container name, anywhere
- Engines::Component_var aComponent =
+ Engines::EngineComponent_var aComponent =
app->lcc()->FindComponent(params, componentDataType().toLatin1().constData() );
if ( !CORBA::is_nil(aComponent) && aComponent->hasObjectInfo() ) {
- LightApp_RootObject* aRoot = dynamic_cast<LightApp_RootObject*>( root() );
- if ( aRoot && aRoot->study() )
- return QString( aComponent->getObjectInfo( aRoot->study()->id(), entry().toLatin1().constData()) );
+ LightApp_RootObject* aRoot = dynamic_cast<LightApp_RootObject*>( root() );
+ if ( aRoot && aRoot->study() ) {
+ CORBA::String_var data = aComponent->getObjectInfo( entry().toUtf8().constData());
+ QString objInfo = data.in();
+ QStringList l;
+ l << name();
+ if ( !objInfo.isEmpty() )
+ l << objInfo;
+ return l.join("\n");
+ }
}
}
}
return QString( "Object \'%1\', module \'%2\', ID=%3" ).arg( name() ).arg( componentDataType() ).arg( entry() );
}
+/*!
+ \brief Get font to be used for data object rendering in the item views
+ \param id column id
+ \return font to be used for the item rendering
+*/
+QFont SalomeApp_DataObject::font( const int id ) const
+{
+ QFont f = LightApp_DataObject::font( id );
+ if ( id == NameId ) {
+ if ( !expandable() && hasChildren() ) {
+ // set bold font to highlight the item which is non-expandable but has children
+ f.setBold( true );
+ }
+ }
+ return f;
+}
+
/*!
\brief Get component type.
\return component type
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
return obj;
}
+/*!
+ \brief Check if object has children
+ \return \c true if object has at least one child sub-object and \c false otherwise
+*/
+bool SalomeApp_DataObject::hasChildren() const
+{
+ bool ok = false;
+
+ // tmp??
+ _PTR(UseCaseBuilder) aUseCaseBuilder = SalomeApp_Application::getStudy()->GetUseCaseBuilder();
+ if (aUseCaseBuilder->IsUseCaseNode(myObject)) {
+ ok = aUseCaseBuilder->HasChildren(myObject);
+ // TODO: check name as below?
+ }
+ else {
+ _PTR(ChildIterator) it ( SalomeApp_Application::getStudy()->NewChildIterator( myObject ) );
+ for ( ; it->More() && !ok; it->Next() ) {
+ _PTR(SObject) obj = it->Value();
+ if ( obj ) {
+ _PTR(SObject) refObj;
+ //if ( obj->ReferencedObject( refObj ) ) continue; // omit references
+ if ( obj->GetName() != "" ) ok = true;
+ }
+ }
+ }
+ return ok;
+}
+
+/*!
+ \brief Check if the object is expandable (e.g. in the data tree view)
+ \return \c true if object is expandable and \c false otherwise
+*/
+bool SalomeApp_DataObject::expandable() const
+{
+ bool exp = true;
+ _PTR(GenericAttribute) anAttr;
+ if ( myObject && myObject->FindAttribute( anAttr, "AttributeExpandable" ) ) {
+ _PTR(AttributeExpandable) aAttrExp = anAttr;
+ exp = aAttrExp->IsExpandable();
+ }
+ return exp;
+}
+
+/*!
+ \brief Check if the object is visible.
+ \return \c true if this object is displayable or \c false otherwise
+*/
+bool SalomeApp_DataObject::isVisible() const
+{
+ bool isDraw = true;
+ _PTR(GenericAttribute) anAttr;
+ if ( myObject && myObject->FindAttribute(anAttr, "AttributeDrawable") )
+ {
+ _PTR(AttributeDrawable) aAttrDraw = anAttr;
+ isDraw = aAttrDraw->IsDrawable();
+ }
+ return isDraw && LightApp_DataObject::isVisible() && ( !name().isEmpty() || isReference() );
+}
+
/*!
\brief Check if the specified column supports custom sorting.
\param id column id
_PTR(AttributeIOR) iorAttr = attr;
if ( iorAttr )
{
- std::string str = iorAttr->Value();
- txt = QString( str.c_str() );
+ std::string str = iorAttr->Value();
+ txt = QString( str.c_str() );
}
}
}
{
_PTR(AttributeString) strAttr = attr;
std::string str = strAttr->Value();
- QString aStrings = QString( str.c_str() );
+ QString aStrings = fromUtf8( str );
//Special case to show NoteBook variables in the "Value" column of the OB
- if ( LightApp_RootObject* aRoot = dynamic_cast<LightApp_RootObject*>( root() ) )
+ bool ok = false;
+ QStringList aSectionList = aStrings.split( "|" );
+ if ( !aSectionList.isEmpty() )
{
- if ( SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( aRoot->study() ) )
+ QString aLastSection = aSectionList.last();
+ QStringList aStringList = aLastSection.split( ":" );
+ if ( !aStringList.isEmpty() )
{
- _PTR(Study) studyDS( aStudy->studyDS() );
-
- bool ok = false;
- QStringList aSectionList = aStrings.split( "|" );
- if ( !aSectionList.isEmpty() )
- {
- QString aLastSection = aSectionList.last();
- QStringList aStringList = aLastSection.split( ":" );
- if ( !aStringList.isEmpty() )
- {
- ok = true;
- for ( int i = 0, n = aStringList.size(); i < n; i++ )
- {
- QString aStr = aStringList[i];
- if ( studyDS->IsVariable( aStr.toStdString() ) )
- val.append( aStr + ", " );
- }
-
- if ( !val.isEmpty() )
- val.remove( val.length() - 2, 2 );
- }
- }
- if( !ok )
- val = aStrings;
+ ok = true;
+ for ( int i = 0, n = aStringList.size(); i < n; i++ )
+ {
+ QString aStr = aStringList[i];
+ if ( SalomeApp_Application::getStudy()->IsVariable( aStr.toStdString() ) )
+ val.append( aStr + ", " );
+ }
+
+ if ( !val.isEmpty() )
+ val.remove( val.length() - 2, 2 );
}
}
+ if( !ok )
+ val = aStrings;
}
else if ( obj->FindAttribute( attr, "AttributeInteger" ) )
{
{
_PTR(AttributeComment) comm = attr;
std::string str = comm->Value();
- val = QString( str.c_str() );
+ val = fromUtf8( str );
}
return val;
}
+void SalomeApp_DataObject::insertChildAtTag( SalomeApp_DataObject* obj, int tag )
+{
+ int pos = 0;
+ int npos = qMin( tag-1,childCount() );
+ for ( int i = npos; i > 0; i-- )
+ {
+ if ( (dynamic_cast<SalomeApp_DataObject*>( childObject( i-1 ) ) )->object()->Tag() < tag )
+ {
+ pos = i;
+ break;
+ }
+ }
+ insertChildAtPos( obj, pos );
+}
+
+void SalomeApp_DataObject::updateItem()
+{
+ if ( modified() ) return;
+ setModified( true );
+}
+
/*!
\class SalomeApp_ModuleObject
\brief This class is used for optimized access to the SALOMEDS-based
\param parent parent data object
*/
SalomeApp_ModuleObject::SalomeApp_ModuleObject( const _PTR(SObject)& sobj,
- SUIT_DataObject* parent )
+ SUIT_DataObject* parent )
: CAM_DataObject( parent ),
LightApp_DataObject( parent ),
SalomeApp_DataObject( sobj, parent ),
\param parent parent data object
*/
SalomeApp_ModuleObject::SalomeApp_ModuleObject( CAM_DataModel* dm,
- const _PTR(SObject)& sobj,
- SUIT_DataObject* parent )
+ const _PTR(SObject)& sobj,
+ SUIT_DataObject* parent )
: CAM_DataObject( parent ),
LightApp_DataObject( parent ),
SalomeApp_DataObject( sobj, parent ),
\brief Get data object icon for the specified column.
\param id column id
\return object icon for the specified column
+ \sa CAM_ModuleObject class
*/
QPixmap SalomeApp_ModuleObject::icon( const int id ) const
{
- return SalomeApp_DataObject::icon( id );
+ QPixmap p = SalomeApp_DataObject::icon( id );
+ // The module might not provide a separate small icon
+ // for Obj. Browser representation -> always try to scale it
+ // See CAM_ModuleObject::icon()
+ if ( !p.isNull() )
+ p = Qtx::scaleIcon( p, 16 );
+ return p;
}
/*!
: CAM_DataObject( 0 ),
LightApp_DataObject( 0 ),
SalomeApp_DataObject( 0 ),
- LightApp_RootObject( study )
+ LightApp_RootObject( study ),
+ _toSynchronize(true)
{
}
\param id save point ID
\param study study
*/
-SalomeApp_SavePointObject::SalomeApp_SavePointObject( SUIT_DataObject* parent,
- const int id,
- SalomeApp_Study* study )
-: LightApp_DataObject( parent ),
- CAM_DataObject( parent ),
- myId( id ),
- myStudy( study )
+SalomeApp_SavePointObject::SalomeApp_SavePointObject( SUIT_DataObject* parent,
+ const int id,
+ SalomeApp_Study* study )
+ : CAM_DataObject( parent ),
+ LightApp_DataObject( parent ),
+ myId( id ),
+ myStudy( study )
{
}