From: vsr Date: Thu, 18 Feb 2010 11:02:56 +0000 (+0000) Subject: 0020632: EDF 1173 GEOM : Extrusion with multiple selection X-Git-Tag: V5_1_4a1~57 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e1706ff05c3b5a3d64c665bc2c0c2c6b5ecae150;p=modules%2Fgeom.git 0020632: EDF 1173 GEOM : Extrusion with multiple selection Additional changes (to set object name in the dialog boxes properly) --- diff --git a/src/GEOMBase/GEOMBase.cxx b/src/GEOMBase/GEOMBase.cxx index 455cb6875..d11495fe4 100644 --- a/src/GEOMBase/GEOMBase.cxx +++ b/src/GEOMBase/GEOMBase.cxx @@ -806,7 +806,7 @@ bool GEOMBase::DefineDlgPosition(QWidget* aDlg, int& x, int& y) // function : GetDefaultName() // purpose : Generates default names //======================================================================= -QString GEOMBase::GetDefaultName(const QString& theOperation) +QString GEOMBase::GetDefaultName(const QString& theOperation, const bool extractPrefix) { QString aName = ""; @@ -830,8 +830,23 @@ QString GEOMBase::GetDefaultName(const QString& theOperation) // build a unique name int aNumber = 0; bool isUnique = false; + QString prefix = theOperation; + + if ( extractPrefix ) { + QStringList parts = prefix.split( "_", QString::KeepEmptyParts ); + if ( parts.count() > 1 ) { + bool ok; + aNumber = parts.last().toLong(&ok); + if ( ok ) { + parts.removeLast(); + prefix = parts.join( "_" ); + aNumber--; + } + } + } + while (!isUnique) { - aName = theOperation + "_" + QString::number(++aNumber); + aName = prefix + "_" + QString::number(++aNumber); isUnique = (aSet.count(aName.toStdString()) == 0); } diff --git a/src/GEOMBase/GEOMBase.h b/src/GEOMBase/GEOMBase.h index 33c4b15a0..b27bc0136 100644 --- a/src/GEOMBase/GEOMBase.h +++ b/src/GEOMBase/GEOMBase.h @@ -108,7 +108,8 @@ public : static bool DefineDlgPosition(QWidget* aDlg, int& x, int& y); /* This method generates default names for results of geometrical operations */ - static QString GetDefaultName(const QString& theOperation); + static QString GetDefaultName(const QString& theOperation, const bool extractPrefix = false); + /* Shows message box with error code and comment */ static void ShowErrorMessage(const char* theErrorCode, const char* theComment = 0); diff --git a/src/GEOMBase/GEOMBase_Helper.cxx b/src/GEOMBase/GEOMBase_Helper.cxx index c17facd82..3db5e7844 100755 --- a/src/GEOMBase/GEOMBase_Helper.cxx +++ b/src/GEOMBase/GEOMBase_Helper.cxx @@ -824,7 +824,7 @@ bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction ) aName = getPrefix(obj); if (nbObjs <= 30) { // Try to find a unique name - aName = GEOMBase::GetDefaultName(aName); + aName = GEOMBase::GetDefaultName(aName, extractPrefix()); } else { // Don't check name uniqueness in case of numerous objects aName = aName + "_" + QString::number(aNumber++); @@ -959,6 +959,17 @@ QString GEOMBase_Helper::getNewObjectName() const return QString::null; } +//================================================================ +// Function : extractPrefix +// Purpose : Redefine this method to return \c true if necessary +// to extract prefix when generating new name for the +// object(s) being created +//================================================================ +bool GEOMBase_Helper::extractPrefix() const +{ + return false; +} + //================================================================ // Function : getPrefix // Purpose : Get prefix for name of created object diff --git a/src/GEOMBase/GEOMBase_Helper.h b/src/GEOMBase/GEOMBase_Helper.h index 42a7cc4cb..d88621ea6 100755 --- a/src/GEOMBase/GEOMBase_Helper.h +++ b/src/GEOMBase/GEOMBase_Helper.h @@ -161,6 +161,7 @@ protected: // as a top-level object. virtual QString getNewObjectName() const; + virtual bool extractPrefix() const; virtual void addSubshapesToStudy(); GEOM::GEOM_Object_ptr findObjectInFather( GEOM::GEOM_Object_ptr theFather, const QString& theName );