X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FExchangePlugin%2FExchangePlugin_Import.cpp;h=6178b225988b2e0285ed52a153dbfce469a6b077;hb=a74fbd0025bc36fc76b5559d960857f419446ecb;hp=34128fa65df6f4abdb7636d3568727476e2ecba3;hpb=745c72679f6346375d5e886b25cc3865f3c4daae;p=modules%2Fshaper.git diff --git a/src/ExchangePlugin/ExchangePlugin_Import.cpp b/src/ExchangePlugin/ExchangePlugin_Import.cpp index 34128fa65..6178b2259 100644 --- a/src/ExchangePlugin/ExchangePlugin_Import.cpp +++ b/src/ExchangePlugin/ExchangePlugin_Import.cpp @@ -67,25 +67,22 @@ DocumentPtr findDocument(DocumentPtr thePartSetDoc, const std::wstring& thePartN } -ExchangePlugin_Import::ExchangePlugin_Import() -{ -} - -ExchangePlugin_Import::~ExchangePlugin_Import() -{ - // TODO Auto-generated destructor stub -} - /* * Request for initialization of data model of the feature: adding all attributes */ -void ExchangePlugin_Import::initAttributes() +void ExchangePlugin_ImportBase::initAttributes() { data()->addAttribute(FILE_PATH_ID(), ModelAPI_AttributeString::typeId()); - data()->addAttribute(STEP_FILE_PATH_ID(), ModelAPI_AttributeString::typeId()); - data()->addAttribute(IMPORT_TYPE_ID(), ModelAPI_AttributeString::typeId()); data()->addAttribute(TARGET_PART_ID(), ModelAPI_AttributeInteger::typeId()); data()->addAttribute(TARGET_PARTS_LIST_ID(), ModelAPI_AttributeStringArray::typeId()); +} + +void ExchangePlugin_Import::initAttributes() +{ + ExchangePlugin_ImportBase::initAttributes(); + + data()->addAttribute(STEP_FILE_PATH_ID(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(IMPORT_TYPE_ID(), ModelAPI_AttributeString::typeId()); data()->addAttribute(STEP_TARGET_PART_ID(), ModelAPI_AttributeInteger::typeId()); data()->addAttribute(STEP_TARGET_PARTS_LIST_ID(), ModelAPI_AttributeStringArray::typeId()); data()->addAttribute(STEP_MATERIALS_ID(), ModelAPI_AttributeBoolean::typeId()); @@ -96,12 +93,12 @@ void ExchangePlugin_Import::initAttributes() /* * Computes or recomputes the results */ + void ExchangePlugin_Import::execute() { AttributeStringPtr aFormatAttr = this->string(ExchangePlugin_Import::IMPORT_TYPE_ID()); std::string aFormat = aFormatAttr->value(); - AttributeStringPtr aFilePathAttr; std::string aFilePath; AttributeStringArrayPtr aPartsAttr; @@ -142,23 +139,46 @@ void ExchangePlugin_Import::execute() } AttributeStringPtr aImportTypeAttr = - aData->string(ExchangePlugin_ImportFeature::IMPORT_TYPE_ID()); + aData->string(ExchangePlugin_ImportFeature::IMPORT_TYPE_ID()); aData->boolean(ExchangePlugin_ImportFeature::STEP_MATERIALS_ID()) - ->setValue(boolean(ExchangePlugin_Import::STEP_MATERIALS_ID())->value()); + ->setValue(boolean(ExchangePlugin_Import::STEP_MATERIALS_ID())->value()); aData->boolean(ExchangePlugin_ImportFeature::STEP_COLORS_ID()) - ->setValue(boolean(ExchangePlugin_Import::STEP_COLORS_ID())->value()); + ->setValue(boolean(ExchangePlugin_Import::STEP_COLORS_ID())->value()); aData->boolean(ExchangePlugin_ImportFeature::STEP_SCALE_INTER_UNITS_ID()) - ->setValue(boolean(ExchangePlugin_Import::STEP_SCALE_INTER_UNITS_ID())->value()); + ->setValue(boolean(ExchangePlugin_Import::STEP_SCALE_INTER_UNITS_ID())->value()); aPathAttr->setValue(aFilePathAttr->value()); aImportTypeAttr->setValue(aFormat); - aImportFeature->execute(); } } +void ExchangePlugin_Import_Image::execute() +{ + AttributeStringPtr aFilePathAttr = string(ExchangePlugin_ImportBase::FILE_PATH_ID()); + std::string aFilePath = aFilePathAttr->value(); + if (aFilePath.empty()) { + setError("File path is empty."); + return; + } + // get the document where to import + AttributeStringArrayPtr aPartsAttr = stringArray(TARGET_PARTS_LIST_ID()); + AttributeIntegerPtr aTargetAttr = integer(TARGET_PART_ID()); + SessionPtr aSession = ModelAPI_Session::get(); + DocumentPtr aDoc = findDocument(aSession->moduleDocument(), + Locale::Convert::toWString(aPartsAttr->value(aTargetAttr->value()))); + + if (aDoc.get()) { + FeaturePtr aImportFeature = aDoc->addFeature(ExchangePlugin_Import_ImageFeature::ID()); + DataPtr aData = aImportFeature->data(); + AttributeStringPtr aPathAttr = + aData->string(ExchangePlugin_Import_ImageFeature::FILE_PATH_ID()); + aPathAttr->setValue(aFilePathAttr->value()); + aImportFeature->execute(); + } +} void ExchangePlugin_Import::attributeChanged(const std::string& theID) { AttributeStringPtr aFilePathAttr; @@ -184,41 +204,55 @@ void ExchangePlugin_Import::attributeChanged(const std::string& theID) } } -void ExchangePlugin_Import::updatePart(AttributeStringArrayPtr& thePartsAttr, - AttributeIntegerPtr& theTargetAttr) +void ExchangePlugin_Import_Image::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()); + updatePart(aPartsAttr, aTargetAttr); + } +} + +void ExchangePlugin_ImportBase::updatePart(AttributeStringArrayPtr& aPartsAttr, + AttributeIntegerPtr& aTargetAttr) { - // update the list of target parts - SessionPtr aSession = ModelAPI_Session::get(); - DocumentPtr aDoc = document(); - bool isPartSet = aDoc == aSession->moduleDocument(); - if (isPartSet) { - std::list anAcceptedValues; - anAcceptedValues.push_back(THE_NEW_PART_STR); - - // append names of all parts - std::list aSubFeatures = aDoc->allFeatures(); - for (std::list::iterator aFIt = aSubFeatures.begin(); - aFIt != aSubFeatures.end(); ++aFIt) { - if ((*aFIt)->getKind() == PartSetPlugin_Part::ID()) - anAcceptedValues.push_back((*aFIt)->name()); - } - if ((size_t)thePartsAttr->size() != anAcceptedValues.size()) - theTargetAttr->setValue(0); + // update the list of target parts + SessionPtr aSession = ModelAPI_Session::get(); + DocumentPtr aDoc = document(); + bool isPartSet = aDoc == aSession->moduleDocument(); + if (isPartSet) { + std::list anAcceptedValues; + anAcceptedValues.push_back(THE_NEW_PART_STR); - thePartsAttr->setSize((int)anAcceptedValues.size()); - std::list::iterator anIt = anAcceptedValues.begin(); - for (int anInd = 0; anIt != anAcceptedValues.end(); ++anIt, ++anInd) - thePartsAttr->setValue(anInd, Locale::Convert::toString(*anIt)); + // append names of all parts + std::list aSubFeatures = aDoc->allFeatures(); + for (std::list::iterator aFIt = aSubFeatures.begin(); + aFIt != aSubFeatures.end(); ++aFIt) { + if ((*aFIt)->getKind() == PartSetPlugin_Part::ID()) + anAcceptedValues.push_back((*aFIt)->name()); } - else { - // keep only the name of the current part - if (thePartsAttr->size() == 0) { - FeaturePtr aPartFeature = ModelAPI_Tools::findPartFeature(aSession->moduleDocument(), aDoc); - - thePartsAttr->setSize(1); - thePartsAttr->setValue(0, Locale::Convert::toString(aPartFeature->name())); - theTargetAttr->setValue(0); - } + + if ((size_t)aPartsAttr->size() != anAcceptedValues.size()) + aTargetAttr->setValue(0); + + aPartsAttr->setSize((int)anAcceptedValues.size()); + std::list::iterator anIt = anAcceptedValues.begin(); + for (int anInd = 0; anIt != anAcceptedValues.end(); ++anIt, ++anInd) + aPartsAttr->setValue(anInd, Locale::Convert::toString(*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, Locale::Convert::toString(aPartFeature->name())); + aTargetAttr->setValue(0); } + } }