-// Copyright (C) 2014-2019 CEA/DEN, EDF R&D
+// Copyright (C) 2014-2022 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// Returns true if all features can be exported.
static bool verifyExport(const std::list<FeaturePtr>& theFeatures,
std::list<FeaturePtr>& theExternalReferences,
- std::list<FeaturePtr>& theExportedParts);
+ std::list<FeaturePtr>& theExportedParts,
+ std::list<FeaturePtr>& theReferredParts);
+// Collect names of features as a single string
+static std::wstring namesOfFeatures(const std::list<FeaturePtr>& theFeatures);
ExchangePlugin_ExportPart::ExchangePlugin_ExportPart()
if (aFeaturesToExport.back()->getKind() == ExchangePlugin_ExportPart::ID())
aFeaturesToExport.pop_back();
- std::list<FeaturePtr> anExternalLinks, aReferredParts;
- if (!verifyExport(aFeaturesToExport, anExternalLinks, aReferredParts)) {
+ std::list<FeaturePtr> anExternalLinks, anExportedParts, aReferredParts;
+ if (!verifyExport(aFeaturesToExport, anExternalLinks, anExportedParts, aReferredParts)) {
if (!anExternalLinks.empty()) {
- // collect names of features as a string
- std::ostringstream aListOfFeatures;
- for (std::list<FeaturePtr>::iterator anIt = anExternalLinks.begin();
- anIt != anExternalLinks.end(); ++anIt) {
- if (anIt != anExternalLinks.begin())
- aListOfFeatures << ", ";
- aListOfFeatures << "'" << (*anIt)->name() << "'";
- }
+ std::wstring aListOfFeatures = namesOfFeatures(anExternalLinks);
std::string aMessage = "The selected results were created using external references "
"outside of this Part from features %1. "
"Please, remove these references or select another "
"sub-set of results to be able to export.";
- Events_InfoMessage(getKind(), aMessage).arg(aListOfFeatures.str()).send();
+ Events_InfoMessage(getKind(), aMessage).arg(aListOfFeatures).send();
}
if (!aReferredParts.empty()) {
- // collect names of parts as a string
- std::ostringstream aListOfParts;
- for (std::list<FeaturePtr>::iterator anIt = aReferredParts.begin();
- anIt != aReferredParts.end(); ++anIt) {
- if (anIt != aReferredParts.begin())
- aListOfParts << ", ";
- aListOfParts << "'" << (*anIt)->name() << "'";
- }
+ std::wstring aListOfParts = namesOfFeatures(aReferredParts);
std::string aMessage = "The selected results were created using references "
- "to results of Parts %1. Please, remove these references "
+ "to the results of Parts: %1. Please, remove these references "
"or select another sub-set of results to be able to export.";
- Events_InfoMessage(getKind(), aMessage).arg(aListOfParts.str()).send();
+ Events_InfoMessage(getKind(), aMessage).arg(aListOfParts).send();
+ }
+ if (!anExportedParts.empty()) {
+ std::wstring aListOfParts = namesOfFeatures(anExportedParts);
+
+ std::string aMessage = "The export of Part's result is forbidden (%1).";
+ Events_InfoMessage(getKind(), aMessage).arg(aListOfParts).send();
}
// should not export anything
aFeaturesToExport.clear();
std::set<FeaturePtr> aFeaturesToExport;
for (int anIndex = 0, aSize = theSelected->size(); anIndex < aSize; ++anIndex) {
AttributeSelectionPtr aCurrent = theSelected->value(anIndex);
- FeaturePtr aCurrentFeature = ModelAPI_Feature::feature(aCurrent->context());
- if (aCurrentFeature)
- aFeaturesToExport.insert(aCurrentFeature);
+ FeaturePtr aCurFeature = ModelAPI_Feature::feature(aCurrent->context());
+ if (aCurFeature)
+ aFeaturesToExport.insert(aCurFeature);
}
// recursively collect all features used for the selected results
allReferencedFeatures(aFeaturesToExport, aFeaturesToExport);
bool verifyExport(const std::list<FeaturePtr>& theFeatures,
std::list<FeaturePtr>& theExternalReferences,
- std::list<FeaturePtr>& theExportedParts)
+ std::list<FeaturePtr>& theExportedParts,
+ std::list<FeaturePtr>& theReferredParts)
{
for (std::list<FeaturePtr>::const_iterator anIt = theFeatures.begin();
anIt != theFeatures.end(); ++anIt) {
theExternalReferences.push_back(*anIt);
// feature refers to result of a part
if (aFeature->getKind() == PartSetPlugin_Part::ID())
- theExportedParts.push_back(*anIt);
+ theReferredParts.push_back(*anIt);
}
}
}
}
- return theExternalReferences.empty() && theExportedParts.empty();
+ return theExternalReferences.empty() && theExportedParts.empty() && theReferredParts.empty();
+}
+
+std::wstring namesOfFeatures(const std::list<FeaturePtr>& theFeatures)
+{
+ std::wostringstream aListOfFeatures;
+ for (std::list<FeaturePtr>::const_iterator anIt = theFeatures.begin();
+ anIt != theFeatures.end(); ++anIt) {
+ if (anIt != theFeatures.begin())
+ aListOfFeatures << ", ";
+ aListOfFeatures << "'" << (*anIt)->name() << "'";
+ }
+ return aListOfFeatures.str();
}