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
210 loadNamingDS(aGeomShape, aResult);
212 // create color group
213 if (anColorGroupSelected)
215 setColorGroups(aResult);
218 // create Materiel group
219 if (anMaterialsGroupSelected){
220 setMaterielGroup(aResult,theMaterialShape);
224 aResult->clearShapeNameAndColor();
228 void ExchangePlugin_ImportFeature::setColorGroups(
229 std::shared_ptr<ModelAPI_ResultBody> theResultBody)
231 std::vector<int> aColor;
233 std::list<std::vector<int>> aColorsRead;
235 ModelAPI_Tools::getColor(theResultBody, aColor);
236 if (!aColor.empty() ){
237 std::wstringstream aColorName;
238 aColorName <<L"Color_"<< anIndice;
239 setColorGroup(theResultBody, aColor, aColorName.str());
241 aColorsRead.push_back(aColor);
244 std::list<ResultPtr> allRes;
245 ModelAPI_Tools::allSubs(theResultBody, allRes);
246 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); ++aRes) {
247 ModelAPI_Tools::getColor(*aRes, aColor);
248 if (!aColor.empty() ){
249 auto it = std::find(aColorsRead.begin(), aColorsRead.end(), aColor);
250 if ( it == aColorsRead.end() ){
251 std::wstringstream aColorName;
252 aColorName<<L"Color_"<< anIndice;
253 setColorGroup(theResultBody, aColor, aColorName.str());
255 aColorsRead.push_back(aColor);
261 void ExchangePlugin_ImportFeature::setColorGroup(
262 std::shared_ptr<ModelAPI_ResultBody> theResultBody,
263 std::vector<int> &theColor,
264 const std::wstring& theName )
266 std::vector<int> aColor;
267 std::shared_ptr<ModelAPI_Feature> aGroupFeature = addFeature("Group");
270 aGroupFeature->data()->setName(theName);
273 AttributeSelectionListPtr aSelectionList = aGroupFeature->selectionList("group_list");
275 ModelAPI_Tools::getColor(theResultBody, aColor);
276 if (!aColor.empty()){
277 if (aColor == theColor) {
278 GeomShapePtr aShape = theResultBody->shape();
279 aSelectionList->setSelectionType(aShape->shapeTypeStr());
280 aSelectionList->append(theResultBody,aShape);
283 // add element with the same color
284 std::list<ResultPtr> allRes;
285 ModelAPI_Tools::allSubs(theResultBody, allRes);
286 for(std::list<ResultPtr>::iterator aRes = allRes.begin();
287 aRes != allRes.end(); ++aRes) {
288 ModelAPI_Tools::getColor(*aRes, aColor);
289 GeomShapePtr aShape = (*aRes)->shape();
291 if (!aColor.empty()){
292 if (aRes->get() && aColor == theColor) {
293 aSelectionList->setSelectionType(aShape->shapeTypeStr());
294 aSelectionList->append(theResultBody,aShape);
299 // Create the group in the document to be able to set its color
300 ResultPtr aGroup = document()->createGroup(aGroupFeature->data());
301 aGroupFeature->setResult(aGroup);
303 ModelAPI_Tools::setColor(aGroupFeature->lastResult(),theColor);
305 if (aSelectionList->size() == 0) {
306 document()->removeFeature(aGroupFeature);
310 void ExchangePlugin_ImportFeature::setMaterielGroup(
311 std::shared_ptr<ModelAPI_ResultBody> theResultBody,
312 std::map< std::wstring,std::list<std::wstring>>& theMaterialShape)
314 std::map< std::wstring, std::list<std::wstring>>::iterator anIt;
315 for (anIt = theMaterialShape.begin(); anIt != theMaterialShape.end(); ++anIt) {
317 std::shared_ptr<ModelAPI_Feature> aGroupFeature = addFeature("Group");
319 aGroupFeature->data()->setName((*anIt).first);
322 AttributeSelectionListPtr aSelectionList = aGroupFeature->selectionList("group_list");
324 std::list<ResultPtr> allRes;
325 ModelAPI_Tools::allSubs(theResultBody, allRes);
326 for (std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); ++aRes) {
328 GeomShapePtr aShape = (*aRes)->shape();
329 for (std::list<std::wstring>::iterator aResMat = anIt->second.begin();
330 aResMat != anIt->second.end(); ++aResMat) {
331 if (aRes->get() && ((*aRes)->data()->name() == (*aResMat)))
333 aSelectionList->append(theResultBody,aShape);
334 aSelectionList->setSelectionType(aShape->shapeTypeStr());
339 if (aSelectionList->size() == 0){
340 document()->removeFeature(aGroupFeature);
345 void ExchangePlugin_ImportFeature::importXAO(const std::string& theFileName)
351 std::shared_ptr<GeomAPI_Shape> aGeomShape = XAOImport(theFileName, anError, &aXao);
353 if (!anError.empty()) {
354 setError("An error occurred while importing " + theFileName + ": " + anError);
358 XAO::Geometry* aXaoGeometry = aXao.getGeometry();
360 // use the geometry name or the file name for the feature
361 std::string aBodyName = aXaoGeometry->getName();
362 if (aBodyName.empty())
363 aBodyName = GeomAlgoAPI_Tools::File_Tools::name(theFileName);
364 data()->setName(Locale::Convert::toWString(aBodyName));
366 ResultBodyPtr aResultBody = createResultBody(aGeomShape);
367 setResult(aResultBody);
369 // Process groups/fields
370 std::shared_ptr<ModelAPI_AttributeRefList> aRefListOfGroups =
371 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(data()->attribute(FEATURES_ID()));
373 // Remove previous groups/fields stored in RefList
374 std::list<ObjectPtr> anGroupList = aRefListOfGroups->list();
375 std::list<ObjectPtr>::iterator anGroupIt = anGroupList.begin();
376 for (; anGroupIt != anGroupList.end(); ++anGroupIt) {
377 std::shared_ptr<ModelAPI_Feature> aFeature = ModelAPI_Feature::feature(*anGroupIt);
379 document()->removeFeature(aFeature);
383 for (int aGroupIndex = 0; aGroupIndex < aXao.countGroups(); ++aGroupIndex) {
384 XAO::Group* aXaoGroup = aXao.getGroup(aGroupIndex);
386 std::shared_ptr<ModelAPI_Feature> aGroupFeature = addFeature("Group");
389 if (!aXaoGroup->getName().empty())
390 aGroupFeature->data()->setName(Locale::Convert::toWString(aXaoGroup->getName()));
393 AttributeSelectionListPtr aSelectionList = aGroupFeature->selectionList("group_list");
395 // conversion of dimension
396 std::string aDimensionString = XAO::XaoUtils::dimensionToString(aXaoGroup->getDimension());
397 std::string aSelectionType =
398 ExchangePlugin_Tools::xaoDimension2selectionType(aDimensionString);
400 aSelectionList->setSelectionType(aSelectionType);
401 for (int anElementIndex = 0; anElementIndex < aXaoGroup->count(); ++anElementIndex) {
402 aSelectionList->append(aResultBody, GeomShapePtr());
403 // complex conversion of element index to reference id
404 int anElementID = aXaoGroup->get(anElementIndex);
405 std::string aReferenceString =
406 aXaoGeometry->getElementReference(aXaoGroup->getDimension(), anElementID);
407 int aReferenceID = XAO::XaoUtils::stringToInt(aReferenceString);
409 aSelectionList->value(anElementIndex)->setId(aReferenceID);
413 for (int aFieldIndex = 0; aFieldIndex < aXao.countFields(); ++aFieldIndex) {
414 XAO::Field* aXaoField = aXao.getField(aFieldIndex);
416 std::shared_ptr<ModelAPI_Feature> aFieldFeature = addFeature("Field");
419 if (!aXaoField->getName().empty())
420 aFieldFeature->data()->setName(Locale::Convert::toWString(aXaoField->getName()));
423 AttributeSelectionListPtr aSelectionList = aFieldFeature->selectionList("selected");
425 // conversion of dimension
426 std::string aDimensionString = XAO::XaoUtils::dimensionToString(aXaoField->getDimension());
427 std::string aSelectionType =
428 ExchangePlugin_Tools::xaoDimension2selectionType(aDimensionString);
429 aSelectionList->setSelectionType(aSelectionType);
430 // limitation: now in XAO fields are related to everything, so, iterate all sub-shapes to fill
431 int aCountSelected = aXaoField->countElements();
432 std::list<ResultPtr>::const_iterator aResIter = results().begin();
433 for(; aResIter != results().end() && aCountSelected; aResIter++) {
434 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(*aResIter);
437 // check that only results that were created before this field are used
438 FeaturePtr aResultFeature = document()->feature(aBody);
439 if (!aResultFeature.get())
441 GeomShapePtr aShape = aBody->shape();
442 if (!aShape.get() || aShape->isNull())
444 GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::shapeTypeByStr(aSelectionType));
445 for(; anExp.more(); anExp.next()) {
446 aSelectionList->append(aBody, anExp.current());
448 if (aCountSelected == 0)
453 // conversion of type
454 XAO::Type aFieldType = aXaoField->getType();
455 std::string aTypeString = XAO::XaoUtils::fieldTypeToString(aFieldType);
456 ModelAPI_AttributeTables::ValueType aType =
457 ExchangePlugin_Tools::xaoType2valuesType(aTypeString);
458 // set components names
459 AttributeStringArrayPtr aComponents = aFieldFeature->stringArray("components_names");
460 aComponents->setSize(aXaoField->countComponents());
461 for(int aComp = 0; aComp < aXaoField->countComponents(); aComp++) {
462 aComponents->setValue(aComp, aXaoField->getComponentName(aComp));
465 AttributeIntArrayPtr aStamps = aFieldFeature->intArray("stamps");
466 aStamps->setSize(aXaoField->countSteps());
467 std::shared_ptr<ModelAPI_AttributeTables> aTables = aFieldFeature->tables("values");
469 aXaoField->countElements() + 1, aXaoField->countComponents(), aXaoField->countSteps());
470 aTables->setType(aType);
472 XAO::stepIterator aStepIter = aXaoField->begin();
473 for(int aStepIndex = 0; aStepIter != aXaoField->end(); aStepIter++, aStepIndex++) {
474 aStamps->setValue(aStepIndex, (*aStepIter)->getStamp());
475 for(int aRow = 1; aRow <= aXaoField->countElements(); aRow++) {
476 for(int aCol = 0; aCol < aXaoField->countComponents(); aCol++) {
477 ModelAPI_AttributeTables::Value aVal;
478 std::string aValStr = (*aStepIter)->getStringValue(aRow - 1, aCol);
480 case ModelAPI_AttributeTables::BOOLEAN:
481 aVal.myBool = aValStr == "true";
483 case ModelAPI_AttributeTables::INTEGER:
484 aVal.myInt = atoi(aValStr.c_str());
486 case ModelAPI_AttributeTables::DOUBLE:
487 aVal.myDouble = atof(aValStr.c_str());
489 case ModelAPI_AttributeTables::STRING:
490 aVal.myStr = aValStr;
493 aTables->setValue(aVal, aRow, aCol, aStepIndex);
497 // remove everything with zero-values: zeroes are treated as defaults
498 std::set<int> aRowsToRemove;
499 for(int aRow = 1; aRow < aTables->rows(); aRow++) {
501 for(int aCol = 0; aCol < aTables->columns() && isZero; aCol++) {
502 for(int aStepIndex = 0; aStepIndex != aTables->tables() && isZero; aStepIndex++) {
503 if (aTables->valueStr(aRow, aCol, aStepIndex) != aTables->valueStr(0, aCol, aStepIndex))
508 aRowsToRemove.insert(aRow - 1); // -1 to make prepared for remove from SelectionList
510 if (!aRowsToRemove.empty()) { // move usefull rows on bottom to the up of the tables
511 // number of rows passed during going through: the current rows will
512 // be moved up for this value
513 int aRemovedPassed = 0;
514 for(int aRow = 1; aRow < aTables->rows(); aRow++) {
515 if (aRowsToRemove.find(aRow - 1) != aRowsToRemove.end()) {
517 } else if (aRemovedPassed != 0) { // copy the line up
518 for(int aCol = 0; aCol < aTables->columns(); aCol++) {
519 for(int aTable = 0; aTable != aTables->tables(); aTable++) {
521 aTables->value(aRow, aCol, aTable), aRow - aRemovedPassed, aCol, aTable);
526 aTables->setSize(aTables->rows() - aRemovedPassed, aTables->columns(), aTables->tables());
527 aSelectionList->remove(aRowsToRemove); // remove also selected elements
530 // Top avoid problems in Object Browser update: issue #1647.
531 ModelAPI_EventCreator::get()->sendReordered(
532 std::dynamic_pointer_cast<ModelAPI_Feature>(aRefListOfGroups->owner()));
535 } catch (XAO::XAO_Exception& e) {
536 std::string anError = e.what();
537 setError("An error occurred while importing " + theFileName + ": " + anError);
543 //============================================================================
544 std::shared_ptr<ModelAPI_Feature> ExchangePlugin_ImportFeatureBase::addFeature(
547 std::shared_ptr<ModelAPI_Feature> aNew = document()->addFeature(theID, false);
549 data()->reflist(FEATURES_ID())->append(aNew);
550 // set as current also after it becomes sub to set correctly enabled for other subs
551 //document()->setCurrentFeature(aNew, false);
556 void ExchangePlugin_ImportFeatureBase::removeFeature(
557 std::shared_ptr<ModelAPI_Feature> theFeature)
559 if (!data()->isValid())
561 AttributeRefListPtr aList = reflist(FEATURES_ID());
562 aList->remove(theFeature);
566 int ExchangePlugin_ImportFeatureBase::numberOfSubs(bool /*forTree*/) const
568 return data()->reflist(FEATURES_ID())->size(true);
571 std::shared_ptr<ModelAPI_Feature> ExchangePlugin_ImportFeatureBase::subFeature(
572 const int theIndex, bool /*forTree*/)
574 ObjectPtr anObj = data()->reflist(FEATURES_ID())->object(theIndex, false);
575 FeaturePtr aRes = std::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
580 int ExchangePlugin_ImportFeatureBase::subFeatureId(const int theIndex) const
582 std::shared_ptr<ModelAPI_AttributeRefList> aRefList = std::dynamic_pointer_cast<
583 ModelAPI_AttributeRefList>(data()->attribute(FEATURES_ID()));
584 std::list<ObjectPtr> aFeatures = aRefList->list();
585 std::list<ObjectPtr>::const_iterator anIt = aFeatures.begin();
586 int aResultIndex = 1; // number of the counted (created) features, started from 1
587 int aFeatureIndex = -1; // number of the not-empty features in the list
588 for (; anIt != aFeatures.end(); anIt++) {
591 if (aFeatureIndex == theIndex)
599 bool ExchangePlugin_ImportFeatureBase::isSub(ObjectPtr theObject) const
601 // check is this feature of result
602 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
604 return data()->reflist(FEATURES_ID())->isInList(aFeature);
608 //============================================================================
609 void ExchangePlugin_ImportFeatureBase::loadNamingDS(
610 std::shared_ptr<GeomAPI_Shape> theGeomShape,
611 std::shared_ptr<ModelAPI_ResultBody> theResultBody)
614 theResultBody->store(theGeomShape);
616 std::string aNameMS = "Shape";
617 theResultBody->loadFirstLevel(theGeomShape, aNameMS);
620 void ExchangePlugin_Import_ImageFeature::importFile(const std::string& theFileName)
623 std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(theFileName);
624 std::string theTextureFileName = "";
625 // Perform the import
627 std::shared_ptr<GeomAPI_Shape> aGeomShape;
628 if (anExtension == "PNG" || anExtension == "GIF" ||
629 anExtension == "TIFF" || anExtension == "JPE" ||
630 anExtension == "JPG" || anExtension == "JPEG" ||
631 anExtension == "BMP"|| anExtension == "PPM"
633 aGeomShape = ImageImport(theFileName, anError);
635 theTextureFileName = theFileName;
637 anError = "Unsupported format: " + anExtension;
640 // Check if shape is valid
641 if (!anError.empty()) {
642 setError("An error occurred while importing " + theFileName + ": " + anError);
646 // Pass the results into the model
647 std::string anObjectName = GeomAlgoAPI_Tools::File_Tools::name(theFileName);
648 data()->setName(Locale::Convert::toWString(anObjectName));
650 auto resultBody = createResultBody(aGeomShape);
651 resultBody->setTextureFile(theTextureFileName);
652 setResult(resultBody);