X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_Tools.cpp;h=5cf560636b93be6c263d9eea048d6b664f0c32b6;hb=12621bb509825d0eb1fb0847a7f9c8011021ca5a;hp=ef83b089c674db4b39750e6776401ef73c8876a7;hpb=f09c9895be486d30c9aa48da040c3aeb3ccbaa74;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_Tools.cpp b/src/XGUI/XGUI_Tools.cpp index ef83b089c..5cf560636 100644 --- a/src/XGUI/XGUI_Tools.cpp +++ b/src/XGUI/XGUI_Tools.cpp @@ -1,77 +1,84 @@ - #include "XGUI_Tools.h" +#include +#include + #include +#include +#include -//****************************************************************** -QString library( const QString& str ) +namespace XGUI_Tools { - QString path = dir( str, false ); - QString name = file( str, false ); - QString ext = extension( str ); - -#ifndef WIN32 - if ( !name.startsWith( "lib" ) ) - name = QString( "lib" ) + name; -#endif - -#ifdef WIN32 - QString libExt( "dll" ); -#else - QString libExt( "so" ); -#endif - - if ( ext.toLower() != QString( "so" ) && ext.toLower() != QString( "dll" ) ) - { - if ( !name.isEmpty() && !ext.isEmpty() ) - name += QString( "." ); - name += ext; - } - - ext = libExt; - - QString fileName = addSlash( path ) + name + QString( "." ) + ext; - - return fileName; -} - //****************************************************************** -QString dir( const QString& path, bool isAbs ) +QString dir(const QString& path, bool isAbs) { - QDir aDir = QFileInfo( path ).dir(); + QDir aDir = QFileInfo(path).dir(); QString dirPath = isAbs ? aDir.absolutePath() : aDir.path(); - if ( dirPath == QString( "." ) ) + if (dirPath == QString(".")) dirPath = QString(); return dirPath; } - //****************************************************************** -QString file( const QString& path, bool withExt ) +QString file(const QString& path, bool withExt) { QString fPath = path; - while ( !fPath.isEmpty() && ( fPath[fPath.length() - 1] =='\\' || fPath[fPath.length() - 1] == '/' ) ) - fPath.remove( fPath.length() - 1, 1 ); + while(!fPath.isEmpty() && (fPath[fPath.length() - 1] == '\\' || fPath[fPath.length() - 1] == '/')) + fPath.remove(fPath.length() - 1, 1); - if ( withExt ) - return QFileInfo( fPath ).fileName(); + if (withExt) + return QFileInfo(fPath).fileName(); else - return QFileInfo( fPath ).completeBaseName(); + return QFileInfo(fPath).completeBaseName(); } //****************************************************************** -QString extension( const QString& path, bool full ) +QString extension(const QString& path, bool full) { - return full ? QFileInfo( path ).completeSuffix() : QFileInfo( path ).suffix(); + return full ? QFileInfo(path).completeSuffix() : QFileInfo(path).suffix(); } //****************************************************************** -QString addSlash( const QString& path ) +QString addSlash(const QString& path) { QString res = path; - if ( !res.isEmpty() && res.at( res.length() - 1 ) != QChar( '/' ) && - res.at( res.length() - 1 ) != QChar( '\\' ) ) - res += QDir::separator(); + if (!res.isEmpty() && res.at(res.length() - 1) != QChar('/') + && res.at(res.length() - 1) != QChar('\\')) + res += QDir::separator(); return res; } + +//****************************************************************** +QRect makeRect(const int x1, const int y1, const int x2, const int y2) +{ + return QRect(qMin(x1, x2), qMin(y1, y2), qAbs(x2 - x1), qAbs(y2 - y1)); +} + +//****************************************************************** +bool isModelObject(FeaturePtr theFeature) +{ + return theFeature && !theFeature->data(); +} + +//****************************************************************** +std::string featureInfo(FeaturePtr theFeature) +{ + std::ostringstream aStream; + if (theFeature) + aStream << theFeature.get() << " " << theFeature->getKind(); + return QString(aStream.str().c_str()).toStdString(); +} + +//****************************************************************** +FeaturePtr realFeature(const FeaturePtr theFeature) +{ + if (theFeature->data()) { + return theFeature; + } else { + ObjectPtr aObject = boost::dynamic_pointer_cast(theFeature); + return aObject->featureRef(); + } +} + +}