X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModelHighAPI%2FModelHighAPI_FeatureStore.cpp;h=f0d4deb48d9b2f427daa53e5b842b01ac79a8bf5;hb=fec33ea37fbbd369bda3da328abf6171d08a6c42;hp=bf32bdbbd7b50d68d4341300beadd07261baff7b;hpb=47f93d1e56aff0b9c0515b0e767cbc46ef576ec4;p=modules%2Fshaper.git diff --git a/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp b/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp index bf32bdbbd..f0d4deb48 100644 --- a/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp +++ b/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp @@ -1,8 +1,22 @@ -// Copyright (C) 2016-20xx CEA/DEN, EDF R&D --> - -// File: ModelHighAPI_FeatureStore.cpp -// Created: 12 August 2016 -// Author: Mikhail PONIKAROV +// Copyright (C) 2014-2017 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 +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or +// email : webmaster.salome@opencascade.com +// #include @@ -21,7 +35,9 @@ #include #include #include +#include #include +#include #include #include @@ -39,47 +55,56 @@ #define PRECISION 6 #define TOLERANCE (1.e-7) -ModelHighAPI_FeatureStore::ModelHighAPI_FeatureStore(FeaturePtr theFeature) { - storeData(theFeature->data(), myAttrs); - // iterate results to store - std::list allResults; - ModelAPI_Tools::allResults(theFeature, allResults); - std::list::iterator aRes = allResults.begin(); - for(; aRes != allResults.end(); aRes++) { - std::map aResDump; - storeData((*aRes)->data(), aResDump); - myRes.push_back(aResDump); +ModelHighAPI_FeatureStore::ModelHighAPI_FeatureStore(ObjectPtr theObject) { + storeData(theObject->data(), myAttrs); + + FeaturePtr aFeature = std::dynamic_pointer_cast(theObject); + if (aFeature) { + // iterate results to store + std::list allResults; + ModelAPI_Tools::allResults(aFeature, allResults); + std::list::iterator aRes = allResults.begin(); + for(; aRes != allResults.end(); aRes++) { + std::map aResDump; + storeData((*aRes)->data(), aResDump); + myRes.push_back(aResDump); + } } } -std::string ModelHighAPI_FeatureStore::compare(FeaturePtr theFeature) { - std::string anError = compareData(theFeature->data(), myAttrs); +std::string ModelHighAPI_FeatureStore::compare(ObjectPtr theObject) { + std::string anError = compareData(theObject->data(), myAttrs); if (!anError.empty()) { - return "Features '" + theFeature->name() + "' differ:" + anError; - } - std::list allResults; - ModelAPI_Tools::allResults(theFeature, allResults); - std::list::iterator aRes = allResults.begin(); - std::list >::iterator aResIter = myRes.begin(); - for(; aRes != allResults.end() && aResIter != myRes.end(); aRes++, aResIter++) { - anError = compareData((*aRes)->data(), *aResIter); - if (!anError.empty()) - return "Results of feature '" + theFeature->name() + "' '" + (*aRes)->data()->name() + - "' differ:" + anError; + return "Features '" + theObject->data()->name() + "' differ:" + anError; } - if (aRes != allResults.end()) { - return "Current model has more results '" + (*aRes)->data()->name() + "'"; - } - if (aResIter != myRes.end()) { - return "Original model had more results '" + (*aResIter)["__name__"] + "'"; + + FeaturePtr aFeature = std::dynamic_pointer_cast(theObject); + if (aFeature) { + std::list allResults; + ModelAPI_Tools::allResults(aFeature, allResults); + std::list::iterator aRes = allResults.begin(); + std::list >::iterator aResIter = myRes.begin(); + for(; aRes != allResults.end() && aResIter != myRes.end(); aRes++, aResIter++) { + anError = compareData((*aRes)->data(), *aResIter); + if (!anError.empty()) + return "Results of feature '" + aFeature->name() + "' '" + (*aRes)->data()->name() + + "' differ:" + anError; + } + if (aRes != allResults.end()) { + return "Current model has more results '" + (*aRes)->data()->name() + "'"; + } + if (aResIter != myRes.end()) { + return "Original model had more results '" + (*aResIter)["__name__"] + "'"; + } } return ""; // ok } -void ModelHighAPI_FeatureStore::storeData(std::shared_ptr theData, +void ModelHighAPI_FeatureStore::storeData(std::shared_ptr theData, std::map& theAttrs) { - theAttrs["__name__"] = theData->name(); // store name to keep also this information and output if needed + // store name to keep also this information and output if needed + theAttrs["__name__"] = theData->name(); std::list > allAttrs = theData->attributes(""); std::list >::iterator anAttr = allAttrs.begin(); for(; anAttr != allAttrs.end(); anAttr++) { @@ -92,7 +117,7 @@ void ModelHighAPI_FeatureStore::storeData(std::shared_ptr theData } } -std::string ModelHighAPI_FeatureStore::compareData(std::shared_ptr theData, +std::string ModelHighAPI_FeatureStore::compareData(std::shared_ptr theData, std::map& theAttrs) { std::map aThis; @@ -103,7 +128,7 @@ std::string ModelHighAPI_FeatureStore::compareData(std::shared_ptrfirst + "'"; } if (theAttrs[aThisIter->first] != aThisIter->second) { - return "attribute '" + aThisIter->first + "' is different (original != current) '" + + return "attribute '" + aThisIter->first + "' is different (original != current) '" + theAttrs[aThisIter->first] + "' != '" + aThisIter->second + "'"; } } @@ -117,7 +142,8 @@ std::string ModelHighAPI_FeatureStore::compareData(std::shared_ptr 0) @@ -142,7 +168,7 @@ std::string ModelHighAPI_FeatureStore::dumpAttr(const AttributePtr& theAttr) { return aResult.str(); } else if (aType == ModelAPI_AttributeString::typeId()) { // special case for attribute "SolverError" - if (theAttr->id() == "SolverError" && + if (theAttr->id() == "SolverError" && std::dynamic_pointer_cast(theAttr->owner())->getKind() == "Sketch") return ""; } @@ -183,6 +209,10 @@ std::string ModelHighAPI_FeatureStore::dumpAttr(const AttributePtr& theAttr) { aResult<value(); } else if (aType == ModelAPI_AttributeString::typeId()) { AttributeStringPtr anAttr = std::dynamic_pointer_cast(theAttr); + // do not dump solver DOF for sketch as it may be changed unexpectedly + if(anAttr->id() == "SolverDOF") { + return ""; + } aResult<value(); } else if (aType == ModelAPI_AttributeReference::typeId()) { AttributeReferencePtr anAttr = @@ -193,11 +223,11 @@ std::string ModelHighAPI_FeatureStore::dumpAttr(const AttributePtr& theAttr) { aResult<<"__empty__"; } } else if (aType == ModelAPI_AttributeSelection::typeId()) { - AttributeSelectionPtr anAttr = + AttributeSelectionPtr anAttr = std::dynamic_pointer_cast(theAttr); aResult<namingName(); } else if (aType == ModelAPI_AttributeSelectionList::typeId()) { - AttributeSelectionListPtr anAttr = + AttributeSelectionListPtr anAttr = std::dynamic_pointer_cast(theAttr); for(int a = 0; a < anAttr->size(); a++) { if (a != 0) @@ -205,7 +235,7 @@ std::string ModelHighAPI_FeatureStore::dumpAttr(const AttributePtr& theAttr) { aResult<value(a)->namingName(); } } else if (aType == ModelAPI_AttributeRefAttr::typeId()) { - AttributeRefAttrPtr anAttr = + AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast(theAttr); ObjectPtr anObj = anAttr->isObject() ? anAttr->object() : anAttr->attr()->owner(); if (anObj.get()) { @@ -217,10 +247,10 @@ std::string ModelHighAPI_FeatureStore::dumpAttr(const AttributePtr& theAttr) { aResult<<"__empty__"; } } else if (aType == ModelAPI_AttributeRefList::typeId()) { - AttributeRefListPtr anAttr = + AttributeRefListPtr anAttr = std::dynamic_pointer_cast(theAttr); // for sketch sub-features the empty values may be skipped and order is not important - bool isSketchFeatures = anAttr->id() == "Features" && + bool isSketchFeatures = anAttr->id() == "Features" && std::dynamic_pointer_cast(anAttr->owner())->getKind() == "Sketch"; std::list aList = anAttr->list(); std::list aResList; // list of resulting strings @@ -237,7 +267,7 @@ std::string ModelHighAPI_FeatureStore::dumpAttr(const AttributePtr& theAttr) { aResult<<*aR<<" "; } } else if (aType == ModelAPI_AttributeRefAttrList::typeId()) { - AttributeRefAttrListPtr anAttr = + AttributeRefAttrListPtr anAttr = std::dynamic_pointer_cast(theAttr); std::list > aList = anAttr->list(); std::list >::iterator aL = aList.begin(); @@ -255,15 +285,44 @@ std::string ModelHighAPI_FeatureStore::dumpAttr(const AttributePtr& theAttr) { } } } else if (aType == ModelAPI_AttributeIntArray::typeId()) { - AttributeIntArrayPtr anAttr = + AttributeIntArrayPtr anAttr = std::dynamic_pointer_cast(theAttr); for(int a = 0; a < anAttr->size(); a++) aResult<value(a)<<" "; } else if (aType == ModelAPI_AttributeDoubleArray::typeId()) { - AttributeDoubleArrayPtr anAttr = + AttributeDoubleArrayPtr anAttr = std::dynamic_pointer_cast(theAttr); for(int a = 0; a < anAttr->size(); a++) aResult<value(a)<<" "; + } else if (aType == ModelAPI_AttributeStringArray::typeId()) { + AttributeStringArrayPtr anAttr = + std::dynamic_pointer_cast(theAttr); + for(int a = 0; a < anAttr->size(); a++) + aResult<<"'"<value(a)<<"'"<<" "; + } else if (aType == ModelAPI_AttributeTables::typeId()) { + AttributeTablesPtr anAttr = + std::dynamic_pointer_cast(theAttr); + aResult<tables()<<"x"<rows()<<"x"<columns()<<" "; + for(int aTab = 0; aTab < anAttr->tables(); aTab++) { + for(int aRow = 0; aRow < anAttr->rows(); aRow++) { + for( int aCol = 0; aCol < anAttr->columns(); aCol++) { + switch(anAttr->type()) { + case ModelAPI_AttributeTables::BOOLEAN: + aResult<value(aRow, aCol, aTab).myBool<<" "; + break; + case ModelAPI_AttributeTables::INTEGER: + aResult<value(aRow, aCol, aTab).myInt<<" "; + break; + case ModelAPI_AttributeTables::DOUBLE: + aResult<value(aRow, aCol, aTab).myDouble<<" "; + break; + case ModelAPI_AttributeTables::STRING: + aResult<<"'"<value(aRow, aCol, aTab).myStr.c_str()<<"' "; + break; + } + } + } + } } else if (aType == GeomDataAPI_Point::typeId()) { AttributePointPtr anAttr = std::dynamic_pointer_cast(theAttr); double aValues[3] = {anAttr->x(), anAttr->y(), anAttr->z()}; @@ -275,7 +334,7 @@ std::string ModelHighAPI_FeatureStore::dumpAttr(const AttributePtr& theAttr) { } else if (aType == GeomDataAPI_Point2D::typeId()) { // do not dump flyout point for constraints as it may be changed unexpectedly if (theAttr->id() == "ConstraintFlyoutValuePnt") - return ""; + return "__notinitialized__"; AttributePoint2DPtr anAttr = std::dynamic_pointer_cast(theAttr); double aValues[2] = {anAttr->x(), anAttr->y()}; dumpArray(aResult, aValues, 2); @@ -301,13 +360,14 @@ std::string ModelHighAPI_FeatureStore::dumpShape(std::shared_ptr& aResult<<": "< 1.e-7) { - aResult<<"Volume: "< 1.e-5) { + aResult<<"Volume: "<< + std::fixed< aCenter = GeomAlgoAPI_ShapeTools::centreOfMass(theShape); aResult<<"Center of mass: "; double aCenterVals[3] = {aCenter->x(), aCenter->y(), aCenter->z()}; - dumpArray(aResult, aCenterVals, 3); + dumpArray(aResult, aCenterVals, 3, 5); aResult<