-// Copyright (C) 2014-2021 CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023 CEA, EDF
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
#include <ModelAPI_Document.h>
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_Events.h>
-
-#include <ModuleBase_Tools.h>
+#include <ModelAPI_ResultPart.h>
#include <cmath>
#include <sstream>
aNbTransactions = aNbUndo;
++aTransactionID;
}
- static std::string anOperationPrefix(ModuleBase_Tools::translate("", "Operation").toStdString());
std::ostringstream aTransactionName;
- aTransactionName << anOperationPrefix << "_" << aTransactionID;
- ModelAPI_Session::get()->startOperation(aTransactionName.str());
+ aTransactionName << "Operation_" << aTransactionID;
+
+ // check the first transaction and part, automatically created on start of PartSet
+ std::shared_ptr<ModelAPI_Session> aSession = ModelAPI_Session::get();
+ if (aSession->undoList().empty() && aSession->redoList().empty() && // no undo/redo available
+ aSession->moduleDocument()->size(ModelAPI_ResultPart::group()) == 1 && // only one part
+ aSession->moduleDocument()->size(ModelAPI_Feature::group()) == 1) // only part feature
+ {
+ ResultPartPtr aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>
+ (aSession->moduleDocument()->object(ModelAPI_ResultPart::group(), 0));
+ if (aPartRes.get() && aPartRes->isActivated())
+ {
+ DocumentPtr aPartDoc = aPartRes->partDoc();
+ if (aPartDoc.get() && aPartDoc->size(ModelAPI_Feature::group()) == 0) // no features in part
+ {
+ // remove the automtically created part
+ aSession->startOperation("Delete automatic part");
+ FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(
+ aSession->moduleDocument()->object(ModelAPI_Feature::group(), 0));
+ aSession->setActiveDocument(aSession->moduleDocument());
+ aSession->moduleDocument()->removeFeature(aPartFeature);
+ aSession->finishOperation();
+ aSession->clearUndoRedo();
+ }
+ }
+ }
+
+ aSession->startOperation(aTransactionName.str());
}
void end()