#include <ModelHighAPI_Integer.h>
#include <ModelHighAPI_Selection.h>
#include <ModelHighAPI_Tools.h>
-#include <ModelHighAPI_ComponentValue.h>
#include <ModelAPI_AttributeTables.h>
#include <ModelAPI_AttributeStringArray.h>
void CollectionAPI_Field::setValuesType(const std::string& theType)
{
fillAttribute(int(valueTypeByStr(theType)), myvaluesType);
+ myvalues->setType(valueTypeByStr(theType));
execute();
}
void CollectionAPI_Field::setStepsNum(const ModelHighAPI_Integer& theSteps)
{
fillAttribute(theSteps, mystepsNum);
+ mystamps->setSize(theSteps.intValue());
execute();
}
}
//=================================================================================================
-void CollectionAPI_Field::addStep(const ModelHighAPI_Integer& theStepNum,
- const ModelHighAPI_Integer& theStamp,
- const std::list<std::list<ModelHighAPI_ComponentValue> >& theComponents)
-{
- // set the table size to be sure the values are up to date
- myvalues->setSize(myselection->size() + 1 /* with defaults */,
- mycomponentsNum->value(), mystepsNum->value());
-
- // set values one by one
- int aRowIndex = 0;
- std::list<std::list<ModelHighAPI_ComponentValue> >::const_iterator
- aRowsIter = theComponents.begin();
- for(; aRowsIter != theComponents.end(); aRowsIter++, aRowIndex++) {
- int aColIndex = 0;
- std::list<ModelHighAPI_ComponentValue>::const_iterator aColIter = aRowsIter->begin();
- for(; aColIter != aRowsIter->end(); aColIter++, aColIndex++) {
- aColIter->fill(myvalues, theStepNum.intValue(), aColIndex, aRowIndex);
- }
- }
- execute();
+#define addStepImplementation(type, fieldType, type2, fieldType2, type3, fieldType3) \
+void CollectionAPI_Field::addStep(const ModelHighAPI_Integer& theStepNum, \
+ const ModelHighAPI_Integer& theStamp, \
+ const std::list<std::list<type> >& theComponents) \
+{ \
+ myvalues->setSize(myselection->size() + 1, \
+ mycomponentsNum->value(), mystepsNum->value()); \
+ mystamps->setValue(theStepNum.intValue(), theStamp.intValue()); \
+ int aRowIndex = 0; \
+ std::list<std::list<type> >::const_iterator \
+ aRowsIter = theComponents.begin(); \
+ for(; aRowsIter != theComponents.end(); aRowsIter++, aRowIndex++) { \
+ int aColIndex = 0; \
+ std::list<type>::const_iterator aColIter = aRowsIter->begin(); \
+ for(; aColIter != aRowsIter->end(); aColIter++, aColIndex++) { \
+ ModelAPI_AttributeTables::Value aVal; \
+ aVal.fieldType = *aColIter; \
+ aVal.fieldType2 = type2(*aColIter); \
+ aVal.fieldType3 = type3(*aColIter); \
+ myvalues->setValue(aVal, aRowIndex, aColIndex, theStepNum.intValue()); \
+ } \
+ } \
+ execute(); \
}
+addStepImplementation(double, myDouble, int, myInt, bool, myBool);
+addStepImplementation(int, myInt, double, myDouble, bool, myBool);
+addStepImplementation(bool, myBool, int, myInt, double, myDouble);
+addStepImplementation(std::string, myStr, std::string, myStr, std::string, myStr);
+
//=================================================================================================
void CollectionAPI_Field::dump(ModelHighAPI_Dumper& theDumper) const
{
FeaturePtr aBase = feature();
const std::string& aDocName = theDumper.name(aBase->document());
- theDumper<<aBase<<" = model.addField("<<aDocName<<", "<<mystepsNum<<", "
- <<strByValueType(ModelAPI_AttributeTables::ValueType(myvaluesType->value()))<<", "
+ theDumper<<aBase<<" = model.addField("<<aDocName<<", "<<mystepsNum->value()<<", \""
+ <<strByValueType(ModelAPI_AttributeTables::ValueType(myvaluesType->value()))<<"\", "
<<mycomponentsNum->value()<<", ";
theDumper<<mycomponentsNames<<", ";
theDumper<<myselection<<")"<<std::endl;
for(int aCol = 0; aCol < myvalues->columns(); aCol++) {
if (aCol != 0)
theDumper<<", ";
- switch(myvalues->type()) {
+ switch(myvaluesType->value()) {
case ModelAPI_AttributeTables::BOOLEAN:
theDumper<<myvalues->value(aRow, aCol, aStep).myBool;
break;
theDumper<<myvalues->value(aRow, aCol, aStep).myDouble;
break;
case ModelAPI_AttributeTables::STRING:
- theDumper<<myvalues->value(aRow, aCol, aStep).myStr;
+ theDumper<<'"'<<myvalues->value(aRow, aCol, aStep).myStr<<'"';
break;
}
}
theDumper<<"]";
}
- theDumper<<")"<<std::endl;
+ theDumper<<"])"<<std::endl;
}
}
//=================================================================================================
FieldPtr addField(const std::shared_ptr<ModelAPI_Document>& thePart,
const ModelHighAPI_Integer& theStepsNum,
- std::string& theComponentType,
+ const std::string& theComponentType,
const int theComponentsNum,
const std::list<std::string>& theComponentNames,
const std::list<ModelHighAPI_Selection>& theSelectionList)