-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// File: CollectionAPI_Field.cpp
-// Created: 16 Nov 2016
-// Author: Mikhail Ponikarov
+// 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
+// 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 "CollectionAPI_Field.h"
#include <ModelHighAPI_Integer.h>
#include <ModelHighAPI_Selection.h>
#include <ModelHighAPI_Tools.h>
-#include <ModelHighAPI_ComponentValue.h>
#include <ModelAPI_AttributeTables.h>
#include <ModelAPI_AttributeStringArray.h>
execute();
}
-//=================================================================================================
-void CollectionAPI_Field::setComponentsNum(const ModelHighAPI_Integer& theNum)
-{
- fillAttribute(theNum, mycomponentsNum);
- execute();
-}
-
//=================================================================================================
void CollectionAPI_Field::setComponentsNames(const std::list<std::string>& theNames)
{
//=================================================================================================
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) \
+{ \
+ 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()))<<", "
- <<mycomponentsNum->value()<<", ";
+ theDumper<<aBase<<" = model.addField("<<aDocName<<", "<<myvalues->tables()<<", \""
+ <<strByValueType(myvalues->type())<<"\", "<<mycomponentsNames->size()<<", ";
theDumper<<mycomponentsNames<<", ";
theDumper<<myselection<<")"<<std::endl;
// set values step by step
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;
}
}
+std::shared_ptr<ModelAPI_AttributeTables> CollectionAPI_Field::tableValues()
+{
+ return myvalues;
+}
+
//=================================================================================================
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)
std::shared_ptr<CollectionAPI_Field> aField(new CollectionAPI_Field(aFeature));
aField->setStepsNum(theStepsNum);
aField->setValuesType(theComponentType);
- aField->setComponentsNum(theComponentsNum);
aField->setComponentsNames(theComponentNames);
aField->setSelection(theSelectionList);
+ aField->tableValues()->setSize(
+ int(theSelectionList.size() + 1), theComponentsNum, theStepsNum.intValue());
return aField;
}