-// 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 <GeomDataAPI_Point2D.h>
#include <GeomDataAPI_Point2DArray.h>
//--------------------------------------------------------------------------------------
+#include <GeomAlgoAPI_Tools.h>
+//--------------------------------------------------------------------------------------
+#include <Locale_Convert.h>
+//--------------------------------------------------------------------------------------
#include <ModelAPI_AttributeBoolean.h>
#include <ModelAPI_AttributeDocRef.h>
#include <ModelAPI_AttributeDouble.h>
void fillAttribute(const std::list<std::shared_ptr<ModelAPI_Object> > & theValue,
const std::shared_ptr<ModelAPI_AttributeRefList> & theAttribute)
{
- theAttribute->clear();
- for (auto it = theValue.begin(); it != theValue.end(); ++it)
+ int aSize = theAttribute->size();
+ // keep objects at the beginning of the list if they the same
+ auto it = theValue.begin();
+ for (int anIndex = 0; it != theValue.end() && anIndex < aSize; ++it, ++anIndex)
+ if (theAttribute->object(anIndex) != *it) {
+ // remove the tail of the list
+ while (++anIndex <= aSize)
+ theAttribute->removeLast();
+ break;
+ }
+ // append the rest of elements
+ for (; it != theValue.end(); ++it)
theAttribute->append(*it);
}
theAttribute->setValue(theValue);
}
+//--------------------------------------------------------------------------------------
+void fillAttribute(const std::wstring & theValue,
+ const std::shared_ptr<ModelAPI_AttributeString> & theAttribute)
+{
+ theAttribute->setValue(theValue);
+}
+
//--------------------------------------------------------------------------------------
void fillAttribute(const char * theValue,
const std::shared_ptr<ModelAPI_AttributeString> & theAttribute)
{
GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::SHAPE;
- std::transform(theShapeTypeStr.begin(), theShapeTypeStr.end(),
- theShapeTypeStr.begin(), ::tolower);
+ std::transform(theShapeTypeStr.begin(), theShapeTypeStr.end(), theShapeTypeStr.begin(),
+ [](char c) { return static_cast<char>(::tolower(c)); });
if(theShapeTypeStr == "compound") {
aShapeType = GeomAPI_Shape::COMPOUND;
case ModelHighAPI_Selection::VT_ResultSubShapePair: {
ResultSubShapePair aPair = theSelection.resultSubShapePair();
GeomShapePtr aShape = aPair.second;
- if(!aShape.get()) {
+ if(!aShape.get() && aPair.first.get()) {
aShape = aPair.first->shape();
}
if(!aShape.get()) {
aShapeType = shapeTypeByStr(aType);
break;
}
+ default:
+ break; // do nothing [to avoid compilation warning]
}
return aShapeType;
ModelAPI_AttributeTables::ValueType valueTypeByStr(const std::string& theValueTypeStr)
{
std::string aType = theValueTypeStr;
- std::transform(aType.begin(), aType.end(), aType.begin(), ::tolower);
+ std::transform(aType.begin(), aType.end(), aType.begin(),
+ [](char c) { return static_cast<char>(::tolower(c)); });
if (aType == "boolean")
return ModelAPI_AttributeTables::BOOLEAN;
else if (aType == "integer")
if (theCompare) {
aDocFind = theStore.find(theDocName);
if (aDocFind == theStore.end()) {
- return "Document '" + ModelAPI_Tools::toString(theDocName) + "' not found";
+ return "Document '" + Locale::Convert::toString(theDocName) + "' not found";
}
}
// store the model features information: iterate all features
- int anObjectsCount = 0; // stores the number of compared features for this document to compare
+ size_t anObjectsCount = 0; // stores the number of compared features for this document to compare
std::set<std::wstring> aProcessed; // processed features names (that are in the current document)
// process all objects (features and folders)
std::map<std::wstring, ModelHighAPI_FeatureStore>::iterator
anObjFind = aDocFind->second.find(anObject->data()->name());
if (anObjFind == aDocFind->second.end()) {
- return "Document '" + ModelAPI_Tools::toString(theDocName)
- + "' feature '" + ModelAPI_Tools::toString(anObject->data()->name()) + "' not found";
+ return "Document '" + Locale::Convert::toString(theDocName)
+ + "' feature '" + Locale::Convert::toString(anObject->data()->name()) + "' not found";
}
std::string anError = anObjFind->second.compare(anObject);
if (!anError.empty()) {
- anError = "Document " + ModelAPI_Tools::toString(theDocName) + " " + anError;
+ anError = "Document " + Locale::Convert::toString(theDocName) + " " + anError;
return anError;
}
anObjectsCount++;
aLostName = aLostIter->first;
}
}
- return "For document '" + ModelAPI_Tools::toString(theDocName) +
+ return "For document '" + Locale::Convert::toString(theDocName) +
"' the number of features is decreased, there is no feature '" +
- ModelAPI_Tools::toString(aLostName) + "'";
+ Locale::Convert::toString(aLostName) + "'";
}
}
return ""; // ok
if (aDump.get()) {
aDump->string("file_path")->setValue(theFilename);
aDump->string("file_format")->setValue("py");
+ std::string aTrek = GeomAlgoAPI_Tools::File_Tools::path(theFilename);
+ aDump->string("dump_dir")->setValue(aTrek);
aDump->boolean("topological_naming")->setValue((theSelectionType & CHECK_NAMING) != 0);
aDump->boolean("geometric_selection")->setValue((theSelectionType & CHECK_GEOMETRICAL) != 0);
aDump->boolean("weak_naming")->setValue((theSelectionType & CHECK_WEAK) != 0);
// execute the dumped
PyGILState_STATE gstate = PyGILState_Ensure(); /* acquire python thread */
static char aReadMode[] = "r";
- FILE* PyFileObject = _Py_fopen(theFilename, aReadMode);
+ FILE* PyFileObject = fopen(theFilename, aReadMode);
PyRun_SimpleFileEx(PyFileObject, theFilename, 1);
PyGILState_Release(gstate); /* release python thread */
// compare with the stored data
std::string anError =
- storeFeatures(ModelAPI_Tools::toWString(theSession->moduleDocument()->kind()),
+ storeFeatures(Locale::Convert::toWString(theSession->moduleDocument()->kind()),
theSession->moduleDocument(), theStorage, true);
if (!anError.empty()) {
std::cout << anError << std::endl;
return true;
}
-bool checkPyDump(const std::string& theFilenameNaming,
- const std::string& theFilenameGeo,
- const std::string& theFilenameWeak,
- const checkDumpType theCheckType)
+bool checkPyDump(
+#ifdef _DEBUG
+ const std::string&, const std::string&, const std::string&,
+#else
+ const std::string& theFilenameNaming,
+ const std::string& theFilenameGeo,
+ const std::string& theFilenameWeak,
+#endif
+ const checkDumpType theCheckType)
{
static const std::string anErrorByNaming("checkPythonDump by naming");
static const std::string anErrorByGeometry("checkPythonDump by geometry");
// map from document name to feature name to feature data
std::map<std::wstring, std::map<std::wstring, ModelHighAPI_FeatureStore> > aStore;
std::string anError =
- storeFeatures(ModelAPI_Tools::toWString(aSession->moduleDocument()->kind()),
+ storeFeatures(Locale::Convert::toWString(aSession->moduleDocument()->kind()),
aSession->moduleDocument(), aStore, false);
if (!anError.empty()) {
Events_InfoMessage anErrorMsg(std::string("checkPythonDump"), anError);