+void ExchangePlugin_ImportPart::attributeChanged(const std::string& theID)
+{
+ if (theID == FILE_PATH_ID()) {
+ AttributeStringPtr aFilePathAttr = string(FILE_PATH_ID());
+ if (aFilePathAttr->value().empty())
+ return;
+
+ AttributeStringArrayPtr aPartsAttr = stringArray(TARGET_PARTS_LIST_ID());
+ AttributeIntegerPtr aTargetAttr = integer(TARGET_PART_ID());
+
+ // update the list of target parts
+ SessionPtr aSession = ModelAPI_Session::get();
+ DocumentPtr aDoc = document();
+ bool isPartSet = aDoc == aSession->moduleDocument();
+ if (isPartSet) {
+ std::list<std::string> anAcceptedValues;
+ anAcceptedValues.push_back(THE_NEW_PART_STR);
+
+ std::list<FeaturePtr> anImportedFeatures;
+ if (aDoc->importPart(aFilePathAttr->value().c_str(), anImportedFeatures, isPartSet))
+ anAcceptedValues.push_back(THE_PART_SET_STR);
+
+ // append names of all parts
+ std::list<FeaturePtr> aSubFeatures = aDoc->allFeatures();
+ for (std::list<FeaturePtr>::iterator aFIt = aSubFeatures.begin();
+ aFIt != aSubFeatures.end(); ++aFIt) {
+ if ((*aFIt)->getKind() == PartSetPlugin_Part::ID())
+ anAcceptedValues.push_back((*aFIt)->name());
+ }
+
+ if (aPartsAttr->size() != anAcceptedValues.size())
+ aTargetAttr->setValue(0);
+
+ aPartsAttr->setSize((int)anAcceptedValues.size());
+ std::list<std::string>::iterator anIt = anAcceptedValues.begin();
+ for (int anInd = 0; anIt != anAcceptedValues.end(); ++anIt, ++anInd)
+ aPartsAttr->setValue(anInd, *anIt);
+ }
+ else {
+ // keep only the name of the current part
+ if (aPartsAttr->size() == 0) {
+ FeaturePtr aPartFeature = ModelAPI_Tools::findPartFeature(aSession->moduleDocument(), aDoc);
+
+ aPartsAttr->setSize(1);
+ aPartsAttr->setValue(0, aPartFeature->name());
+ aTargetAttr->setValue(0);
+ }
+ }
+ }
+}
+