-// Copyright (C) 2014-2019 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 <PartSetPlugin_Part.h>
-#include <OSD_OpenFile.hxx>
-
#include <fstream>
+#include <iomanip>
+#include <cctype>
+#include <cmath>
// =========== Implementation of storage of dumped data ===========
static const int THE_DUMP_PRECISION = 16;
/// Dump std::endl
friend
DumpStorageBuffer& operator<<(DumpStorageBuffer& theBuffer,
- std::basic_ostream<char>& (*theEndl)(std::basic_ostream<char>&))
+ std::basic_ostream<char>& (*)(std::basic_ostream<char>&))
{
theBuffer.write("\n");
return theBuffer;
bool ModelHighAPI_Dumper::DumpStorage::exportTo(const std::string& theFilename,
const ModulesSet& theUsedModules)
{
- std::ofstream aFile;
- OSD_OpenStream(aFile, theFilename.c_str(), std::ofstream::out);
+ std::ofstream aFile(theFilename.c_str(), std::ofstream::out);
if (!aFile.is_open())
return false;
int aFullIndex = 0;
NbFeaturesMap::const_iterator aFIt = myFeatureCount.begin();
for (; aFIt != myFeatureCount.end(); ++aFIt) {
- std::map<std::string, std::pair<int, int> >::const_iterator aFound =
+ std::map<std::string, std::pair<int, int> >::const_iterator aFoundKind =
aFIt->second.find(aKind);
- if (aFound != aFIt->second.end())
- aFullIndex += aFound->second.first;
+ if (aFoundKind != aFIt->second.end())
+ aFullIndex += aFoundKind->second.first;
}
aDefaultName << aKind << "_" << aFullIndex;
}
bool isFeatureDefaultName = myNames[theFeature].myIsDefault;
// Save only names of results which is not correspond to default feature name
- const std::list<ResultPtr>& aResults = theFeature->results();
std::list<ResultPtr> allRes;
ModelAPI_Tools::allResults(theFeature, allRes);
for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
- std::pair<std::wstring, bool> aName = ModelAPI_Tools::getDefaultName(*aRes);
+ std::pair<std::wstring, bool> aName = ModelAPI_Tools::getDefaultName(*aRes, true, true);
std::string aDefaultName = Locale::Convert::toString(aName.first);
std::string aResName = Locale::Convert::toString((*aRes)->data()->name());
bool isUserDefined = !(isFeatureDefaultName && aDefaultName == aResName);
return true;
}
+size_t ModelHighAPI_Dumper::indexOfFirstNotDumped(
+ const std::shared_ptr<ModelAPI_AttributeRefList>& theRefList) const
+{
+ size_t anIndex = 0;
+ std::list<ObjectPtr> anObjects = theRefList->list();
+ for (std::list<ObjectPtr>::const_iterator anIt = anObjects.begin();
+ anIt != anObjects.end(); ++anIt, ++anIndex)
+ if (!isDumped(ModelAPI_Feature::feature(*anIt)))
+ break;
+ return anIndex;
+}
+
static bool isSketchSub(const FeaturePtr& theFeature)
{
static const std::string SKETCH("Sketch");
if (aFilters)
return false;
// all other features should be commented before the dump
- return true;
+ return !isDumped(theFeature);
}
ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const char theChar)
{
static const int aSize = 3;
double aValues[aSize] = {thePoint->x(), thePoint->y(), thePoint->z()};
- std::string aTexts[aSize] = {thePoint->textX(), thePoint->textY(), thePoint->textZ()};
+ std::string aTexts[aSize] = {
+ Locale::Convert::toString(thePoint->textX()),
+ Locale::Convert::toString(thePoint->textY()),
+ Locale::Convert::toString(thePoint->textZ())
+ };
myDumpStorage->dumpArray(aSize, aValues, aTexts);
return *this;
}
{
static const int aSize = 2;
double aValues[aSize] = {thePoint->x(), thePoint->y()};
- std::string aTexts[aSize] = {thePoint->textX(), thePoint->textY()};
+ std::string aTexts[aSize] = {
+ Locale::Convert::toString(thePoint->textX()),
+ Locale::Convert::toString(thePoint->textY())
+ };
myDumpStorage->dumpArray(aSize, aValues, aTexts);
return *this;
}
ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
const std::shared_ptr<ModelAPI_AttributeInteger>& theAttrInt)
{
- std::string aText = theAttrInt->text();
+ std::string aText = Locale::Convert::toString(theAttrInt->text());
if (aText.empty())
*myDumpStorage << theAttrInt->value();
else
ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
const std::shared_ptr<ModelAPI_AttributeDouble>& theAttrReal)
{
- std::string aText = theAttrReal->text();
+ std::string aText = Locale::Convert::toString(theAttrReal->text());
if (aText.empty())
*myDumpStorage << theAttrReal->value();
else
ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
const std::shared_ptr<ModelAPI_AttributeString>& theAttrStr)
{
- *myDumpStorage << "\"" << theAttrStr->value() << "\"";
+ // escaping the quote signs in the string under dumping
+ std::string aStr = theAttrStr->value();
+ /*
+ size_t aPos = aStr.find("\"");
+ while (aPos != std::string::npos) {
+ aStr.insert(aPos, "\\");
+ aPos = aStr.find("\"", aPos + 2);
+ }
+ aPos = aStr.find("\'");
+ while (aPos != std::string::npos) {
+ aStr.insert(aPos, "\\");
+ aPos = aStr.find("\'", aPos + 2);
+ }
+ */
+ size_t aPos = aStr.find_first_of("\"\'");
+ while (aPos != std::string::npos) {
+ aStr.insert(aPos, "\\");
+ aPos = aStr.find_first_of("\"\'", aPos + 2);
+ }
+ *myDumpStorage << "'" << aStr << "'";
return *this;
}
bool isAdded = false;
std::list<ObjectPtr>::const_iterator anIt = aList.begin();
for (; anIt != aList.end(); ++anIt) {
+ if (!(*anIt))
+ continue;
+ if (!isDumped(ModelAPI_Feature::feature(*anIt)))
+ break; // stop if the object is not dumped yet (parent feature should be postponed)
+
if (isAdded)
*myDumpStorage << ", ";
else
}
if(isAdded) {
- *myDumpStorage << ", ";
// print each attribute on separate line with the appropriate shift
if (aNbSpaces > 0) {
std::string aSpaces(aNbSpaces + 1, ' ');
- *myDumpStorage << "\n" << aSpaces;
- }
+ *myDumpStorage << ",\n" << aSpaces;
+ } else
+ *myDumpStorage << ", ";
} else {
isAdded = true;
}
exportVariable(anEntry, aNameIter->second.myCurrentName);
size_t aSize = aFeature->results().size();
if (aSize > 1) { // additional entries for features with more than one result
- for(int a = 1; a < aSize; a++) {
+ for(size_t a = 1; a < aSize; a++) {
std::ostringstream aResEntryStr;
aResEntryStr<<anEntry<<":"<<a;
std::string aResEntry = aResEntryStr.str();