1 // Copyright (C) 2014-2020 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <ExchangePlugin_ImportFeature.h>
25 #include <Config_Common.h>
26 #include <Config_PropManager.h>
28 #include <GeomAlgoAPI_BREPImport.h>
29 #include <GeomAlgoAPI_IGESImport.h>
30 #include <GeomAlgoAPI_STEPImport.h>
31 #include <GeomAlgoAPI_Tools.h>
32 #include <GeomAlgoAPI_XAOImport.h>
33 #include <GeomAlgoAPI_STLImport.h>
34 #include <GeomAlgoAPI_ImageImport.h>
36 #include <GeomAPI_Shape.h>
37 #include <GeomAPI_Face.h>
38 #include <GeomAPI_ShapeExplorer.h>
40 #include <Locale_Convert.h>
42 #include <ModelAPI_AttributeRefList.h>
43 #include <ModelAPI_AttributeSelectionList.h>
44 #include <ModelAPI_AttributeString.h>
45 #include <ModelAPI_AttributeStringArray.h>
46 #include <ModelAPI_AttributeIntArray.h>
47 #include <ModelAPI_AttributeTables.h>
48 #include <ModelAPI_AttributeBoolean.h>
49 #include <ModelAPI_AttributeInteger.h>
50 #include <ModelAPI_BodyBuilder.h>
51 #include <ModelAPI_Data.h>
52 #include <ModelAPI_Document.h>
53 #include <ModelAPI_Events.h>
54 #include <ModelAPI_Object.h>
55 #include <ModelAPI_ResultBody.h>
56 #include <ModelAPI_ResultGroup.h>
57 #include <ModelAPI_Session.h>
58 #include <ModelAPI_Validator.h>
59 #include <ModelAPI_Tools.h>
61 #include <XAO_Xao.hxx>
62 #include <XAO_Group.hxx>
63 #include <XAO_Field.hxx>
64 #include <XAO_Step.hxx>
66 #include <ExchangePlugin_Tools.h>
70 * Request for initialization of data model of the feature: adding all attributes
72 void ExchangePlugin_ImportFeatureBase::initAttributes()
74 data()->addAttribute(ExchangePlugin_ImportFeatureBase::FILE_PATH_ID(),
75 ModelAPI_AttributeString::typeId());
76 AttributePtr aFeaturesAttribute =
77 data()->addAttribute(ExchangePlugin_ImportFeatureBase::FEATURES_ID(),
78 ModelAPI_AttributeRefList::typeId());
79 aFeaturesAttribute->setIsArgument(false);
81 ModelAPI_Session::get()->validators()->registerNotObligatory(
82 getKind(), ExchangePlugin_ImportFeatureBase::FEATURES_ID());
85 void ExchangePlugin_ImportFeature::initAttributes()
87 ExchangePlugin_ImportFeatureBase::initAttributes();
89 data()->addAttribute(STEP_FILE_PATH_ID(), ModelAPI_AttributeString::typeId());
90 data()->addAttribute(IMPORT_TYPE_ID(), ModelAPI_AttributeString::typeId());
91 data()->addAttribute(STEP_MATERIALS_ID(), ModelAPI_AttributeBoolean::typeId());
92 data()->addAttribute(STEP_COLORS_ID(), ModelAPI_AttributeBoolean::typeId());
93 data()->addAttribute(STEP_SCALE_INTER_UNITS_ID(), ModelAPI_AttributeBoolean::typeId());
95 ModelAPI_Session::get()->validators()->registerNotObligatory(
96 getKind(), ExchangePlugin_ImportFeature::STEP_COLORS_ID());
97 ModelAPI_Session::get()->validators()->registerNotObligatory(
98 getKind(), ExchangePlugin_ImportFeature::STEP_MATERIALS_ID());
99 ModelAPI_Session::get()->validators()->registerNotObligatory(
100 getKind(), ExchangePlugin_ImportFeature::STEP_SCALE_INTER_UNITS_ID());
101 ModelAPI_Session::get()->validators()->registerNotObligatory(
102 getKind(), ExchangePlugin_ImportFeature::STEP_FILE_PATH_ID());
103 ModelAPI_Session::get()->validators()->registerNotObligatory(
104 getKind(), ExchangePlugin_ImportFeature::FILE_PATH_ID());
107 * Computes or recomputes the results
109 void ExchangePlugin_ImportFeature::execute()
111 AttributeStringPtr aImportTypeAttr = string(ExchangePlugin_ImportFeature::IMPORT_TYPE_ID());
112 std::string aFormat = aImportTypeAttr->value();
113 AttributeStringPtr aFilePathAttr;
114 if (aFormat == "STEP" || aFormat == "STP")
116 aFilePathAttr = string(ExchangePlugin_ImportFeature::STEP_FILE_PATH_ID());
118 aFilePathAttr = string(ExchangePlugin_ImportFeature::FILE_PATH_ID());
120 std::string aFilePath = aFilePathAttr->value();
121 if (aFilePath.empty()) {
122 setError("File path is empty.");
126 importFile(aFilePath);
129 void ExchangePlugin_Import_ImageFeature::execute()
131 AttributeStringPtr aFilePathAttr = string(ExchangePlugin_Import_ImageFeature::FILE_PATH_ID());
132 std::string aFilePath = aFilePathAttr->value();
133 if (aFilePath.empty()) {
134 setError("File path is empty.");
137 importFile(aFilePath);
140 std::shared_ptr<ModelAPI_ResultBody> ExchangePlugin_ImportFeatureBase::createResultBody(
141 std::shared_ptr<GeomAPI_Shape> aGeomShape)
143 std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
144 //LoadNamingDS of the imported shape
145 loadNamingDS(aGeomShape, aResultBody);
149 void ExchangePlugin_ImportFeature::importFile(const std::string& theFileName)
151 // "*.brep" -> "BREP"
152 std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(theFileName);
154 if (anExtension == "XAO") {
155 importXAO(theFileName);
159 // Perform the import
161 std::shared_ptr<GeomAPI_Shape> aGeomShape;
162 std::map<std::wstring, std::list<std::wstring>> theMaterialShape;
164 std::string anObjectName = GeomAlgoAPI_Tools::File_Tools::name(theFileName);
165 data()->setName(Locale::Convert::toWString(anObjectName));
167 ResultBodyPtr aResult = document()->createBody(data());
169 bool anColorGroupSelected = boolean(ExchangePlugin_ImportFeature::STEP_COLORS_ID())->value();
170 bool anMaterialsGroupSelected =
171 boolean(ExchangePlugin_ImportFeature::STEP_MATERIALS_ID())->value();
172 if (anExtension == "BREP" || anExtension == "BRP") {
173 aGeomShape = BREPImport(theFileName, anExtension, anError);
174 } else if (anExtension == "STEP" || anExtension == "STP") {
175 bool anScalInterUnits =
176 boolean(ExchangePlugin_ImportFeature::STEP_SCALE_INTER_UNITS_ID())->value();
178 // Process groups/fields
179 std::shared_ptr<ModelAPI_AttributeRefList> aRefListOfGroups =
180 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(data()->attribute(FEATURES_ID()));
182 // Remove previous groups/fields stored in RefList
183 std::list<ObjectPtr> anGroupList = aRefListOfGroups->list();
184 std::list<ObjectPtr>::iterator anGroupIt = anGroupList.begin();
185 for (; anGroupIt != anGroupList.end(); ++anGroupIt) {
186 std::shared_ptr<ModelAPI_Feature> aFeature = ModelAPI_Feature::feature(*anGroupIt);
188 document()->removeFeature(aFeature);
191 aGeomShape = STEPImportAttributs(theFileName, aResult, anScalInterUnits,
192 anMaterialsGroupSelected, anColorGroupSelected,
193 theMaterialShape, anError);
194 } else if (anExtension == "IGES" || anExtension == "IGS") {
195 aGeomShape = IGESImport(theFileName, anExtension, anError);
196 } else if (anExtension == "STL") {
197 aGeomShape = STLImport(theFileName, anError);
199 anError = "Unsupported format: " + anExtension;
202 // Check if shape is valid
203 if (!anError.empty()) {
204 setError("An error occurred while importing " + theFileName + ": " + anError);
208 // Pass the results into the model
209 loadNamingDS(aGeomShape, aResult);
211 // create color group
212 if (anColorGroupSelected)
214 setColorGroups(aResult);
217 // create Materiel group
218 if (anMaterialsGroupSelected){
219 setMaterielGroup(aResult,theMaterialShape);
223 aResult->clearShapeNameAndColor();
227 void ExchangePlugin_ImportFeature::setColorGroups(
228 std::shared_ptr<ModelAPI_ResultBody> theResultBody)
230 std::vector<int> aColor;
232 std::list<std::vector<int>> aColorsRead;
234 ModelAPI_Tools::getColor(theResultBody, aColor);
235 if (!aColor.empty() ){
236 std::wstringstream aColorName;
237 aColorName <<L"Color_"<< anIndice;
238 setColorGroup(theResultBody, aColor, aColorName.str());
240 aColorsRead.push_back(aColor);
243 std::list<ResultPtr> allRes;
244 ModelAPI_Tools::allSubs(theResultBody, allRes);
245 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); ++aRes) {
246 ModelAPI_Tools::getColor(*aRes, aColor);
247 if (!aColor.empty() ){
248 auto it = std::find(aColorsRead.begin(), aColorsRead.end(), aColor);
249 if ( it == aColorsRead.end() ){
250 std::wstringstream aColorName;
251 aColorName<<L"Color_"<< anIndice;
252 setColorGroup(theResultBody, aColor, aColorName.str());
254 aColorsRead.push_back(aColor);
260 void ExchangePlugin_ImportFeature::setColorGroup(
261 std::shared_ptr<ModelAPI_ResultBody> theResultBody,
262 std::vector<int> &theColor,
263 const std::wstring& theName )
265 std::vector<int> aColor;
266 std::shared_ptr<ModelAPI_Feature> aGroupFeature = addFeature("Group");
269 aGroupFeature->data()->setName(theName);
272 AttributeSelectionListPtr aSelectionList = aGroupFeature->selectionList("group_list");
274 ModelAPI_Tools::getColor(theResultBody, aColor);
275 if (!aColor.empty()){
276 if (aColor == theColor) {
277 GeomShapePtr aShape = theResultBody->shape();
278 aSelectionList->setSelectionType(aShape->shapeTypeStr());
279 aSelectionList->append(theResultBody,aShape);
282 // add element with the same color
283 std::list<ResultPtr> allRes;
284 ModelAPI_Tools::allSubs(theResultBody, allRes);
285 for(std::list<ResultPtr>::iterator aRes = allRes.begin();
286 aRes != allRes.end(); ++aRes) {
287 ModelAPI_Tools::getColor(*aRes, aColor);
288 GeomShapePtr aShape = (*aRes)->shape();
290 if (!aColor.empty()){
291 if (aRes->get() && aColor == theColor) {
292 aSelectionList->setSelectionType(aShape->shapeTypeStr());
293 aSelectionList->append(theResultBody,aShape);
298 // Create the group in the document to be able to set its color
299 ResultPtr aGroup = document()->createGroup(aGroupFeature->data());
300 aGroupFeature->setResult(aGroup);
302 ModelAPI_Tools::setColor(aGroupFeature->lastResult(),theColor);
304 if (aSelectionList->size() == 0) {
305 document()->removeFeature(aGroupFeature);
309 void ExchangePlugin_ImportFeature::setMaterielGroup(
310 std::shared_ptr<ModelAPI_ResultBody> theResultBody,
311 std::map< std::wstring,std::list<std::wstring>>& theMaterialShape)
313 std::map< std::wstring, std::list<std::wstring>>::iterator anIt;
314 for (anIt = theMaterialShape.begin(); anIt != theMaterialShape.end(); ++anIt) {
316 std::shared_ptr<ModelAPI_Feature> aGroupFeature = addFeature("Group");
318 aGroupFeature->data()->setName((*anIt).first);
321 AttributeSelectionListPtr aSelectionList = aGroupFeature->selectionList("group_list");
323 std::list<ResultPtr> allRes;
324 ModelAPI_Tools::allSubs(theResultBody, allRes);
325 for (std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); ++aRes) {
327 GeomShapePtr aShape = (*aRes)->shape();
328 for (std::list<std::wstring>::iterator aResMat = anIt->second.begin();
329 aResMat != anIt->second.end(); ++aResMat) {
330 if (aRes->get() && ((*aRes)->data()->name() == (*aResMat)))
332 aSelectionList->append(theResultBody,aShape);
333 aSelectionList->setSelectionType(aShape->shapeTypeStr());
338 if (aSelectionList->size() == 0){
339 document()->removeFeature(aGroupFeature);
344 void ExchangePlugin_ImportFeature::importXAO(const std::string& theFileName)
350 std::shared_ptr<GeomAPI_Shape> aGeomShape = XAOImport(theFileName, anError, &aXao);
352 if (!anError.empty()) {
353 setError("An error occurred while importing " + theFileName + ": " + anError);
357 XAO::Geometry* aXaoGeometry = aXao.getGeometry();
359 // use the geometry name or the file name for the feature
360 std::string aBodyName = aXaoGeometry->getName();
361 if (aBodyName.empty())
362 aBodyName = GeomAlgoAPI_Tools::File_Tools::name(theFileName);
363 data()->setName(Locale::Convert::toWString(aBodyName));
365 ResultBodyPtr aResultBody = createResultBody(aGeomShape);
366 setResult(aResultBody);
368 // Process groups/fields
369 std::shared_ptr<ModelAPI_AttributeRefList> aRefListOfGroups =
370 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(data()->attribute(FEATURES_ID()));
372 // Remove previous groups/fields stored in RefList
373 std::list<ObjectPtr> anGroupList = aRefListOfGroups->list();
374 std::list<ObjectPtr>::iterator anGroupIt = anGroupList.begin();
375 for (; anGroupIt != anGroupList.end(); ++anGroupIt) {
376 std::shared_ptr<ModelAPI_Feature> aFeature = ModelAPI_Feature::feature(*anGroupIt);
378 document()->removeFeature(aFeature);
382 for (int aGroupIndex = 0; aGroupIndex < aXao.countGroups(); ++aGroupIndex) {
383 XAO::Group* aXaoGroup = aXao.getGroup(aGroupIndex);
385 std::shared_ptr<ModelAPI_Feature> aGroupFeature = addFeature("Group");
388 if (!aXaoGroup->getName().empty())
389 aGroupFeature->data()->setName(Locale::Convert::toWString(aXaoGroup->getName()));
392 AttributeSelectionListPtr aSelectionList = aGroupFeature->selectionList("group_list");
394 // conversion of dimension
395 std::string aDimensionString = XAO::XaoUtils::dimensionToString(aXaoGroup->getDimension());
396 std::string aSelectionType =
397 ExchangePlugin_Tools::xaoDimension2selectionType(aDimensionString);
399 aSelectionList->setSelectionType(aSelectionType);
400 for (int anElementIndex = 0; anElementIndex < aXaoGroup->count(); ++anElementIndex) {
401 aSelectionList->append(aResultBody, GeomShapePtr());
402 // complex conversion of element index to reference id
403 int anElementID = aXaoGroup->get(anElementIndex);
404 std::string aReferenceString =
405 aXaoGeometry->getElementReference(aXaoGroup->getDimension(), anElementID);
406 int aReferenceID = XAO::XaoUtils::stringToInt(aReferenceString);
408 aSelectionList->value(anElementIndex)->setId(aReferenceID);
412 for (int aFieldIndex = 0; aFieldIndex < aXao.countFields(); ++aFieldIndex) {
413 XAO::Field* aXaoField = aXao.getField(aFieldIndex);
415 std::shared_ptr<ModelAPI_Feature> aFieldFeature = addFeature("Field");
418 if (!aXaoField->getName().empty())
419 aFieldFeature->data()->setName(Locale::Convert::toWString(aXaoField->getName()));
422 AttributeSelectionListPtr aSelectionList = aFieldFeature->selectionList("selected");
424 // conversion of dimension
425 std::string aDimensionString = XAO::XaoUtils::dimensionToString(aXaoField->getDimension());
426 std::string aSelectionType =
427 ExchangePlugin_Tools::xaoDimension2selectionType(aDimensionString);
428 aSelectionList->setSelectionType(aSelectionType);
429 // limitation: now in XAO fields are related to everything, so, iterate all sub-shapes to fill
430 int aCountSelected = aXaoField->countElements();
431 std::list<ResultPtr>::const_iterator aResIter = results().begin();
432 for(; aResIter != results().end() && aCountSelected; aResIter++) {
433 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aResIter);
436 // check that only results that were created before this field are used
437 FeaturePtr aResultFeature = document()->feature(aBody);
438 if (!aResultFeature.get())
440 GeomShapePtr aShape = aBody->shape();
441 if (!aShape.get() || aShape->isNull())
443 GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::shapeTypeByStr(aSelectionType));
444 for(; anExp.more(); anExp.next()) {
445 aSelectionList->append(aBody, anExp.current());
447 if (aCountSelected == 0)
452 // conversion of type
453 XAO::Type aFieldType = aXaoField->getType();
454 std::string aTypeString = XAO::XaoUtils::fieldTypeToString(aFieldType);
455 ModelAPI_AttributeTables::ValueType aType =
456 ExchangePlugin_Tools::xaoType2valuesType(aTypeString);
457 // set components names
458 AttributeStringArrayPtr aComponents = aFieldFeature->stringArray("components_names");
459 aComponents->setSize(aXaoField->countComponents());
460 for(int aComp = 0; aComp < aXaoField->countComponents(); aComp++) {
461 aComponents->setValue(aComp, aXaoField->getComponentName(aComp));
464 AttributeIntArrayPtr aStamps = aFieldFeature->intArray("stamps");
465 aStamps->setSize(aXaoField->countSteps());
466 std::shared_ptr<ModelAPI_AttributeTables> aTables = aFieldFeature->tables("values");
468 aXaoField->countElements() + 1, aXaoField->countComponents(), aXaoField->countSteps());
469 aTables->setType(aType);
471 XAO::stepIterator aStepIter = aXaoField->begin();
472 for(int aStepIndex = 0; aStepIter != aXaoField->end(); aStepIter++, aStepIndex++) {
473 aStamps->setValue(aStepIndex, (*aStepIter)->getStamp());
474 for(int aRow = 1; aRow <= aXaoField->countElements(); aRow++) {
475 for(int aCol = 0; aCol < aXaoField->countComponents(); aCol++) {
476 ModelAPI_AttributeTables::Value aVal;
477 std::string aValStr = (*aStepIter)->getStringValue(aRow - 1, aCol);
479 case ModelAPI_AttributeTables::BOOLEAN:
480 aVal.myBool = aValStr == "true";
482 case ModelAPI_AttributeTables::INTEGER:
483 aVal.myInt = atoi(aValStr.c_str());
485 case ModelAPI_AttributeTables::DOUBLE:
486 aVal.myDouble = atof(aValStr.c_str());
488 case ModelAPI_AttributeTables::STRING:
489 aVal.myStr = aValStr;
492 aTables->setValue(aVal, aRow, aCol, aStepIndex);
496 // remove everything with zero-values: zeroes are treated as defaults
497 std::set<int> aRowsToRemove;
498 for(int aRow = 1; aRow < aTables->rows(); aRow++) {
500 for(int aCol = 0; aCol < aTables->columns() && isZero; aCol++) {
501 for(int aStepIndex = 0; aStepIndex != aTables->tables() && isZero; aStepIndex++) {
502 if (aTables->valueStr(aRow, aCol, aStepIndex) != aTables->valueStr(0, aCol, aStepIndex))
507 aRowsToRemove.insert(aRow - 1); // -1 to make prepared for remove from SelectionList
509 if (!aRowsToRemove.empty()) { // move usefull rows on bottom to the up of the tables
510 // number of rows passed during going through: the current rows will
511 // be moved up for this value
512 int aRemovedPassed = 0;
513 for(int aRow = 1; aRow < aTables->rows(); aRow++) {
514 if (aRowsToRemove.find(aRow - 1) != aRowsToRemove.end()) {
516 } else if (aRemovedPassed != 0) { // copy the line up
517 for(int aCol = 0; aCol < aTables->columns(); aCol++) {
518 for(int aTable = 0; aTable != aTables->tables(); aTable++) {
520 aTables->value(aRow, aCol, aTable), aRow - aRemovedPassed, aCol, aTable);
525 aTables->setSize(aTables->rows() - aRemovedPassed, aTables->columns(), aTables->tables());
526 aSelectionList->remove(aRowsToRemove); // remove also selected elements
529 // Top avoid problems in Object Browser update: issue #1647.
530 ModelAPI_EventCreator::get()->sendReordered(
531 std::dynamic_pointer_cast<ModelAPI_Feature>(aRefListOfGroups->owner()));
534 } catch (XAO::XAO_Exception& e) {
535 std::string anError = e.what();
536 setError("An error occurred while importing " + theFileName + ": " + anError);
542 //============================================================================
543 std::shared_ptr<ModelAPI_Feature> ExchangePlugin_ImportFeatureBase::addFeature(
546 std::shared_ptr<ModelAPI_Feature> aNew = document()->addFeature(theID, false);
548 data()->reflist(FEATURES_ID())->append(aNew);
549 // set as current also after it becomes sub to set correctly enabled for other subs
550 //document()->setCurrentFeature(aNew, false);
555 void ExchangePlugin_ImportFeatureBase::removeFeature(
556 std::shared_ptr<ModelAPI_Feature> theFeature)
558 if (!data()->isValid())
560 AttributeRefListPtr aList = reflist(FEATURES_ID());
561 aList->remove(theFeature);
565 int ExchangePlugin_ImportFeatureBase::numberOfSubs(bool /*forTree*/) const
567 return data()->reflist(FEATURES_ID())->size(true);
570 std::shared_ptr<ModelAPI_Feature> ExchangePlugin_ImportFeatureBase::subFeature(
571 const int theIndex, bool /*forTree*/)
573 ObjectPtr anObj = data()->reflist(FEATURES_ID())->object(theIndex, false);
574 FeaturePtr aRes = std::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
579 int ExchangePlugin_ImportFeatureBase::subFeatureId(const int theIndex) const
581 std::shared_ptr<ModelAPI_AttributeRefList> aRefList = std::dynamic_pointer_cast<
582 ModelAPI_AttributeRefList>(data()->attribute(FEATURES_ID()));
583 std::list<ObjectPtr> aFeatures = aRefList->list();
584 std::list<ObjectPtr>::const_iterator anIt = aFeatures.begin();
585 int aResultIndex = 1; // number of the counted (created) features, started from 1
586 int aFeatureIndex = -1; // number of the not-empty features in the list
587 for (; anIt != aFeatures.end(); anIt++) {
590 if (aFeatureIndex == theIndex)
598 bool ExchangePlugin_ImportFeatureBase::isSub(ObjectPtr theObject) const
600 // check is this feature of result
601 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
603 return data()->reflist(FEATURES_ID())->isInList(aFeature);
607 //============================================================================
608 void ExchangePlugin_ImportFeatureBase::loadNamingDS(
609 std::shared_ptr<GeomAPI_Shape> theGeomShape,
610 std::shared_ptr<ModelAPI_ResultBody> theResultBody)
613 theResultBody->store(theGeomShape);
615 std::string aNameMS = "Shape";
616 theResultBody->loadFirstLevel(theGeomShape, aNameMS);
619 void ExchangePlugin_Import_ImageFeature::importFile(const std::string& theFileName)
622 std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(theFileName);
623 std::string theTextureFileName = "";
624 // Perform the import
626 std::shared_ptr<GeomAPI_Shape> aGeomShape;
627 if (anExtension == "PNG" || anExtension == "GIF" ||
628 anExtension == "TIFF" || anExtension == "JPE" ||
629 anExtension == "JPG" || anExtension == "JPEG" ||
630 anExtension == "BMP"|| anExtension == "PPM"
632 aGeomShape = ImageImport(theFileName, anError);
634 theTextureFileName = theFileName;
636 anError = "Unsupported format: " + anExtension;
639 // Check if shape is valid
640 if (!anError.empty()) {
641 setError("An error occurred while importing " + theFileName + ": " + anError);
645 // Pass the results into the model
646 std::string anObjectName = GeomAlgoAPI_Tools::File_Tools::name(theFileName);
647 data()->setName(Locale::Convert::toWString(anObjectName));
649 auto resultBody = createResultBody(aGeomShape);
650 resultBody->setTextureFile(theTextureFileName);
651 setResult(resultBody);