#include <ModelAPI_AttributeSelectionList.h>
#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeStringArray.h>
+#include <ModelAPI_AttributeIntArray.h>
+#include <ModelAPI_AttributeTables.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_Object.h>
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_ResultGroup.h>
+#include <ModelAPI_ResultField.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
#include <XAO_Group.hxx>
+#include <XAO_Field.hxx>
#include <XAO_Xao.hxx>
#include <ExchangePlugin_Tools.h>
// conversion of dimension
std::string aSelectionType = aSelectionList->selectionType();
- std::string aDimensionString = ExchangePlugin_Tools::selectionType2xaoDimension(aSelectionType);
+ std::string aDimensionString =
+ ExchangePlugin_Tools::selectionType2xaoDimension(aSelectionType);
XAO::Dimension aGroupDimension = XAO::XaoUtils::stringToDimension(aDimensionString);
XAO::Group* aXaoGroup = aXao.addGroup(aGroupDimension,
}
}
+ // fields
+ int aFieldCount = document()->size(ModelAPI_ResultField::group());
+ for (int aFieldIndex = 0; aFieldIndex < aFieldCount; ++aFieldIndex) {
+ ResultFieldPtr aResultField =
+ std::dynamic_pointer_cast<ModelAPI_ResultField>(
+ document()->object(ModelAPI_ResultField::group(), aFieldIndex));
+
+ FeaturePtr aFieldFeature = document()->feature(aResultField);
+
+ AttributeSelectionListPtr aSelectionList =
+ aFieldFeature->selectionList("selected");
+
+ // conversion of dimension
+ std::string aSelectionType = aSelectionList->selectionType();
+ std::string aDimensionString =
+ ExchangePlugin_Tools::selectionType2xaoDimension(aSelectionType);
+ XAO::Dimension aFieldDimension = XAO::XaoUtils::stringToDimension(aDimensionString);
+ bool isWholePart = aSelectionType == "part";
+ // get tables and their type
+ std::shared_ptr<ModelAPI_AttributeTables> aTables = aFieldFeature->tables("values");
+ std::string aTypeString = ExchangePlugin_Tools::valuesType2xaoType(aTables->type());
+ XAO::Type aFieldType = XAO::XaoUtils::stringToFieldType(aTypeString);
+
+ XAO::Field* aXaoField = aXao.addField(aFieldType, aFieldDimension, aTables->columns(),
+ aResultField->data()->name());
+ // set components names
+ AttributeStringArrayPtr aComponents = aFieldFeature->stringArray("components_names");
+ for(int aComp = 0; aComp < aComponents->size(); aComp++) {
+ std::string aName = aComponents->value(aComp);
+ aXaoField->setComponentName(aComp, aName);
+ }
+
+ AttributeIntArrayPtr aStamps = aFieldFeature->intArray("stamps");
+ for (int aStepIndex = 0; aStepIndex < aTables->tables(); aStepIndex++) {
+ XAO::Step* aStep = aXaoField->addNewStep(aStepIndex);
+ aStep->setStep(aStepIndex);
+ int aStampIndex = aStamps->value(aStepIndex);
+ aStep->setStamp(aStampIndex);
+ int aNumElements = isWholePart ? aXaoField->countElements() : aTables->rows();
+ int aNumComps = aTables->columns();
+ // omit default values first row
+ for(int aRow = isWholePart ? 0 : 1; aRow < aNumElements; aRow++) {
+ for(int aCol = 0; aCol < aNumComps; aCol++) {
+ int anElementID = 0;
+ if (!isWholePart) {
+ // element index actually is the ID of the selection
+ AttributeSelectionPtr aSelection = aSelectionList->value(aRow - 1);
+
+ // complex conversion of reference id to element index
+ int aReferenceID = aSelection->Id();
+ std::string aReferenceString = XAO::XaoUtils::intToString(aReferenceID);
+ int anElementID =
+ aXao.getGeometry()->getElementIndexByReference(aFieldDimension, aReferenceString);
+ }
+
+ ModelAPI_AttributeTables::Value aVal = aTables->value(
+ isWholePart ? 0 : aRow, aCol, aStepIndex);
+ std::ostringstream aStr; // string value
+ switch(aTables->type()) {
+ case ModelAPI_AttributeTables::BOOLEAN:
+ aStr<<(aVal.myBool ? "True" : "False");
+ break;
+ case ModelAPI_AttributeTables::INTEGER:
+ aStr<<aVal.myInt;
+ break;
+ case ModelAPI_AttributeTables::DOUBLE:
+ aStr<<aVal.myDouble;
+ break;
+ case ModelAPI_AttributeTables::STRING:
+ aStr<<aVal.myStr;
+ break;
+ }
+ std::string aStrVal = aStr.str();
+ aStep->setStringValue(isWholePart ? aRow : anElementID, aCol, aStrVal);
+ }
+ }
+ }
+ }
+
+
// exporting
XAOExport(theFileName, &aXao, anError);
} catch (XAO::XAO_Exception& e) {
std::string anError = e.what();
- setError("An error occurred while importing " + theFileName + ": " + anError);
+ setError("An error occurred while exporting " + theFileName + ": " + anError);
return;
}
}
#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_AttributeSelectionList.h>
#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeStringArray.h>
+#include <ModelAPI_AttributeIntArray.h>
+#include <ModelAPI_AttributeTables.h>
#include <ModelAPI_BodyBuilder.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Document.h>
#include <XAO_Xao.hxx>
#include <XAO_Group.hxx>
+#include <XAO_Field.hxx>
+#include <XAO_Step.hxx>
#include <ExchangePlugin_Tools.h>
ResultBodyPtr aResultBody = createResultBody(aGeomShape);
setResult(aResultBody);
- // Process groups
+ // Process groups/fields
std::shared_ptr<ModelAPI_AttributeRefList> aRefListOfGroups =
std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(data()->attribute(FEATURES_ID()));
- // Remove previous groups stored in RefList
+ // Remove previous groups/fields stored in RefList
std::list<ObjectPtr> anGroupList = aRefListOfGroups->list();
std::list<ObjectPtr>::iterator anGroupIt = anGroupList.begin();
for (; anGroupIt != anGroupList.end(); ++anGroupIt) {
AttributeSelectionListPtr aSelectionList = aGroupFeature->selectionList("group_list");
// conversion of dimension
- XAO::Dimension aGroupDimension = aXaoGroup->getDimension();
std::string aDimensionString = XAO::XaoUtils::dimensionToString(aXaoGroup->getDimension());
- std::string aSelectionType = ExchangePlugin_Tools::xaoDimension2selectionType(aDimensionString);
+ std::string aSelectionType =
+ ExchangePlugin_Tools::xaoDimension2selectionType(aDimensionString);
aSelectionList->setSelectionType(aSelectionType);
for (int anElementIndex = 0; anElementIndex < aXaoGroup->count(); ++anElementIndex) {
aSelectionList->value(anElementIndex)->setId(aReferenceID);
}
}
+ // Create new fields
+ for (int aFieldIndex = 0; aFieldIndex < aXao.countFields(); ++aFieldIndex) {
+ XAO::Field* aXaoField = aXao.getField(aFieldIndex);
+
+ std::shared_ptr<ModelAPI_Feature> aFieldFeature = addFeature("Field");
+
+ // group name
+ if (!aXaoField->getName().empty())
+ aFieldFeature->data()->setName(aXaoField->getName());
+
+ // fill selection
+ AttributeSelectionListPtr aSelectionList = aFieldFeature->selectionList("selected");
+
+ // conversion of dimension
+ std::string aDimensionString = XAO::XaoUtils::dimensionToString(aXaoField->getDimension());
+ std::string aSelectionType =
+ ExchangePlugin_Tools::xaoDimension2selectionType(aDimensionString);
+ aSelectionList->setSelectionType(aSelectionType);
+ // conversion of type
+ XAO::Type aFieldType = aXaoField->getType();
+ std::string aTypeString = XAO::XaoUtils::fieldTypeToString(aFieldType);
+ ModelAPI_AttributeTables::ValueType aType =
+ ExchangePlugin_Tools::xaoType2valuesType(aTypeString);
+ // set components names
+ AttributeStringArrayPtr aComponents = aFieldFeature->stringArray("components_names");
+ aComponents->setSize(aXaoField->countComponents());
+ for(int aComp = 0; aComp < aXaoField->countComponents(); aComp++) {
+ aComponents->setValue(aComp, aXaoField->getComponentName(aComp));
+ }
+
+ AttributeIntArrayPtr aStamps = aFieldFeature->intArray("stamps");
+ aStamps->setSize(aXaoField->countSteps());
+ std::shared_ptr<ModelAPI_AttributeTables> aTables = aFieldFeature->tables("values");
+ aTables->setSize(
+ aXaoField->countElements() + 1, aXaoField->countComponents(), aXaoField->countSteps());
+ aTables->setType(aType);
+ // iterate steps
+ XAO::stepIterator aStepIter = aXaoField->begin();
+ for(int aStepIndex = 0; aStepIter != aXaoField->end(); aStepIter++, aStepIndex++) {
+ aStamps->setValue(aStepIndex, (*aStepIter)->getStamp());
+ for(int aRow = 1; aRow <= aXaoField->countElements(); aRow++) {
+ for(int aCol = 0; aCol < aXaoField->countComponents(); aCol++) {
+ ModelAPI_AttributeTables::Value aVal;
+ std::string aValStr = (*aStepIter)->getStringValue(aRow - 1, aCol);
+ switch(aType) {
+ case ModelAPI_AttributeTables::BOOLEAN:
+ aVal.myBool = aValStr == "True";
+ break;
+ case ModelAPI_AttributeTables::INTEGER:
+ aVal.myInt = atoi(aValStr.c_str());
+ break;
+ case ModelAPI_AttributeTables::DOUBLE:
+ aVal.myDouble = atof(aValStr.c_str());
+ break;
+ case ModelAPI_AttributeTables::STRING:
+ aVal.myStr = aValStr;
+ break;
+ }
+ aTables->setValue(aVal, aRow, aCol, aStepIndex);
+ }
+ }
+ }
+ }
// Top avoid problems in Object Browser update: issue #1647.
ModelAPI_EventCreator::get()->sendReordered(
std::dynamic_pointer_cast<ModelAPI_Feature>(aRefListOfGroups->owner()));
return "face";
else if (theType == "Solids" || theType == "solid")
return "solid";
+ else if (theType == "Part" || theType == "part")
+ return "part";
return std::string();
}
return std::string();
}
+
+std::string ExchangePlugin_Tools::valuesType2xaoType(
+ const ModelAPI_AttributeTables::ValueType& theType)
+{
+ switch(theType) {
+ case ModelAPI_AttributeTables::BOOLEAN:
+ return "boolean";
+ case ModelAPI_AttributeTables::INTEGER:
+ return "integer";
+ case ModelAPI_AttributeTables::DOUBLE:
+ return "double";
+ case ModelAPI_AttributeTables::STRING:
+ return "string";
+ }
+ return "";
+}
+
+ModelAPI_AttributeTables::ValueType ExchangePlugin_Tools::xaoType2valuesType(std::string theType)
+{
+ if (theType == "boolean")
+ return ModelAPI_AttributeTables::BOOLEAN;
+ if (theType == "integer")
+ return ModelAPI_AttributeTables::INTEGER;
+ if (theType == "double")
+ return ModelAPI_AttributeTables::DOUBLE;
+ if (theType == "string")
+ return ModelAPI_AttributeTables::STRING;
+ return ModelAPI_AttributeTables::DOUBLE;
+}
#define EXCHANGEPLUGIN_TOOLS_H_
#include <ExchangePlugin.h>
+#include <ModelAPI_AttributeTables.h>
#include <list>
#include <string>
/// Converts string representation of XAO dimension to selection type.
static std::string xaoDimension2selectionType(const std::string& theDimension);
+ /// Converts representation of values type to XAO type.
+ static std::string valuesType2xaoType(const ModelAPI_AttributeTables::ValueType& theType);
+ /// Converts representation of values type to XAO type.
+ static ModelAPI_AttributeTables::ValueType xaoType2valuesType(std::string theType);
};
#endif /* EXCHANGEPLUGIN_TOOLS_H_ */
return XAO::FACE;
if (dimension == "solid")
return XAO::SOLID;
- if (dimension == "whole")
+ if (dimension == "part")
return XAO::WHOLE;
throw XAO_Exception(MsgBuilder() << "Bad dimension: " << dimension);