// function : GetDefaultName()
// purpose : Generates default names
//=======================================================================
-QString GEOMBase::GetDefaultName(const QString& theOperation)
+QString GEOMBase::GetDefaultName(const QString& theOperation, const bool extractPrefix)
{
QString aName = "";
// 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);
}
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);
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++);
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
// 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 );