X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModelHighAPI%2FModelHighAPI_Tools.cpp;h=89f61b480228a57056086ce65d2cf058bf440204;hb=54c444b74ff9a608c7ddfdf9310dde0b0e7c90d6;hp=3f82be3116c48e983e4c9fd7f2672f6f979bd981;hpb=1dfcab3d738e427bea678317e167c587dfbff195;p=modules%2Fshaper.git diff --git a/src/ModelHighAPI/ModelHighAPI_Tools.cpp b/src/ModelHighAPI/ModelHighAPI_Tools.cpp index 3f82be311..89f61b480 100644 --- a/src/ModelHighAPI/ModelHighAPI_Tools.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Tools.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2020 CEA/DEN, EDF R&D +// Copyright (C) 2014-2021 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 @@ -29,6 +29,10 @@ #include #include //-------------------------------------------------------------------------------------- +#include +//-------------------------------------------------------------------------------------- +#include +//-------------------------------------------------------------------------------------- #include #include #include @@ -166,8 +170,18 @@ void fillAttribute(const std::shared_ptr & theValue, void fillAttribute(const std::list > & theValue, const std::shared_ptr & 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); } @@ -212,6 +226,13 @@ void fillAttribute(const std::string & theValue, theAttribute->setValue(theValue); } +//-------------------------------------------------------------------------------------- +void fillAttribute(const std::wstring & theValue, + const std::shared_ptr & theAttribute) +{ + theAttribute->setValue(theValue); +} + //-------------------------------------------------------------------------------------- void fillAttribute(const char * theValue, const std::shared_ptr & theAttribute) @@ -277,8 +298,8 @@ GeomAPI_Shape::ShapeType shapeTypeByStr(std::string theShapeTypeStr) { 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(::tolower(c)); }); if(theShapeTypeStr == "compound") { aShapeType = GeomAPI_Shape::COMPOUND; @@ -347,7 +368,7 @@ GeomAPI_Shape::ShapeType getShapeType(const ModelHighAPI_Selection& theSelection 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()) { @@ -386,7 +407,8 @@ GeomAPI_Shape::ShapeType getShapeType(const ModelHighAPI_Selection& theSelection 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(::tolower(c)); }); if (aType == "boolean") return ModelAPI_AttributeTables::BOOLEAN; else if (aType == "integer") @@ -409,20 +431,20 @@ std::string strByValueType(const ModelAPI_AttributeTables::ValueType theType) } /// stores the features information, recursively stores sub-documents features -std::string storeFeatures(const std::string& theDocName, DocumentPtr theDoc, - std::map >& theStore, +std::string storeFeatures(const std::wstring& theDocName, DocumentPtr theDoc, + std::map >& theStore, const bool theCompare) // if false => store { - std::map >::iterator aDocFind; + std::map >::iterator aDocFind; if (theCompare) { aDocFind = theStore.find(theDocName); if (aDocFind == theStore.end()) { - return "Document '" + theDocName + "' not found"; + return "Document '" + Locale::Convert::toString(theDocName) + "' not found"; } } // store the model features information: iterate all features size_t anObjectsCount = 0; // stores the number of compared features for this document to compare - std::set aProcessed; // processed features names (that are in the current document) + std::set aProcessed; // processed features names (that are in the current document) // process all objects (features and folders) std::list allObjects = theDoc->allObjects(); @@ -430,18 +452,23 @@ std::string storeFeatures(const std::string& theDocName, DocumentPtr theDoc, for(; allIter != allObjects.end(); allIter++) { ObjectPtr anObject = *allIter; FeaturePtr aFeature = std::dynamic_pointer_cast(anObject); - if (aFeature && aFeature->getKind() == "SketchConstraintCoincidenceInternal") - continue; // no need to dump and check internal constraints + //if (aFeature && aFeature->getKind() == "SketchConstraintCoincidenceInternal") + if (aFeature) { + std::string aStr = aFeature->getKind().substr(0, 16); + if (aStr == "SketchConstraint") + continue; // no need to dump and check constraints + } if (theCompare) { - std::map::iterator + std::map::iterator anObjFind = aDocFind->second.find(anObject->data()->name()); if (anObjFind == aDocFind->second.end()) { - return "Document '" + theDocName + "' feature '" + 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 " + theDocName + " " + anError; + anError = "Document " + Locale::Convert::toString(theDocName) + " " + anError; return anError; } anObjectsCount++; @@ -473,22 +500,23 @@ std::string storeFeatures(const std::string& theDocName, DocumentPtr theDoc, if (theCompare) { if (aDocFind->second.size() != anObjectsCount) { // search for disappeared feature - std::string aLostName; - std::map::iterator aLostIter; + std::wstring aLostName; + std::map::iterator aLostIter; for(aLostIter = aDocFind->second.begin(); aLostIter != aDocFind->second.end(); aLostIter++) { if (aProcessed.find(aLostIter->first) == aProcessed.end()) { aLostName = aLostIter->first; } } - return "For document '" + theDocName + - "' the number of features is decreased, there is no feature '" + aLostName + "'"; + return "For document '" + Locale::Convert::toString(theDocName) + + "' the number of features is decreased, there is no feature '" + + Locale::Convert::toString(aLostName) + "'"; } } return ""; // ok } //================================================================================================== -typedef std::map > Storage; +typedef std::map > Storage; static bool dumpToPython(SessionPtr theSession, const std::string& theFilename, @@ -503,6 +531,8 @@ static bool dumpToPython(SessionPtr theSession, 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); @@ -534,8 +564,9 @@ static bool checkDump(SessionPtr theSession, PyGILState_Release(gstate); /* release python thread */ // compare with the stored data - std::string anError = storeFeatures( - theSession->moduleDocument()->kind(), theSession->moduleDocument(), theStorage, true); + std::string anError = + storeFeatures(Locale::Convert::toWString(theSession->moduleDocument()->kind()), + theSession->moduleDocument(), theStorage, true); if (!anError.empty()) { std::cout << anError << std::endl; Events_InfoMessage anErrorMsg(theErrorMsgContext, anError); @@ -546,10 +577,15 @@ static bool checkDump(SessionPtr theSession, 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"); @@ -573,9 +609,10 @@ bool checkPyDump(const std::string& theFilenameNaming, return false; // map from document name to feature name to feature data - std::map > aStore; - std::string anError = storeFeatures( - aSession->moduleDocument()->kind(), aSession->moduleDocument(), aStore, false); + std::map > aStore; + std::string anError = + storeFeatures(Locale::Convert::toWString(aSession->moduleDocument()->kind()), + aSession->moduleDocument(), aStore, false); if (!anError.empty()) { Events_InfoMessage anErrorMsg(std::string("checkPythonDump"), anError); anErrorMsg.send();