-// 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<mailto:webmaster.salome@opencascade.com>
+//
#include <ModelHighAPI_FeatureStore.h>
#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_AttributeSelectionList.h>
#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeStringArray.h>
#include <ModelAPI_AttributeDoubleArray.h>
+#include <ModelAPI_AttributeTables.h>
#include <ModelAPI_Validator.h>
#include <GeomDataAPI_Dir.h>
#define PRECISION 6
#define TOLERANCE (1.e-7)
-ModelHighAPI_FeatureStore::ModelHighAPI_FeatureStore(FeaturePtr theFeature) {
- storeData(theFeature->data(), myAttrs);
- // iterate results to store
- std::list<ResultPtr> allResults;
- ModelAPI_Tools::allResults(theFeature, allResults);
- std::list<ResultPtr>::iterator aRes = allResults.begin();
- for(; aRes != allResults.end(); aRes++) {
- std::map<std::string, std::string> 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<ModelAPI_Feature>(theObject);
+ if (aFeature) {
+ // iterate results to store
+ std::list<ResultPtr> allResults;
+ ModelAPI_Tools::allResults(aFeature, allResults);
+ std::list<ResultPtr>::iterator aRes = allResults.begin();
+ for(; aRes != allResults.end(); aRes++) {
+ std::map<std::string, std::string> 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<ResultPtr> allResults;
- ModelAPI_Tools::allResults(theFeature, allResults);
- std::list<ResultPtr>::iterator aRes = allResults.begin();
- std::list<std::map<std::string, std::string> >::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;
- }
- if (aRes != allResults.end()) {
- return "Current model has more results '" + (*aRes)->data()->name() + "'";
+ return "Features '" + theObject->data()->name() + "' differ:" + anError;
}
- if (aResIter != myRes.end()) {
- return "Original model had more results '" + (*aResIter)["__name__"] + "'";
+
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
+ if (aFeature) {
+ std::list<ResultPtr> allResults;
+ ModelAPI_Tools::allResults(aFeature, allResults);
+ std::list<ResultPtr>::iterator aRes = allResults.begin();
+ std::list<std::map<std::string, std::string> >::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<ModelAPI_Data> theData,
+void ModelHighAPI_FeatureStore::storeData(std::shared_ptr<ModelAPI_Data> theData,
std::map<std::string, std::string>& 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<std::shared_ptr<ModelAPI_Attribute> > allAttrs = theData->attributes("");
std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = allAttrs.begin();
for(; anAttr != allAttrs.end(); anAttr++) {
}
}
-std::string ModelHighAPI_FeatureStore::compareData(std::shared_ptr<ModelAPI_Data> theData,
+std::string ModelHighAPI_FeatureStore::compareData(std::shared_ptr<ModelAPI_Data> theData,
std::map<std::string, std::string>& theAttrs)
{
std::map<std::string, std::string> aThis;
return "original model had no attribute '" + aThisIter->first + "'";
}
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 + "'";
}
}
return "";
}
-static void dumpArray(std::ostringstream& theOutput, const double theArray[], int theSize, int thePrecision = PRECISION)
+static void dumpArray(std::ostringstream& theOutput, const double theArray[],
+ int theSize, int thePrecision = PRECISION)
{
for (int i = 0; i < theSize; ++i) {
if (i > 0)
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<ModelAPI_Feature>(theAttr->owner())->getKind() == "Sketch")
return "";
}
aResult<<anAttr->value();
} else if (aType == ModelAPI_AttributeString::typeId()) {
AttributeStringPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeString>(theAttr);
+ // do not dump solver DOF for sketch as it may be changed unexpectedly
+ if(anAttr->id() == "SolverDOF") {
+ return "";
+ }
aResult<<anAttr->value();
} else if (aType == ModelAPI_AttributeReference::typeId()) {
AttributeReferencePtr anAttr =
aResult<<"__empty__";
}
} else if (aType == ModelAPI_AttributeSelection::typeId()) {
- AttributeSelectionPtr anAttr =
+ AttributeSelectionPtr anAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttr);
aResult<<anAttr->namingName();
} else if (aType == ModelAPI_AttributeSelectionList::typeId()) {
- AttributeSelectionListPtr anAttr =
+ AttributeSelectionListPtr anAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttr);
for(int a = 0; a < anAttr->size(); a++) {
if (a != 0)
aResult<<anAttr->value(a)->namingName();
}
} else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
- AttributeRefAttrPtr anAttr =
+ AttributeRefAttrPtr anAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttr);
ObjectPtr anObj = anAttr->isObject() ? anAttr->object() : anAttr->attr()->owner();
if (anObj.get()) {
aResult<<"__empty__";
}
} else if (aType == ModelAPI_AttributeRefList::typeId()) {
- AttributeRefListPtr anAttr =
+ AttributeRefListPtr anAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(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<ModelAPI_Feature>(anAttr->owner())->getKind() == "Sketch";
std::list<ObjectPtr> aList = anAttr->list();
std::list<std::string> aResList; // list of resulting strings
aResult<<*aR<<" ";
}
} else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
- AttributeRefAttrListPtr anAttr =
+ AttributeRefAttrListPtr anAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttr);
std::list<std::pair<ObjectPtr, AttributePtr> > aList = anAttr->list();
std::list<std::pair<ObjectPtr, AttributePtr> >::iterator aL = aList.begin();
}
}
} else if (aType == ModelAPI_AttributeIntArray::typeId()) {
- AttributeIntArrayPtr anAttr =
+ AttributeIntArrayPtr anAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeIntArray>(theAttr);
for(int a = 0; a < anAttr->size(); a++)
aResult<<anAttr->value(a)<<" ";
} else if (aType == ModelAPI_AttributeDoubleArray::typeId()) {
- AttributeDoubleArrayPtr anAttr =
+ AttributeDoubleArrayPtr anAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(theAttr);
for(int a = 0; a < anAttr->size(); a++)
aResult<<anAttr->value(a)<<" ";
+ } else if (aType == ModelAPI_AttributeStringArray::typeId()) {
+ AttributeStringArrayPtr anAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeStringArray>(theAttr);
+ for(int a = 0; a < anAttr->size(); a++)
+ aResult<<"'"<<anAttr->value(a)<<"'"<<" ";
+ } else if (aType == ModelAPI_AttributeTables::typeId()) {
+ AttributeTablesPtr anAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeTables>(theAttr);
+ aResult<<anAttr->tables()<<"x"<<anAttr->rows()<<"x"<<anAttr->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<<anAttr->value(aRow, aCol, aTab).myBool<<" ";
+ break;
+ case ModelAPI_AttributeTables::INTEGER:
+ aResult<<anAttr->value(aRow, aCol, aTab).myInt<<" ";
+ break;
+ case ModelAPI_AttributeTables::DOUBLE:
+ aResult<<anAttr->value(aRow, aCol, aTab).myDouble<<" ";
+ break;
+ case ModelAPI_AttributeTables::STRING:
+ aResult<<"'"<<anAttr->value(aRow, aCol, aTab).myStr.c_str()<<"' ";
+ break;
+ }
+ }
+ }
+ }
} else if (aType == GeomDataAPI_Point::typeId()) {
AttributePointPtr anAttr = std::dynamic_pointer_cast<GeomDataAPI_Point>(theAttr);
double aValues[3] = {anAttr->x(), anAttr->y(), anAttr->z()};
} 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<GeomDataAPI_Point2D>(theAttr);
double aValues[2] = {anAttr->x(), anAttr->y()};
dumpArray(aResult, aValues, 2);
aResult<<": "<<aCount<<std::endl;
}
// output the main characteristics
- aResult<<"Volume: "<<setprecision(2)<<GeomAlgoAPI_ShapeTools::volume(theShape)<<std::endl;
+ if (GeomAlgoAPI_ShapeTools::volume(theShape) > 1.e-5) {
+ aResult<<"Volume: "<<
+ std::fixed<<setprecision(3)<<GeomAlgoAPI_ShapeTools::volume(theShape)<<std::endl;
+ }
std::shared_ptr<GeomAPI_Pnt> 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<<std::endl;
return aResult.str();
}